< Summary - CoreWCF Coverage — PR #1766

Information
Class: CoreWCF.IdentityModel.Tokens.AggregateTokenResolver
Assembly: CoreWCF.Primitives
File(s): /home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.Primitives/src/CoreWCF/IdentityModel/Tokens/AggregateTokenResolver.cs
Line coverage
28%
Covered lines: 10
Uncovered lines: 25
Coverable lines: 35
Total lines: 138
Line coverage: 28.5%
Branch coverage
20%
Covered branches: 5
Total branches: 24
Branch coverage: 20.8%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity NPath complexity Sequence coverage
.ctor(...)50%2283.33%
TryResolveSecurityKeyCore(...)0%660%
TryResolveTokenCore(...)0%660%
TryResolveTokenCore(...)0%660%
AddNonEmptyResolvers(...)100%44100%

File(s)

/home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.Primitives/src/CoreWCF/IdentityModel/Tokens/AggregateTokenResolver.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.Collections.Generic;
 5using System.Collections.ObjectModel;
 6using CoreWCF.IdentityModel.Selectors;
 7
 8namespace CoreWCF.IdentityModel.Tokens
 9{
 10    /// <summary>
 11    /// This class defines a TokenResolver that can wrap multiple Token Resolvers
 12    /// and resolve tokens across all the wrapped token resolvers.
 13    /// </summary>
 14    internal class AggregateTokenResolver : SecurityTokenResolver
 15    {
 14816        private readonly List<SecurityTokenResolver> _tokenResolvers = new List<SecurityTokenResolver>();
 17
 18        /// <summary>
 19        /// Initializes an instance of <see cref="AggregateTokenResolver"/>
 20        /// </summary>
 21        /// <param name="tokenResolvers">IEnumerable list of TokenResolvers to be wrapped.</param>
 22        /// <exception cref="ArgumentNullException">The input argument 'tokenResolvers' is null.</exception>
 23        /// <exception cref="ArgumentException">The input 'tokenResolver' list does not contain a valid
 24        /// SecurityTokenResolver. At least one SecurityTokenResolver should be specified.</exception>
 14825        public AggregateTokenResolver(IEnumerable<SecurityTokenResolver> tokenResolvers)
 26        {
 14827            if (tokenResolvers == null)
 28            {
 029                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(tokenResolvers));
 30            }
 31
 14832            AddNonEmptyResolvers(tokenResolvers);
 14833        }
 34
 35        /// <summary>
 36        /// Gets a read-only collection of TokenResolvers.
 37        /// </summary>
 38        public ReadOnlyCollection<SecurityTokenResolver> TokenResolvers
 39        {
 40            get
 41            {
 4042                return _tokenResolvers.AsReadOnly();
 43            }
 44        }
 45
 46        /// <summary>
 47        /// Override of the base class. Resolves the given SecurityKeyIdentifierClause to a
 48        /// SecurityKey.
 49        /// </summary>
 50        /// <param name="keyIdentifierClause">The Clause to be resolved.</param>
 51        /// <param name="key">The resolved SecurityKey</param>
 52        /// <returns>True if successfully resolved.</returns>
 53        /// <exception cref="ArgumentNullException">Input argument 'keyIdentifierClause' is null.</exception>
 54        protected override bool TryResolveSecurityKeyCore(SecurityKeyIdentifierClause keyIdentifierClause, out SecurityK
 55        {
 056            if (keyIdentifierClause == null)
 57            {
 058                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(keyIdentifierClause));
 59            }
 60
 061            key = null;
 062            foreach (SecurityTokenResolver tokenResolver in _tokenResolvers)
 63            {
 064                if (tokenResolver.TryResolveSecurityKey(keyIdentifierClause, out key))
 65                {
 066                    return true;
 67                }
 68            }
 69
 070            return false;
 071        }
 72
 73        /// <summary>
 74        /// Override of the base class. Resolves the given SecurityKeyIdentifier to a
 75        /// SecurityToken.
 76        /// </summary>
 77        /// <param name="keyIdentifier">The KeyIdentifier to be resolved.</param>
 78        /// <param name="token">The resolved SecurityToken</param>
 79        /// <returns>True if successfully resolved.</returns>
 80        /// <exception cref="ArgumentNullException">Input argument 'keyIdentifier' is null.</exception>
 81        protected override bool TryResolveTokenCore(SecurityKeyIdentifier keyIdentifier, out SecurityToken token)
 82        {
 083            if (keyIdentifier == null)
 84            {
 085                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(keyIdentifier));
 86            }
 87
 088            token = null;
 089            foreach (SecurityTokenResolver tokenResolver in _tokenResolvers)
 90            {
 091                if (tokenResolver.TryResolveToken(keyIdentifier, out token))
 92                {
 093                    return true;
 94                }
 95            }
 96
 097            return false;
 098        }
 99
 100        /// <summary>
 101        /// Override of the base class. Resolves the given SecurityKeyIdentifierClause to a
 102        /// SecurityToken.
 103        /// </summary>
 104        /// <param name="keyIdentifierClause">The KeyIdentifier to be resolved.</param>
 105        /// <param name="token">The resolved SecurityToken</param>
 106        /// <returns>True if successfully resolved.</returns>
 107        /// <exception cref="ArgumentNullException">Input argument 'keyIdentifierClause' is null.</exception>
 108        protected override bool TryResolveTokenCore(SecurityKeyIdentifierClause keyIdentifierClause, out SecurityToken t
 109        {
 0110            if (keyIdentifierClause == null)
 111            {
 0112                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(keyIdentifierClause));
 113            }
 114
 0115            token = null;
 0116            foreach (SecurityTokenResolver tokenResolver in _tokenResolvers)
 117            {
 0118                if (tokenResolver.TryResolveToken(keyIdentifierClause, out token))
 119                {
 0120                    return true;
 121                }
 122            }
 123
 0124            return false;
 0125        }
 126
 127        private void AddNonEmptyResolvers(IEnumerable<SecurityTokenResolver> resolvers)
 128        {
 596129            foreach (SecurityTokenResolver resolver in resolvers)
 130            {
 150131                if (resolver != null) // && resolver != EmptySecurityTokenResolver.Instance)
 132                {
 150133                    _tokenResolvers.Add(resolver);
 134                }
 135            }
 148136        }
 137    }
 138}