< Summary - CoreWCF Coverage — PR #1766

Information
Class: CoreWCF.Security.IssuedTokenServiceCredential
Assembly: CoreWCF.Primitives
File(s): /home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.Primitives/src/CoreWCF/Security/IssuedTokenServiceCredential.cs
Line coverage
38%
Covered lines: 30
Uncovered lines: 47
Coverable lines: 77
Total lines: 222
Line coverage: 38.9%
Branch coverage
6%
Covered branches: 1
Total branches: 16
Branch coverage: 6.2%
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()0%10100%
MakeReadOnly()100%110%
ThrowIfImmutable()50%2266.66%

File(s)

/home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.Primitives/src/CoreWCF/Security/IssuedTokenServiceCredential.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.Collections.Generic;
 6using System.Security.Cryptography.X509Certificates;
 7using CoreWCF.IdentityModel.Selectors;
 8
 9namespace CoreWCF.Security
 10{
 11    public class IssuedTokenServiceCredential
 12    {
 13        internal const bool DefaultAllowUntrustedRsaIssuers = false;
 14        internal const AudienceUriMode DefaultAudienceUriMode = AudienceUriMode.Always;
 15        internal const X509CertificateValidationMode DefaultCertificateValidationMode = X509CertificateValidationMode.Ch
 16        internal const X509RevocationMode DefaultRevocationMode = X509RevocationMode.Online;
 17        internal const StoreLocation DefaultTrustedStoreLocation = StoreLocation.LocalMachine;
 18        private readonly List<string> _allowedAudienceUris;
 11819        private AudienceUriMode _audienceUriMode = DefaultAudienceUriMode;
 20        private readonly List<X509Certificate2> _knownCertificates;
 21        private SamlSerializer _samlSerializer;
 11822        private X509CertificateValidationMode _certificateValidationMode = DefaultCertificateValidationMode;
 11823        private X509RevocationMode _revocationMode = DefaultRevocationMode;
 11824        private StoreLocation _trustedStoreLocation = DefaultTrustedStoreLocation;
 25        private X509CertificateValidator _customCertificateValidator = null;
 26        private bool _allowUntrustedRsaIssuers = DefaultAllowUntrustedRsaIssuers;
 27        private bool _isReadOnly;
 28
 5229        internal IssuedTokenServiceCredential()
 30        {
 5231            _allowedAudienceUris = new List<string>();
 5232            _knownCertificates = new List<X509Certificate2>();
 5233        }
 34
 6635        internal IssuedTokenServiceCredential(IssuedTokenServiceCredential other)
 36        {
 6637            _audienceUriMode = other._audienceUriMode;
 6638            _allowedAudienceUris = new List<string>(other._allowedAudienceUris);
 6639            _samlSerializer = other._samlSerializer;
 6640            _knownCertificates = new List<X509Certificate2>(other._knownCertificates);
 6641            _certificateValidationMode = other._certificateValidationMode;
 6642            _customCertificateValidator = other._customCertificateValidator;
 6643            _trustedStoreLocation = other._trustedStoreLocation;
 6644            _revocationMode = other._revocationMode;
 6645            _allowUntrustedRsaIssuers = other._allowUntrustedRsaIssuers;
 6646            _isReadOnly = other._isReadOnly;
 6647        }
 48
 49        public IList<string> AllowedAudienceUris
 50        {
 51            get
 52            {
 053                if (_isReadOnly)
 54                {
 055                    return _allowedAudienceUris.AsReadOnly();
 56                }
 57                else
 58                {
 059                    return _allowedAudienceUris;
 60                }
 61            }
 62        }
 63
 64        public AudienceUriMode AudienceUriMode
 65        {
 66            get
 67            {
 068                return _audienceUriMode;
 69            }
 70            set
 71            {
 072                ThrowIfImmutable();
 073                AudienceUriModeValidationHelper.Validate(_audienceUriMode);
 074                _audienceUriMode = value;
 075            }
 76        }
 77
 78
 79        public IList<X509Certificate2> KnownCertificates
 80        {
 81            get
 82            {
 083                if (_isReadOnly)
 84                {
 085                    return _knownCertificates.AsReadOnly();
 86                }
 87                else
 88                {
 089                    return _knownCertificates;
 90                }
 91            }
 92        }
 93
 94        public SamlSerializer SamlSerializer
 95        {
 96            get
 97            {
 298                return _samlSerializer;
 99            }
 100            set
 101            {
 0102                ThrowIfImmutable();
 0103                _samlSerializer = value;
 0104            }
 105        }
 106
 107        public X509CertificateValidationMode CertificateValidationMode
 108        {
 109            get
 110            {
 0111                return _certificateValidationMode;
 112            }
 113            set
 114            {
 2115                X509CertificateValidationModeHelper.Validate(value);
 2116                ThrowIfImmutable();
 2117                _certificateValidationMode = value;
 2118            }
 119        }
 120
 121        public X509RevocationMode RevocationMode
 122        {
 123            get
 124            {
 0125                return _revocationMode;
 126            }
 127            set
 128            {
 2129                ThrowIfImmutable();
 2130                _revocationMode = value;
 2131            }
 132        }
 133
 134        public StoreLocation TrustedStoreLocation
 135        {
 136            get
 137            {
 0138                return _trustedStoreLocation;
 139            }
 140            set
 141            {
 0142                ThrowIfImmutable();
 0143                _trustedStoreLocation = value;
 0144            }
 145        }
 146
 147        public X509CertificateValidator CustomCertificateValidator
 148        {
 149            get
 150            {
 0151                return _customCertificateValidator;
 152            }
 153            set
 154            {
 0155                ThrowIfImmutable();
 0156                _customCertificateValidator = value;
 0157            }
 158        }
 159
 160        public bool AllowUntrustedRsaIssuers
 161        {
 162            get
 163            {
 0164                return _allowUntrustedRsaIssuers;
 165            }
 166            set
 167            {
 0168                ThrowIfImmutable();
 0169                _allowUntrustedRsaIssuers = value;
 0170            }
 171        }
 172
 173        internal X509CertificateValidator GetCertificateValidator()
 174        {
 0175            if (_certificateValidationMode == X509CertificateValidationMode.None)
 176            {
 0177                return X509CertificateValidator.None;
 178            }
 0179            else if (_certificateValidationMode == X509CertificateValidationMode.PeerTrust)
 180            {
 0181                return X509CertificateValidator.PeerTrust;
 182            }
 0183            else if (_certificateValidationMode == X509CertificateValidationMode.Custom)
 184            {
 0185                if (_customCertificateValidator == null)
 186                {
 0187                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.Format(SR
 188                }
 0189                return _customCertificateValidator;
 190            }
 191            else
 192            {
 0193                bool useMachineContext = _trustedStoreLocation == StoreLocation.LocalMachine;
 0194                X509ChainPolicy chainPolicy = new X509ChainPolicy
 0195                {
 0196                    RevocationMode = _revocationMode
 0197                };
 0198                if (_certificateValidationMode == X509CertificateValidationMode.ChainTrust)
 199                {
 0200                    return X509CertificateValidator.CreateChainTrustValidator(useMachineContext, chainPolicy);
 201                }
 202                else
 203                {
 0204                    return X509CertificateValidator.CreatePeerOrChainTrustValidator(useMachineContext, chainPolicy);
 205                }
 206            }
 207        }
 208
 209        internal void MakeReadOnly()
 210        {
 0211            _isReadOnly = true;
 0212        }
 213
 214        private void ThrowIfImmutable()
 215        {
 4216            if (_isReadOnly)
 217            {
 0218                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.Format(SR.Obj
 219            }
 4220        }
 221    }
 222}