< Summary - CoreWCF Coverage — PR #1766

Information
Class: CoreWCF.TcpTransportSecurity
Assembly: CoreWCF.NetTcp
File(s): /home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.NetTcp/src/CoreWCF/TcpTransportSecurity.cs
Line coverage
60%
Covered lines: 28
Uncovered lines: 18
Coverable lines: 46
Total lines: 131
Line coverage: 60.8%
Branch coverage
37%
Covered branches: 6
Total branches: 16
Branch coverage: 37.5%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity NPath complexity Sequence coverage
.ctor()100%11100%
CreateSslBindingElement(...)50%2277.77%
CreateTransportProtectionOnly()100%11100%
CreateTransportProtectionAndAuthentication()100%44100%

File(s)

/home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.NetTcp/src/CoreWCF/TcpTransportSecurity.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 System.Net.Security;
 7using System.Security.Authentication;
 8using System.Security.Authentication.ExtendedProtection;
 9using CoreWCF.Channels;
 10using CoreWCF.Security;
 11
 12namespace CoreWCF
 13{
 14    public sealed partial class TcpTransportSecurity
 15    {
 16        internal const TcpClientCredentialType DefaultClientCredentialType = TcpClientCredentialType.Windows;
 17        internal const ProtectionLevel DefaultProtectionLevel = ProtectionLevel.EncryptAndSign;
 18
 19        private TcpClientCredentialType _clientCredentialType;
 20        private ProtectionLevel _protectionLevel;
 21        private ExtendedProtectionPolicy _extendedProtectionPolicy;
 22        private SslProtocols _sslProtocols;
 23
 11824        public TcpTransportSecurity()
 25        {
 11826            _clientCredentialType = DefaultClientCredentialType;
 11827            _protectionLevel = DefaultProtectionLevel;
 11828            _extendedProtectionPolicy = ChannelBindingUtility.DefaultPolicy;
 11829            _sslProtocols = TransportDefaults.SslProtocols;
 11830        }
 31
 32        [DefaultValue(DefaultClientCredentialType)]
 33        public TcpClientCredentialType ClientCredentialType
 34        {
 035            get { return _clientCredentialType; }
 36            set
 37            {
 1038                if (!TcpClientCredentialTypeHelper.IsDefined(value))
 39                {
 040                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(val
 41                }
 1042                _clientCredentialType = value;
 1043            }
 44        }
 45
 46        [DefaultValue(DefaultProtectionLevel)]
 47        public ProtectionLevel ProtectionLevel
 48        {
 049            get { return _protectionLevel; }
 50            set
 51            {
 052                if (!ProtectionLevelHelper.IsDefined(value))
 53                {
 054                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(val
 55                }
 056                _protectionLevel = value;
 057            }
 58        }
 59
 60        public ExtendedProtectionPolicy ExtendedProtectionPolicy
 61        {
 62            get
 63            {
 112264                return _extendedProtectionPolicy;
 65            }
 66            set
 67            {
 068                if (value == null)
 69                {
 070                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(value));
 71                }
 72
 073                if (value.PolicyEnforcement == PolicyEnforcement.Always &&
 074                    !ExtendedProtectionPolicy.OSSupportsExtendedProtection)
 75                {
 076                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(
 077                        new PlatformNotSupportedException(SR.ExtendedProtectionNotSupported));
 78                }
 079                _extendedProtectionPolicy = value;
 080            }
 81        }
 82
 83        [DefaultValue(TransportDefaults.SslProtocols)]
 84        public SslProtocols SslProtocols
 85        {
 086            get { return _sslProtocols; }
 87            set
 88            {
 1089                SslProtocolsHelper.Validate(value);
 1090                _sslProtocols = value;
 1091            }
 92        }
 93
 94        private SslStreamSecurityBindingElement CreateSslBindingElement(bool requireClientCertificate)
 95        {
 9096            if (_protectionLevel != ProtectionLevel.EncryptAndSign)
 97            {
 098                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.Format(
 099                    SR.UnsupportedSslProtectionLevel, _protectionLevel)));
 100            }
 101
 90102            SslStreamSecurityBindingElement result = new SslStreamSecurityBindingElement
 90103            {
 90104                RequireClientCertificate = requireClientCertificate,
 90105                SslProtocols = _sslProtocols
 90106            };
 90107            return result;
 108        }
 109
 110        internal BindingElement CreateTransportProtectionOnly()
 111        {
 74112            return CreateSslBindingElement(false);
 113        }
 114
 115        internal BindingElement CreateTransportProtectionAndAuthentication()
 116        {
 172117            if (_clientCredentialType == TcpClientCredentialType.Certificate || _clientCredentialType == TcpClientCreden
 118            {
 16119                return CreateSslBindingElement(_clientCredentialType == TcpClientCredentialType.Certificate);
 120            }
 121            else
 122            {
 156123                WindowsStreamSecurityBindingElement result = new WindowsStreamSecurityBindingElement
 156124                {
 156125                    ProtectionLevel = _protectionLevel
 156126                };
 156127                return result;
 128            }
 129        }
 130    }
 131}