36 lines
1.3 KiB
JavaScript
36 lines
1.3 KiB
JavaScript
import { test } from 'node:test';
|
|
import assert from 'node:assert/strict';
|
|
import { spawn } from 'node:child_process';
|
|
import fs from 'node:fs';
|
|
import os from 'node:os';
|
|
import path from 'node:path';
|
|
import { fileURLToPath } from 'node:url';
|
|
import { stableVeraeUserId } from '../src/ids.js';
|
|
|
|
const root = path.join(path.dirname(fileURLToPath(import.meta.url)), '..');
|
|
|
|
test('identity bind is stable and not a JWT', async () => {
|
|
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'id-'));
|
|
const port = 18026;
|
|
const child = spawn(process.execPath, ['src/server.js'], {
|
|
cwd: root,
|
|
env: { ...process.env, PORT: String(port), IDENTITY_PATH: path.join(dir, 'id.json') },
|
|
stdio: ['ignore', 'pipe', 'pipe'],
|
|
});
|
|
await new Promise((r) => setTimeout(r, 400));
|
|
try {
|
|
const h = await (await fetch(`http://127.0.0.1:${port}/health`)).json();
|
|
assert.equal(h.role, 'zappier-identity');
|
|
const b = await (
|
|
await fetch(`http://127.0.0.1:${port}/bind`, {
|
|
method: 'POST',
|
|
headers: { 'content-type': 'application/json' },
|
|
body: JSON.stringify({ email: 'Ada@Example.com', customerId: 'cust_x' }),
|
|
})
|
|
).json();
|
|
assert.equal(b.veraeUserId, stableVeraeUserId('ada@example.com'));
|
|
assert.doesNotMatch(JSON.stringify(b), /eyJ|mock-jwt/);
|
|
} finally {
|
|
child.kill('SIGTERM');
|
|
}
|
|
});
|