Files
RuneStone/browser-runtime/test/agent.test.mjs
T
2026-11-16 04:21:21 -07:00

19 lines
899 B
JavaScript

import test from 'node:test';
import assert from 'node:assert/strict';
import { AgentController } from '../src/agent.mjs';
test('agent grants bind profile, tab, document and expiry', () => {
let now = 100;
const tabs = new Map([['a', { profileId: 'agent', epoch: 1 }], ['p', { profileId: 'personal', epoch: 1 }]]);
const agent = new AgentController(id => tabs.get(id), () => now);
assert.throws(() => agent.grant('p', 'agent'));
const token = agent.grant('a', 'agent');
assert.throws(() => agent.authorized(token, 'p'));
assert.equal(agent.authorized(token, 'a'), tabs.get('a'));
tabs.get('a').epoch++;
assert.throws(() => agent.authorized(token, 'a'));
const next = agent.grant('a', 'agent'); now += 300_001;
assert.throws(() => agent.authorized(next, 'a'));
const last = agent.grant('a', 'agent'); agent.revokeAll();
assert.throws(() => agent.authorized(last, 'a'));
});