< Summary - CoreWCF Coverage — PR #1766

Information
Class: CoreWCF.Channels.WindowsStreamSecurityBindingElement
Assembly: CoreWCF.NetFramingBase
File(s): /home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.NetFramingBase/src/CoreWCF/Channels/WindowsStreamSecurityBindingElement.cs
Line coverage
48%
Covered lines: 17
Uncovered lines: 18
Coverable lines: 35
Total lines: 104
Line coverage: 48.5%
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
.ctor()100%11100%
.ctor(...)100%11100%
Clone()100%11100%
BuildServerStreamUpgradeProvider(...)100%11100%
GetProperty(...)66.66%6671.42%
GetTransportTokenAssertion()100%110%
CoreWCF.Description.IPolicyExportExtension.ExportPolicy(...)0%440%

File(s)

/home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.NetFramingBase/src/CoreWCF/Channels/WindowsStreamSecurityBindingElement.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.Net.Security;
 5using System.Security.Principal;
 6using System.Xml;
 7using CoreWCF.Description;
 8using CoreWCF.Security;
 9
 10namespace CoreWCF.Channels
 11{
 12    public class WindowsStreamSecurityBindingElement : StreamUpgradeBindingElement, ITransportTokenAssertionProvider, IP
 13    {
 14        private ProtectionLevel _protectionLevel;
 15
 16        public WindowsStreamSecurityBindingElement()
 15617            : base()
 18        {
 15619            _protectionLevel = ConnectionOrientedTransportDefaults.ProtectionLevel;
 15620        }
 21
 22        protected WindowsStreamSecurityBindingElement(WindowsStreamSecurityBindingElement elementToBeCloned)
 19223            : base(elementToBeCloned)
 24        {
 19225            _protectionLevel = elementToBeCloned._protectionLevel;
 19226        }
 27
 28        public ProtectionLevel ProtectionLevel
 29        {
 30            get
 31            {
 1232                return _protectionLevel;
 33            }
 34            set
 35            {
 15636                ProtectionLevelHelper.Validate(value);
 15637                _protectionLevel = value;
 15638            }
 39        }
 40
 41        public override BindingElement Clone()
 42        {
 19243            return new WindowsStreamSecurityBindingElement(this);
 44        }
 45
 46        public override StreamUpgradeProvider BuildServerStreamUpgradeProvider(BindingContext context)
 47        {
 1248            return new WindowsStreamSecurityUpgradeProvider(this, context);
 49        }
 50
 51        public override T GetProperty<T>(BindingContext context)
 52        {
 3653            if (context == null)
 54            {
 055                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(context));
 56            }
 3657            if (typeof(T) == typeof(ISecurityCapabilities))
 58            {
 1259                return (T)(object)new SecurityCapabilities(true, true, true, _protectionLevel, _protectionLevel);
 60            }
 2461            else if (typeof(T) == typeof(IdentityVerifier))
 62            {
 063                return (T)(object)IdentityVerifier.CreateDefault();
 64            }
 65            else
 66            {
 2467                return context.GetInnerProperty<T>();
 68            }
 69        }
 70
 71        #region ITransportTokenAssertionProvider Members
 72
 73        public XmlElement GetTransportTokenAssertion()
 74        {
 075            XmlDocument document = new XmlDocument();
 076            XmlElement assertion =
 077                document.CreateElement(TransportPolicyConstants.DotNetFramingPrefix,
 078                TransportPolicyConstants.WindowsTransportSecurityName,
 079                TransportPolicyConstants.DotNetFramingNamespace);
 080            XmlElement protectionLevelElement = document.CreateElement(TransportPolicyConstants.DotNetFramingPrefix,
 081                TransportPolicyConstants.ProtectionLevelName, TransportPolicyConstants.DotNetFramingNamespace);
 082            protectionLevelElement.AppendChild(document.CreateTextNode(this.ProtectionLevel.ToString()));
 083            assertion.AppendChild(protectionLevelElement);
 084            return assertion;
 85        }
 86
 87        #endregion
 88
 89        void IPolicyExportExtension.ExportPolicy(MetadataExporter exporter, PolicyConversionContext context)
 90        {
 091            if (exporter == null)
 92            {
 093                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(exporter));
 94            }
 95
 096            if (context == null)
 97            {
 098                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(context));
 99            }
 100
 0101            SecurityBindingElement.ExportPolicyForTransportTokenAssertionProviders(exporter, context);
 0102        }
 103    }
 104}