Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions backend/__tests__/unit/middleware/platformRateLimit.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,19 @@ describe('platformIpRateLimit — the bucket is the caller', () => {
await probe(app, { 'cf-connecting-ip': '203.0.113.8' }).expect(429);
});

test('header-free req.ip has a limited bucket independent of CF clients', async () => {
const app = buildApp({ windowMs: 60000, limit: 1, label: 'fallback proof' });
// All requests share Supertest's loopback req.ip. Only these two carry
// distinct edge client addresses; exhausting one must not affect either
// the other CF client or the header-free fallback.
await probe(app, { 'cf-connecting-ip': '203.0.113.20' }).expect(200);
await probe(app, { 'cf-connecting-ip': '203.0.113.20' }).expect(429);
await probe(app).expect(200);
await probe(app).expect(429);
await probe(app, { 'cf-connecting-ip': '203.0.113.21' }).expect(200);
await probe(app, { 'cf-connecting-ip': '203.0.113.21' }).expect(429);
});

test('the budget is enforced per caller, so the shared bucket is not what expires', async () => {
const app = buildApp({ windowMs: 60000, limit: 2, label: 'test budget' });
const spendTwo = async (ip) => {
Expand Down
Loading