< Summary - CoreWCF Coverage — PR #1766

Information
Class: CoreWCF.IdentityModel.Selectors.SecurityTokenProvider
Assembly: CoreWCF.Primitives
File(s): /home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.Primitives/src/CoreWCF/IdentityModel/Selectors/SecurityTokenProvider.cs
Line coverage
19%
Covered lines: 7
Uncovered lines: 29
Coverable lines: 36
Total lines: 118
Line coverage: 19.4%
Branch coverage
7%
Covered branches: 1
Total branches: 14
Branch coverage: 7.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%
GetToken(...)50%2275%
GetTokenAsync(...)100%11100%
RenewToken(...)0%440%
RenewTokenAsync()0%440%
CancelToken(...)0%220%
CancelTokenAsync(...)0%220%
RenewTokenCore(...)100%110%
CancelTokenCore(...)100%110%
GetTokenCoreAsync(...)100%11100%
RenewTokenCoreAsync(...)100%110%
CancelTokenCoreAsync(...)100%110%

File(s)

/home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.Primitives/src/CoreWCF/IdentityModel/Selectors/SecurityTokenProvider.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.Threading;
 6using System.Threading.Tasks;
 7using CoreWCF.IdentityModel.Tokens;
 8
 9namespace CoreWCF.IdentityModel.Selectors
 10{
 11    public abstract class SecurityTokenProvider
 12    {
 3413        protected SecurityTokenProvider() { }
 14
 15        public virtual bool SupportsTokenRenewal
 16        {
 017            get { return false; }
 18        }
 19
 20        public virtual bool SupportsTokenCancellation
 21        {
 022            get { return false; }
 23        }
 24
 25        public SecurityToken GetToken(TimeSpan timeout)
 26        {
 1727            SecurityToken token = GetTokenCore(timeout);
 1728            if (token == null)
 29            {
 030                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new SecurityTokenException(SR.Format(SR.TokenP
 31            }
 1732            return token;
 33        }
 34
 35        public Task<SecurityToken> GetTokenAsync(CancellationToken token)
 36        {
 1737            return GetTokenCoreAsync(token);
 38        }
 39
 40        public SecurityToken RenewToken(TimeSpan timeout, SecurityToken tokenToBeRenewed)
 41        {
 042            if (tokenToBeRenewed == null)
 43            {
 044                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(tokenToBeRenewed));
 45            }
 046            SecurityToken token = RenewTokenCore(timeout, tokenToBeRenewed);
 047            if (token == null)
 48            {
 049                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new SecurityTokenException(SR.Format(SR.TokenP
 50            }
 051            return token;
 52        }
 53
 54        public async Task<SecurityToken> RenewTokenAsync(SecurityToken tokenToBeRenewed, TimeSpan timeout)
 55        {
 056            if (tokenToBeRenewed == null)
 57            {
 058                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(tokenToBeRenewed));
 59            }
 060            SecurityToken token = await RenewTokenCoreAsync(tokenToBeRenewed, timeout);
 061            if (token == null)
 62            {
 063                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new SecurityTokenException(SR.Format(SR.TokenP
 64            }
 065            return token;
 066        }
 67
 68        public void CancelToken(TimeSpan timeout, SecurityToken token)
 69        {
 070            if (token == null)
 71            {
 072                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(token));
 73            }
 074            CancelTokenCore(timeout, token);
 075        }
 76
 77        public Task CancelTokenAsync(SecurityToken token, TimeSpan timeout)
 78        {
 079            if (token == null)
 80            {
 081                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(token));
 82            }
 083            return CancelTokenCoreAsync(token, timeout);
 84        }
 85
 86        // protected methods
 87        protected abstract SecurityToken GetTokenCore(TimeSpan timeout);
 88
 89        protected virtual SecurityToken RenewTokenCore(TimeSpan timeout, SecurityToken tokenToBeRenewed)
 90        {
 091            throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new NotSupportedException(SR.Format(SR.TokenRenewa
 92        }
 93
 94        protected virtual void CancelTokenCore(TimeSpan timeout, SecurityToken token)
 95        {
 096            throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new NotSupportedException(SR.Format(SR.TokenCancel
 97        }
 98
 99        protected virtual Task<SecurityToken> GetTokenCoreAsync(CancellationToken cancellationToken)
 100        {
 17101            SecurityToken token = GetToken(Timeout.InfiniteTimeSpan);
 17102            return Task.FromResult(token);
 103        }
 104
 105        protected virtual Task<SecurityToken> RenewTokenCoreAsync(SecurityToken tokenToBeRenewed, TimeSpan timeout)
 106        {
 0107            SecurityToken token = RenewTokenCore(timeout, tokenToBeRenewed);
 0108            return Task.FromResult(token);
 109        }
 110
 111        protected virtual Task CancelTokenCoreAsync(SecurityToken token, TimeSpan timeout)
 112        {
 0113            CancelToken(timeout, token);
 0114            return Task.CompletedTask;
 115        }
 116    }
 117}
 118