< Summary - CoreWCF Coverage — PR #1766

Information
Class: CoreWCF.BasicHttpMessageSecurity
Assembly: CoreWCF.Http
File(s): /home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.Http/src/CoreWCF/BasicHttpMessageSecurity.cs
Line coverage
59%
Covered lines: 19
Uncovered lines: 13
Coverable lines: 32
Total lines: 109
Line coverage: 59.3%
Branch coverage
25%
Covered branches: 3
Total branches: 12
Branch coverage: 25%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity NPath complexity Sequence coverage
.ctor()100%11100%
CreateMessageSecurity(...)33.33%6671.42%
InternalShouldSerialize()0%220%
ShouldSerializeAlgorithmSuite()100%110%
ShouldSerializeClientCredentialType()100%110%

File(s)

/home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.Http/src/CoreWCF/BasicHttpMessageSecurity.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.Runtime;
 5using CoreWCF.Channels;
 6using CoreWCF.Security;
 7using System.ComponentModel;
 8using System;
 9using CoreWCF.Runtime;
 10
 11namespace CoreWCF
 12{
 13    public sealed class BasicHttpMessageSecurity
 14    {
 15        internal const BasicHttpMessageCredentialType DefaultClientCredentialType = BasicHttpMessageCredentialType.UserN
 16        private BasicHttpMessageCredentialType _clientCredentialType;
 17        private SecurityAlgorithmSuite _algorithmSuite;
 18
 42719        public BasicHttpMessageSecurity()
 20        {
 42721            _clientCredentialType = DefaultClientCredentialType;
 42722            _algorithmSuite = SecurityAlgorithmSuite.Default;
 42723        }
 24
 25        public BasicHttpMessageCredentialType ClientCredentialType
 26        {
 127            get { return _clientCredentialType; }
 28            set
 29            {
 1230                if (!BasicHttpMessageCredentialTypeHelper.IsDefined(value))
 31                {
 032                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(val
 33                }
 1234                _clientCredentialType = value;
 1235            }
 36        }
 37
 38        public SecurityAlgorithmSuite AlgorithmSuite
 39        {
 7040            get { return _algorithmSuite; }
 41            set
 42            {
 043                if (value == null)
 44                {
 045                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(value));
 46                }
 047                _algorithmSuite = value;
 048            }
 49        }
 50
 51        // if any changes are made to this method, please reflect them in the corresponding TryCrete() method
 52        internal SecurityBindingElement CreateMessageSecurity(bool isSecureTransportMode)
 53        {
 54            SecurityBindingElement result;
 55
 7056            if (isSecureTransportMode)
 57            {
 7058                MessageSecurityVersion version = MessageSecurityVersion.WSSecurity10WSTrustFebruary2005WSSecureConversat
 7059                switch (_clientCredentialType)
 60                {
 61                    case BasicHttpMessageCredentialType.Certificate:
 062                        result = SecurityBindingElement.CreateCertificateOverTransportBindingElement(version);
 063                        break;
 64                    case BasicHttpMessageCredentialType.UserName:
 7065                        result = SecurityBindingElement.CreateUserNameOverTransportBindingElement();
 7066                        result.MessageSecurityVersion = version;
 7067                        break;
 68                    default:
 69                        Fx.Assert("Unsupported basic http message credential type");
 070                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new NotSupportedException());
 71                }
 72            }
 73            else
 74            {
 075                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new NotSupportedException(SR.Format(SR.Unsuppo
 76                //if (_clientCredentialType != BasicHttpMessageCredentialType.Certificate)
 77                //{
 78                //    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.Format(
 79                //}
 80                //result = SecurityBindingElement.CreateMutualCertificateBindingElement(MessageSecurityVersion.WSSecurit
 81            }
 82
 7083            result.DefaultAlgorithmSuite = AlgorithmSuite;
 7084            result.SecurityHeaderLayout = SecurityHeaderLayout.Lax;
 7085            result.SetKeyDerivation(false);
 86           // result.DoNotEmitTrust = true;
 87
 7088            return result;
 89        }
 90
 91        internal bool InternalShouldSerialize()
 92        {
 093            return ShouldSerializeAlgorithmSuite()
 094                || ShouldSerializeClientCredentialType();
 95        }
 96
 97        [EditorBrowsable(EditorBrowsableState.Never)]
 98        public bool ShouldSerializeAlgorithmSuite()
 99        {
 0100            return _algorithmSuite.GetType() != SecurityAlgorithmSuite.Default.GetType();
 101        }
 102
 103        [EditorBrowsable(EditorBrowsableState.Never)]
 104        public bool ShouldSerializeClientCredentialType()
 105        {
 0106            return _clientCredentialType != DefaultClientCredentialType;
 107        }
 108    }
 109}