ci: expand CI checks and make consumer sync opt-in
- Add Go, npm, Python, and Java validation to CI - Run Go tests against PostgreSQL - Record performance fixes in the report
This commit is contained in:
1 parent
199a5efaef
commit
22887fef03
100 files changed
+9740
-429
No files matched your search
@@ -108,6 +108,43 @@ test('validate throws InvalidSessionError when AuthGuard reports invalid', async
|
||||
await assert.rejects(() => client.validate('bad-token'), InvalidSessionError);
|
||||
});
|
||||
|
||||
test('validate reuses a positive and a negative answer within the cache window', async () => {
|
||||
const fetchImpl = recordingFetch([
|
||||
{ status: 200, body: { valid: true, user_id: 7, username: 'gabriel', role: 'admin' } },
|
||||
{ status: 401, body: { valid: false } },
|
||||
]);
|
||||
const client = new AuthClient('https://auth.example.com', { fetchImpl });
|
||||
assert.deepEqual(await client.validate('good-token'), { id: 7, username: 'gabriel', role: 'admin' });
|
||||
assert.deepEqual(await client.validate('good-token'), { id: 7, username: 'gabriel', role: 'admin' });
|
||||
await assert.rejects(() => client.validate('bad-token'), InvalidSessionError);
|
||||
await assert.rejects(() => client.validate('bad-token'), InvalidSessionError);
|
||||
assert.equal(fetchImpl.calls.length, 2);
|
||||
});
|
||||
|
||||
test('logout drops the cached answer for that token', async () => {
|
||||
const fetchImpl = recordingFetch([
|
||||
{ status: 200, body: { valid: true, user_id: 7, username: 'gabriel', role: 'admin' } },
|
||||
{ status: 200, body: {} },
|
||||
{ status: 401, body: { valid: false } },
|
||||
]);
|
||||
const client = new AuthClient('https://auth.example.com', { fetchImpl });
|
||||
await client.validate('good-token');
|
||||
await client.logout('good-token');
|
||||
await assert.rejects(() => client.validate('good-token'), InvalidSessionError);
|
||||
assert.equal(fetchImpl.calls.length, 3);
|
||||
});
|
||||
|
||||
test('setBaseUrl clears cached answers', async () => {
|
||||
const fetchImpl = recordingFetch([
|
||||
{ status: 200, body: { valid: true, user_id: 7, username: 'gabriel', role: 'admin' } },
|
||||
]);
|
||||
const client = new AuthClient('https://auth.example.com', { fetchImpl });
|
||||
await client.validate('good-token');
|
||||
client.setBaseUrl('https://auth2.example.com');
|
||||
await client.validate('good-token');
|
||||
assert.equal(fetchImpl.calls.length, 2);
|
||||
});
|
||||
|
||||
test('tokenFromRequest prefers the Authorization header over the cookie', () => {
|
||||
const client = new AuthClient('https://auth.example.com');
|
||||
const req = {
|
||||
@@ -361,3 +398,32 @@ test('deleteManagedUser DELETEs /api/admin/users/{id}', async () => {
|
||||
assert.equal(fetchImpl.calls[0].init.method, 'DELETE');
|
||||
assert.equal(fetchImpl.calls[0].url, 'https://auth.example.com/api/admin/users/6');
|
||||
});
|
||||
|
||||
test('credential calls send the end user address as X-Forwarded-For when given a clientIp', async () => {
|
||||
const user = { id: 1, username: 'a', email: '', role: 'user' };
|
||||
const fetchImpl = recordingFetch([{ status: 200, body: { user } }]);
|
||||
const client = new AuthClient('https://authguard.example', { fetchImpl });
|
||||
await client.login('a', 'secret-password', '', { clientIp: '203.0.113.9' });
|
||||
await client.register('a', 'a@b.com', 'secret-password', { clientIp: '2001:db8::1' });
|
||||
await client.totpVerify('tok', '123456', { clientIp: '203.0.113.9' });
|
||||
await client.totpDisable('tok', '123456', { clientIp: '203.0.113.9' });
|
||||
await client.requestPasswordReset('a', { clientIp: '203.0.113.9' });
|
||||
await client.confirmPasswordReset('CODE', 'secret-password', { clientIp: '203.0.113.9' });
|
||||
assert.deepEqual(
|
||||
fetchImpl.calls.map((call) => call.init.headers['X-Forwarded-For']),
|
||||
['203.0.113.9', '2001:db8::1', '203.0.113.9', '203.0.113.9', '203.0.113.9', '203.0.113.9'],
|
||||
);
|
||||
});
|
||||
|
||||
test('no X-Forwarded-For is sent without a clientIp, or for a value that is not an IP address', async () => {
|
||||
const user = { id: 1, username: 'a', email: '', role: 'user' };
|
||||
const fetchImpl = recordingFetch([{ status: 200, body: { user } }]);
|
||||
const client = new AuthClient('https://authguard.example', { fetchImpl });
|
||||
await client.login('a', 'secret-password');
|
||||
await client.login('a', 'secret-password', '', { clientIp: '203.0.113.9\r\nX-Evil: 1' });
|
||||
await client.login('a', 'secret-password', '', { clientIp: 'not-an-ip' });
|
||||
await client.me('tok');
|
||||
for (const call of fetchImpl.calls) {
|
||||
assert.equal('X-Forwarded-For' in call.init.headers, false);
|
||||
}
|
||||
});
|
||||
Reference in new issue
Block a user