< Summary - CoreWCF Coverage — PR #1766

Information
Class: CoreWCF.IdentityModel.Tokens.IssuerTokenResolver
Assembly: CoreWCF.Primitives
File(s): /home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.Primitives/src/CoreWCF/IdentityModel/Tokens/IssuerTokenResolver.cs
Line coverage
20%
Covered lines: 8
Uncovered lines: 31
Coverable lines: 39
Total lines: 135
Line coverage: 20.5%
Branch coverage
4%
Covered branches: 1
Total branches: 24
Branch coverage: 4.1%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity NPath complexity Sequence coverage
.cctor()100%11100%
.ctor()100%11100%
.ctor(...)50%22100%
TryResolveSecurityKeyCore(...)0%880%
TryResolveTokenCore(...)0%660%
TryResolveTokenCore(...)0%880%

File(s)

/home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.Primitives/src/CoreWCF/IdentityModel/Tokens/IssuerTokenResolver.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.Security.Cryptography.X509Certificates;
 5using CoreWCF.IdentityModel.Selectors;
 6
 7namespace CoreWCF.IdentityModel.Tokens
 8{
 9    /// <summary>
 10    /// Resolves issuer tokens received from service partners.
 11    /// </summary>
 12    public class IssuerTokenResolver : SecurityTokenResolver
 13    {
 14        /// <summary>
 15        /// Default store for resolving X509 certificates.
 16        /// </summary>
 217        public static readonly StoreName DefaultStoreName = StoreName.TrustedPeople;
 18        /// <summary>
 19        /// Default store location for resolving X509 certificates.
 20        /// </summary>
 221        public static readonly StoreLocation DefaultStoreLocation = StoreLocation.LocalMachine;
 222        internal static IssuerTokenResolver s_defaultInstance = new IssuerTokenResolver();
 23
 24        /// <summary>
 25        /// Creates an instance of IssuerTokenResolver.
 26        /// </summary>
 27        public IssuerTokenResolver()
 228            : this( new X509CertificateStoreTokenResolver( DefaultStoreName, DefaultStoreLocation ) )
 29        {
 230        }
 31
 32        /// <summary>
 33        /// Creates an instance of IssuerTokenResolver using a given <see cref="SecurityTokenResolver"/>.
 34        /// </summary>
 35        /// <param name="wrappedTokenResolver">The <see cref="SecurityTokenResolver"/> to use.</param>
 236        public IssuerTokenResolver( SecurityTokenResolver wrappedTokenResolver )
 37        {
 238            WrappedTokenResolver = wrappedTokenResolver ?? throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentN
 239        }
 40
 41        /// <summary>
 42        /// Gets the <see cref="SecurityTokenResolver"/> wrapped by this class.
 43        /// </summary>
 044        public SecurityTokenResolver WrappedTokenResolver { get; } = null;
 45
 46        /// <summary>
 47        /// Inherited from <see cref="SecurityTokenResolver"/>.
 48        /// </summary>
 49        protected override bool TryResolveSecurityKeyCore( SecurityKeyIdentifierClause keyIdentifierClause, out Security
 50        {
 051            if ( keyIdentifierClause == null )
 52            {
 053                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull( nameof(keyIdentifierClause) );
 54            }
 55
 056            if (keyIdentifierClause is X509RawDataKeyIdentifierClause rawDataClause)
 57            {
 058                key = rawDataClause.CreateKey();
 059                return true;
 60            }
 61
 062            if (keyIdentifierClause is RsaKeyIdentifierClause rsaClause)
 63            {
 064                key = rsaClause.CreateKey();
 065                return true;
 66            }
 67
 068            if ( WrappedTokenResolver.TryResolveSecurityKey( keyIdentifierClause, out key ) )
 69            {
 070                return true;
 71            }
 72
 073            return false;
 74        }
 75
 76        /// <summary>
 77        /// Inherited from <see cref="SecurityTokenResolver"/>.
 78        /// </summary>
 79        protected override bool TryResolveTokenCore( SecurityKeyIdentifier keyIdentifier, out SecurityToken token )
 80        {
 081            if ( keyIdentifier == null )
 82            {
 083                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(keyIdentifier));
 84            }
 85
 086            token = null;
 087            foreach ( SecurityKeyIdentifierClause clause in keyIdentifier )
 88            {
 089                if ( TryResolveTokenCore( clause, out token ) )
 90                {
 091                    return true;
 92                }
 93            }
 94
 095            return false;
 096        }
 97
 98        /// <summary>
 99        /// Inherited from <see cref="SecurityTokenResolver"/>.
 100        /// </summary>
 101        protected override bool TryResolveTokenCore( SecurityKeyIdentifierClause keyIdentifierClause, out SecurityToken 
 102        {
 0103            if ( keyIdentifierClause == null )
 104            {
 0105                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull( nameof(keyIdentifierClause) );
 106            }
 107
 108
 109            //
 110            // Try raw X509
 111            //
 0112            if (keyIdentifierClause is X509RawDataKeyIdentifierClause rawDataClause)
 113            {
 0114                token = new X509SecurityToken(new X509Certificate2(rawDataClause.GetX509RawData()));
 0115                return true;
 116            }
 117
 118            //
 119            // Try RSA
 120            //
 0121            if (keyIdentifierClause is RsaKeyIdentifierClause rsaClause)
 122            {
 0123                token = new RsaSecurityToken(rsaClause.Rsa);
 0124                return true;
 125            }
 126
 0127            if ( WrappedTokenResolver.TryResolveToken( keyIdentifierClause, out token ) )
 128            {
 0129                return true;
 130            }
 131
 0132            return false;
 133        }
 134    }
 135}