< Summary - CoreWCF Coverage — PR #1766

Information
Class: CoreWCF.WSHTTPSecurity
Assembly: CoreWCF.Http
File(s): /home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.Http/src/CoreWCF/WSHTTPSecurity.cs
Line coverage
83%
Covered lines: 31
Uncovered lines: 6
Coverable lines: 37
Total lines: 136
Line coverage: 83.7%
Branch coverage
61%
Covered branches: 11
Total branches: 18
Branch coverage: 61.1%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity NPath complexity Sequence coverage
.ctor()100%11100%
.ctor(...)50%44100%
GetDefaultHttpTransportSecurity()100%11100%
ApplyTransportSecurity(...)100%22100%
ApplyTransportSecurity(...)100%110%
CreateMessageSecurity(...)100%44100%
ShouldSerializeMode()100%110%
ApplyAuthorizationPolicySupport(...)50%22100%

File(s)

/home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.Http/src/CoreWCF/WSHTTPSecurity.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.ComponentModel;
 6using CoreWCF.Channels;
 7
 8namespace CoreWCF
 9{
 10    public sealed class WSHTTPSecurity
 11    {
 12        internal const SecurityMode DefaultMode = SecurityMode.Message;
 13        private SecurityMode _mode;
 14        private HttpTransportSecurity _transportSecurity;
 15        private NonDualMessageSecurityOverHttp _messageSecurity;
 16
 17        public WSHTTPSecurity()
 4518            : this(DefaultMode, GetDefaultHttpTransportSecurity(), new NonDualMessageSecurityOverHttp())
 19        {
 4520        }
 21
 4522        internal WSHTTPSecurity(SecurityMode mode, HttpTransportSecurity transportSecurity, NonDualMessageSecurityOverHt
 23        {
 4524            _mode = mode;
 4525            _transportSecurity = transportSecurity ?? GetDefaultHttpTransportSecurity();
 4526            _messageSecurity = messageSecurity ?? new NonDualMessageSecurityOverHttp();
 4527        }
 28
 29        internal static HttpTransportSecurity GetDefaultHttpTransportSecurity()
 30        {
 4531            HttpTransportSecurity transportSecurity = new HttpTransportSecurity
 4532            {
 4533                ClientCredentialType = HttpClientCredentialType.Windows
 4534            };
 4535            return transportSecurity;
 36        }
 37
 38        public SecurityMode Mode
 39        {
 69740            get { return _mode; }
 41            set
 42            {
 4143                if (!SecurityModeHelper.IsDefined(value))
 44                {
 045                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(val
 46                }
 4147                _mode = value;
 4148            }
 49        }
 50
 51        public HttpTransportSecurity Transport
 52        {
 61053            get { return _transportSecurity; }
 54            set
 55            {
 656                _transportSecurity = value ?? throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNull
 657            }
 58        }
 59
 60        public NonDualMessageSecurityOverHttp Message
 61        {
 3462            get { return _messageSecurity; }
 63            set
 64            {
 065                _messageSecurity = value ?? throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullEx
 066            }
 67        }
 68
 69        internal void ApplyTransportSecurity(HttpsTransportBindingElement https)
 70        {
 22471            if (_mode == SecurityMode.TransportWithMessageCredential)
 72            {
 13073                _transportSecurity.ConfigureTransportProtectionOnly(https);
 74            }
 75            else
 76            {
 9477                _transportSecurity.ConfigureTransportProtectionAndAuthentication(https);
 78            }
 9479        }
 80
 81        internal static void ApplyTransportSecurity(HttpsTransportBindingElement transport, HttpTransportSecurity transp
 82        {
 083            HttpTransportSecurity.ConfigureTransportProtectionAndAuthentication(transport, transportSecurity);
 084        }
 85
 86        internal SecurityBindingElement CreateMessageSecurity(bool isReliableSessionEnabled, MessageSecurityVersion vers
 87        {
 29388            if (_mode == SecurityMode.Message || _mode == SecurityMode.TransportWithMessageCredential)
 89            {
 8790                return _messageSecurity.CreateSecurityBindingElement(Mode == SecurityMode.TransportWithMessageCredential
 91            }
 92            else
 93            {
 20694                return null;
 95            }
 96        }
 97
 98        //internal static bool TryCreate(SecurityBindingElement sbe, UnifiedSecurityMode mode, HttpTransportSecurity tra
 99        //{
 100        //    security = null;
 101        //    NonDualMessageSecurityOverHttp messageSecurity = null;
 102        //    SecurityMode securityMode = SecurityMode.None;
 103        //    if (sbe != null)
 104        //    {
 105        //        mode &= UnifiedSecurityMode.Message | UnifiedSecurityMode.TransportWithMessageCredential;
 106        //        securityMode = SecurityModeHelper.ToSecurityMode(mode);
 107        //        Fx.Assert(SecurityModeHelper.IsDefined(securityMode), string.Format("Invalid SecurityMode value: {0}."
 108        //        if (!MessageSecurityOverHttp.TryCreate(sbe, securityMode == SecurityMode.TransportWithMessageCredentia
 109        //        {
 110        //            return false;
 111        //        }
 112        //    }
 113        //    else
 114        //    {
 115        //        mode &= ~(UnifiedSecurityMode.Message | UnifiedSecurityMode.TransportWithMessageCredential);
 116        //        securityMode = SecurityModeHelper.ToSecurityMode(mode);
 117        //    }
 118        //    Fx.Assert(SecurityModeHelper.IsDefined(securityMode), string.Format("Invalid SecurityMode value: {0}.", se
 119        //    security = new WSHttpSecurity(securityMode, transportSecurity, messageSecurity);
 120        //    return true;
 121        //}
 122
 123        [EditorBrowsable(EditorBrowsableState.Never)]
 124        public bool ShouldSerializeMode()
 125        {
 0126            return Mode != DefaultMode;
 127        }
 128
 129        internal void ApplyAuthorizationPolicySupport(HttpTransportBindingElement httpTransport)
 130        {
 224131            httpTransport.AlwaysUseAuthorizationPolicySupport =
 224132                Transport.AlwaysUseAuthorizationPolicySupport
 224133                || Transport.ClientCredentialType == HttpClientCredentialType.InheritedFromHost;
 224134        }
 135    }
 136}