< Summary - CoreWCF Coverage — PR #1766

Information
Class: CoreWCF.Security.Tokens.SecurityContextSecurityTokenResolver
Assembly: CoreWCF.Primitives
File(s): /home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.Primitives/src/CoreWCF/Security/Tokens/SecurityContextSecurityTokenResolver.cs
Line coverage
42%
Covered lines: 18
Uncovered lines: 24
Coverable lines: 42
Total lines: 134
Line coverage: 42.8%
Branch coverage
20%
Covered branches: 2
Total branches: 10
Branch coverage: 20%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity NPath complexity Sequence coverage
.ctor(...)50%4481.81%
.ctor(...)100%11100%
AddContext(...)100%11100%
TryAddContext(...)100%110%
ClearContexts()100%110%
RemoveContext(...)100%110%
RemoveAllContexts(...)100%11100%
GetContext(...)100%11100%
GetAllContexts(...)100%110%
UpdateContextCachingTime(...)100%110%
TryResolveTokenCore(...)0%220%
TryResolveSecurityKeyCore(...)0%220%
TryResolveTokenCore(...)0%220%

File(s)

/home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.Primitives/src/CoreWCF/Security/Tokens/SecurityContextSecurityTokenResolver.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.ObjectModel;
 6using System.Xml;
 7using CoreWCF.IdentityModel;
 8using CoreWCF.IdentityModel.Selectors;
 9using CoreWCF.IdentityModel.Tokens;
 10
 11namespace CoreWCF.Security.Tokens
 12{
 13    public class SecurityContextSecurityTokenResolver : SecurityTokenResolver, ISecurityContextSecurityTokenCache
 14    {
 15        private readonly SecurityContextTokenCache _tokenCache;
 2316        private TimeSpan _clockSkew = SecurityProtocolFactory.defaultMaxClockSkew;
 17
 18        public SecurityContextSecurityTokenResolver(int securityContextCacheCapacity, bool removeOldestTokensOnCacheFull
 2319            : this(securityContextCacheCapacity, removeOldestTokensOnCacheFull, SecurityProtocolFactory.defaultMaxClockS
 20        {
 2321        }
 22
 2323        public SecurityContextSecurityTokenResolver(int securityContextCacheCapacity, bool removeOldestTokensOnCacheFull
 24        {
 2325            if (securityContextCacheCapacity <= 0)
 26            {
 027                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(securit
 28            }
 29
 2330            if (clockSkew < TimeSpan.Zero)
 31            {
 032                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(clockSk
 33            }
 34
 2335            SecurityContextTokenCacheCapacity = securityContextCacheCapacity;
 2336            RemoveOldestTokensOnCacheFull = removeOldestTokensOnCacheFull;
 2337            _clockSkew = clockSkew;
 2338            _tokenCache = new SecurityContextTokenCache(SecurityContextTokenCacheCapacity, RemoveOldestTokensOnCacheFull
 2339        }
 40
 2341        public int SecurityContextTokenCacheCapacity { get; }
 42
 43        public TimeSpan ClockSkew
 44        {
 45            get
 46            {
 047                return _clockSkew;
 48            }
 49        }
 50
 2351        public bool RemoveOldestTokensOnCacheFull { get; }
 52
 53        public void AddContext(SecurityContextSecurityToken token)
 54        {
 1055            _tokenCache.AddContext(token);
 1056        }
 57
 58        public bool TryAddContext(SecurityContextSecurityToken token)
 59        {
 060            return _tokenCache.TryAddContext(token);
 61        }
 62
 63
 64        public void ClearContexts()
 65        {
 066            _tokenCache.ClearContexts();
 067        }
 68
 69        public void RemoveContext(UniqueId contextId, UniqueId generation)
 70        {
 071            _tokenCache.RemoveContext(contextId, generation, false);
 072        }
 73
 74        public void RemoveAllContexts(UniqueId contextId)
 75        {
 1076            _tokenCache.RemoveAllContexts(contextId);
 1077        }
 78
 79        public SecurityContextSecurityToken GetContext(UniqueId contextId, UniqueId generation)
 80        {
 2081            return _tokenCache.GetContext(contextId, generation);
 82        }
 83
 84        public Collection<SecurityContextSecurityToken> GetAllContexts(UniqueId contextId)
 85        {
 086            return _tokenCache.GetAllContexts(contextId);
 87        }
 88
 89        public void UpdateContextCachingTime(SecurityContextSecurityToken context, DateTime expirationTime)
 90        {
 091            _tokenCache.UpdateContextCachingTime(context, expirationTime);
 092        }
 93
 94        protected override bool TryResolveTokenCore(SecurityKeyIdentifierClause keyIdentifierClause, out SecurityToken t
 95        {
 096            if (keyIdentifierClause is SecurityContextKeyIdentifierClause sctSkiClause)
 97            {
 098                token = _tokenCache.GetContext(sctSkiClause.ContextId, sctSkiClause.Generation);
 99            }
 100            else
 101            {
 0102                token = null;
 103            }
 0104            return (token != null);
 105        }
 106
 107        protected override bool TryResolveSecurityKeyCore(SecurityKeyIdentifierClause keyIdentifierClause, out SecurityK
 108        {
 0109            if (TryResolveTokenCore(keyIdentifierClause, out SecurityToken sct))
 110            {
 0111                key = ((SecurityContextSecurityToken)sct).SecurityKeys[0];
 0112                return true;
 113            }
 114            else
 115            {
 0116                key = null;
 0117                return false;
 118            }
 119        }
 120
 121        protected override bool TryResolveTokenCore(SecurityKeyIdentifier keyIdentifier, out SecurityToken token)
 122        {
 0123            if (keyIdentifier.TryFind<SecurityContextKeyIdentifierClause>(out SecurityContextKeyIdentifierClause sctSkiC
 124            {
 0125                return TryResolveToken(sctSkiClause, out token);
 126            }
 127            else
 128            {
 0129                token = null;
 0130                return false;
 131            }
 132        }
 133    }
 134}