< Summary

Information
Class: Elsa.ExternalAuthentication.Endpoints.Connections.ConnectionEndpointSupport
Assembly: Elsa.ExternalAuthentication
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.ExternalAuthentication/Endpoints/Connections/ConnectionEndpointSupport.cs
Line coverage
85%
Covered lines: 18
Uncovered lines: 3
Coverable lines: 21
Total lines: 55
Line coverage: 85.7%
Branch coverage
60%
Covered branches: 17
Total branches: 28
Branch coverage: 60.7%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
TryGetExpectedRevision(...)50%1212100%
SetEtag(...)100%11100%
SendMutationResultAsync(...)70%141066.66%
SendErrorAsync(...)100%11100%
SendErrorAsync(...)100%11100%
HasPermission(...)50%22100%
RequiresPolicyManagement(...)75%44100%
IsDatabaseOwned(...)100%11100%

File(s)

/home/runner/work/elsa-core/elsa-core/src/modules/Elsa.ExternalAuthentication/Endpoints/Connections/ConnectionEndpointSupport.cs

#LineLine coverage
 1using Elsa.Authorization;
 2using Elsa.ExternalAuthentication.Contracts;
 3using Elsa.ExternalAuthentication.Models;
 4using Elsa.ExternalAuthentication.Services;
 5using Microsoft.AspNetCore.Http;
 6using Microsoft.Extensions.DependencyInjection;
 7
 8namespace Elsa.ExternalAuthentication.Endpoints.Connections;
 9
 10internal static class ConnectionEndpointSupport
 11{
 12    public static bool TryGetExpectedRevision(HttpContext context, out long revision)
 13    {
 3014        revision = 0;
 3015        var value = context.Request.Headers.IfMatch.FirstOrDefault();
 3016        return !string.IsNullOrWhiteSpace(value) && value is ['"', _, ..] && value[^1] == '"' && long.TryParse(value[1..
 17    }
 18
 4019    public static void SetEtag(HttpContext context, long revision) => context.Response.Headers.ETag = $"\"{revision}\"";
 20
 1821    public static Task SendMutationResultAsync(HttpContext context, ManagementConnectionMutationResult result, IdentityP
 1822    {
 023        ManagementConnectionMutationResult.NotFound => SendErrorAsync(context, StatusCodes.Status404NotFound, "not_found
 024        ManagementConnectionMutationResult.Forbidden => SendErrorAsync(context, StatusCodes.Status403Forbidden, "forbidd
 425        ManagementConnectionMutationResult.Conflict conflict => SendErrorAsync(context, StatusCodes.Status409Conflict, "
 226        ManagementConnectionMutationResult.PreconditionFailed conflict => SendErrorAsync(context, StatusCodes.Status412P
 1227        ManagementConnectionMutationResult.ValidationFailed validation => SendErrorAsync(context, StatusCodes.Status400B
 028        _ => throw new InvalidOperationException("A successful connection mutation must be handled by the endpoint.")
 1829    };
 30
 31    public static Task SendErrorAsync(HttpContext context, int statusCode, string error, string message, object? details
 32    {
 2733        context.Response.StatusCode = statusCode;
 2734        return context.Response.WriteAsJsonAsync(
 2735            new ManagementErrorResponse(error, message, details, BrokerErrorFactory.CreateCorrelationId()),
 2736            cancellationToken);
 37    }
 38
 939    public static Task SendErrorAsync(HttpContext context, int statusCode, string error, string message, CancellationTok
 40
 41    /// <summary>
 42    /// Whether the acting user holds <paramref name="resource"/> and <paramref name="verb"/>.
 43    /// </summary>
 44    /// <remarks>
 45    /// These are the checks an endpoint makes after its own <c>RequirePermission</c> gate has passed, for the
 46    /// extra operations a single request can opt into: managing a policy, revoking sessions, or confirming an
 47    /// unsafe setting. Routing them through <see cref="IPermissionEvaluator"/> is what makes a wildcard grant
 48    /// mean the same thing here as it does on the gate itself. Comparing claim values directly, as this used
 49    /// to, also silently stopped matching anything once the legacy permission names were retired.
 50    /// </remarks>
 51    public static bool HasPermission(HttpContext context, string resource, string verb) =>
 1952        (context.RequestServices.GetService<IPermissionEvaluator>() ?? PermissionEvaluator.Shared).HasPermission(context
 4053    public static bool RequiresPolicyManagement(ConnectionRequest request) => request.UnlinkedPolicy is not null || requ
 3054    public static bool IsDatabaseOwned(EffectiveIdentityProviderConnection connection) => connection.Ownership == Connec
 55}