companion-token-custody-stress.test.mjs
33 lines 1.8 KB
Raw
sha256:b5f647cb9c409f563d4671fe3fc05ddea01fabfed9b41fc11cb923588e1c1baf mirror: GitHub Phase A durable MCP OAuth (#270) Human minor ⚠ breaking 10 days ago
1 /**
2 * Tier 4 — STRESS: many store/rotate/load cycles stay consistent and bounded; the store never
3 * accumulates stale secrets across rotations.
4 */
5 import { describe, it } from 'node:test';
6 import assert from 'node:assert/strict';
7 import { KEYCHAIN_ACCOUNTS, buildSessionMeta, createTokenCustody } from '../lib/companion-token-custody.mjs';
8 import { makeSyncKeychain } from './helpers/companion-keychain-fake.mjs';
9
10 describe('Stress — repeated rotation keeps a single live secret per account', () => {
11 it('10k access-token rotations leave exactly one access token and bounded store size', async () => {
12 const kc = makeSyncKeychain();
13 const custody = createTokenCustody(kc);
14 const baseMeta = buildSessionMeta({ expiresIn: 60, refreshToken: 'r0', scope: null, tokenType: 'Bearer' }, { now: 0, refreshTtlMs: 1_000_000 });
15 await custody.storeSession({ accessToken: 'jwt0', refreshToken: 'r0', meta: baseMeta });
16 for (let i = 1; i <= 10_000; i++) {
17 await custody.updateAccessToken({ accessToken: 'jwt' + i, refreshToken: 'r' + i, meta: buildSessionMeta({ expiresIn: 60, refreshToken: 'r' + i, scope: null, tokenType: 'Bearer' }, { now: i, refreshTtlMs: 1_000_000 }) });
18 }
19 const loaded = await custody.loadSession();
20 assert.equal(loaded.accessToken, 'jwt10000');
21 assert.equal(loaded.refreshToken, 'r10000');
22 // Store holds only the 3 session accounts (no per-rotation accumulation).
23 assert.ok(kc._store.size <= 4);
24 });
25
26 it('10k loopback rotations always yield the latest token only', async () => {
27 const kc = makeSyncKeychain();
28 const custody = createTokenCustody(kc);
29 for (let i = 0; i < 10_000; i++) await custody.rotateLoopbackToken('lb' + i);
30 assert.equal(await custody.getLoopbackToken(), 'lb9999');
31 assert.equal(kc._store.get(KEYCHAIN_ACCOUNTS.LOOPBACK_TOKEN), 'lb9999');
32 });
33 });
File History 2 commits
sha256:b5f647cb9c409f563d4671fe3fc05ddea01fabfed9b41fc11cb923588e1c1baf mirror: GitHub Phase A durable MCP OAuth (#270) Human minor 10 days ago
sha256:d8c648b20a4d53b2673c5c082ee7edfa7b2fc9b11080832da1f38807b6bf940b fix(7C-L1b): route hosted delegation proposals through cani… Human minor 29 days ago