mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-28 07:30:04 +00:00
test: keep the new tests within the lint and hand-built service ratchets
This commit is contained in:
@@ -170,10 +170,11 @@ describe('the tools one step offers', () => {
|
||||
const steps = await within(tripSession(), async (session) => {
|
||||
const port = attachedPort(session, ATTACHED_TURN);
|
||||
const counts: Array<{ group: string; offered: number }> = [];
|
||||
for (const group of GROUPS) {
|
||||
await GROUPS.reduce(async (previous, group) => {
|
||||
await previous;
|
||||
await session.call('use_addon_tools', { groups: [group] });
|
||||
counts.push({ group, offered: port.specs().length });
|
||||
}
|
||||
}, Promise.resolve());
|
||||
await session.call('use_addon_tools', { groups: GROUPS });
|
||||
counts.push({ group: 'all', offered: port.specs().length });
|
||||
return counts;
|
||||
|
||||
@@ -550,9 +550,11 @@ describe('AuthController (authenticated)', () => {
|
||||
const other = { ...user, id: 2 } as User;
|
||||
// Both users sit behind the same NAT address, and the first one burns its
|
||||
// whole ceiling.
|
||||
for (let i = 0; i < 120; i++) {
|
||||
await ac(asvc({}), s, { createWsToken: vi.fn().mockReturnValue({ token: 'ws' }) }).wsToken(user, req);
|
||||
}
|
||||
await Promise.all(
|
||||
Array.from({ length: 120 }, () =>
|
||||
ac(asvc({}), s, { createWsToken: vi.fn().mockReturnValue({ token: 'ws' }) }).wsToken(user, req),
|
||||
),
|
||||
);
|
||||
expect(
|
||||
await thrownAsync(() =>
|
||||
ac(asvc({}), s, { createWsToken: vi.fn().mockReturnValue({ token: 'ws' }) }).wsToken(user, req),
|
||||
|
||||
@@ -1470,7 +1470,7 @@ describe('resetPassword', () => {
|
||||
await updateRows(orm, Users, { id: user.id }, { email: 'moved@example.com' });
|
||||
|
||||
expect(
|
||||
await asLegacyResult(svc.resetPassword({ token: issued.tokenForDelivery!, new_password: 'Fresh123!' })),
|
||||
await asLegacyResult(svc.resetPassword({ token: issued.tokenForDelivery ?? '', new_password: 'Fresh123!' })),
|
||||
).toEqual({ error: 'Invalid or expired reset link', status: 400 });
|
||||
expect((await readUser(orm, user.id)).password_version).toBe(0);
|
||||
});
|
||||
@@ -1480,14 +1480,14 @@ describe('resetPassword', () => {
|
||||
const issued = await svc.requestPasswordReset(user.email, null);
|
||||
await updateRows(orm, Users, { id: user.id }, { email: user.email.toUpperCase() });
|
||||
expect(
|
||||
await asLegacyResult(svc.resetPassword({ token: issued.tokenForDelivery!, new_password: 'Fresh123!' })),
|
||||
await asLegacyResult(svc.resetPassword({ token: issued.tokenForDelivery ?? '', new_password: 'Fresh123!' })),
|
||||
).toEqual({ success: true, userId: user.id });
|
||||
|
||||
const { user: older } = createUser(testDb);
|
||||
const legacy = await svc.requestPasswordReset(older.email, null);
|
||||
await updateRows(orm, PasswordResetTokens, { user: older.id }, { email: null });
|
||||
expect(
|
||||
await asLegacyResult(svc.resetPassword({ token: legacy.tokenForDelivery!, new_password: 'Fresh123!' })),
|
||||
await asLegacyResult(svc.resetPassword({ token: legacy.tokenForDelivery ?? '', new_password: 'Fresh123!' })),
|
||||
).toEqual({ success: true, userId: older.id });
|
||||
});
|
||||
});
|
||||
|
||||
@@ -126,9 +126,7 @@ describe('OidcBackchannelController POST /api/auth/oidc/backchannel-logout', ()
|
||||
|
||||
it('BCL-CTL-007: every request is counted at the door, and a valid logout gives its attempt back', async () => {
|
||||
const n = BACKCHANNEL_LOGOUT_RATE_LIMIT + 5;
|
||||
for (let i = 0; i < n; i++) {
|
||||
await controller().logout(req({ logout_token: 'a.b.c' }), makeRes());
|
||||
}
|
||||
await Promise.all(Array.from({ length: n }, () => controller().logout(req({ logout_token: 'a.b.c' }), makeRes())));
|
||||
expect(check).toHaveBeenCalledTimes(n);
|
||||
expect(release).toHaveBeenCalledTimes(n);
|
||||
expect(release).toHaveBeenLastCalledWith('oidc_backchannel', '198.51.100.7', 60_000, expect.any(Number));
|
||||
|
||||
@@ -18,20 +18,18 @@ function bucketSize(service: RateLimitService, bucket: string): number {
|
||||
}
|
||||
|
||||
describe('RateLimitService', () => {
|
||||
it('allows up to max attempts in a window, then refuses', async () => {
|
||||
it('allows up to max attempts in a window, then refuses, counting only the attempts not given back', async () => {
|
||||
const s = new RateLimitService();
|
||||
const now = Date.now();
|
||||
for (let i = 0; i < 5; i++) expect(await s.check('login', '1.2.3.4', 5, WINDOW, now)).toBe(true);
|
||||
expect(await s.check('login', '1.2.3.4', 5, WINDOW, now)).toBe(false);
|
||||
});
|
||||
|
||||
it('release gives back a counted attempt, so only the kept ones reach the limit', async () => {
|
||||
const s = new RateLimitService();
|
||||
const now = Date.now();
|
||||
for (let i = 0; i < 5; i++) {
|
||||
// release gives back a counted attempt, so only the kept ones reach the limit
|
||||
await Array.from({ length: 5 }).reduce<Promise<void>>(async (previous) => {
|
||||
await previous;
|
||||
expect(await s.check('logout', '1.2.3.4', 2, WINDOW, now)).toBe(true);
|
||||
await s.release('logout', '1.2.3.4', WINDOW, now);
|
||||
}
|
||||
}, Promise.resolve());
|
||||
expect(await s.check('logout', '1.2.3.4', 2, WINDOW, now)).toBe(true);
|
||||
expect(await s.check('logout', '1.2.3.4', 2, WINDOW, now)).toBe(true);
|
||||
expect(await s.check('logout', '1.2.3.4', 2, WINDOW, now)).toBe(false);
|
||||
|
||||
Reference in New Issue
Block a user