Beweist die Auth-Gating-Garantie und härtet das System ab (Definition of Done #1, #2, #3, #7, #8): - Routen-Manifest (tests/e2e/routes.manifest.ts) als einzige Quelle der Wahrheit; anonyme Seite -> Redirect /login, anonyme API -> 401. - Kritische auth-gating.spec.ts: genau ein Fall je Manifest-Eintrag, ohne Daten-Leak. - Driftschutz (routes.manifest.spec.ts + tests/unit/routes-manifest.test.ts): keine ungetestete neue Route unter src/app/**. - Default-Deny-Beweis für Server Actions (server-actions-guard.spec.ts + tests/unit/server-actions-guard.test.ts): jede "use server"-Funktion ruft als erste Anweisung einen Guard; Login-Actions per Allowlist ausgenommen. - Wiederverwendbare reine Scanner unter tests/support (route-scan, guard-scan) — offline lauffähig, in Vitest und Playwright geteilt. - rbac-scoping, search-eta, login-ratelimit, security-headers Specs (gegen geseedeten Server; in der Sandbox deferred, per test.skip abgesichert). - global-setup (Migration + Seed) und auth.setup (Login je Konto -> storageState); Playwright-Projekte setup -> chromium verdrahtet. - src/lib/security/headers.test.ts: statischer Beleg für CSP, HSTS, X-Frame-Options DENY, nosniff, Permissions-Policy. - vitest.config.ts: Coverage-Schwellen (>=90 %) für src/lib/search + src/lib/geo. - package.json: Scripts test:unit, test:coverage, test:e2e, test:e2e:gating. - docs/reference/sicherheitshaertung-checkliste.md: jeder Härtungspunkt mit Test/Befehl und Negativ-Probe. Offline verifiziert: tsc --noEmit (0), vitest run (229 passed / 7 db-skipped), drizzle-kit check (ok), next build (exit 0), next lint (0 Fehler), playwright --list (98 Tests, 15 Dateien). DB-/Server-/Browser-abhängige E2E-Läufe sind deferred (kein Postgres/Server in der Sandbox). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
51 lines
2.0 KiB
TypeScript
51 lines
2.0 KiB
TypeScript
import { test, expect } from "@playwright/test";
|
|
|
|
/**
|
|
* Security-Header & Cookie-Flags (Definition of Done #8, Querschnittsstandard
|
|
* 1, 9, 11).
|
|
*
|
|
* NICHT in der Sandbox ausführbar (kein Server) — deferred. Wird über
|
|
* `npm run test:e2e` gegen einen laufenden Server ausgeführt. Der statische
|
|
* Header-Satz ist zusätzlich offline durch src/lib/security/headers.test.ts
|
|
* abgesichert.
|
|
*
|
|
* Verifikation entspricht: `curl -sI https://<host>/login | grep -i x-frame-options`.
|
|
*/
|
|
test.use({ storageState: { cookies: [], origins: [] } });
|
|
|
|
test.describe("Security-Header auf /login", () => {
|
|
test("setzt X-Frame-Options, nosniff, CSP frame-ancestors none, HSTS", async ({
|
|
request,
|
|
}) => {
|
|
const res = await request.get("/login");
|
|
const h = res.headers();
|
|
expect(h["x-frame-options"]).toBe("DENY");
|
|
expect(h["x-content-type-options"]).toBe("nosniff");
|
|
expect(h["content-security-policy"]).toContain("frame-ancestors 'none'");
|
|
expect(h["strict-transport-security"]).toMatch(/max-age=\d+/);
|
|
});
|
|
});
|
|
|
|
test.describe("Session-Cookie-Flags", () => {
|
|
test("nach Login: Session-Cookie ist httpOnly + sameSite", async ({
|
|
context,
|
|
page,
|
|
}) => {
|
|
// Erwartet einen funktionierenden Credentials-Login (Seed). Deferred.
|
|
await page.goto("/login");
|
|
await page.getByLabel(/E-Mail/i).fill("wehr-admin-a@example.test");
|
|
await page.getByLabel(/Passwort/i).fill("Test-Passwort-1234");
|
|
await page.getByRole("button", { name: /Anmelden/i }).click();
|
|
await page.waitForURL((url) => !url.pathname.startsWith("/login"));
|
|
|
|
const cookies = await context.cookies();
|
|
const session = cookies.find((c) => /authjs|next-auth|__Secure-/.test(c.name));
|
|
expect(session, "Session-Cookie gesetzt").toBeTruthy();
|
|
expect(session?.httpOnly).toBe(true);
|
|
expect(session?.sameSite).toMatch(/Lax|Strict/);
|
|
// `secure` nur unter https (Querschnittsstandard 9). Lokal (http) false.
|
|
const isHttps = (process.env.E2E_BASE_URL ?? "").startsWith("https://");
|
|
expect(session?.secure).toBe(isHttps);
|
|
});
|
|
});
|