// Negative control: proves csp_check's detection works. Serves a page containing an inline script and an // inline event handler under the same CSP and expects Chromium to refuse them. import { createRequire } from 'node:module'; const require = createRequire(process.env.PW_DIR + '/'); const { chromium } = require('playwright'); const BASE = process.env.BASE; const b = await chromium.launch(); const p = await b.newPage(); const seen = []; p.on('console', (m) => { if (/Content Security Policy|Refused to/i.test(m.text())) seen.push(m.text().slice(0, 140)); }); await p.goto(BASE + '/csp-negative-control.html', { waitUntil: 'networkidle' }); console.log('inline script ran:', await p.evaluate(() => window.__ran === true)); console.log('violations seen:', seen.length); seen.forEach((s) => console.log(' -', s)); await b.close(); process.exit(seen.length ? 0 : 1);