Set Content-Security-Policy
This commit is contained in:
1 parent
af0a8c9fee
commit
870d55b44f
7 files changed
+67
-25
No files matched your search
+11
@@ -152,6 +152,7 @@ async function open(
|
||||
page.on('websocket', (ws) => ws.url().startsWith(base.replace('http', 'ws')) || trackers.push(ws));
|
||||
page.on('pageerror', (error) => errors.push(`${name}: ${error.message}`));
|
||||
await page.addInitScript(trackPeers);
|
||||
await page.addInitScript(failOnCsp);
|
||||
if (init) await page.addInitScript(init);
|
||||
await page.goto(base);
|
||||
return page;
|
||||
@@ -187,6 +188,14 @@ async function hash(path: string) {
|
||||
|
||||
const log = (page: Page) => page.locator('#log').textContent();
|
||||
|
||||
// Init script for every page: whatever index.html's Content-Security-Policy blocks fails the test, the
|
||||
// browsers only log it.
|
||||
function failOnCsp() {
|
||||
document.addEventListener('securitypolicyviolation', ({ violatedDirective, blockedURI }) => {
|
||||
throw new Error(`Content-Security-Policy blocked ${blockedURI || 'inline'} by ${violatedDirective}`);
|
||||
});
|
||||
}
|
||||
|
||||
// Init script for every page: keeps its peer connections in window.peers, so a test can check that
|
||||
// they were closed. It runs in the hidden frames too, only the app's own window counts.
|
||||
function trackPeers() {
|
||||
@@ -1241,7 +1250,9 @@ for (const name of Object.keys(BROWSERS)) {
|
||||
const [sender, receiver] = await Promise.all(profiles.map((profile) => profile.newPage()));
|
||||
for (const page of [sender!, receiver!]) {
|
||||
sockets.set(page, []);
|
||||
page.on('pageerror', (error) => errors.push(`${name}: ${error.message}`));
|
||||
await page.addInitScript(trackPeers);
|
||||
await page.addInitScript(failOnCsp);
|
||||
}
|
||||
await Promise.all([sender!.goto(url), receiver!.goto(url)]);
|
||||
await transfer('offline', sender!, receiver!, source, LARGE_SIZE);
|
||||
|
||||
Reference in new issue
Block a user