feat(core): Rate-limit login endpoint to mitigate brute force password guessing attacks (#9028)
This commit is contained in:
committed by
कारतोफ्फेलस्क्रिप्ट™
parent
4668db20fb
commit
a6446fe057
40
packages/cli/test/unit/decorators/registerController.test.ts
Normal file
40
packages/cli/test/unit/decorators/registerController.test.ts
Normal file
@@ -0,0 +1,40 @@
|
||||
jest.mock('@/constants', () => ({
|
||||
inE2ETests: false,
|
||||
inTest: false,
|
||||
}));
|
||||
|
||||
import express from 'express';
|
||||
import { agent as testAgent } from 'supertest';
|
||||
|
||||
import { Get, RestController, registerController } from '@/decorators';
|
||||
import { AuthService } from '@/auth/auth.service';
|
||||
import { mockInstance } from '../../shared/mocking';
|
||||
|
||||
describe('registerController', () => {
|
||||
@RestController('/test')
|
||||
class TestController {
|
||||
@Get('/unlimited', { skipAuth: true })
|
||||
@Get('/rate-limited', { skipAuth: true, rateLimit: true })
|
||||
endpoint() {
|
||||
return { ok: true };
|
||||
}
|
||||
}
|
||||
|
||||
mockInstance(AuthService);
|
||||
const app = express();
|
||||
registerController(app, TestController);
|
||||
const agent = testAgent(app);
|
||||
|
||||
it('should not rate-limit by default', async () => {
|
||||
for (let i = 0; i < 6; i++) {
|
||||
await agent.get('/rest/test/unlimited').expect(200);
|
||||
}
|
||||
});
|
||||
|
||||
it('should rate-limit when configured', async () => {
|
||||
for (let i = 0; i < 5; i++) {
|
||||
await agent.get('/rest/test/rate-limited').expect(200);
|
||||
}
|
||||
await agent.get('/rest/test/rate-limited').expect(429);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user