< Summary - Syki

Information
Class: Syki.Back.Configs.RateLimiterConfigs
Assembly: Back
File(s): /home/runner/work/syki/syki/Back/Configs/RateLimiterConfigs.cs
Tag: 4_16869239191
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 =>
 62616                RateLimitPartition.GetFixedWindowLimiter(
 62617                    partitionKey: httpContext.Connection.RemoteIpAddress?.ToString(),
 62818                    factory: _ => new FixedWindowRateLimiterOptions
 62819                    {
 62820                        PermitLimit = settings.SuperVerySmall,
 62821                        Window = TimeSpan.FromHours(1)
 62822                    }));
 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 =>
 230834                RateLimitPartition.GetFixedWindowLimiter(
 230835                    partitionKey: httpContext.Connection.RemoteIpAddress?.ToString(),
 231036                    factory: _ => new FixedWindowRateLimiterOptions
 231037                    {
 231038                        PermitLimit = settings.Small,
 231039                        Window = TimeSpan.FromHours(1)
 231040                    }));
 241
 242            options.AddPolicy(nameof(settings.Medium), httpContext =>
 494043                RateLimitPartition.GetFixedWindowLimiter(
 494044                    partitionKey: httpContext.Connection.RemoteIpAddress?.ToString(),
 494245                    factory: _ => new FixedWindowRateLimiterOptions
 494246                    {
 494247                        PermitLimit = settings.Medium,
 494248                        Window = TimeSpan.FromHours(1)
 494249                    }));
 450        });
 251    }
 52}