< Summary - CoreWCF Coverage — PR #1766

Information
Class: CoreWCF.IdentityModel.Tokens.WindowsSecurityToken
Assembly: CoreWCF.Primitives
File(s): /home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.Primitives/src/CoreWCF/IdentityModel/Tokens/WindowsSecurityToken.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 36
Coverable lines: 36
Total lines: 98
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 12
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%110%
.ctor(...)100%110%
.ctor(...)100%110%
.ctor()100%110%
Initialize(...)100%110%
Initialize(...)0%660%
Dispose()0%440%
ThrowIfDisposed()0%220%

File(s)

/home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.Primitives/src/CoreWCF/IdentityModel/Tokens/WindowsSecurityToken.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.Security.Principal;
 7using CoreWCF.Security;
 8
 9namespace CoreWCF.IdentityModel.Tokens
 10{
 11    public class WindowsSecurityToken : SecurityToken, IDisposable
 12    {
 13        private string _id;
 14        private DateTime _effectiveTime;
 15        private DateTime _expirationTime;
 16        private WindowsIdentity _windowsIdentity;
 17        private bool _disposed = false;
 18
 19        public WindowsSecurityToken(WindowsIdentity windowsIdentity)
 020            : this(windowsIdentity, SecurityUniqueId.Create().Value)
 21        {
 022        }
 23
 24        public WindowsSecurityToken(WindowsIdentity windowsIdentity, string id)
 025            : this(windowsIdentity, id, null)
 26        {
 027        }
 28
 029        public WindowsSecurityToken(WindowsIdentity windowsIdentity, string id, string authenticationType)
 30        {
 031            DateTime effectiveTime = DateTime.UtcNow;
 032            Initialize(id, authenticationType, effectiveTime, DateTime.UtcNow.AddHours(10), windowsIdentity, true);
 033        }
 34
 035        protected WindowsSecurityToken()
 36        {
 037        }
 38
 39        protected void Initialize(string id, DateTime effectiveTime, DateTime expirationTime, WindowsIdentity windowsIde
 40        {
 041            Initialize(id, null, effectiveTime, expirationTime, windowsIdentity, clone);
 042        }
 43
 44        protected void Initialize(string id, string authenticationType, DateTime effectiveTime, DateTime expirationTime,
 45        {
 046            if (windowsIdentity == null)
 47            {
 048                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(windowsIdentity));
 49            }
 50
 051            _id = id ?? throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(id));
 052            AuthenticationType = authenticationType;
 053            _effectiveTime = effectiveTime;
 054            _expirationTime = expirationTime;
 055            _windowsIdentity = clone ? SecurityUtils.CloneWindowsIdentityIfNecessary(windowsIdentity, authenticationType
 056        }
 57
 058        public override string Id => _id;
 59
 060        public string AuthenticationType { get; private set; }
 61
 062        public override DateTime ValidFrom => _effectiveTime;
 63
 064        public override DateTime ValidTo => _expirationTime;
 65
 66        public virtual WindowsIdentity WindowsIdentity
 67        {
 68            get
 69            {
 070                ThrowIfDisposed();
 071                return _windowsIdentity;
 72            }
 73        }
 74
 075        public override ReadOnlyCollection<SecurityKey> SecurityKeys => EmptyReadOnlyCollection<SecurityKey>.Instance;
 76
 77        public virtual void Dispose()
 78        {
 079            if (!_disposed)
 80            {
 081                _disposed = true;
 082                if (_windowsIdentity != null)
 83                {
 084                    _windowsIdentity.Dispose();
 085                    _windowsIdentity = null;
 86                }
 87            }
 088        }
 89
 90        protected void ThrowIfDisposed()
 91        {
 092            if (_disposed)
 93            {
 094                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ObjectDisposedException(GetType().FullName
 95            }
 096        }
 97    }
 98}