25 lines
968 B
TypeScript
25 lines
968 B
TypeScript
import { describe, it, expect } from 'vitest';
|
|
import { mintAppHarnessToken, verifyAppHarnessToken, revokeAppHarnessToken } from './app-harness-token.js';
|
|
|
|
describe('app-harness-token', () => {
|
|
it('mints + verifies a scoped token', () => {
|
|
const t = mintAppHarnessToken({ userId: 'u1', spaceId: 's1' });
|
|
expect(verifyAppHarnessToken(t)).toEqual({ userId: 'u1', spaceId: 's1' });
|
|
});
|
|
it('rejects unknown/garbage tokens', () => {
|
|
expect(verifyAppHarnessToken('nope')).toBeNull();
|
|
});
|
|
it('rejects after revoke', () => {
|
|
const t = mintAppHarnessToken({ userId: 'u1', spaceId: 's1' });
|
|
revokeAppHarnessToken(t);
|
|
expect(verifyAppHarnessToken(t)).toBeNull();
|
|
});
|
|
it('rejects after expiry', () => {
|
|
const t = mintAppHarnessToken({ userId: 'u1', spaceId: 's1' }, 1);
|
|
// wait past TTL
|
|
const until = Date.now() + 5;
|
|
while (Date.now() < until) { /* spin briefly */ }
|
|
expect(verifyAppHarnessToken(t)).toBeNull();
|
|
});
|
|
});
|