companion-token-custody-data-integrity.test.mjs
51 lines 2.5 KB
Raw
sha256:1ccd31d41a3e3c90917cc0b460edeafcc615c6e74fa2ed104b2f6673ab0ec0b8 Merge feat/companion-phase-7-distribution: production macOS… Human 27 days ago
1 /**
2 * Tier 5 — DATA INTEGRITY: buildSessionMeta is pure/deterministic; what is stored is exactly what
3 * is loaded; metadata holds no secret; the module reads nothing from the environment.
4 */
5 import { describe, it } from 'node:test';
6 import assert from 'node:assert/strict';
7 import { buildSessionMeta, createTokenCustody } from '../lib/companion-token-custody.mjs';
8 import { makeSyncKeychain } from './helpers/companion-keychain-fake.mjs';
9
10 describe('Data integrity — buildSessionMeta is pure/deterministic', () => {
11 it('same inputs → identical metadata', () => {
12 const tr = { expiresIn: 3600, refreshToken: 'r', scope: 'vault:read', tokenType: 'Bearer' };
13 const ctx = { now: 12345, refreshTtlMs: 1000, issuer: 'https://knowtation.store' };
14 assert.deepEqual(buildSessionMeta(tr, ctx), buildSessionMeta(tr, ctx));
15 });
16 it('does not mutate its inputs', () => {
17 const tr = { expiresIn: 3600, refreshToken: 'r', scope: 'vault:read', tokenType: 'Bearer' };
18 const ctx = { now: 1, refreshTtlMs: 1000 };
19 const trSnap = JSON.stringify(tr);
20 const ctxSnap = JSON.stringify(ctx);
21 buildSessionMeta(tr, ctx);
22 assert.equal(JSON.stringify(tr), trSnap);
23 assert.equal(JSON.stringify(ctx), ctxSnap);
24 });
25 });
26
27 describe('Data integrity — store/load fidelity', () => {
28 it('loaded session fields equal the stored values', async () => {
29 const custody = createTokenCustody(makeSyncKeychain());
30 const meta = buildSessionMeta({ expiresIn: 7200, refreshToken: 'r', scope: 'vault:read vault:write', tokenType: 'Bearer' }, { now: 500, refreshTtlMs: 2000, issuer: 'https://knowtation.store', clientId: 'client-1' });
31 await custody.storeSession({ accessToken: 'jwt', refreshToken: 'r', meta });
32 const loaded = await custody.loadSession();
33 assert.equal(loaded.expiresAt, meta.expiresAt);
34 assert.equal(loaded.refreshExpiresAt, meta.refreshExpiresAt);
35 assert.equal(loaded.scope, 'vault:read vault:write');
36 assert.equal(loaded.issuer, 'https://knowtation.store');
37 assert.equal(loaded.tokenType, 'Bearer');
38 assert.equal(loaded.clientId, 'client-1');
39 });
40 });
41
42 describe('Data integrity — environment independence', () => {
43 it('metadata does not change with process.env', () => {
44 const tr = { expiresIn: 60, refreshToken: null, scope: null, tokenType: 'Bearer' };
45 const before = buildSessionMeta(tr, { now: 0 });
46 process.env.KNOWTATION_CUSTODY_TEST = 'x';
47 const after = buildSessionMeta(tr, { now: 0 });
48 delete process.env.KNOWTATION_CUSTODY_TEST;
49 assert.deepEqual(before, after);
50 });
51 });
File History 7 commits
sha256:1ccd31d41a3e3c90917cc0b460edeafcc615c6e74fa2ed104b2f6673ab0ec0b8 Merge feat/companion-phase-7-distribution: production macOS… Human 27 days ago
sha256:6256c13e26667f2de19ea84b32a992deabbe8f70f5108f49ce8ddb76fef37c62 Merge 'chore/security-audit-lock-refresh' into 'main' — pro… Human 28 days ago
sha256:9eaa2a7ec9aaf5866cd03d0deadf843cca97778299d1857b5452f71d92a1880a feat(f24): flip DOCS_NOTION_HUB_KEY_AUTHORIZED=true (Tier 3) Human minor ⚠ 63 days ago
sha256:e4c529f14a0bb908c1caaaeb3f95f3623a1a82e636e7e3722ca2cd3dc9821263 security: npm audit fix pre-bridge 2026-07-29 Human 87 days ago
sha256:b5f647cb9c409f563d4671fe3fc05ddea01fabfed9b41fc11cb923588e1c1baf mirror: GitHub Phase A durable MCP OAuth (#270) Human minor ⚠ 103 days ago
sha256:873e30b7fafe601346295f8f4289f388f21d8f715f28584d5481899ba2b714fc Merge pull request #249 from aaronrene/muse-mirror Agent 120 days ago
sha256:d8c648b20a4d53b2673c5c082ee7edfa7b2fc9b11080832da1f38807b6bf940b fix(7C-L1b): route hosted delegation proposals through cani… Human minor ⚠ 123 days ago