< Summary

Information
Class: ArturRios.Util.WebApi.Security.Extensions.EndpointMetadataExtensions
Assembly: ArturRios.Util.WebApi
File(s): /home/runner/work/dotnet-webapi-util/dotnet-webapi-util/src/Security/Extensions/EndpointMetadataExtensions.cs
Line coverage
100%
Covered lines: 2
Uncovered lines: 0
Coverable lines: 2
Total lines: 26
Line coverage: 100%
Branch coverage
100%
Covered branches: 2
Total branches: 2
Branch coverage: 100%
Method coverage
100%
Covered methods: 2
Fully covered methods: 2
Total methods: 2
Method coverage: 100%
Full method coverage: 100%

Metrics

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

File(s)

/home/runner/work/dotnet-webapi-util/dotnet-webapi-util/src/Security/Extensions/EndpointMetadataExtensions.cs

#LineLine coverage
 1using Microsoft.AspNetCore.Authorization;
 2using Microsoft.AspNetCore.Http;
 3using Microsoft.AspNetCore.Mvc.Abstractions;
 4
 5namespace ArturRios.Util.WebApi.Security.Extensions;
 6
 7/// <summary>Detects endpoints exempt from authentication, marked with this library's
 8/// <see cref="Attributes.AllowAnonymousAttribute"/> or ASP.NET Core's own <c>[AllowAnonymous]</c>.</summary>
 9internal static class EndpointMetadataExtensions
 10{
 11    /// <param name="endpoint">The endpoint the request was routed to, if any.</param>
 12    extension(Endpoint? endpoint)
 13    {
 14        /// <summary>Whether the endpoint carries <see cref="IAllowAnonymous"/> metadata.</summary>
 15        public bool AllowsAnonymous() =>
 1616            endpoint?.Metadata.GetMetadata<IAllowAnonymous>() is not null;
 17    }
 18
 19    /// <param name="actionDescriptor">The MVC action being authorized.</param>
 20    extension(ActionDescriptor actionDescriptor)
 21    {
 22        /// <summary>Whether the action carries <see cref="IAllowAnonymous"/> metadata, at action or controller level.</
 23        public bool AllowsAnonymous() =>
 1124            actionDescriptor.EndpointMetadata.OfType<IAllowAnonymous>().Any();
 25    }
 26}