feat: добавил поддержку ограничения частоты запросов
Backend CI / build-and-test (push) Successful in 48s
Frontend CI / build-and-check (push) Failing after 23s
🚀 Create and publish a Docker image / Detect changes in backend and frontend (push) Successful in 9s
🚀 Create and publish a Docker image / Build & publish backend image (push) Successful in 1m21s
🚀 Create and publish a Docker image / Build & publish frontend image (push) Successful in 30s
🚀 Create and publish a Docker image / Update stack on Portainer (push) Successful in 7s
Backend CI / build-and-test (push) Successful in 48s
Frontend CI / build-and-check (push) Failing after 23s
🚀 Create and publish a Docker image / Detect changes in backend and frontend (push) Successful in 9s
🚀 Create and publish a Docker image / Build & publish backend image (push) Successful in 1m21s
🚀 Create and publish a Docker image / Build & publish frontend image (push) Successful in 30s
🚀 Create and publish a Docker image / Update stack on Portainer (push) Successful in 7s
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
using System.Net;
|
||||
using Microsoft.AspNetCore.Mvc.Testing;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using UniVerse.Api.Tests.Helpers;
|
||||
using Xunit;
|
||||
|
||||
namespace UniVerse.Api.Tests.RateLimiting;
|
||||
|
||||
public class RateLimitingTests
|
||||
{
|
||||
[Fact]
|
||||
public async Task GlobalRateLimiter_Returns429_WhenPartitionExceedsLimit()
|
||||
{
|
||||
await using var factory = new ApiWebApplicationFactory()
|
||||
.WithWebHostBuilder(builder =>
|
||||
{
|
||||
builder.ConfigureAppConfiguration((_, config) =>
|
||||
{
|
||||
config.AddInMemoryCollection(new Dictionary<string, string?>
|
||||
{
|
||||
["RateLimiting:PermitLimit"] = "1",
|
||||
["RateLimiting:WindowSeconds"] = "60",
|
||||
["RateLimiting:QueueLimit"] = "0"
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
using var client = factory.CreateClient();
|
||||
client.DefaultRequestHeaders.Add("Authorization", TestJwtFactory.BearerHeader("Student"));
|
||||
|
||||
using var firstResponse = await client.GetAsync("api/v1/tags");
|
||||
using var secondResponse = await client.GetAsync("api/v1/tags");
|
||||
|
||||
Assert.NotEqual(HttpStatusCode.TooManyRequests, firstResponse.StatusCode);
|
||||
Assert.Equal(HttpStatusCode.TooManyRequests, secondResponse.StatusCode);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user