< Summary - CoreWCF Coverage — PR #1766

Information
Class: CoreWCF.Primitives.Tests.CustomSecurity.MyTestServiceAuthorizationManagerBase
Assembly: UnitTests.Common
File(s): /home/runner/work/CoreWCF/CoreWCF/src/Common/UnitTests.Common/CustomSecurity/MyTestServiceAuthorizationManager.cs
Line coverage
93%
Covered lines: 29
Uncovered lines: 2
Coverable lines: 31
Total lines: 55
Line coverage: 93.5%
Branch coverage
80%
Covered branches: 8
Total branches: 10
Branch coverage: 80%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity NPath complexity Sequence coverage
.ctor()80%101093.54%

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    {
 412        protected Func<OperationContext, bool> Logic = (OperationContext operationContext) =>
 413        {
 414            // Extract the action URI from the OperationContext. Match this against the claims
 415            // in the AuthorizationContext.
 416            string action = operationContext.RequestContext.RequestMessage.Headers.Action;
 417            // Iterate through the various claim sets in the AuthorizationContext.
 418            bool isWIndowIdentity = false;
 1419            foreach (ClaimSet cs in operationContext.ServiceSecurityContext.AuthorizationContext.ClaimSets)
 420            {
 421                // Examine only those claim sets issued by System.
 422                if (cs.Issuer == ClaimSet.System)
 423                {
 1824                    foreach (Claim c in cs.FindClaims("http://tempuri.org/claims/allowedoperation",
 425                                 Rights.PossessProperty))
 426                    {
 427                        // If the Claim resource matches the action URI then return true to allow access.
 628                        if (action == c.Resource.ToString())
 429                        {
 230                            return true;
 431                        }
 432                    }
 433                }
 034                else if (cs.Issuer == ClaimSet.Windows)
 435                {
 036                    isWIndowIdentity = true; // unconditionally for windows
 437                }
 438            }
 439
 440            // If this point is reached, return false to deny access.
 241            return isWIndowIdentity || false;
 642        };
 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    {
 53        protected override ValueTask<bool> CheckAccessCoreAsync(OperationContext operationContext) => new(Logic(operatio
 54    }
 55}

Methods/Properties

.ctor()