mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2026-05-28 18:26:54 +00:00
test(api): flaky rate-limit test (#56120)
This commit is contained in:
committed by
GitHub
parent
fb1c2f1fc2
commit
5c4fd56e60
@@ -61,12 +61,16 @@ describe('auth0 routes', () => {
|
||||
});
|
||||
|
||||
it('should be rate-limited', async () => {
|
||||
await Promise.all(
|
||||
[...Array(10).keys()].map(() => superGet('/mobile-login'))
|
||||
);
|
||||
|
||||
// Rather than spamming the endpoint, we can check the headers.
|
||||
const res = await superGet('/mobile-login');
|
||||
expect(res.status).toBe(429);
|
||||
// These headers are semi-official
|
||||
// https://www.ietf.org/archive/id/draft-polli-ratelimit-headers-02.html
|
||||
// so should not depend on the details of the rate-limiting library
|
||||
expect(res.headers['ratelimit-limit']).toBe('10');
|
||||
expect(res.headers['ratelimit-remaining']).toBe('9');
|
||||
|
||||
const res2 = await superGet('/mobile-login');
|
||||
expect(res2.headers['ratelimit-remaining']).toBe('8');
|
||||
});
|
||||
|
||||
it('should return 401 if the authorization header is invalid', async () => {
|
||||
|
||||
Reference in New Issue
Block a user