From 0f67a6884ceed0634b68bc61cab72464179fbdbe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rados=C5=82aw=20Smoli=C5=84ski?= Date: Tue, 1 Dec 2026 10:46:42 +0100 Subject: [PATCH] e2e:built: a locked staff account and the panel actions checked on the built site (both bundlers) Co-Authored-By: Claude Opus 5.5 --- reference/e2e/sign-in-answers.spec.ts | 59 +++++++++++++++++++++++++++ scripts/e2e-built.mjs | 6 ++- 2 files changed, 63 insertions(+), 2 deletions(-) create mode 100644 reference/e2e/sign-in-answers.spec.ts diff --git a/reference/e2e/sign-in-answers.spec.ts b/reference/e2e/sign-in-answers.spec.ts new file mode 100644 index 0000000..64a5c8d --- /dev/null +++ b/reference/e2e/sign-in-answers.spec.ts @@ -0,0 +1,59 @@ +import { type APIRequestContext, expect, test } from '@playwright/test' +import { randomUUID } from 'node:crypto' + +import { totp } from './totp' + +/** + * On the BUILT site (pnpm e2e:built, webpack and Turbopack), what 1.17.2 changed at the sign-in and in the panel: + * - a locked staff account answers its login exactly like a wrong password (accounts.lockedAnswer) — the hook + * recognises Payload's error by the name Payload gives it, which a minified bundle must keep; + * - the plugin's panel actions refuse a request from another origin (adminSameOrigin), the site's own still works. + * Needs the E2E_* test admin (e2e/create-test-admin.ts). The locked account is a fresh one made here, so the test + * admins are never locked. + */ +const { E2E_ADMIN_EMAIL: adminEmail, E2E_ADMIN_PASSWORD: password, E2E_TOTP_SECRET: secret } = process.env + +let admin: APIRequestContext + +test.beforeAll(async ({ baseURL, playwright }) => { + test.skip(!adminEmail || !password || !secret, 'E2E_ADMIN_* values are not set') + admin = await playwright.request.newContext({ baseURL, extraHTTPHeaders: { origin: baseURL! } }) + expect((await admin.post('/api/users/login', { data: { email: adminEmail, password } })).status()).toBe(200) + expect((await (await admin.post('/api/verify-totp', { data: { token: totp(secret!) } })).json()).ok).toBe(true) +}) +test.afterAll(async () => { + await admin?.dispose() +}) + +test('a locked staff account gets the wrong-password answer, REST and GraphQL', async ({ baseURL, playwright }) => { + const email = `locked-${randomUUID().slice(0, 8)}@example.com` + const own = `L-${randomUUID()}` + expect((await admin.post('/api/users', { data: { email, password: own, roles: ['editor'] } })).status()).toBe(201) + const anon = await playwright.request.newContext({ baseURL }) + const login = async (address: string, pass: string) => { + const res = await anon.post('/api/users/login', { data: { email: address, password: pass } }) + return { body: await res.text(), status: res.status() } + } + for (let i = 0; i < 5; i++) {await login(email, 'a-wrong-password-1')} + const invented = await login(`nobody-${randomUUID().slice(0, 8)}@example.com`, 'a-wrong-password-1') + expect(invented.status).toBe(401) + expect(await login(email, own)).toEqual(invented) + const gql = async (address: string, pass: string) => { + const res = await anon.post('/api/graphql', { data: { query: `mutation { loginUser(email: ${JSON.stringify(address)}, password: ${JSON.stringify(pass)}) { token } }` } }) + const error = ((await res.json()) as { errors?: { extensions?: { name?: string }; message: string }[] }).errors?.[0] + return { message: error?.message, name: error?.extensions?.name } + } + expect(await gql(email, own)).toEqual(await gql(`nobody-${randomUUID().slice(0, 8)}@example.com`, 'x-wrong-password-1')) + await anon.dispose() +}) + +test('panel actions: another origin gets 403 with the admin cookie, the site itself goes through', async ({ baseURL }) => { + const foreign = await admin.fetch('/api/ipal/cookie-approval', { + data: '{"ids":[]}', + headers: { 'content-type': 'text/plain', origin: 'https://blog.example.test', 'sec-fetch-site': 'same-site' }, + method: 'POST', + }) + expect(foreign.status()).toBe(403) + const own = await admin.fetch('/api/ipal/cookie-approval', { data: '{"ids":[]}', headers: { 'content-type': 'text/plain', origin: baseURL! }, method: 'POST' }) + expect(own.status()).toBe(200) +}) diff --git a/scripts/e2e-built.mjs b/scripts/e2e-built.mjs index c614f0b..e6721cd 100644 --- a/scripts/e2e-built.mjs +++ b/scripts/e2e-built.mjs @@ -14,7 +14,9 @@ * route under Next, the state block in the panel's production bundle) and the smoke tests "no package.json is published", * "client hints" (Payload's colour-scheme headers on the admin only; a public page is requested once), every * "consent" test (banner at first paint, Global Privacy Control, equal prominence, withdrawal, the consent log) - * and e2e/sign-in-look.spec.ts (the sign-in panel in the first HTML, on a phone, the language links, the 2FA screen). + * and e2e/sign-in-look.spec.ts (the sign-in panel in the first HTML, on a phone, the language links, the 2FA screen), + * e2e/sign-in-answers.spec.ts (1.17.2: a locked staff account answers like a wrong password; the panel actions refuse + * another origin). * * Needs what the reference site's "Production check" needs (reference/README.md): reference/.env with a local, * seeded database and the E2E_* test admin. The test admins are reset by Playwright's global setup. @@ -89,7 +91,7 @@ for (const bundler of bundlers) { process.exit(1) } console.log(`[e2e:built] ✓ ${bundler}: no package manifest among ${files.length} public files`) - run(`${bundler}: the built site — late-staff spec, the mail service, closed doors, the published-files check, the client hints, consent and the sign-in look`, 'pnpm', ['exec', 'playwright', 'test', 'late-staff', 'mail-relay', 'closed-doors', 'smoke', 'sign-in-look', '--grep', 'late staff collection|the mail service|closed doors|no package.json is published|client hints|consent|sign-in look'], site, { ALLOW_LOCAL_MEDIA: process.env.ALLOW_LOCAL_MEDIA ?? '1', E2E_LATE_STAFF: '1' }) + run(`${bundler}: the built site — late-staff spec, the mail service, closed doors, the published-files check, the client hints, consent, the sign-in look and the sign-in answers`, 'pnpm', ['exec', 'playwright', 'test', 'late-staff', 'mail-relay', 'closed-doors', 'smoke', 'sign-in-look', 'sign-in-answers', '--grep', 'late staff collection|the mail service|closed doors|no package.json is published|client hints|consent|sign-in look|locked staff account|panel actions'], site, { ALLOW_LOCAL_MEDIA: process.env.ALLOW_LOCAL_MEDIA ?? '1', E2E_LATE_STAFF: '1' }) passed.push(bundler) } console.log(`\n[e2e:built] passed: ${passed.join(' and ')}. (The reference site's .next now holds the ${passed.at(-1)} build WITH the fixture: rebuild with \`pnpm build\` there before other checks.)`)