/** * @file Vérifie qu'un envoi de toolbox chiffré fonctionne de bout en bout sous la CSP du serveur Node. */ import { expect, test } from "@playwright/test"; async function watchCsp(page, violations) { await page.exposeFunction("reportCspViolation", (violation) => violations.push(violation)); await page.addInitScript(() => { globalThis.document.addEventListener("securitypolicyviolation", (event) => globalThis.reportCspViolation(`${event.violatedDirective} ${event.blockedURI}`)); }); } test("a toolbox is sent and received under the production CSP", async ({ page, browser }) => { const violations = []; await watchCsp(page, violations); await page.goto("/#/toolboxes"); await page.getByRole("button", { name: "Nouvelle toolbox" }).click(); const creation = page.getByRole("dialog", { name: "Nouvelle toolbox" }); await creation.getByLabel("Nom").fill("Envoi CSP"); await creation.getByRole("button", { name: "Créer", exact: true }).click(); await page.goto("/#/toolboxes"); await page.getByRole("button", { name: "Envoyer Envoi CSP", exact: true }).click(); const dialog = page.getByRole("dialog", { name: "Envoyer « Envoi CSP »" }); await dialog.getByRole("button", { name: "Créer le lien" }).click(); const link = await dialog.getByLabel("Lien à transmettre").inputValue(); expect(link).toMatch(/\/#\/receive\/[A-Za-z0-9_-]{22}#[A-Za-z0-9_-]{43}$/); const context = await browser.newContext(); const recipient = await context.newPage(); const recipientViolations = []; await watchCsp(recipient, recipientViolations); await recipient.goto(link); await recipient.getByRole("button", { name: "Recevoir et importer" }).click(); await expect(recipient.getByRole("heading", { name: "Envoi CSP", exact: true })).toBeVisible(); await context.close(); expect(violations).toEqual([]); expect(recipientViolations).toEqual([]); });