< Summary - CoreWCF Coverage — PR #1766

Information
Class: CoreWCF.IdentityModel.Selectors.SecurityTokenRequirement
Assembly: CoreWCF.Primitives
File(s): /home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.Primitives/src/CoreWCF/IdentityModel/Selectors/SecurityTokenRequirement.cs
Line coverage
82%
Covered lines: 41
Uncovered lines: 9
Coverable lines: 50
Total lines: 160
Line coverage: 82%
Branch coverage
36%
Covered branches: 8
Total branches: 22
Branch coverage: 36.3%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity NPath complexity Sequence coverage
.ctor()100%11100%
Initialize()100%11100%
GetProperty(...)50%2266.66%
TryGetProperty(...)83.33%6685.71%

File(s)

/home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.Primitives/src/CoreWCF/IdentityModel/Selectors/SecurityTokenRequirement.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 CoreWCF.IdentityModel.Tokens;
 7
 8namespace CoreWCF.IdentityModel.Selectors
 9{
 10    public class SecurityTokenRequirement
 11    {
 12        private const string Namespace = "http://schemas.microsoft.com/ws/2006/05/identitymodel/securitytokenrequirement
 13        private const string tokenTypeProperty = Namespace + "/TokenType";
 14        private const string keyUsageProperty = Namespace + "/KeyUsage";
 15        private const string keyTypeProperty = Namespace + "/KeyType";
 16        private const string keySizeProperty = Namespace + "/KeySize";
 17        private const string requireCryptographicTokenProperty = Namespace + "/RequireCryptographicToken";
 18        private const string peerAuthenticationMode = Namespace + "/PeerAuthenticationMode";
 19        private const string isOptionalTokenProperty = Namespace + "/IsOptionalTokenProperty";
 20        private const bool defaultRequireCryptographicToken = false;
 21        private const SecurityKeyUsage defaultKeyUsage = SecurityKeyUsage.Signature;
 22        private const SecurityKeyType defaultKeyType = SecurityKeyType.SymmetricKey;
 23        private const int defaultKeySize = 0;
 24        private const bool defaultIsOptionalToken = false;
 25        private readonly Dictionary<string, object> _properties;
 26
 9927        public SecurityTokenRequirement()
 28        {
 9929            _properties = new Dictionary<string, object>();
 9930            Initialize();
 9931        }
 32
 22233        public static string TokenTypeProperty { get { return tokenTypeProperty; } }
 18634        public static string KeyUsageProperty { get { return keyUsageProperty; } }
 15735        public static string KeyTypeProperty { get { return keyTypeProperty; } }
 9936        public static string KeySizeProperty { get { return keySizeProperty; } }
 19837        public static string RequireCryptographicTokenProperty { get { return requireCryptographicTokenProperty; } }
 038        public static string PeerAuthenticationMode { get { return peerAuthenticationMode; } }
 9939        public static string IsOptionalTokenProperty { get { return isOptionalTokenProperty; } }
 40
 41        public string TokenType
 42        {
 43            get
 44            {
 12345                return (TryGetProperty<string>(TokenTypeProperty, out string result)) ? result : null;
 46            }
 47            set
 48            {
 9949                _properties[TokenTypeProperty] = value;
 9950            }
 51        }
 52
 53        internal bool IsOptionalToken
 54        {
 55            get
 56            {
 057                return (TryGetProperty<bool>(IsOptionalTokenProperty, out bool result)) ? result : defaultIsOptionalToke
 58            }
 59            set
 60            {
 9961                _properties[IsOptionalTokenProperty] = value;
 9962            }
 63        }
 64
 65        public bool RequireCryptographicToken
 66        {
 67            get
 68            {
 069                return (TryGetProperty<bool>(RequireCryptographicTokenProperty, out bool result)) ? result : defaultRequ
 70            }
 71            set
 72            {
 19873                _properties[RequireCryptographicTokenProperty] = (object)value;
 19874            }
 75        }
 76
 77        public SecurityKeyUsage KeyUsage
 78        {
 79            get
 80            {
 081                return (TryGetProperty<SecurityKeyUsage>(KeyUsageProperty, out SecurityKeyUsage result)) ? result : defa
 82            }
 83            set
 84            {
 18685                SecurityKeyUsageHelper.Validate(value);
 18686                _properties[KeyUsageProperty] = (object)value;
 18687            }
 88        }
 89
 90        internal SecurityKeyType KeyType
 91        {
 92            get
 93            {
 094                return (TryGetProperty<SecurityKeyType>(KeyTypeProperty, out SecurityKeyType result)) ? result : default
 95            }
 96            set
 97            {
 15798                SecurityKeyTypeHelper.Validate(value);
 15799                _properties[KeyTypeProperty] = (object)value;
 157100            }
 101        }
 102
 103        public int KeySize
 104        {
 105            get
 106            {
 0107                return (TryGetProperty<int>(KeySizeProperty, out int result)) ? result : defaultKeySize;
 108            }
 109            set
 110            {
 99111                if (value < 0)
 112                {
 0113                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(val
 114                }
 99115                Properties[KeySizeProperty] = value;
 99116            }
 117        }
 118
 119        public IDictionary<string, object> Properties
 120        {
 121            get
 122            {
 1351123                return _properties;
 124            }
 125        }
 126
 127        private void Initialize()
 128        {
 99129            KeyType = defaultKeyType;
 99130            KeyUsage = defaultKeyUsage;
 99131            RequireCryptographicToken = defaultRequireCryptographicToken;
 99132            KeySize = defaultKeySize;
 99133            IsOptionalToken = defaultIsOptionalToken;
 99134        }
 135
 136        public TValue GetProperty<TValue>(string propertyName)
 137        {
 69138            if (!TryGetProperty<TValue>(propertyName, out TValue result))
 139            {
 0140                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentException(SR.Format(SR.SecurityTok
 141            }
 69142            return result;
 143        }
 144
 145        public bool TryGetProperty<TValue>(string propertyName, out TValue result)
 146        {
 341147            if (!Properties.TryGetValue(propertyName, out object dictionaryValue))
 148            {
 34149                result = default;
 34150                return false;
 151            }
 307152            if (dictionaryValue != null && !typeof(TValue).IsAssignableFrom(dictionaryValue.GetType()))
 153            {
 0154                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentException(SR.Format(SR.SecurityTok
 155            }
 307156            result = (TValue)dictionaryValue;
 307157            return true;
 158        }
 159    }
 160}