< Summary - Kestrun — Combined Coverage

Information
Class: Kestrun.Claims.ClaimPolicyExtensions
Assembly: Kestrun
File(s): /home/runner/work/Kestrun/Kestrun/src/CSharp/Kestrun/Claims/ClaimPolicyExtensions.cs
Tag: Kestrun/Kestrun@9d3a582b2d63930269564a7591aa77ef297cadeb
Line coverage
100%
Covered lines: 8
Uncovered lines: 0
Coverable lines: 8
Total lines: 26
Line coverage: 100%
Branch coverage
100%
Covered branches: 2
Total branches: 2
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Coverage history

Coverage history 0 25 50 75 100

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
ToAuthzDelegate(...)100%22100%

File(s)

/home/runner/work/Kestrun/Kestrun/src/CSharp/Kestrun/Claims/ClaimPolicyExtensions.cs

#LineLine coverage
 1using Microsoft.AspNetCore.Authorization;
 2
 3namespace Kestrun.Claims;
 4
 5
 6/// <summary>
 7/// Extension methods for converting ClaimPolicyConfig into ASP.NET Core authorization setup.
 8/// </summary>
 9public static class ClaimPolicyExtensions
 10{
 11    /// <summary>
 12    /// Turns <see cref="ClaimPolicyConfig"/> into the delegate that
 13    /// <c>services.AddAuthorization(...)</c> needs.
 14    /// </summary>
 15    /// <param name="cfg">The claim-based policy configuration.</param>
 16    /// <returns>An <see cref="Action{AuthorizationOptions}"/> that registers all policies.</returns>
 17    public static Action<AuthorizationOptions> ToAuthzDelegate(this ClaimPolicyConfig cfg)
 1018        => options =>
 1019        {
 4420            foreach (var (name, rule) in cfg.Policies)
 1021            {
 1222                options.AddPolicy(name, p =>
 2423                    p.RequireClaim(rule.ClaimType, rule.AllowedValues));
 1024            }
 2025        };
 26}