Initial import of verae-access-authz from zapier monorepo
This commit is contained in:
commit
481851d504
10 changed files with 476 additions and 0 deletions
35
test/health.test.js
Normal file
35
test/health.test.js
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
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)), '..');
|
||||
|
||||
test('authz health policy and check', async () => {
|
||||
const port = 18020;
|
||||
const child = spawn(process.execPath, ['src/server.js'], {
|
||||
cwd: root,
|
||||
env: { ...process.env, PORT: String(port) },
|
||||
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, 'verae-access-authz');
|
||||
const ok = await fetch(`http://127.0.0.1:${port}/check`, {
|
||||
method: 'POST',
|
||||
headers: { 'content-type': 'application/json' },
|
||||
body: JSON.stringify({ plane: 'web', subject: 'verae.billing.statement.get' }),
|
||||
});
|
||||
assert.equal(ok.status, 200);
|
||||
const no = await fetch(`http://127.0.0.1:${port}/check`, {
|
||||
method: 'POST',
|
||||
headers: { 'content-type': 'application/json' },
|
||||
body: JSON.stringify({ plane: 'leaf', subject: 'verae.billing.balance.adjust' }),
|
||||
});
|
||||
assert.equal(no.status, 403);
|
||||
} finally {
|
||||
child.kill('SIGTERM');
|
||||
}
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue