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 tests/unit/rate-limit-key.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,17 @@ describe('keyByAuthKeyOrIp', () => {
const b = keyByAuthKeyOrIp(fakeReq({ ip: '2001:db8:1234:5700::1' }));
expect(a).not.toBe(b);
});

test('falls back to req.socket.remoteAddress when req.ip is missing', () => {
// #287 swapped the deprecated req.connection for req.socket.
// Exercise the fallback explicitly: no authKey, no req.ip, but
// req.socket.remoteAddress is set — the keygen should pick it
// up and route it through the IPv6/IPv4-aware helper.
const req = {
get: () => undefined,
socket: { remoteAddress: '10.20.30.40' },
};
const k = keyByAuthKeyOrIp(req);
expect(k).toBe('ip:10.20.30.40');
});
});