< Summary - CoreWCF Coverage — PR #1766

Information
Class: CoreWCF.HttpTransportHelpers
Assembly: CoreWCF.WebHttp
File(s): /home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.WebHttp/src/CoreWCF/HttpTransportHelpers.cs
Line coverage
66%
Covered lines: 20
Uncovered lines: 10
Coverable lines: 30
Total lines: 84
Line coverage: 66.6%
Branch coverage
40%
Covered branches: 4
Total branches: 10
Branch coverage: 40%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity NPath complexity Sequence coverage
ConfigureTransportProtectionAndAuthentication(...)100%11100%
ConfigureTransportAuthentication(...)50%2275%
DisableTransportAuthentication(...)100%11100%
ConfigureAuthentication(...)100%11100%
MapToAuthenticationScheme(...)37.5%8835.71%
DisableAuthentication(...)100%11100%

File(s)

/home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.WebHttp/src/CoreWCF/HttpTransportHelpers.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 CoreWCF.Channels;
 7using CoreWCF.Runtime;
 8
 9namespace CoreWCF
 10{
 11    internal static class HttpTransportHelpers
 12    {
 13        private const string DefaultRealm = HttpTransportDefaults.Realm;
 14
 15        internal static void ConfigureTransportProtectionAndAuthentication(HttpsTransportBindingElement https, HttpTrans
 16        {
 2217            ConfigureAuthentication(https, transportSecurity);
 2218            https.RequireClientCertificate = (transportSecurity.ClientCredentialType == HttpClientCredentialType.Certifi
 2219        }
 20
 21        internal static void ConfigureTransportAuthentication(HttpTransportBindingElement http, HttpTransportSecurity tr
 22        {
 12423            if (transportSecurity.ClientCredentialType == HttpClientCredentialType.Certificate)
 24            {
 025                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.CertificateUn
 26            }
 27
 12428            ConfigureAuthentication(http, transportSecurity);
 12429        }
 30
 31        internal static void DisableTransportAuthentication(HttpTransportBindingElement http)
 32        {
 63133            DisableAuthentication(http);
 63134        }
 35
 36        private static void ConfigureAuthentication(HttpTransportBindingElement http, HttpTransportSecurity transportSec
 37        {
 14638            http.AuthenticationScheme = MapToAuthenticationScheme(transportSecurity.ClientCredentialType);
 14639            http.Realm = transportSecurity.Realm;
 14640            http.ExtendedProtectionPolicy = transportSecurity.ExtendedProtectionPolicy;
 14641        }
 42
 43        private static AuthenticationSchemes MapToAuthenticationScheme(HttpClientCredentialType clientCredentialType)
 44        {
 45            AuthenticationSchemes result;
 46            switch (clientCredentialType)
 47            {
 48                case HttpClientCredentialType.Certificate:
 49                // fall through to None case
 50                case HttpClientCredentialType.None:
 2251                    result = AuthenticationSchemes.Anonymous;
 2252                    break;
 53                case HttpClientCredentialType.Basic:
 054                    result = AuthenticationSchemes.Basic;
 055                    break;
 56                case HttpClientCredentialType.Digest:
 057                    result = AuthenticationSchemes.Digest;
 058                    break;
 59                case HttpClientCredentialType.Ntlm:
 060                    result = AuthenticationSchemes.Ntlm;
 061                    break;
 62                case HttpClientCredentialType.Windows:
 063                    result = AuthenticationSchemes.Negotiate;
 064                    break;
 65                case HttpClientCredentialType.InheritedFromHost:
 12466                    result = AuthenticationSchemes.None;
 12467                    break;
 68                default:
 69                    Fx.Assert("unsupported client credential type");
 070                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new NotSupportedException());
 71            }
 14672            return result;
 73        }
 74
 75        private static void DisableAuthentication(HttpTransportBindingElement http)
 76        {
 63177            http.AuthenticationScheme = AuthenticationSchemes.Anonymous;
 63178            http.Realm = DefaultRealm;
 79            //ExtendedProtectionPolicy is always copied - even for security mode None, Message and TransportWithMessageC
 80            //because the settings for ExtendedProtectionPolicy are always below the <security><transport> element
 81            //http.ExtendedProtectionPolicy = extendedProtectionPolicy;
 63182        }
 83    }
 84}