< Summary - CoreWCF Coverage — PR #1766

Information
Class: CoreWCF.UnixDomainSocketTransportSecurity
Assembly: CoreWCF.UnixDomainSocket
File(s): /home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.UnixDomainSocket/src/CoreWCF/UnixDomainSocketTransportSecurity.cs
Line coverage
40%
Covered lines: 25
Uncovered lines: 36
Coverable lines: 61
Total lines: 168
Line coverage: 40.9%
Branch coverage
30%
Covered branches: 8
Total branches: 26
Branch coverage: 30.7%
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%110%
CreatePosixIdentityOnlyBinding()100%11100%
CreateTransportProtectionAndAuthentication()42.85%141433.33%

File(s)

/home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.UnixDomainSocket/src/CoreWCF/UnixDomainSocketTransportSecurity.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.Runtime.InteropServices;
 8using System.Security.Authentication;
 9using System.Security.Authentication.ExtendedProtection;
 10using CoreWCF.Channels;
 11using CoreWCF.Security;
 12
 13namespace CoreWCF
 14{
 15    public sealed partial class UnixDomainSocketTransportSecurity
 16    {
 17        internal const UnixDomainSocketClientCredentialType DefaultClientCredentialType = UnixDomainSocketClientCredenti
 18        internal const ProtectionLevel DefaultProtectionLevel = ProtectionLevel.EncryptAndSign;
 19
 20        private UnixDomainSocketClientCredentialType _clientCredentialType;
 21        private ProtectionLevel _protectionLevel;
 22        private ExtendedProtectionPolicy _extendedProtectionPolicy;
 23        private SslProtocols _sslProtocols;
 24
 1225        public UnixDomainSocketTransportSecurity()
 26        {
 1227            _clientCredentialType = DefaultClientCredentialType;
 1228            _protectionLevel = DefaultProtectionLevel;
 1229            _extendedProtectionPolicy = ChannelBindingUtility.DefaultPolicy;
 1230            _sslProtocols = TransportDefaults.SslProtocols;
 1231        }
 32
 33        [DefaultValue(DefaultClientCredentialType)]
 34        public UnixDomainSocketClientCredentialType ClientCredentialType
 35        {
 3536            get { return _clientCredentialType; }
 37            set
 38            {
 539                if (!UnixDomainSocketClientCredentialTypeHelper.IsDefined(value))
 40                {
 041                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(val
 42                }
 543                _clientCredentialType = value;
 544            }
 45        }
 46
 47        [DefaultValue(DefaultProtectionLevel)]
 48        public ProtectionLevel ProtectionLevel
 49        {
 050            get { return _protectionLevel; }
 51            set
 52            {
 053                if (!Security.ProtectionLevelHelper.IsDefined(value))
 54                {
 055                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(val
 56                }
 57
 058                _protectionLevel = value;
 059            }
 60        }
 61
 62        public ExtendedProtectionPolicy ExtendedProtectionPolicy
 63        {
 64            get
 65            {
 066                return _extendedProtectionPolicy;
 67            }
 68            set
 69            {
 070                if (value == null)
 71                {
 072                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(value));
 73                }
 74
 075                if (value.PolicyEnforcement == PolicyEnforcement.Always &&
 076                    !ExtendedProtectionPolicy.OSSupportsExtendedProtection)
 77                {
 078                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(
 079                        new PlatformNotSupportedException(SR.ExtendedProtectionNotSupported));
 80                }
 081                _extendedProtectionPolicy = value;
 082            }
 83        }
 84
 85        [DefaultValue(TransportDefaults.SslProtocols)]
 86        public SslProtocols SslProtocols
 87        {
 088            get { return _sslProtocols; }
 89            set
 90            {
 091                SslProtocolsHelper.Validate(value);
 092                _sslProtocols = value;
 093            }
 94        }
 95
 96        private SslStreamSecurityBindingElement CreateSslBindingElement(bool requireClientCertificate)
 97        {
 1698            if (_protectionLevel != ProtectionLevel.EncryptAndSign)
 99            {
 0100                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.Format(
 0101                    SR.UnsupportedSslProtectionLevel, _protectionLevel)));
 102            }
 103
 16104            SslStreamSecurityBindingElement result = new SslStreamSecurityBindingElement
 16105            {
 16106                RequireClientCertificate = requireClientCertificate,
 16107                SslProtocols = _sslProtocols
 16108            };
 16109            return result;
 110        }
 111
 112        internal BindingElement CreateTransportProtectionOnly()
 113        {
 0114            return CreateSslBindingElement(false);
 115        }
 116
 117        internal BindingElement CreatePosixIdentityOnlyBinding()
 118        {
 16119            return new UnixPosixIdentityBindingElement();
 120        }
 121
 122        internal BindingElement CreateTransportProtectionAndAuthentication()
 123        {
 32124            if (_clientCredentialType == UnixDomainSocketClientCredentialType.Default)
 125            {
 0126                if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
 127                {
 0128                    return new WindowsStreamSecurityBindingElement
 0129                    {
 0130                        ProtectionLevel = _protectionLevel
 0131                    };
 132                }
 133                else
 134                {
 0135                    return CreatePosixIdentityOnlyBinding();
 136                }
 137            }
 32138            else if (_clientCredentialType == UnixDomainSocketClientCredentialType.Certificate)
 139            {
 16140                return CreateSslBindingElement(true);
 141            }
 16142            else if (_clientCredentialType == UnixDomainSocketClientCredentialType.Windows)
 143            {
 0144                return new WindowsStreamSecurityBindingElement
 0145                {
 0146                    ProtectionLevel = _protectionLevel
 0147                };
 148            }
 16149            else if (_clientCredentialType == UnixDomainSocketClientCredentialType.PosixIdentity)
 150            {
 16151                if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
 152                {
 0153                    throw new NotSupportedException();
 154                }
 16155                return CreatePosixIdentityOnlyBinding();
 156            }
 0157            else if (_clientCredentialType == UnixDomainSocketClientCredentialType.None)
 158            {
 0159                return CreateTransportProtectionOnly();
 160            }
 161            else
 162            {
 0163                return null;
 164            }
 165        }
 166
 167    }
 168}