< Summary

Information
Class: Elsa.Extensions.ApplicationBuilderExtensions
Assembly: Elsa.Http
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Http/Extensions/ApplicationBuilderExtensions.cs
Line coverage
92%
Covered lines: 13
Uncovered lines: 1
Coverable lines: 14
Total lines: 58
Line coverage: 92.8%
Branch coverage
66%
Covered branches: 8
Total branches: 12
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
UseWorkflows(...)100%11100%
UseWorkflowsRateLimiting(...)50%22100%
UseWorkflowsRateLimiting(...)66.66%6683.33%
NormalizeBasePath(...)75%4480%

File(s)

/home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Http/Extensions/ApplicationBuilderExtensions.cs

#LineLine coverage
 1using Elsa.Http.Middleware;
 2using Microsoft.AspNetCore.Builder;
 3using Microsoft.AspNetCore.Http;
 4
 5// ReSharper disable once CheckNamespace
 6namespace Elsa.Extensions;
 7
 8/// <summary>
 9/// Adds extension methods to <see cref="IApplicationBuilder"/> related to workflow middleware components.
 10/// </summary>
 11public static class ApplicationBuilderExtensions
 12{
 13    /// <summary>
 14    /// Installs the <see cref="HttpWorkflowsMiddleware"/> component.
 15    /// </summary>
 316    public static IApplicationBuilder UseWorkflows(this IApplicationBuilder app) => app.UseMiddleware<HttpWorkflowsMiddl
 17
 18    /// <summary>
 19    /// Applies an ASP.NET Core rate limiting policy to inbound HTTP workflow trigger routes.
 20    /// </summary>
 21    /// <param name="app">The application builder.</param>
 22    /// <param name="basePath">The HTTP workflow trigger base path to protect.</param>
 23    /// <param name="policyName">The registered ASP.NET Core rate limiting policy name. Leave empty to skip rate limitin
 24    public static IApplicationBuilder UseWorkflowsRateLimiting(this IApplicationBuilder app, PathString? basePath, strin
 25    {
 326        var normalizedBasePath = basePath?.ToString();
 327        return app.UseWorkflowsRateLimiting(normalizedBasePath, policyName);
 28    }
 29
 30    /// <summary>
 31    /// Applies an ASP.NET Core rate limiting policy to inbound HTTP workflow trigger routes.
 32    /// </summary>
 33    /// <param name="app">The application builder.</param>
 34    /// <param name="basePath">The HTTP workflow trigger base path to protect.</param>
 35    /// <param name="policyName">The registered ASP.NET Core rate limiting policy name. Leave empty to skip rate limitin
 36    public static IApplicationBuilder UseWorkflowsRateLimiting(this IApplicationBuilder app, string? basePath, string? p
 37    {
 1138        if (string.IsNullOrWhiteSpace(policyName) || string.IsNullOrWhiteSpace(basePath))
 339            return app;
 40
 841        var pathPrefix = NormalizeBasePath(basePath);
 842        return pathPrefix.HasValue
 843            ? app.UseRateLimitingPolicyForPath(pathPrefix, policyName, "Elsa HTTP workflow trigger rate limiting endpoin
 844            : app;
 45    }
 46
 47    private static PathString NormalizeBasePath(string basePath)
 48    {
 849        var value = basePath.Trim();
 50
 851        if (string.IsNullOrEmpty(value))
 052            return PathString.Empty;
 53
 854        value = value.Trim('/');
 55
 856        return string.IsNullOrEmpty(value) ? PathString.Empty : new PathString("/" + value);
 57    }
 58}