25 lines
1.7 KiB
JavaScript
25 lines
1.7 KiB
JavaScript
import { test } from 'node:test';
|
|
import assert from 'node:assert/strict';
|
|
import { refreshFixtureCredential } from '../src/refresh-fixture.mjs';
|
|
const expired = () => ({ type: 'oauth', access: 'FIXTURE_OLD_ACCESS', refresh: 'FIXTURE_OLD_REFRESH', expires: 1 });
|
|
test('fixed fake process rotates both OAuth fields without mutating caller input', async () => {
|
|
const input = expired(), result = await refreshFixtureCredential('openai-codex', input);
|
|
assert.ok(result.access !== input.access && result.refresh !== input.refresh);
|
|
assert.ok(result.expires > Date.now() + 300000);
|
|
assert.equal(input.expires, 1);
|
|
});
|
|
test('concurrent isolated processes preserve separate provider credentials', async () => {
|
|
const a = { type: 'api_key', key: 'FIXTURE_ACCOUNT_A' }, b = { type: 'api_key', key: 'FIXTURE_ACCOUNT_B' };
|
|
const results = await Promise.all([refreshFixtureCredential('provider-a', a), refreshFixtureCredential('provider-b', b)]);
|
|
assert.deepEqual(results, [a, b]);
|
|
});
|
|
for (const [mode, code] of [['failure', 'refresh-failed'], ['malformed', 'invalid-refresh-output'], ['timeout', 'refresh-timeout'], ['unchanged', 'refresh-not-ready']]) {
|
|
test(`fake ${mode} is refused with fixed diagnostics`, async () => {
|
|
await assert.rejects(refreshFixtureCredential('openai-codex', expired(), { mode, timeoutMs: mode === 'timeout' ? 100 : 2000 }), e => e.message === code);
|
|
});
|
|
}
|
|
test('caller executable/environment injection is rejected before spawning', async () => {
|
|
await assert.rejects(refreshFixtureCredential('openai-codex', expired(), { executable: '/bin/false' }), /invalid-fixture-input/);
|
|
await assert.rejects(refreshFixtureCredential('openai-codex', expired(), { env: {} }), /invalid-fixture-input/);
|
|
});
|