< Summary

Information
Class: Elsa.ExternalAuthentication.Services.ExternalAuthenticationCallbackUris
Assembly: Elsa.ExternalAuthentication
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.ExternalAuthentication/Services/ExternalAuthenticationCallbackUris.cs
Line coverage
93%
Covered lines: 15
Uncovered lines: 1
Coverable lines: 16
Total lines: 33
Line coverage: 93.7%
Branch coverage
66%
Covered branches: 4
Total branches: 6
Branch coverage: 66.6%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
GetAuthorizationCallbackUri(...)75%4483.33%
GetLogoutCallbackUri(...)100%11100%
AppendPath(...)50%22100%

File(s)

/home/runner/work/elsa-core/elsa-core/src/modules/Elsa.ExternalAuthentication/Services/ExternalAuthenticationCallbackUris.cs

#LineLine coverage
 1using Elsa.ExternalAuthentication.Models;
 2
 3namespace Elsa.ExternalAuthentication.Services;
 4
 5/// <summary>Builds Elsa-owned upstream callback URIs without allowing a configured base path to be discarded.</summary>
 6public static class ExternalAuthenticationCallbackUris
 7{
 8    /// <summary>Returns the provider callback for a normal external sign-in or an administrator preview.</summary>
 829    public static Uri GetAuthorizationCallbackUri(Uri externalCallbackBaseUri, IdentityProviderConnection connection, Br
 8210    {
 4511        BrokerTransactionPurpose.ExternalSignIn => AppendPath(externalCallbackBaseUri, $"external-authentication/callbac
 3712        BrokerTransactionPurpose.Preview => AppendPath(externalCallbackBaseUri, $"external-authentication/previews/callb
 013        _ => throw new InvalidOperationException($"Broker transaction purpose '{purpose}' cannot initiate an upstream au
 8214    };
 15
 16    /// <summary>Returns the provider callback for a broker-initiated upstream logout.</summary>
 17    public static Uri GetLogoutCallbackUri(Uri externalCallbackBaseUri, string connectionKey) =>
 218        AppendPath(externalCallbackBaseUri, $"external-authentication/logout/callback/{Uri.EscapeDataString(ConnectionRe
 19
 20    private static Uri AppendPath(Uri externalCallbackBaseUri, string relativePath)
 21    {
 8422        ArgumentNullException.ThrowIfNull(externalCallbackBaseUri);
 23
 8424        var builder = new UriBuilder(externalCallbackBaseUri)
 8425        {
 8426            Path = $"{externalCallbackBaseUri.AbsolutePath.TrimEnd('/')}/{relativePath.TrimStart('/')}",
 8427            Query = string.Empty,
 8428            Fragment = string.Empty,
 8429            Port = externalCallbackBaseUri.IsDefaultPort ? -1 : externalCallbackBaseUri.Port
 8430        };
 8431        return builder.Uri;
 32    }
 33}