< Summary - CoreWCF Coverage — PR #1766

Information
Class: CoreWCF.HttpTransportSecurity
Assembly: CoreWCF.Http
File(s): /home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.Http/src/CoreWCF/HttpTransportSecurity.cs
Line coverage
62%
Covered lines: 30
Uncovered lines: 18
Coverable lines: 48
Total lines: 143
Line coverage: 62.5%
Branch coverage
16%
Covered branches: 2
Total branches: 12
Branch coverage: 16.6%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

File(s)

/home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.Http/src/CoreWCF/HttpTransportSecurity.cs

#LineLine coverage
 1// Licensed to the .NET Foundation under one or more agreements.
 2// The .NET Foundation licenses this file to you under the MIT license.
 3
 4using System;
 5using System.Net;
 6using System.Security.Authentication.ExtendedProtection;
 7using CoreWCF.Channels;
 8
 9namespace CoreWCF
 10{
 11    public sealed class HttpTransportSecurity
 12    {
 13        internal const HttpClientCredentialType DefaultClientCredentialType = HttpClientCredentialType.None;
 14        internal const string DefaultRealm = HttpTransportDefaults.Realm;
 15        private HttpClientCredentialType _clientCredentialType;
 16        private ExtendedProtectionPolicy _extendedProtectionPolicy;
 17
 61318        public HttpTransportSecurity()
 19        {
 61320            _clientCredentialType = DefaultClientCredentialType;
 61321            Realm = DefaultRealm;
 61322            _extendedProtectionPolicy = ChannelBindingUtility.DefaultPolicy;
 61323        }
 24
 25        public HttpClientCredentialType ClientCredentialType
 26        {
 617827            get { return _clientCredentialType; }
 28            set
 29            {
 16730                if (!HttpClientCredentialTypeHelper.IsDefined(value))
 31                {
 032                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(val
 33                }
 16734                _clientCredentialType = value;
 16735            }
 36        }
 37
 598638        public bool AlwaysUseAuthorizationPolicySupport { get; set; }
 39
 228240        public string Realm { get; set; }
 41
 42        public ExtendedProtectionPolicy ExtendedProtectionPolicy
 43        {
 44            get
 45            {
 30646                return _extendedProtectionPolicy;
 47            }
 48            set
 49            {
 050                if (value == null)
 51                {
 052                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(value));
 53                }
 54
 055                if (value.PolicyEnforcement == PolicyEnforcement.Always &&
 056                    !ExtendedProtectionPolicy.OSSupportsExtendedProtection)
 57                {
 058                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(
 059                        new PlatformNotSupportedException(SR.ExtendedProtectionNotSupported));
 60                }
 61
 062                _extendedProtectionPolicy = value;
 063            }
 64        }
 65
 66        internal void ConfigureTransportProtectionOnly(HttpsTransportBindingElement https)
 67        {
 21868            DisableAuthentication(https);
 21869            https.RequireClientCertificate = false;
 21870        }
 71
 72        private void ConfigureAuthentication(HttpTransportBindingElement http)
 73        {
 151374            http.AuthenticationScheme = HttpClientCredentialTypeHelper.MapToAuthenticationScheme(_clientCredentialType);
 151375            http.Realm = Realm;
 151376            http.ExtendedProtectionPolicy = _extendedProtectionPolicy;
 151377        }
 78
 79        private static void ConfigureAuthentication(HttpTransportBindingElement http, HttpTransportSecurity transportSec
 80        {
 081            transportSecurity._clientCredentialType = HttpClientCredentialTypeHelper.MapToClientCredentialType(http.Auth
 082            transportSecurity.Realm = http.Realm;
 083            transportSecurity._extendedProtectionPolicy = http.ExtendedProtectionPolicy;
 084        }
 85
 86        private void DisableAuthentication(HttpTransportBindingElement http)
 87        {
 369088            http.AuthenticationScheme = AuthenticationSchemes.Anonymous;
 369089            http.Realm = DefaultRealm;
 90            //ExtendedProtectionPolicy is always copied - even for security mode None, Message and TransportWithMessageC
 91            //because the settings for ExtendedProtectionPolicy are always below the <security><transport> element
 92            //http.ExtendedProtectionPolicy = extendedProtectionPolicy;
 369093        }
 94
 95        //static bool IsDisabledAuthentication(HttpTransportBindingElement http)
 96        //{
 97        //    return http.AuthenticationScheme == AuthenticationSchemes.Anonymous && http.ProxyAuthenticationScheme == A
 98        //}
 99
 100        internal void ConfigureTransportProtectionAndAuthentication(HttpsTransportBindingElement https)
 101        {
 539102            ConfigureAuthentication(https);
 539103            https.RequireClientCertificate = (_clientCredentialType == HttpClientCredentialType.Certificate);
 539104        }
 105
 106        internal static void ConfigureTransportProtectionAndAuthentication(HttpsTransportBindingElement https, HttpTrans
 107        {
 0108            ConfigureAuthentication(https, transportSecurity);
 0109            if (https.RequireClientCertificate)
 110            {
 0111                transportSecurity.ClientCredentialType = HttpClientCredentialType.Certificate;
 112            }
 0113        }
 114
 115        internal void ConfigureTransportAuthentication(HttpTransportBindingElement http)
 116        {
 974117            if (_clientCredentialType == HttpClientCredentialType.Certificate)
 118            {
 0119                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.CertificateUn
 120            }
 121
 974122            ConfigureAuthentication(http);
 974123        }
 124
 125        //internal static bool IsConfiguredTransportAuthentication(HttpTransportBindingElement http, HttpTransportSecuri
 126        //{
 127        //    if (HttpClientCredentialTypeHelper.MapToClientCredentialType(http.AuthenticationScheme) == HttpClientCrede
 128        //        return false;
 129        //    ConfigureAuthentication(http, transportSecurity);
 130        //    return true;
 131        //}
 132
 133        internal void DisableTransportAuthentication(HttpTransportBindingElement http)
 134        {
 3472135            DisableAuthentication(http);
 3472136        }
 137
 138        //internal static bool IsDisabledTransportAuthentication(HttpTransportBindingElement http)
 139        //{
 140        //    return IsDisabledAuthentication(http);
 141        //}
 142    }
 143}