< Summary - CoreWCF Coverage — PR #1766

Information
Class: CoreWCF.Primitives.Tests.CustomSecurity.MyAsyncTestServiceAuthorizationManager
Assembly: UnitTests.Common
File(s): /home/runner/work/CoreWCF/CoreWCF/src/Common/UnitTests.Common/CustomSecurity/MyTestServiceAuthorizationManager.cs
Line coverage
100%
Covered lines: 1
Uncovered lines: 0
Coverable lines: 1
Total lines: 55
Line coverage: 100%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity NPath complexity Sequence coverage
CheckAccessCoreAsync(...)100%11100%

File(s)

/home/runner/work/CoreWCF/CoreWCF/src/Common/UnitTests.Common/CustomSecurity/MyTestServiceAuthorizationManager.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.Threading.Tasks;
 6using CoreWCF.IdentityModel.Claims;
 7
 8namespace CoreWCF.Primitives.Tests.CustomSecurity
 9{
 10    public abstract class MyTestServiceAuthorizationManagerBase : ServiceAuthorizationManager
 11    {
 12        protected Func<OperationContext, bool> Logic = (OperationContext operationContext) =>
 13        {
 14            // Extract the action URI from the OperationContext. Match this against the claims
 15            // in the AuthorizationContext.
 16            string action = operationContext.RequestContext.RequestMessage.Headers.Action;
 17            // Iterate through the various claim sets in the AuthorizationContext.
 18            bool isWIndowIdentity = false;
 19            foreach (ClaimSet cs in operationContext.ServiceSecurityContext.AuthorizationContext.ClaimSets)
 20            {
 21                // Examine only those claim sets issued by System.
 22                if (cs.Issuer == ClaimSet.System)
 23                {
 24                    foreach (Claim c in cs.FindClaims("http://tempuri.org/claims/allowedoperation",
 25                                 Rights.PossessProperty))
 26                    {
 27                        // If the Claim resource matches the action URI then return true to allow access.
 28                        if (action == c.Resource.ToString())
 29                        {
 30                            return true;
 31                        }
 32                    }
 33                }
 34                else if (cs.Issuer == ClaimSet.Windows)
 35                {
 36                    isWIndowIdentity = true; // unconditionally for windows
 37                }
 38            }
 39
 40            // If this point is reached, return false to deny access.
 41            return isWIndowIdentity || false;
 42        };
 43    }
 44
 45    public class MySyncTestServiceAuthorizationManager : MyTestServiceAuthorizationManagerBase
 46    {
 47        [Obsolete("Implementers should override CheckAccessCoreAsync.")]
 48        protected override bool CheckAccessCore(OperationContext operationContext) => Logic(operationContext);
 49    }
 50
 51    public class MyAsyncTestServiceAuthorizationManager : MyTestServiceAuthorizationManagerBase
 52    {
 253        protected override ValueTask<bool> CheckAccessCoreAsync(OperationContext operationContext) => new(Logic(operatio
 54    }
 55}