Files
pipelines/web/test/artifact-security-probe.mjs
T

21 lines
1.0 KiB
JavaScript

// Invoked by the Go scratch-server test, never against the deployed service.
import assert from "node:assert/strict";
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)");
// 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();
}