"use strict"; // adpanel:db-proxy-harness-ci — scripts/verify-db-proxy-session-auth.js is the // standalone verification harness for the /db-access proxy hardening (findings // 2.4/2.5): session-bound authorization (no IP fallback), cookie-only // credentials (the token never appears in any URL, HTML or Set-Cookie path), // the in-middleware session-checked heartbeat, revocation scopes, request/ // response header hygiene toward backend and browser, and the cluster-safe // token store. The harness lives in scripts/ and was therefore NOT matched by // the npm-test glob ("utils/*.test.js" "tests/*.test.js"), so every property // it proves was manual-run only; the globbed db-proxy tests pin the store and // index.js wiring, not the middleware/header behavior. This wrapper pins the // harness into CI: it spawns the harness as a child process from the repo root // and requires BOTH exit 0 AND the harness's own final success marker // ("ALL CHECKS PASSED") on stdout, so neither a hung run nor a silent // exit-0 can count as green. The harness is fully self-contained (mock // Express response, stubbed http.request, tmpdir file store, inline // throw-on-call Redis fake), so no live Redis or other infra is required and // no skip logic is needed. A harness failure here is NEW evidence about the // db-proxy ledger fixes — report it, never "fix" utils/db-proxy.js from it. const test = require("node:test"); const assert = require("node:assert"); const path = require("node:path"); const { spawnSync } = require("node:child_process"); const ROOT = path.join(__dirname, ".."); const HARNESS = path.join(ROOT, "scripts", "verify-db-proxy-session-auth.js"); // The harness completes in well under a second when healthy (no network, no // real timers); 60s is a generous hard cap. A hang means a proxy/store path // stopped settling — fail fast instead of wedging the suite. const HARNESS_TIMEOUT_MS = 60_000; test("verify-db-proxy-session-auth harness: every session-auth/header-hygiene check passes", () => { const res = spawnSync(process.execPath, [HARNESS], { cwd: ROOT, // repo root so the harness's relative requires resolve encoding: "utf8", timeout: HARNESS_TIMEOUT_MS, killSignal: "SIGKILL", maxBuffer: 16 * 1024 * 1024, }); // Hard timeout: spawnSync already SIGKILLed the child; surface it loudly // with whatever partial output exists. const timedOut = res.status === null && res.signal === "SIGKILL"; const timedOutErr = res.error && res.error.code === "ETIMEDOUT"; if (timedOut || timedOutErr) { assert.fail( `verify-db-proxy-session-auth.js did not finish within ${HARNESS_TIMEOUT_MS}ms and was killed ` + `(a middleware/token-store path must have stopped settling). ` + `Partial stdout:\n${res.stdout}\nstderr:\n${res.stderr}` ); } assert.strictEqual( res.status, 0, `harness exited with status ${res.status} (expected 0)\nstdout:\n${res.stdout}\nstderr:\n${res.stderr}` ); assert.doesNotMatch( res.stdout, /VERIFY FAILED/, "the harness's own failure banner must never appear on a green run" ); // A bare exit 0 is not enough: the marker is printed only after the last // ok() assertion of the last section, so its presence proves every check // ran and passed (the harness counts each ok() as it asserts). const marker = res.stdout.match(/ALL (\d+) CHECKS PASSED/); assert.ok( marker, `the harness's success marker "ALL CHECKS PASSED" is missing from stdout — ` + `exit 0 without the marker means the assertions never ran.\nstdout:\n${res.stdout}\nstderr:\n${res.stderr}` ); const passed = Number(marker[1]); assert.ok( passed > 0, `the harness reported ${passed} passing checks — zero means no assertions executed` ); });