Adds the sign-in screen, sign-out, and a server-side guard on every application route. The guard lives in the layout rather than the proxy because the proxy cannot query the database to check whether a session was revoked — and revocation is the reason sessions are stored there. Sign-in returns one message for an unknown account and for a wrong password, and verifies a dummy hash when the account does not exist, so neither the wording nor the timing enumerates staff addresses. An end-to-end test compares the two messages rather than trusting the code to keep them aligned. The shell now shows the signed-in person and their role from the database instead of hardcoded initials. Playwright signs in once in a setup project and shares the cookie; argon2 is deliberately slow, and logging in per test would also drive the shared failed-attempt counter toward a lockout. The seed resets that counter so repeated local runs cannot lock the demo account. Two test locators had to be scoped to the form: Next's route announcer carries role="alert" and an empty string, which silently satisfied the assertion. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Cr9dkEHwbDgkWPnyGj1Rjv
74 lines
2.3 KiB
TypeScript
74 lines
2.3 KiB
TypeScript
import { defineConfig, devices } from '@playwright/test';
|
|
|
|
import { STORAGE_STATE } from './tests/e2e/storage';
|
|
|
|
/**
|
|
* Certains environnements fournissent déjà un Chromium dont la révision ne
|
|
* correspond pas à celle qu'attend cette version de Playwright.
|
|
* PLAYWRIGHT_CHROMIUM_PATH permet de le réutiliser plutôt que d'en télécharger
|
|
* un second.
|
|
*/
|
|
const chromiumOverride = process.env.PLAYWRIGHT_CHROMIUM_PATH
|
|
? { launchOptions: { executablePath: process.env.PLAYWRIGHT_CHROMIUM_PATH } }
|
|
: {};
|
|
|
|
const PORT = Number(process.env.E2E_PORT ?? 3100);
|
|
const baseURL = `http://127.0.0.1:${PORT}`;
|
|
|
|
export default defineConfig({
|
|
testDir: './tests/e2e',
|
|
fullyParallel: true,
|
|
forbidOnly: Boolean(process.env.CI),
|
|
retries: process.env.CI ? 2 : 0,
|
|
// Serial in CI so the single Postgres service is not raced.
|
|
...(process.env.CI ? { workers: 1 } : {}),
|
|
reporter: process.env.CI ? [['github'], ['html', { open: 'never' }]] : 'list',
|
|
|
|
use: {
|
|
baseURL,
|
|
trace: 'on-first-retry',
|
|
},
|
|
|
|
projects: [
|
|
// Ouvre une session et enregistre le cookie ; les autres projets
|
|
// le réutilisent.
|
|
{
|
|
name: 'setup',
|
|
testMatch: /auth\.setup\.ts/,
|
|
use: { ...devices['Desktop Chrome'], ...chromiumOverride },
|
|
},
|
|
// Parcours d'authentification : doit partir d'un navigateur vierge.
|
|
{
|
|
name: 'anonyme',
|
|
testMatch: /auth\.spec\.ts/,
|
|
use: { ...devices['Desktop Chrome'], ...chromiumOverride },
|
|
},
|
|
{
|
|
name: 'chromium',
|
|
testIgnore: /auth\.(setup|spec)\.ts/,
|
|
dependencies: ['setup'],
|
|
use: {
|
|
...devices['Desktop Chrome'],
|
|
...chromiumOverride,
|
|
storageState: STORAGE_STATE,
|
|
},
|
|
},
|
|
],
|
|
|
|
webServer: {
|
|
// Exercise the standalone server, which is what the Docker image runs.
|
|
// `next start` is not compatible with `output: standalone`, and testing a
|
|
// different server than the one deployed defeats the purpose of this suite.
|
|
command: [
|
|
'pnpm build',
|
|
'cp -r .next/static .next/standalone/.next/static',
|
|
'cp -r public .next/standalone/public',
|
|
`node .next/standalone/server.js`,
|
|
].join(' && '),
|
|
url: baseURL,
|
|
env: { PORT: String(PORT), HOSTNAME: '127.0.0.1' },
|
|
reuseExistingServer: !process.env.CI,
|
|
timeout: 180_000,
|
|
},
|
|
});
|