harden production headers and probe contract
This commit is contained in:
@@ -4,8 +4,14 @@
|
||||
import { mkdir, writeFile } from 'node:fs/promises';
|
||||
|
||||
const base = String(process.argv[2] || process.env.IHALEIST_LIVE_URL || 'https://ihaleist.com').replace(/\/$/, '');
|
||||
const evidencePath = process.env.IHALEIST_LIVE_EVIDENCE_PATH || 'docs/quality/evidence/qa-live-runtime.json';
|
||||
const timeoutMs = 15_000;
|
||||
const requiredHeaders = ['x-content-type-options', 'referrer-policy', 'permissions-policy'];
|
||||
const requiredHeaders = [
|
||||
'x-content-type-options', 'referrer-policy', 'permissions-policy',
|
||||
'x-frame-options', 'content-security-policy',
|
||||
...(base.startsWith('https://') ? ['strict-transport-security'] : []),
|
||||
];
|
||||
const observedHeaders = [...new Set([...requiredHeaders, 'strict-transport-security'])];
|
||||
const checks = {};
|
||||
|
||||
async function probe(path, successField = null) {
|
||||
@@ -16,7 +22,7 @@ async function probe(path, successField = null) {
|
||||
const result = {
|
||||
status: response.status,
|
||||
contentType: response.headers.get('content-type'),
|
||||
headers: Object.fromEntries(requiredHeaders.map(name => [name, response.headers.get(name)])),
|
||||
headers: Object.fromEntries(observedHeaders.map(name => [name, response.headers.get(name)])),
|
||||
};
|
||||
if (successField) {
|
||||
const raw = await response.text();
|
||||
@@ -33,7 +39,9 @@ async function probe(path, successField = null) {
|
||||
|
||||
checks.home = await probe('/');
|
||||
checks.health = await probe('/api/health', 'ok');
|
||||
checks.ready = await probe('/api/ready', 'success');
|
||||
// /api/health and /api/ready use the same { ok: true } probe contract. The
|
||||
// readiness payload also includes a separate `ready` diagnostic field.
|
||||
checks.ready = await probe('/api/ready', 'ok');
|
||||
const missingHeaders = requiredHeaders.filter(name => [checks.home, checks.health, checks.ready].some(check => check?.headers?.[name] == null));
|
||||
const report = {
|
||||
base,
|
||||
@@ -45,6 +53,6 @@ const report = {
|
||||
};
|
||||
|
||||
await mkdir('docs/quality/evidence', { recursive: true });
|
||||
await writeFile('docs/quality/evidence/qa-live-runtime.json', JSON.stringify(report, null, 2) + '\n');
|
||||
await writeFile(evidencePath, JSON.stringify(report, null, 2) + '\n');
|
||||
console.log(JSON.stringify(report));
|
||||
if (!report.pass) process.exitCode = 1;
|
||||
|
||||
Reference in New Issue
Block a user