CI / UI screenshots (before/after) (push) Skipped
CI / Lint (eslint) (push) Successful in 25s
CI / Test (jest) (push) Successful in 25s
CI / Security (npm audit) (push) Successful in 21s
CI / Scan (secrets, workflows, shell) (push) Successful in 2m0s
CI / Integration (api) (push) Successful in 2m23s
CI / Lint (eslint) (pull_request) Successful in 24s
CI / Test (jest) (pull_request) Successful in 32s
CI / Security (npm audit) (pull_request) Successful in 39s
CI / UI (playwright) (push) Successful in 2m6s
CI / Deploy (push) Skipped
CI / Deploy worker (push) Skipped
CI / Notify (push) Skipped
CI / Integration (api) (pull_request) Successful in 2m13s
CI / Scan (secrets, workflows, shell) (pull_request) Successful in 2m46s
CI / UI screenshots (before/after) (pull_request) Successful in 27s
CI / UI (playwright) (pull_request) Successful in 3m5s
CI / Deploy (pull_request) Skipped
CI / Deploy worker (pull_request) Skipped
CI / Notify (pull_request) Skipped
- Workflow conditions (step.condition and route `if`) are now parsed and interpreted by lib/condition.js instead of being run with Node's vm module. The language covers what workflows use: state/params lookups, parseInt/parseFloat/Number/String/Boolean, a few string methods, the usual operators with JavaScript semantics. Conditions can only read the workflow's own data. Every condition in the production workflows gives the same result as before (differential test, 150 random states each). - Creating and updating a workflow rejects conditions that don't parse (400 with the step and the error). - Creating a workflow requires admin, like editing already did. - Only the admin group may use Pulse (pages, API and live WebSocket); employees get 403. Gandalf and workers use API keys and are unaffected. - The live-update UI test finds its execution's row by id instead of counting rows (the list is capped at 50). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
85 lines
3.6 KiB
JavaScript
85 lines
3.6 KiB
JavaScript
'use strict';
|
|
|
|
// HTTP and WebSocket authentication (#37, #38).
|
|
const { api, sso, SSO, WORKER_KEY, openWs, workerByName, waitFor, gandalf, waitForExecution, commandResult } = require('./helpers');
|
|
|
|
describe('HTTP', () => {
|
|
test('a trusted SSO identity in an allowed group is signed in', async () => {
|
|
const r = await sso('GET', '/api/user');
|
|
expect(r.status).toBe(200);
|
|
expect(r.json.username).toBe('int.tester');
|
|
});
|
|
|
|
test('no identity is 401, and a group outside the allowed list is 403', async () => {
|
|
expect((await api('GET', '/api/user')).status).toBe(401);
|
|
expect((await api('GET', '/api/user', { headers: { ...SSO, 'Remote-Groups': 'guests' } })).status).toBe(403);
|
|
});
|
|
|
|
test('Pulse is admin-only: employees are refused on the API and the pages', async () => {
|
|
const employee = { ...SSO, 'Remote-Groups': 'employee' };
|
|
expect((await api('GET', '/api/user', { headers: employee })).status).toBe(403);
|
|
expect((await api('GET', '/api/workers', { headers: employee })).status).toBe(403);
|
|
expect((await api('GET', '/', { headers: employee })).status).toBe(403);
|
|
});
|
|
|
|
test('worker heartbeats need the worker key', async () => {
|
|
const r = await api('POST', '/api/workers/heartbeat', {
|
|
headers: { 'X-API-Key': 'wrong' }, body: { worker_id: 'x', name: 'x' },
|
|
});
|
|
expect(r.status).toBe(401);
|
|
});
|
|
|
|
test('the public health check reveals no detail beyond status', async () => {
|
|
const r = await api('GET', '/healthz');
|
|
expect(r.status).toBe(200);
|
|
expect(Object.keys(r.json).sort()).toEqual(['db', 'sha', 'status', 'uptime_s', 'version', 'worker_versions', 'workers']);
|
|
});
|
|
});
|
|
|
|
describe('WebSocket upgrade', () => {
|
|
test('is refused with no credentials (worker auth is enforced)', async () => {
|
|
await expect(openWs()).rejects.toMatchObject({ status: 401 });
|
|
});
|
|
|
|
test('is refused with a wrong worker key', async () => {
|
|
await expect(openWs({ Authorization: 'Bearer wrong-key' })).rejects.toMatchObject({ status: 401 });
|
|
});
|
|
|
|
test('is refused for an SSO identity outside the allowed groups', async () => {
|
|
await expect(openWs({ ...SSO, 'Remote-Groups': 'guests' })).rejects.toBeDefined();
|
|
});
|
|
|
|
test('accepts the worker key', async () => {
|
|
const ws = await openWs({ Authorization: `Bearer ${WORKER_KEY}` });
|
|
ws.close();
|
|
});
|
|
|
|
test('a signed-in browser receives live execution events', async () => {
|
|
const ws = await openWs(SSO);
|
|
try {
|
|
const workerId = (await workerByName('node-02')).id;
|
|
const submit = await gandalf('POST', '/api/internal/command', { worker_id: workerId, command: 'echo live' });
|
|
const id = submit.json.execution_id;
|
|
await waitFor(() => ws.messages.some(m => m.type === 'command_result' && m.execution_id === id),
|
|
{ what: 'a command_result broadcast' });
|
|
} finally { ws.close(); }
|
|
});
|
|
|
|
test('a browser connection cannot forge a command result', async () => {
|
|
const ws = await openWs(SSO);
|
|
try {
|
|
const workerId = (await workerByName('node-03')).id;
|
|
const submit = await gandalf('POST', '/api/internal/command', { worker_id: workerId, command: 'sleep 1; echo genuine' });
|
|
const id = submit.json.execution_id;
|
|
ws.send(JSON.stringify({
|
|
type: 'command_result', execution_id: id, worker_id: workerId, command_id: id,
|
|
success: true, stdout: 'forged', stderr: '',
|
|
}));
|
|
const ex = await waitForExecution(id);
|
|
expect(ex.status).toBe('completed');
|
|
expect(commandResult(ex).stdout.trim()).toBe('genuine');
|
|
expect((ex.logs || []).filter(l => l.action === 'command_result')).toHaveLength(1);
|
|
} finally { ws.close(); }
|
|
});
|
|
});
|