import { test } from 'node:test'; import assert from 'node:assert/strict'; import { spawn } from 'node:child_process'; import path from 'node:path'; import { fileURLToPath } from 'node:url'; const root = path.join(path.dirname(fileURLToPath(import.meta.url)), '..'); const authzRoot = path.join(root, '..', 'verae-access-authz'); test('api plane health and authz deny on credits', async () => { const authzPort = 18024; const apiPort = 18025; const authz = spawn(process.execPath, ['src/server.js'], { cwd: authzRoot, env: { ...process.env, PORT: String(authzPort) }, stdio: ['ignore', 'pipe', 'pipe'], }); const api = spawn(process.execPath, ['src/server.js'], { cwd: root, env: { ...process.env, PORT: String(apiPort), AUTHZ_URL: `http://127.0.0.1:${authzPort}` }, stdio: ['ignore', 'pipe', 'pipe'], }); await new Promise((r) => setTimeout(r, 500)); try { const h = await (await fetch(`http://127.0.0.1:${apiPort}/health`)).json(); assert.equal(h.plane, 'api'); const deny = await fetch(`http://127.0.0.1:${authzPort}/check`, { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify({ plane: 'api', subject: 'verae.billing.balance.adjust' }), }); assert.equal(deny.status, 403); } finally { api.kill('SIGTERM'); authz.kill('SIGTERM'); } });