< Summary - CoreWCF Coverage — PR #1766

Information
Class: CoreWCF.Security.X509ClientCertificateAuthentication
Assembly: CoreWCF.Primitives
File(s): /home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.Primitives/src/CoreWCF/Security/X509ClientCertificateAuthentication.cs
Line coverage
56%
Covered lines: 39
Uncovered lines: 30
Coverable lines: 69
Total lines: 185
Line coverage: 56.5%
Branch coverage
57%
Covered branches: 8
Total branches: 14
Branch coverage: 57.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(...)100%11100%
GetCertificateValidator()50%101068.75%
MakeReadOnly()100%110%
ThrowIfImmutable()50%2266.66%

File(s)

/home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.Primitives/src/CoreWCF/Security/X509ClientCertificateAuthentication.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.Security.Cryptography.X509Certificates;
 6using CoreWCF.IdentityModel.Selectors;
 7
 8namespace CoreWCF.Security
 9{
 10    public class X509ClientCertificateAuthentication
 11    {
 12        internal const X509CertificateValidationMode DefaultCertificateValidationMode = X509CertificateValidationMode.Ch
 13        internal const X509RevocationMode DefaultRevocationMode = X509RevocationMode.Online;
 14        internal const StoreLocation DefaultTrustedStoreLocation = StoreLocation.LocalMachine;
 15        internal const bool DefaultMapCertificateToWindowsAccount = false;
 16        private static X509CertificateValidator s_defaultCertificateValidator;
 11817        private X509CertificateValidationMode _certificateValidationMode = DefaultCertificateValidationMode;
 11818        private X509RevocationMode _revocationMode = DefaultRevocationMode;
 11819        private StoreLocation _trustedStoreLocation = DefaultTrustedStoreLocation;
 20        private X509CertificateValidator _customCertificateValidator = null;
 21        private bool _mapClientCertificateToWindowsAccount = DefaultMapCertificateToWindowsAccount;
 11822        private bool _includeWindowsGroups = SspiSecurityTokenProvider.DefaultExtractWindowsGroupClaims;
 23        private bool _isReadOnly;
 24
 5225        internal X509ClientCertificateAuthentication()
 26        {
 5227        }
 28
 6629        internal X509ClientCertificateAuthentication(X509ClientCertificateAuthentication other)
 30        {
 6631            _certificateValidationMode = other._certificateValidationMode;
 6632            _customCertificateValidator = other._customCertificateValidator;
 6633            _includeWindowsGroups = other._includeWindowsGroups;
 6634            _mapClientCertificateToWindowsAccount = other._mapClientCertificateToWindowsAccount;
 6635            _trustedStoreLocation = other._trustedStoreLocation;
 6636            _revocationMode = other._revocationMode;
 6637            _isReadOnly = other._isReadOnly;
 6638        }
 39
 40        internal static X509CertificateValidator DefaultCertificateValidator
 41        {
 42            get
 43            {
 044                if (s_defaultCertificateValidator == null)
 45                {
 046                    bool useMachineContext = DefaultTrustedStoreLocation == StoreLocation.LocalMachine;
 047                    X509ChainPolicy chainPolicy = new X509ChainPolicy
 048                    {
 049                        RevocationMode = DefaultRevocationMode
 050                    };
 051                    s_defaultCertificateValidator = X509CertificateValidator.CreateChainTrustValidator(useMachineContext
 52                }
 053                return s_defaultCertificateValidator;
 54            }
 55        }
 56
 57        public X509CertificateValidationMode CertificateValidationMode
 58        {
 59            get
 60            {
 061                return _certificateValidationMode;
 62            }
 63            set
 64            {
 865                X509CertificateValidationModeHelper.Validate(value);
 866                ThrowIfImmutable();
 867                _certificateValidationMode = value;
 868            }
 69        }
 70
 71        public X509RevocationMode RevocationMode
 72        {
 73            get
 74            {
 075                return _revocationMode;
 76            }
 77            set
 78            {
 079                ThrowIfImmutable();
 080                _revocationMode = value;
 081            }
 82        }
 83
 84        public StoreLocation TrustedStoreLocation
 85        {
 86            get
 87            {
 088                return _trustedStoreLocation;
 89            }
 90            set
 91            {
 092                ThrowIfImmutable();
 093                _trustedStoreLocation = value;
 094            }
 95        }
 96
 97        public X509CertificateValidator CustomCertificateValidator
 98        {
 99            get
 100            {
 0101                return _customCertificateValidator;
 102            }
 103            set
 104            {
 3105                ThrowIfImmutable();
 3106                _customCertificateValidator = value;
 3107            }
 108        }
 109
 110        public bool MapClientCertificateToWindowsAccount
 111        {
 112            get
 113            {
 16114                return _mapClientCertificateToWindowsAccount;
 115            }
 116            set
 117            {
 0118                ThrowIfImmutable();
 0119                _mapClientCertificateToWindowsAccount = value;
 0120            }
 121        }
 122
 123        public bool IncludeWindowsGroups
 124        {
 125            get
 126            {
 16127                return _includeWindowsGroups;
 128            }
 129            set
 130            {
 0131                ThrowIfImmutable();
 0132                _includeWindowsGroups = value;
 0133            }
 134        }
 135
 136        internal X509CertificateValidator GetCertificateValidator()
 137        {
 16138            if (_certificateValidationMode == X509CertificateValidationMode.None)
 139            {
 2140                return X509CertificateValidator.None;
 141            }
 14142            else if (_certificateValidationMode == X509CertificateValidationMode.PeerTrust)
 143            {
 0144                return X509CertificateValidator.PeerTrust;
 145            }
 14146            else if (_certificateValidationMode == X509CertificateValidationMode.Custom)
 147            {
 3148                if (_customCertificateValidator == null)
 149                {
 0150                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.MissingCu
 151                }
 3152                return _customCertificateValidator;
 153            }
 154            else
 155            {
 11156                bool useMachineContext = _trustedStoreLocation == StoreLocation.LocalMachine;
 11157                X509ChainPolicy chainPolicy = new X509ChainPolicy
 11158                {
 11159                    RevocationMode = _revocationMode
 11160                };
 11161                if (_certificateValidationMode == X509CertificateValidationMode.ChainTrust)
 162                {
 11163                    return X509CertificateValidator.CreateChainTrustValidator(useMachineContext, chainPolicy);
 164                }
 165                else
 166                {
 0167                    return X509CertificateValidator.CreatePeerOrChainTrustValidator(useMachineContext, chainPolicy);
 168                }
 169            }
 170        }
 171
 172        internal void MakeReadOnly()
 173        {
 0174            _isReadOnly = true;
 0175        }
 176
 177        private void ThrowIfImmutable()
 178        {
 11179            if (_isReadOnly)
 180            {
 0181                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.ObjectIsReadO
 182            }
 11183        }
 184    }
 185}