1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-01-20 00:08:02 +01:00

feat: update rate-limit (#3248)

https://linear.app/unleash/issue/2-732/rate-limit-auth-endpoints-in-enterprise

Updates the rate-limit to reflect the [recent rate-limiting in
Enterprise](https://github.com/ivarconr/unleash-enterprise/pull/381).
This commit is contained in:
Nuno Góis 2023-03-03 12:09:28 +00:00 committed by GitHub
parent ac38dc9c36
commit 322af1e54f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 5 deletions

View File

@ -14,6 +14,7 @@ import { conditionalMiddleware } from '../middleware';
import EdgeController from './edge-api';
import { PublicInviteController } from './public-invite';
import { Db } from '../db/db';
import { minutesToMilliseconds } from 'date-fns';
class IndexRouter extends Controller {
constructor(config: IUnleashConfig, services: IUnleashServices, db: Db) {
@ -30,8 +31,8 @@ class IndexRouter extends Controller {
'/auth/simple',
new SimplePasswordProvider(config, services).router,
rateLimit({
windowMs: 1 * 60 * 1000,
max: 5,
windowMs: minutesToMilliseconds(1),
max: 10,
standardHeaders: true,
legacyHeaders: false,
}),

View File

@ -30,7 +30,7 @@ const password = 'DtUYwi&l5I1KX4@Le';
let userService: UserService;
let adminUser: IUser;
beforeAll(async () => {
beforeEach(async () => {
db = await dbInit('simple_password_provider_api_serial', getLogger);
stores = db.stores;
app = await setupApp(stores);
@ -72,8 +72,8 @@ test('Can log in', async () => {
.expect(200);
});
test('Gets rate limited after 5 tries', async () => {
for (let statusCode of [200, 200, 200, 200, 429]) {
test('Gets rate limited after 10 tries', async () => {
for (let statusCode of [...Array(10).fill(200), 429]) {
await app.request
.post('/auth/simple/login')
.send({