< Summary - CoreWCF Coverage — PR #1766

Information
Class: CoreWCF.Security.UserNamePasswordServiceCredential
Assembly: CoreWCF.Primitives
File(s): /home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.Primitives/src/CoreWCF/Security/UserNamePasswordServiceCredential.cs
Line coverage
50%
Covered lines: 31
Uncovered lines: 31
Coverable lines: 62
Total lines: 173
Line coverage: 50%
Branch coverage
31%
Covered branches: 5
Total branches: 16
Branch coverage: 31.2%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity NPath complexity Sequence coverage
.cctor()100%11100%
.ctor()100%11100%
.ctor(...)100%11100%
GetUserNamePasswordValidator()50%6657.14%
MakeReadOnly()100%110%
ThrowIfImmutable()50%2266.66%

File(s)

/home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.Primitives/src/CoreWCF/Security/UserNamePasswordServiceCredential.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.Globalization;
 6using CoreWCF.IdentityModel.Selectors;
 7using CoreWCF.Runtime;
 8
 9namespace CoreWCF.Security
 10{
 11    public sealed class UserNamePasswordServiceCredential
 12    {
 13        internal const UserNamePasswordValidationMode DefaultUserNamePasswordValidationMode = UserNamePasswordValidation
 14        internal const bool DefaultCacheLogonTokens = false;
 15        internal const int DefaultMaxCachedLogonTokens = 128;
 16        internal const string DefaultCachedLogonTokenLifetimeString = "00:15:00";
 617        internal static readonly TimeSpan DefaultCachedLogonTokenLifetime = TimeSpan.Parse(DefaultCachedLogonTokenLifeti
 18        private UserNamePasswordValidationMode _validationMode = DefaultUserNamePasswordValidationMode;
 19        private UserNamePasswordValidator _validator;
 20        private readonly object _membershipProvider;
 11821        private bool _includeWindowsGroups = SspiSecurityTokenProvider.DefaultExtractWindowsGroupClaims;
 22        private bool _cacheLogonTokens = DefaultCacheLogonTokens;
 11823        private int _maxCachedLogonTokens = DefaultMaxCachedLogonTokens;
 11824        private TimeSpan _cachedLogonTokenLifetime = DefaultCachedLogonTokenLifetime;
 25        private bool _isReadOnly;
 26
 5227        internal UserNamePasswordServiceCredential()
 28        {
 29            // empty
 5230        }
 31
 6632        internal UserNamePasswordServiceCredential(UserNamePasswordServiceCredential other)
 33        {
 6634            _includeWindowsGroups = other._includeWindowsGroups;
 6635            _membershipProvider = other._membershipProvider;
 6636            _validationMode = other._validationMode;
 6637            _validator = other._validator;
 6638            _cacheLogonTokens = other._cacheLogonTokens;
 6639            _maxCachedLogonTokens = other._maxCachedLogonTokens;
 6640            _cachedLogonTokenLifetime = other._cachedLogonTokenLifetime;
 6641            _isReadOnly = other._isReadOnly;
 6642        }
 43
 44        public UserNamePasswordValidationMode UserNamePasswordValidationMode
 45        {
 46            get
 47            {
 1948                return _validationMode;
 49            }
 50            set
 51            {
 1952                UserNamePasswordValidationModeHelper.Validate(value);
 1953                ThrowIfImmutable();
 1954                if (value == UserNamePasswordValidationMode.MembershipProvider)
 55                {
 056                    throw new PlatformNotSupportedException("MembershipProvider not supported");
 57                }
 58
 1959                _validationMode = value;
 1960            }
 61        }
 62
 63        public UserNamePasswordValidator CustomUserNamePasswordValidator
 64        {
 65            get
 66            {
 067                return _validator;
 68            }
 69            set
 70            {
 1971                ThrowIfImmutable();
 1972                _validator = value;
 1973            }
 74        }
 75
 76        public bool IncludeWindowsGroups
 77        {
 78            get
 79            {
 080                return _includeWindowsGroups;
 81            }
 82            set
 83            {
 084                ThrowIfImmutable();
 085                _includeWindowsGroups = value;
 086            }
 87        }
 88
 89        public bool CacheLogonTokens
 90        {
 91            get
 92            {
 093                return _cacheLogonTokens;
 94            }
 95            set
 96            {
 097                ThrowIfImmutable();
 098                _cacheLogonTokens = value;
 099            }
 100        }
 101
 102        public int MaxCachedLogonTokens
 103        {
 104            get
 105            {
 0106                return _maxCachedLogonTokens;
 107            }
 108            set
 109            {
 0110                if (value <= 0)
 111                {
 0112                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(val
 113                }
 0114                ThrowIfImmutable();
 0115                _maxCachedLogonTokens = value;
 0116            }
 117        }
 118
 119        public TimeSpan CachedLogonTokenLifetime
 120        {
 121            get
 122            {
 0123                return _cachedLogonTokenLifetime;
 124            }
 125            set
 126            {
 0127                if (value <= TimeSpan.Zero)
 128                {
 0129                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(val
 130                }
 131
 0132                if (TimeoutHelper.IsTooLarge(value))
 133                {
 0134                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(val
 0135                        SRCommon.SFxTimeoutOutOfRangeTooBig));
 136                }
 0137                ThrowIfImmutable();
 0138                _cachedLogonTokenLifetime = value;
 0139            }
 140        }
 141
 142        internal UserNamePasswordValidator GetUserNamePasswordValidator()
 143        {
 15144            if (_validationMode == UserNamePasswordValidationMode.MembershipProvider)
 145            {
 0146                throw new PlatformNotSupportedException("MembershipProvider not supported");
 147            }
 15148            else if (_validationMode == UserNamePasswordValidationMode.Custom)
 149            {
 15150                if (_validator == null)
 151                {
 0152                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.MissingCu
 153                }
 15154                return _validator;
 155            }
 156
 0157            throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new NotSupportedException());
 158        }
 159
 160        internal void MakeReadOnly()
 161        {
 0162            _isReadOnly = true;
 0163        }
 164
 165        private void ThrowIfImmutable()
 166        {
 38167            if (_isReadOnly)
 168            {
 0169                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.ObjectIsReadO
 170            }
 38171        }
 172    }
 173}