diff --git a/docs/DELIVERY.md b/docs/DELIVERY.md index c11b274..f119769 100644 --- a/docs/DELIVERY.md +++ b/docs/DELIVERY.md @@ -317,8 +317,10 @@ environnement non public avant l'activation. `npm run build` produit l'application dans `website/dist`. `npm start` sert ce répertoire avec `server.mjs` et, lorsque la fonctionnalité est activée, expose -l'API `/api/cards`. Les tests de Vite Preview couvrent le comportement du build -dans le navigateur, mais ni les en-têtes HTTP ni l'API de ce serveur Node. +l'API `/api/cards`. Les tests E2E de production servent le build avec ce même +serveur, Sokko TCG désactivé : ils couvrent le comportement du build dans le +navigateur sous la CSP de `server.mjs`, mais pas l'API `/api/cards`, que +`npm run test:e2e:cards` valide. La politique de cache du serveur est la suivante : diff --git a/docs/TEST_STRATEGY.md b/docs/TEST_STRATEGY.md index 0964c95..0250817 100644 --- a/docs/TEST_STRATEGY.md +++ b/docs/TEST_STRATEGY.md @@ -32,6 +32,7 @@ not bugs, missing scenarios or a percentage of work remaining. | Planner: editing, quantities, partial-progress resets, prerequisites, subtree reorder, drawer and cross-page persistence | `e2e/task-planner.spec.js`; `tests/task-planner-quantities.test.mjs` and v2 import tests | | Representative visual states and responsive layouts | `e2e/style-layouts.spec.js`, `tool-style-states.spec.js`, `card-surfaces.spec.js`, `nds-controls.spec.js`, `nds-patterns.spec.js` | | Production onboarding | `e2e/production/onboarding.spec.js` | +| Formula tools under the production CSP | `e2e/production/content-security-policy.spec.js`; `tests/server-cache.test.mjs` forbids string evaluation in client code | These suites cover selected risks, not every permutation of every tool. Public formats, product vocabulary, editorial validation, security restrictions @@ -68,9 +69,10 @@ change affects persisted data, imports, user interaction or delivery. `StrictMode`; it validates interactive behavior against source modules. `npm run check:full` lui réserve le port 4181 pour ne pas réutiliser une instance personnelle éventuellement ouverte sur 5173. -- `npm run test:e2e:production` rebuilds the client and exercises the Vite - Preview result. It catches build-only behavior and stale-bundle recovery, but - does not run the Node static server or the production proxy. +- `npm run test:e2e:production` rebuilds the client and serves it with + `server.mjs`, Sokko TCG disabled. It catches build-only behavior, stale-bundle + recovery and anything the Node server's CSP blocks, such as `eval` in a tool. + It does not exercise headers added by the production proxy. - `npm run test:e2e:cards` construit l'application puis lance `server.mjs` avec une base SQLite temporaire, la connexion de test et Sokko TCG activé. Il valide la reprise d'ouverture, l'album, l'administration et le layout à diff --git a/e2e/production/content-security-policy.spec.js b/e2e/production/content-security-policy.spec.js new file mode 100644 index 0000000..a0abe34 --- /dev/null +++ b/e2e/production/content-security-policy.spec.js @@ -0,0 +1,33 @@ +// 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([]); +}); diff --git a/playwright.production.config.js b/playwright.production.config.js index 6a2e0f7..af3864e 100644 --- a/playwright.production.config.js +++ b/playwright.production.config.js @@ -1,4 +1,4 @@ -// Rôle : vérifie le build de production sans réutiliser une instance Vite de développement. +// Rôle : vérifie le build de production servi par server.mjs, sans réutiliser une instance Vite de développement. import { defineConfig, devices } from "@playwright/test"; export default defineConfig({ @@ -12,7 +12,9 @@ export default defineConfig({ screenshot: "only-on-failure" }, webServer: { - command: "npm run preview -- --host 127.0.0.1 --port 4173 --strictPort", + // Le serveur Node livré, et non Vite Preview : il porte la CSP et les en-têtes de production. + command: "node server.mjs", + env: { HOST: "127.0.0.1", PORT: "4173", CARDS_ENABLED: "false" }, url: "http://127.0.0.1:4173", reuseExistingServer: false, timeout: 120000