Files
Nexus/apps/web/e2e/dev-system/auth-session.spec.ts
Hartmut 01f8974314
CI / Architecture Guardrails (pull_request) Successful in 2m59s
CI / Typecheck (pull_request) Successful in 6m41s
CI / Lint (pull_request) Successful in 4m18s
CI / Assistant Split Regression (pull_request) Successful in 5m6s
CI / Unit Tests (pull_request) Successful in 7m21s
CI / Build (pull_request) Successful in 5m21s
CI / Fresh-Linux Docker Deploy (pull_request) Failing after 38s
CI / E2E Tests (pull_request) Successful in 3m28s
CI / Release Images (pull_request) Has been skipped
rename(phase 3): compose/DB/infra names + stray code refs capakraken → nexus
- docker-compose.yml / .prod.yml / .ci.yml: project names, POSTGRES_DB/USER,
  pg_isready, DATABASE_URL, volume names (nexus_pgdata, nexus_prod_*)
- .github/workflows/ci.yml: POSTGRES_PASSWORD, pg_isready, psql credentials,
  GRANT statements, POSTGRES_PASSWORD=nexus_dev for Docker Deploy job
- scripts/db-target-guard.mjs: expectedDatabase default, NEXUS_EXPECTED_DB_NAME
- scripts/prisma-with-env.mjs, e2e/test-server.mjs: env-var rename
- packages/db/src/safe-destructive-env.ts + reset-dispo-import.ts: DB name set
- packages/db/src/destructive-db-guard.ts: PROTECTED_DATABASE_NAMES → "nexus"
- packages/db/src/destructive-db-guard.test.ts: all fixture DB names + comments
- .env.example, tooling/deploy/deploy.env.example: DATABASE_URL, image refs
- packages/api: Redis channel/key prefixes (rbac-invalidate, sse, ratelimit),
  logger service name, app-base-url log prefix
- E2E: DB container names, localStorage/sessionStorage keys, email domains
- scripts: architecture-guardrails filter, export/import-dev-seed defaults,
  harden-postgres defaults, start.sh pg_isready, worktree-hygiene fixture
- tooling/migrate/rename-to-nexus.sh: new maintenance-window cutover script

Only intentional capakraken survivor: anonymization.ts DEFAULT_ANONYMIZATION_SEED
(functional cryptographic constant — changing it would invalidate stored aliases).

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-21 16:35:39 +02:00

116 lines
4.5 KiB
TypeScript

/**
* Auth & Session Registry tests — dev system
*
* Validates that:
* - Login works with the dev-DB seed users
* - After login, all tRPC calls succeed (no 401 "Session revoked")
* - After logout, protected routes redirect to sign-in
* - Invalid credentials are rejected
*
* These tests guard against regressions in the active-session registry
* (token.sid / active_sessions table) introduced in the auth hardening work.
*
* Login-flow tests (describe "Auth") exercise the actual login form and count
* against the rate limiter. Session-registry tests (describe "Session registry")
* reuse pre-authenticated storage state from global setup to avoid rate-limit
* exhaustion when the whole suite runs sequentially.
*/
import { expect, test } from "@playwright/test";
import { STORAGE_STATE } from "../../playwright.dev.config.js";
import { assertNoTrpc401s, DEV_USERS, signIn, signOut } from "./helpers.js";
test.describe("Auth — login / logout", () => {
test("admin login succeeds and lands on a protected page", async ({ page }) => {
await signIn(page, DEV_USERS.admin.email, DEV_USERS.admin.password);
await expect(page).not.toHaveURL(/\/auth\/signin/);
});
test("manager login succeeds", async ({ page }) => {
await signIn(page, DEV_USERS.manager.email, DEV_USERS.manager.password);
await expect(page).not.toHaveURL(/\/auth\/signin/);
});
test("viewer login succeeds", async ({ page }) => {
await signIn(page, DEV_USERS.viewer.email, DEV_USERS.viewer.password);
await expect(page).not.toHaveURL(/\/auth\/signin/);
});
test("invalid credentials show an error and stay on sign-in", async ({ page }) => {
await page.goto("/auth/signin");
await page.fill('input[type="email"]', "nobody@example.com");
await page.fill('input[type="password"]', "wrong");
await page.click('button[type="submit"]');
await expect(page).toHaveURL(/\/auth\/signin/, { timeout: 5000 });
// Error message visible
await expect(page.locator("text=/invalid|incorrect|wrong|credentials/i")).toBeVisible({
timeout: 5000,
});
});
test("after logout, protected routes redirect to sign-in", async ({ page }) => {
await signIn(page, DEV_USERS.admin.email, DEV_USERS.admin.password);
await signOut(page);
await page.goto("/dashboard");
await expect(page).toHaveURL(/\/auth\/signin/, { timeout: 10000 });
});
});
// Session-registry tests reuse stored login state so they don't add to the
// rate-limit counter for the admin account.
test.describe("Session registry — no tRPC 401s after login", () => {
test.use({ storageState: STORAGE_STATE.admin });
test("admin session: dashboard loads without 401s", async ({ page }) => {
await assertNoTrpc401s(page, async () => {
await page.goto("/dashboard");
await page.waitForLoadState("networkidle");
});
});
test("admin navigating to /admin/users fires no 401s and loads user rows", async ({ page }) => {
await assertNoTrpc401s(page, async () => {
await page.goto("/admin/users");
await page.waitForLoadState("networkidle");
});
// At least one user row should be visible
await expect(page.locator("table")).toBeVisible({ timeout: 10000 });
await expect(page.locator("text=/planarchy\\.dev|nexus\\.dev/").first()).toBeVisible({
timeout: 10000,
});
await expect(page.locator("text=No users found")).toHaveCount(0);
});
test("admin navigating to /admin/system-roles fires no 401s", async ({ page }) => {
await assertNoTrpc401s(page, async () => {
await page.goto("/admin/system-roles");
await page.waitForLoadState("networkidle");
});
// Page should render something (not blank)
await expect(page.locator("h1,h2").first()).toBeVisible({ timeout: 10000 });
});
test("viewer session: no 401s on dashboard", async ({ page }) => {
// Override admin storageState for this one test
await page.context().clearCookies();
// Use viewer state via a fresh context — covered separately in rbac-permissions.spec.ts
// Here we just verify no residual 401s from a page refresh after session restore
await assertNoTrpc401s(page, async () => {
await page.goto("/dashboard");
await page.waitForLoadState("networkidle");
});
});
});
test.describe("Session registry — viewer no 401s", () => {
test.use({ storageState: STORAGE_STATE.viewer });
test("viewer session: dashboard loads without 401s", async ({ page }) => {
await assertNoTrpc401s(page, async () => {
await page.goto("/dashboard");
await page.waitForLoadState("networkidle");
});
});
});