backend: Rate limit login attempts per email and IP
This commit is contained in:
1 parent
5470818841
commit
52fb8af684
18 files changed
+106
-116
No files matched your search
@@ -1,4 +1,6 @@
|
||||
using System.Net;
|
||||
using System.Text.Json;
|
||||
using Helpdesk.Application.Auth;
|
||||
using Microsoft.AspNetCore.TestHost;
|
||||
using static Helpdesk.IntegrationTests.BackendFixture;
|
||||
|
||||
@@ -16,16 +18,16 @@ public sealed class ProxyRateLimitTests(BackendFixture fixture) : IClassFixture<
|
||||
await using var api = fixture.CreateApiBehindProxies(externalProxy, web);
|
||||
|
||||
for (var attempt = 0; attempt < 20; attempt++)
|
||||
Assert.Equal(401, await LoginAsync(api.Server, web, firstClient));
|
||||
Assert.Equal(401, await LoginAsync(api.Server, web, firstClient, $"absent-{attempt}@example.test"));
|
||||
|
||||
Assert.Equal(429, await LoginAsync(api.Server, externalProxy, firstClient));
|
||||
Assert.Equal(401, await LoginAsync(api.Server, web, secondClient));
|
||||
Assert.Equal(429, await LoginAsync(api.Server, $"::ffff:{firstClient}", secondClient));
|
||||
Assert.Equal(429, await LoginAsync(api.Server, externalProxy, firstClient, "[email protected]"));
|
||||
Assert.Equal(401, await LoginAsync(api.Server, web, secondClient, "[email protected]"));
|
||||
Assert.Equal(429, await LoginAsync(api.Server, $"::ffff:{firstClient}", secondClient, "[email protected]"));
|
||||
}
|
||||
|
||||
private static async Task<int> LoginAsync(TestServer server, string peer, string client)
|
||||
private static async Task<int> LoginAsync(TestServer server, string peer, string client, string email)
|
||||
{
|
||||
using var body = new MemoryStream("""{"email":"absent@example.test","password":"test-password"}"""u8.ToArray());
|
||||
using var body = new MemoryStream(JsonSerializer.SerializeToUtf8Bytes(new LoginRequest(email, "test-password")));
|
||||
var response = await server.SendAsync(context =>
|
||||
{
|
||||
context.Connection.RemoteIpAddress = IPAddress.Parse(peer);
|
||||
|
||||
Reference in new issue
Block a user