master-zapier-plan-draft/packages/verae-access-api/test/health.test.js
George Lambert 1b199ca4d4
Some checks are pending
offline / test (push) Waiting to run
Separate Zapier, web, API, and leaf access planes with NATS authz
Zapier is one ingress. Direct web, customer API, and S2S leaf nodes are their own services. Every hop to an internal subject must pass verae.access.authz.check (default deny by plane).
2026-09-11 16:05:05 -04:00

37 lines
1.3 KiB
JavaScript

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');
}
});