From 5ff018772ec0dd1459f664f19dfb981a2d8d5979 Mon Sep 17 00:00:00 2001 From: Kamil Kalisz Date: Sat, 21 Nov 2026 00:09:25 +0100 Subject: [PATCH] test(auth): multi-user still challenges a header-less request during lockout The single-user suite pinned this; the multi-user one only showed that header-less requests are not counted. Fill the per-IP bucket with malformed headers, then expect 401 + challenge for no header and 429 for another malformed one. Fails on master. Co-Authored-By: Claude Opus 5.5 --- test/multiuser-auth.test.ts | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/test/multiuser-auth.test.ts b/test/multiuser-auth.test.ts index 83492170..7982d082 100644 --- a/test/multiuser-auth.test.ts +++ b/test/multiuser-auth.test.ts @@ -304,6 +304,20 @@ describe('multi-user auth', () => { expect((await malformed()).statusCode).toBe(429); }); + it('requests without credentials still get the challenge while the IP is locked out', async () => { + const { app } = await startIpServer(); + const ip = '203.0.113.42'; + const malformed = () => + app.inject({ method: 'GET', url: '/api/status', headers: { authorization: 'Bearer x' }, remoteAddress: ip }); + for (let i = 0; i < AUTH_IP_FAILURE_MAX; i++) await malformed(); + + // A 429 never makes a browser show its login dialog; a 401 challenge does. + const bare = await app.inject({ method: 'GET', url: '/api/status', remoteAddress: ip }); + expect(bare.statusCode).toBe(401); + expect(bare.headers['www-authenticate']).toBe('Basic realm="Codeman"'); + expect((await malformed()).statusCode).toBe(429); + }); + it('per-IP pre-gate: a concurrent burst from one IP reaches the verify at most AUTH_IP_FAILURE_MAX times', async () => { const { login, buckets } = await startIpServer(); const ip = '203.0.113.40';