Vite Preview sends none of the headers of server.mjs, so the production E2E passed while the CSP blocked the calculator formulas in production. The build is now served by server.mjs with Sokko TCG disabled, and a new spec saves and updates a calculator result there, failing on any CSP violation. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
33 lines
1.9 KiB
JavaScript
33 lines
1.9 KiB
JavaScript
// Rôle : vérifie que les outils qui évaluent des formules restent utilisables sous la CSP du serveur Node.
|
|
import { expect, test } from "@playwright/test";
|
|
|
|
test("the calculator saves and updates results under the production CSP", async ({ page }) => {
|
|
const violations = [];
|
|
await page.exposeFunction("reportCspViolation", (violation) => violations.push(violation));
|
|
await page.addInitScript(() => {
|
|
globalThis.document.addEventListener("securitypolicyviolation", (event) => globalThis.reportCspViolation(`${event.violatedDirective} ${event.blockedURI}`));
|
|
});
|
|
|
|
const response = await page.goto("/#/toolboxes");
|
|
expect(response.headers()["content-security-policy"]).toMatch(/script-src 'self'/);
|
|
await page.getByRole("button", { name: "Nouvelle toolbox" }).click();
|
|
const dialog = page.getByRole("dialog", { name: "Nouvelle toolbox" });
|
|
await dialog.getByLabel("Nom").fill("CSP");
|
|
await dialog.getByRole("button", { name: "Créer", exact: true }).click();
|
|
await page.getByRole("button", { name: "Ajouter un outil", exact: true }).click();
|
|
await page.getByRole("dialog", { name: "Ajouter un outil" }).getByRole("button", { name: "Calculateur" }).click();
|
|
|
|
const tool = page.locator('[data-module-type="calculator"]');
|
|
const expression = tool.getByRole("textbox", { name: "Calcul", exact: true });
|
|
await expression.fill("10*10");
|
|
await tool.getByLabel("Libellé", { exact: true }).fill("Fer");
|
|
await tool.getByRole("button", { name: "Enregistrer", exact: true }).click();
|
|
const savedResult = tool.locator(".calculator-entry strong").first();
|
|
await expect(savedResult).toHaveAttribute("aria-label", "100");
|
|
|
|
await tool.locator(".tool-split-entry-summary").first().click();
|
|
await expression.fill("10*20");
|
|
await tool.getByRole("button", { name: "Mettre à jour", exact: true }).click();
|
|
await expect(savedResult).toHaveAttribute("aria-label", "200");
|
|
expect(violations).toEqual([]);
|
|
});
|