< Summary

Information
Class: Syki.Back.Configs.RateLimiterConfigs
Assembly: Back
File(s): /home/runner/work/syki/syki/Back/Configs/RateLimiterConfigs.cs
Tag: 22_11348620282
Line coverage
36%
Covered lines: 18
Uncovered lines: 32
Coverable lines: 50
Total lines: 59
Line coverage: 36%
Branch coverage
16%
Covered branches: 2
Total branches: 12
Branch coverage: 16.6%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
AddRateLimiterConfigs(...)16.66%49.751236%

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 IServiceCollection services)
 8    {
 19        services.AddRateLimiter(options =>
 110        {
 111            options.RejectionStatusCode = StatusCodes.Status429TooManyRequests;
 112
 113            if (Env.IsTesting() || Env.IsDevelopment())
 114            {
 415                options.AddFixedWindowLimiter("SuperVerySmall", o => { o.PermitLimit = 10_000; o.Window = TimeSpan.FromH
 416                options.AddFixedWindowLimiter("VerySmall", o => { o.PermitLimit = 10_000; o.Window = TimeSpan.FromHours(
 417                options.AddFixedWindowLimiter("Small", o => { o.PermitLimit = 10_000; o.Window = TimeSpan.FromHours(1); 
 418                options.AddFixedWindowLimiter("Medium", o => { o.PermitLimit = 10_000; o.Window = TimeSpan.FromHours(1);
 119                return;
 120            }
 121
 022            options.AddPolicy("SuperVerySmall", httpContext =>
 023                RateLimitPartition.GetFixedWindowLimiter(
 024                    partitionKey: httpContext.Connection.RemoteIpAddress?.ToString(),
 025                    factory: _ => new FixedWindowRateLimiterOptions
 026                    {
 027                        PermitLimit = 2,
 028                        Window = TimeSpan.FromHours(1)
 029                    }));
 130
 031            options.AddPolicy("VerySmall", httpContext =>
 032                RateLimitPartition.GetFixedWindowLimiter(
 033                    partitionKey: httpContext.Connection.RemoteIpAddress?.ToString(),
 034                    factory: _ => new FixedWindowRateLimiterOptions
 035                    {
 036                        PermitLimit = 10,
 037                        Window = TimeSpan.FromHours(1)
 038                    }));
 139
 040            options.AddPolicy("Small", httpContext =>
 041                RateLimitPartition.GetFixedWindowLimiter(
 042                    partitionKey: httpContext.Connection.RemoteIpAddress?.ToString(),
 043                    factory: _ => new FixedWindowRateLimiterOptions
 044                    {
 045                        PermitLimit = 20,
 046                        Window = TimeSpan.FromHours(1)
 047                    }));
 148
 049            options.AddPolicy("Medium", httpContext =>
 050                RateLimitPartition.GetFixedWindowLimiter(
 051                    partitionKey: httpContext.Connection.RemoteIpAddress?.ToString(),
 052                    factory: _ => new FixedWindowRateLimiterOptions
 053                    {
 054                        PermitLimit = 120,
 055                        Window = TimeSpan.FromHours(1)
 056                    }));
 157        });
 158    }
 59}