// Invoked by the Go scratch-server test, never against the deployed service. import assert from "node:assert/strict"; import { mkdir } from "node:fs/promises"; import { join } from "node:path"; import { launchChrome } from "./browser.mjs"; const url = process.argv[2]; assert.ok(url?.startsWith("http://127.0.0.1:"), "scratch loopback fixture required"); const browser = await launchChrome({ width: 390, height: 844 }); try { const page = await browser.openPage("about:blank"); await page.goto(url); await page.waitForSelector("#report"); assert.equal(await page.evaluate("document.title"), "Safe report"); assert.equal(await page.evaluate("document.querySelector('#report').textContent"), "Readable report"); assert.equal(await page.evaluate("getComputedStyle(document.querySelector('#report')).color"), "rgb(12, 34, 56)"); if (process.env.PIPELINES_CAPTURE_DIR) { await mkdir(process.env.PIPELINES_CAPTURE_DIR, { recursive: true }); await page.screenshot(join(process.env.PIPELINES_CAPTURE_DIR, "artifact-script-blocked.png")); } // The inline attack would change the title and call /attack if it ran. The // server-side test also asserts that endpoint received no request. console.log("Raw HTML report is readable; inline script blocked by response policy."); } finally { await browser.close(); }