< Summary - CoreWCF Coverage — PR #1766

Information
Class: CoreWCF.IdentityModel.Tokens.Saml2SecurityToken
Assembly: CoreWCF.Primitives
File(s): /home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.Primitives/src/CoreWCF/IdentityModel/Tokens/Saml2SecurityToken.cs
Line coverage
12%
Covered lines: 3
Uncovered lines: 22
Coverable lines: 25
Total lines: 87
Line coverage: 12%
Branch coverage
0%
Covered branches: 0
Total branches: 10
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity NPath complexity Sequence coverage
.ctor()100%11100%
.ctor(...)100%110%
.ctor(...)100%110%
op_Explicit(...)100%110%
Initialize(...)0%220%

File(s)

/home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.Primitives/src/CoreWCF/IdentityModel/Tokens/Saml2SecurityToken.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 CoreWCF.Runtime;
 7using CoreWCF.Security;
 8using MSIdentitySAML2 = Microsoft.IdentityModel.Tokens.Saml2;
 9
 10namespace CoreWCF.IdentityModel.Tokens
 11{
 12    /// <summary>
 13    /// A security token backed by a SAML2 assertion.
 14    /// </summary>
 15    public class Saml2SecurityToken : SecurityToken
 16    {
 17        private readonly ReadOnlyCollection<SecurityKey> _keys;
 18
 219        protected Saml2SecurityToken()
 20        {
 221        }
 22
 023        public Saml2SecurityToken(MSIdentitySAML2.Saml2SecurityToken saml2SecurityToken, ReadOnlyCollection<SecurityKey>
 24        {
 25            Fx.Assert(saml2SecurityToken != null, "Saml2SecurityToken can't be null");
 026            WrappedSaml2SecurityToken = saml2SecurityToken;
 027            Assertion = WrappedSaml2SecurityToken.Assertion;
 028            _keys = keys;
 029        }
 30
 031        public Saml2SecurityToken(MSIdentitySAML2.Saml2Assertion assertion)
 32        {
 033            Initialize(assertion);
 034        }
 35
 36        public static explicit operator MSIdentitySAML2.Saml2SecurityToken(Saml2SecurityToken samlSecurityToken)
 37        {
 038            return samlSecurityToken.WrappedSaml2SecurityToken;
 39        }
 40
 41        protected void Initialize(MSIdentitySAML2.Saml2Assertion assertion)
 42        {
 043            Assertion = assertion ?? throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(assertion))
 044        }
 45
 046        internal string AssertionXML { get; set; }
 47
 048        public override string Id => Assertion.Id.Value;
 49
 050        internal MSIdentitySAML2.Saml2SecurityToken WrappedSaml2SecurityToken { get; }
 51
 152        public MSIdentitySAML2.Saml2Assertion Assertion { get; private set; }
 53
 054        internal SecurityToken SigningToken { get; set; }
 55
 56        public override DateTime ValidFrom
 57        {
 58            get
 59            {
 060                if (Assertion.Conditions != null && Assertion.Conditions.NotBefore.HasValue)
 61                {
 062                    return Assertion.Conditions.NotBefore.Value;
 63                }
 64
 065                return SecurityUtils.MinUtcDateTime;
 66            }
 67        }
 68
 69        public override DateTime ValidTo
 70        {
 71            get
 72            {
 073                if (Assertion.Conditions != null && Assertion.Conditions.NotOnOrAfter.HasValue)
 74                {
 075                    return Assertion.Conditions.NotOnOrAfter.Value;
 76                }
 77
 078                return SecurityUtils.MaxUtcDateTime;
 79            }
 80        }
 81
 82        /// <summary>
 83        /// Gets the collection of <see cref="SecurityKey"/> contained in this token.
 84        /// </summary>
 085        public override ReadOnlyCollection<SecurityKey> SecurityKeys => _keys;
 86    }
 87}