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:
parent
ac38dc9c36
commit
322af1e54f
@ -14,6 +14,7 @@ import { conditionalMiddleware } from '../middleware';
|
|||||||
import EdgeController from './edge-api';
|
import EdgeController from './edge-api';
|
||||||
import { PublicInviteController } from './public-invite';
|
import { PublicInviteController } from './public-invite';
|
||||||
import { Db } from '../db/db';
|
import { Db } from '../db/db';
|
||||||
|
import { minutesToMilliseconds } from 'date-fns';
|
||||||
|
|
||||||
class IndexRouter extends Controller {
|
class IndexRouter extends Controller {
|
||||||
constructor(config: IUnleashConfig, services: IUnleashServices, db: Db) {
|
constructor(config: IUnleashConfig, services: IUnleashServices, db: Db) {
|
||||||
@ -30,8 +31,8 @@ class IndexRouter extends Controller {
|
|||||||
'/auth/simple',
|
'/auth/simple',
|
||||||
new SimplePasswordProvider(config, services).router,
|
new SimplePasswordProvider(config, services).router,
|
||||||
rateLimit({
|
rateLimit({
|
||||||
windowMs: 1 * 60 * 1000,
|
windowMs: minutesToMilliseconds(1),
|
||||||
max: 5,
|
max: 10,
|
||||||
standardHeaders: true,
|
standardHeaders: true,
|
||||||
legacyHeaders: false,
|
legacyHeaders: false,
|
||||||
}),
|
}),
|
||||||
|
@ -30,7 +30,7 @@ const password = 'DtUYwi&l5I1KX4@Le';
|
|||||||
let userService: UserService;
|
let userService: UserService;
|
||||||
let adminUser: IUser;
|
let adminUser: IUser;
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeEach(async () => {
|
||||||
db = await dbInit('simple_password_provider_api_serial', getLogger);
|
db = await dbInit('simple_password_provider_api_serial', getLogger);
|
||||||
stores = db.stores;
|
stores = db.stores;
|
||||||
app = await setupApp(stores);
|
app = await setupApp(stores);
|
||||||
@ -72,8 +72,8 @@ test('Can log in', async () => {
|
|||||||
.expect(200);
|
.expect(200);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Gets rate limited after 5 tries', async () => {
|
test('Gets rate limited after 10 tries', async () => {
|
||||||
for (let statusCode of [200, 200, 200, 200, 429]) {
|
for (let statusCode of [...Array(10).fill(200), 429]) {
|
||||||
await app.request
|
await app.request
|
||||||
.post('/auth/simple/login')
|
.post('/auth/simple/login')
|
||||||
.send({
|
.send({
|
||||||
|
Loading…
Reference in New Issue
Block a user