companion-token-custody-stress.test.mjs
33 lines 1.8 KB
Raw
sha256:65ccb454656ea5acdea0a10e559b78bcde1eb6ff753ecc2911bc99d1c3d7cadd feat(calendar): enforce agent context tiers in retrieval AP… Human minor ⚠ breaking 1 day 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:65ccb454656ea5acdea0a10e559b78bcde1eb6ff753ecc2911bc99d1c3d7cadd feat(calendar): enforce agent context tiers in retrieval AP… Human minor 1 day ago
sha256:9103f98c89257ed2b01c237cea895dabb3e85ea337dccb1161c175e4422355b6 docs: accept Calendar Events v0 spec with Phase 0 security … Human 1 day ago