< Summary - Syki

Information
Class: Syki.Back.Configs.RateLimiterConfigs
Assembly: Back
File(s): /home/runner/work/syki/syki/Back/Configs/RateLimiterConfigs.cs
Tag: 21_17346963026
Line coverage
100%
Covered lines: 42
Uncovered lines: 0
Coverable lines: 42
Total lines: 52
Line coverage: 100%
Branch coverage
70%
Covered branches: 17
Total branches: 24
Branch coverage: 70.8%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
AddRateLimiterConfigs(...)70.83%2424100%

File(s)

/home/runner/work/syki/syki/Back/Configs/RateLimiterConfigs.cs

#LineLine coverage
 1using System.Threading.RateLimiting;
 2
 3namespace Syki.Back.Configs;
 4
 5public static class RateLimiterConfigs
 6{
 7    public static void AddRateLimiterConfigs(this WebApplicationBuilder builder)
 8    {
 29        var settings = new RateLimiterSettings(builder.Configuration);
 10
 211        builder.Services.AddRateLimiter(options =>
 212        {
 213            options.RejectionStatusCode = StatusCodes.Status429TooManyRequests;
 214
 215            options.AddPolicy(nameof(settings.SuperVerySmall), httpContext =>
 69016                RateLimitPartition.GetFixedWindowLimiter(
 69017                    partitionKey: httpContext.Connection.RemoteIpAddress?.ToString(),
 69218                    factory: _ => new FixedWindowRateLimiterOptions
 69219                    {
 69220                        PermitLimit = settings.SuperVerySmall,
 69221                        Window = TimeSpan.FromHours(1)
 69222                    }));
 223
 224            options.AddPolicy(nameof(settings.VerySmall), httpContext =>
 225                RateLimitPartition.GetFixedWindowLimiter(
 226                    partitionKey: httpContext.Connection.RemoteIpAddress?.ToString(),
 227                    factory: _ => new FixedWindowRateLimiterOptions
 228                    {
 229                        PermitLimit = settings.VerySmall,
 230                        Window = TimeSpan.FromHours(1)
 231                    }));
 232
 233            options.AddPolicy(nameof(settings.Small), httpContext =>
 243634                RateLimitPartition.GetFixedWindowLimiter(
 243635                    partitionKey: httpContext.Connection.RemoteIpAddress?.ToString(),
 243836                    factory: _ => new FixedWindowRateLimiterOptions
 243837                    {
 243838                        PermitLimit = settings.Small,
 243839                        Window = TimeSpan.FromHours(1)
 243840                    }));
 241
 242            options.AddPolicy(nameof(settings.Medium), httpContext =>
 556243                RateLimitPartition.GetFixedWindowLimiter(
 556244                    partitionKey: httpContext.Connection.RemoteIpAddress?.ToString(),
 556445                    factory: _ => new FixedWindowRateLimiterOptions
 556446                    {
 556447                        PermitLimit = settings.Medium,
 556448                        Window = TimeSpan.FromHours(1)
 556449                    }));
 450        });
 251    }
 52}