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>
110 lines
4.5 KiB
JavaScript
110 lines
4.5 KiB
JavaScript
'use strict';
|
|
|
|
const { parseTrustedProxies } = require('../lib/pageauth');
|
|
const { safeEqual, checkWorkerKey, bearerToken, classifyUpgrade, allowWorkerConnect } = require('../lib/wsauth');
|
|
|
|
const PROXY = '192.0.2.10';
|
|
const KEY = 'worker-secret-key';
|
|
const trusted = parseTrustedProxies(PROXY);
|
|
|
|
function req(remoteAddress, headers = {}) {
|
|
return { headers: { ...headers }, socket: { remoteAddress } };
|
|
}
|
|
const sso = (groups) => ({ 'remote-user': 'alice', 'remote-groups': groups });
|
|
|
|
beforeEach(() => { jest.spyOn(console, 'warn').mockImplementation(() => {}); });
|
|
afterEach(() => jest.restoreAllMocks());
|
|
|
|
describe('safeEqual / checkWorkerKey', () => {
|
|
test('matches only the exact secret', () => {
|
|
expect(safeEqual(KEY, KEY)).toBe(true);
|
|
expect(safeEqual(`${KEY}x`, KEY)).toBe(false);
|
|
expect(safeEqual('short', KEY)).toBe(false);
|
|
});
|
|
|
|
test('an unset or empty secret never matches', () => {
|
|
expect(checkWorkerKey('', '')).toBe(false);
|
|
expect(checkWorkerKey(undefined, undefined)).toBe(false);
|
|
expect(checkWorkerKey('anything', undefined)).toBe(false);
|
|
});
|
|
|
|
test('non-string input is rejected', () => {
|
|
expect(safeEqual(['a'], KEY)).toBe(false);
|
|
expect(safeEqual(null, KEY)).toBe(false);
|
|
});
|
|
});
|
|
|
|
describe('bearerToken', () => {
|
|
test('parses the Authorization header', () => {
|
|
expect(bearerToken(req('x', { authorization: `Bearer ${KEY}` }))).toBe(KEY);
|
|
expect(bearerToken(req('x', { authorization: `bearer ${KEY} ` }))).toBe(KEY);
|
|
expect(bearerToken(req('x', { authorization: 'Basic abc' }))).toBeNull();
|
|
expect(bearerToken(req('x'))).toBeNull();
|
|
});
|
|
});
|
|
|
|
describe('classifyUpgrade', () => {
|
|
const opts = (enforce) => ({ trusted, workerKey: KEY, enforce });
|
|
|
|
test('trusted proxy with an allowed group is a browser', () => {
|
|
expect(classifyUpgrade(req(PROXY, sso('admin')), opts(true))).toBe('browser');
|
|
// Pulse is admin-only: employees are not browsers either.
|
|
expect(classifyUpgrade(req(PROXY, sso('employee')), opts(true))).toBe('reject');
|
|
});
|
|
|
|
test('trusted proxy with a wrong group is not a browser', () => {
|
|
expect(classifyUpgrade(req(PROXY, sso('guests')), opts(true))).toBe('reject');
|
|
expect(classifyUpgrade(req(PROXY, sso('guests')), opts(false))).toBe('pending');
|
|
});
|
|
|
|
test('identity headers from an untrusted host do not make a browser', () => {
|
|
expect(classifyUpgrade(req('192.0.2.99', sso('admin')), opts(true))).toBe('reject');
|
|
expect(classifyUpgrade(req('192.0.2.99', sso('admin')), opts(false))).toBe('pending');
|
|
});
|
|
|
|
test('correct Bearer key is a worker from any host', () => {
|
|
expect(classifyUpgrade(req('192.0.2.99', { authorization: `Bearer ${KEY}` }), opts(true))).toBe('worker');
|
|
});
|
|
|
|
test('wrong Bearer key is rejected even while not enforced', () => {
|
|
expect(classifyUpgrade(req('192.0.2.99', { authorization: 'Bearer nope' }), opts(false))).toBe('reject');
|
|
});
|
|
|
|
test('no credentials: pending while not enforced, rejected once enforced', () => {
|
|
expect(classifyUpgrade(req('192.0.2.99'), opts(false))).toBe('pending');
|
|
expect(classifyUpgrade(req('192.0.2.99'), opts(true))).toBe('reject');
|
|
});
|
|
|
|
test('with WORKER_API_KEY unset no Bearer token is accepted', () => {
|
|
const o = { trusted, workerKey: undefined, enforce: true };
|
|
expect(classifyUpgrade(req('192.0.2.99', { authorization: 'Bearer ' }), o)).toBe('reject');
|
|
expect(classifyUpgrade(req('192.0.2.99', { authorization: 'Bearer undefined' }), o)).toBe('reject');
|
|
});
|
|
});
|
|
|
|
describe('allowWorkerConnect', () => {
|
|
const o = (enforce) => ({ workerKey: KEY, enforce });
|
|
|
|
test('a handshake-authenticated worker may register', () => {
|
|
expect(allowWorkerConnect('worker', undefined, o(true))).toEqual({ ok: true });
|
|
});
|
|
|
|
test('a pending connection with the right api_key may register', () => {
|
|
expect(allowWorkerConnect('pending', KEY, o(true))).toEqual({ ok: true });
|
|
});
|
|
|
|
test('a pending connection with a wrong api_key is refused', () => {
|
|
expect(allowWorkerConnect('pending', 'nope', o(false))).toEqual({ ok: false });
|
|
});
|
|
|
|
test('keyless worker: allowed as legacy while not enforced, refused once enforced', () => {
|
|
expect(allowWorkerConnect('pending', undefined, o(false))).toEqual({ ok: true, legacy: true });
|
|
expect(allowWorkerConnect('pending', undefined, o(true))).toEqual({ ok: false });
|
|
});
|
|
|
|
test('a browser session cannot turn itself into a worker without the key', () => {
|
|
expect(allowWorkerConnect('browser', undefined, o(false))).toEqual({ ok: false });
|
|
expect(allowWorkerConnect('browser', KEY, o(false))).toEqual({ ok: true });
|
|
});
|
|
});
|