< Summary - CoreWCF Coverage — PR #1766

Information
Class: CoreWCF.IdentityModel.Selectors.CustomUserNameSecurityTokenAuthenticator
Assembly: CoreWCF.Primitives
File(s): /home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.Primitives/src/CoreWCF/IdentityModel/Selectors/CustomUserNameSecurityTokenAuthenticator.cs
Line coverage
94%
Covered lines: 17
Uncovered lines: 1
Coverable lines: 18
Total lines: 51
Line coverage: 94.4%
Branch coverage
50%
Covered branches: 2
Total branches: 4
Branch coverage: 50%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity NPath complexity Sequence coverage
.ctor(...)50%22100%
ValidateUserNamePasswordCoreAsync()100%11100%
.ctor(...)50%2290.9%

File(s)

/home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.Primitives/src/CoreWCF/IdentityModel/Selectors/CustomUserNameSecurityTokenAuthenticator.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.Collections.Generic;
 5using System.Collections.ObjectModel;
 6using System.Security.Principal;
 7using System.Threading.Tasks;
 8using CoreWCF.IdentityModel.Claims;
 9using CoreWCF.IdentityModel.Policy;
 10using CoreWCF.Security;
 11
 12namespace CoreWCF.IdentityModel.Selectors
 13{
 14    public class CustomUserNameSecurityTokenAuthenticator : UserNameSecurityTokenAuthenticator
 15    {
 16        private readonly UserNamePasswordValidator _validator;
 17
 1718        public CustomUserNameSecurityTokenAuthenticator(UserNamePasswordValidator validator)
 19        {
 1720            _validator = validator ?? throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(validator)
 1721        }
 22
 23        protected override async ValueTask<ReadOnlyCollection<IAuthorizationPolicy>> ValidateUserNamePasswordCoreAsync(s
 24        {
 1625            await _validator.ValidateAsync(userName, password);
 1226            return SecurityUtils.CreateAuthorizationPolicies(new UserNameClaimSet(userName, _validator.GetType().Name));
 1227        }
 28
 29        private class UserNameClaimSet : DefaultClaimSet, IIdentityInfo
 30        {
 1231            public UserNameClaimSet(string userName, string authType)
 32            {
 1233                if (userName == null)
 34                {
 035                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(userName));
 36                }
 37
 1238                Identity = SecurityUtils.CreateIdentity(userName, authType);
 39
 1240                List<Claim> claims = new List<Claim>(2)
 1241                {
 1242                    new Claim(ClaimTypes.Name, userName, Rights.Identity),
 1243                    Claim.CreateNameClaim(userName)
 1244                };
 1245                Initialize(System, claims);
 1246            }
 47
 1248            public IIdentity Identity { get; }
 49        }
 50    }
 51}