< Summary - CoreWCF Coverage — PR #1766

Information
Class: CoreWCF.AuthorizeRoleAttribute
Assembly: CoreWCF.Primitives
File(s): /home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.Primitives/src/CoreWCF/AuthorizeRoleAttribute.cs
Line coverage
80%
Covered lines: 12
Uncovered lines: 3
Coverable lines: 15
Total lines: 50
Line coverage: 80%
Branch coverage
66%
Covered branches: 8
Total branches: 12
Branch coverage: 66.6%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity NPath complexity Sequence coverage
.ctor(...)100%11100%
BuildClaim(...)66.66%121275%

File(s)

/home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.Primitives/src/CoreWCF/AuthorizeRoleAttribute.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 System.Text;
 7using CoreWCF.Description;
 8using CoreWCF.Dispatcher;
 9using CoreWCF.IdentityModel.Claims;
 10
 11namespace CoreWCF
 12{
 13    [AttributeUsage(CoreWCFAttributeTargets.OperationContract, Inherited = true)]
 14    public class AuthorizeRoleAttribute : Attribute, IAuthorizeOperation
 15    {
 16        private string[] _allowedRoles;
 17
 60518        public AuthorizeRoleAttribute(params string[] allowedRoles)
 19        {
 60520            _allowedRoles = allowedRoles;
 60521        }
 22
 23        public void BuildClaim(OperationDescription operationDescription, DispatchOperation dispatchOperation)
 24        {
 15825            if (operationDescription == null)
 26            {
 027                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(operationDescription));
 28            }
 29
 15830            if (dispatchOperation == null)
 31            {
 032                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(dispatchOperation));
 33            }
 15834            if (_allowedRoles == null || _allowedRoles.Length ==0)
 35            {
 036                return;
 37            }
 15838            List<Claim> allClaims = new List<Claim>();
 79039            foreach(string role in _allowedRoles)
 40            {
 23741                allClaims.Add(new Claim(ClaimTypes.Role, role.Trim(), Rights.Identity));
 42            }
 15843            if(allClaims.Count > 0)
 44            {
 15845                dispatchOperation.AuthorizeClaims.TryAdd(nameof(AuthorizeRoleAttribute), allClaims);
 46            }
 47
 15848        }
 49    }
 50}