sokko-g/e2e/production/toolbox-share.spec.js
Shinuwa bec9ea5b2f
All checks were successful
Validate and deploy Sokko G / validate (push) Successful in 20m39s
Validate and deploy Sokko G / deploy (push) Successful in 12s
Send a toolbox through an encrypted link
Sharing a toolbox meant exporting a JSON file and passing it around by
hand. A toolbox can now be sent from the site while staying local first:
the browser compresses and encrypts the v2 export with AES-GCM, and the
key lives only in the link fragment, so the server keeps for at most
24 hours a copy it cannot read.

- Add the /api/shares service: upload, metadata, download and revoke,
  with files in SHARES_DIR, a purge every 10 minutes, and single-use
  links (the default) deleted only once fully downloaded.
- Cap the server load: 50 MiB per share, total storage, free disk
  space, daily volume, concurrent and stalled uploads, reads per link,
  plus a wide per-connection cap kept in memory without storing IPs.
- Limit each browser to 2 shares and 100 MiB per day and 2 active
  links, and show the existing link of a toolbox already shared.
- Add the send dialog (card and game drawer) and the /receive page,
  which previews or directly imports through the existing import path.
- Move shared HTTP helpers to services/http.js for both APIs.
- Document the format, delivery, server layout and privacy wording.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-11 16:26:05 +01:00

38 lines
1.8 KiB
JavaScript

// Rôle : 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([]);
});