Merge claude/login-page-whitelabel-616f3d: the panel's sign-in look (whiteLabel.signIn), the client's logo, hardened brand image fetch

Conflicts kept both sides: the 2FA texts (twoFactorBusy from A, twoFactorCodeDigit here), the reference index rows,
and the e2e:built line (closed doors from C and the sign-in look here). routes.snapshot.json judges the new public
GET /api/ipal/admin-language.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
Radosław Smoliński
2026-11-26 22:04:30 +01:00
co-authored by Claude Opus 5.5
126 changed files with 2283 additions and 46 deletions
+4 -3
View File
@@ -12,8 +12,9 @@
* 3. Playwright against `next start`: e2e/closed-doors.spec.ts (every door of e2e/closed-doors.ts asked as an anonymous
* visitor, a customer and an editor), e2e/late-staff.spec.ts, e2e/mail-relay.spec.ts (the mail service: the confirm
* 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) and every
* "consent" test (banner at first paint, Global Privacy Control, equal prominence, withdrawal, the consent log).
* "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).
*
* 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.
@@ -88,7 +89,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 and consent`, 'pnpm', ['exec', 'playwright', 'test', 'late-staff', 'mail-relay', 'closed-doors', 'smoke', '--grep', 'late staff collection|the mail service|closed doors|no package.json is published|client hints|consent'], 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 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' })
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.)`)
+184
View File
@@ -0,0 +1,184 @@
#!/usr/bin/env node
/**
* Screenshots of the panel's sign-in screens, for docs/dev/login-page/ (design review, before / after).
*
* node scripts/login-page-shots.mjs --prefix=after --base=http://localhost:3310 [--only=login,forgot] [--logo=keep|none]
*
* Needs the reference site running at --base with a seeded local database and the E2E_* test admin of
* reference/.env (reference/README.md). Writes docs/dev/login-page/<prefix>-<screen>-<variant>.png:
* login (light, dark, phone, Polish), login with a wrong password, forgot password, the 2FA code screen,
* the 2FA setup screen (a throw-away editor, removed at the end).
* --logo=none takes the logo out of Site settings for the run and puts it back (the "no logo" pictures);
* --logo=<file.png> uploads that picture, sets it as the logo for the run and puts the old value back.
* Dark pictures set Payload's theme cookie; the development indicator of Next is hidden.
* create-first-user needs a database without users: point --base at such a site and pass --only=first-user.
*/
import { createHmac } from 'node:crypto'
import { mkdirSync, readFileSync } from 'node:fs'
import { createRequire } from 'node:module'
import path from 'node:path'
import { fileURLToPath } from 'node:url'
const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..')
const require = createRequire(path.join(root, 'reference/package.json'))
const { chromium, request } = require('@playwright/test')
try {
process.loadEnvFile(path.join(root, 'reference/.env'))
} catch {
/* values come from the environment */
}
const arg = (name, fallback) => process.argv.find((a) => a.startsWith(`--${name}=`))?.slice(name.length + 3) ?? fallback
const base = arg('base', process.env.E2E_BASE_URL ?? 'http://localhost:3310')
const prefix = arg('prefix', 'after')
const only = arg('only')?.split(',')
const logoMode = arg('logo', 'keep')
const suffix = arg('suffix', logoMode === 'none' ? '-name' : logoMode === 'keep' ? '' : '-logo')
const out = path.join(root, 'docs/dev/login-page')
mkdirSync(out, { recursive: true })
const want = (name) => !only || only.includes(name)
const admin = { email: process.env.E2E_ADMIN_EMAIL, password: process.env.E2E_ADMIN_PASSWORD, secret: process.env.E2E_TOTP_SECRET }
function totp(secret, now = Date.now()) {
const alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ234567'
let bits = ''
for (const ch of secret.replace(/=+$/, '').toUpperCase()) {bits += alphabet.indexOf(ch).toString(2).padStart(5, '0')}
const key = Buffer.from((bits.match(/.{8}/g) ?? []).map((b) => parseInt(b, 2)))
const counter = Buffer.alloc(8)
counter.writeBigUInt64BE(BigInt(Math.floor(now / 1000 / 30)))
const hmac = createHmac('sha1', key).update(counter).digest()
const offset = hmac[hmac.length - 1] & 0xf
return ((hmac.readUInt32BE(offset) & 0x7fffffff) % 1_000_000).toString().padStart(6, '0')
}
const DESKTOP = { height: 800, width: 1280 }
const PHONE = { height: 844, width: 390 }
const browser = await chromium.launch()
async function shot(name, { colorScheme = 'light', locale = 'en-US', viewport = DESKTOP } = {}, steps) {
const context = await browser.newContext({ baseURL: base, colorScheme, deviceScaleFactor: 1, locale, reducedMotion: 'reduce', viewport })
if (colorScheme === 'dark') {await context.addCookies([{ name: 'payload-theme', url: base, value: 'dark' }])}
// nothing is asked of another host while the pictures are taken
await context.route((url) => url.origin !== new URL(base).origin, (route) => route.abort())
const page = await context.newPage()
try {
await steps(page)
await page.addStyleTag({ content: 'nextjs-portal{display:none!important}' })
await page.waitForLoadState('networkidle').catch(() => undefined)
await page.waitForTimeout(400)
const file = path.join(out, `${prefix}-${name}${suffix}.png`)
await page.screenshot({ fullPage: true, path: file })
console.log(`wrote ${path.relative(root, file)}`)
} finally {
await context.close()
}
}
const signIn = async (page, who) => {
await page.goto('/admin/login')
await page.waitForLoadState('networkidle')
await page.locator('#field-email').pressSequentially(who.email)
await page.locator('#field-password').pressSequentially(who.password)
await page.click('.form-submit button')
}
/**
* ONE fully signed-in API session for the whole run, of the second test admin: a 2FA code counts against the
* account's verify limit (5 in 10 minutes), and the first admin's screens are the ones photographed.
*/
let session = null
async function adminApi() {
if (session) {return session}
const api = await request.newContext({ baseURL: base, extraHTTPHeaders: { origin: base } })
const login = await api.post('/api/users/login', { data: { email: admin.email.replace('@', '-2@'), password: admin.password } })
if (login.status() !== 200) {throw new Error(`test admin cannot sign in (${login.status()})`)}
const verify = await (await api.post('/api/verify-totp', { data: { token: totp(admin.secret) } })).json()
if (!verify.ok) {throw new Error('test admin: the 2FA code was refused (verify limit? run the reference site\'s e2e/create-test-admin.ts)')}
session = api
return api
}
let restoreLogo = null
if (logoMode !== 'keep') {
const api = await adminApi()
const settings = await (await api.get('/api/globals/site-settings?depth=0')).json()
let logo = null
let uploaded = null
if (logoMode !== 'none') {
const file = path.resolve(logoMode)
const res = await api.post('/api/media', {
multipart: { _payload: JSON.stringify({ alt: 'Placeholder logo' }), file: { buffer: readFileSync(file), mimeType: 'image/png', name: path.basename(file) } },
})
uploaded = (await res.json())?.doc?.id
if (!uploaded) {throw new Error(`the logo was not uploaded (${res.status()})`)}
logo = uploaded
}
await api.post('/api/globals/site-settings', { data: { logo } })
restoreLogo = async () => {
await api.post('/api/globals/site-settings', { data: { logo: settings.logo ?? null } })
if (uploaded) {await api.delete(`/api/media/${uploaded}`)}
}
}
try {
if (want('login')) {
await shot('login-light', {}, (page) => page.goto('/admin/login'))
await shot('login-dark', { colorScheme: 'dark' }, (page) => page.goto('/admin/login'))
await shot('login-phone', { viewport: PHONE }, (page) => page.goto('/admin/login'))
await shot('login-phone-dark', { colorScheme: 'dark', viewport: PHONE }, (page) => page.goto('/admin/login'))
await shot('login-pl', { locale: 'pl-PL' }, (page) => page.goto('/admin/login'))
}
if (want('error')) {
const wrong = async (page) => {
await signIn(page, { email: '[email protected]', password: 'wrong-password-1' })
await page.locator('.payload-toast-container li, .toast-error').first().waitFor({ timeout: 10_000 }).catch(() => undefined)
}
await shot('login-error-light', {}, wrong)
await shot('login-error-phone', { viewport: PHONE }, wrong)
}
if (want('forgot')) {
await shot('forgot-light', {}, (page) => page.goto('/admin/forgot'))
await shot('forgot-dark', { colorScheme: 'dark' }, (page) => page.goto('/admin/forgot'))
await shot('forgot-phone', { viewport: PHONE }, (page) => page.goto('/admin/forgot'))
}
if (want('verify') && admin.email) {
const verify = async (page) => {
await signIn(page, admin)
await page.waitForURL(/verify-totp/, { timeout: 20_000 })
}
await shot('2fa-code-light', {}, verify)
await shot('2fa-code-dark', { colorScheme: 'dark' }, verify)
await shot('2fa-code-phone', { viewport: PHONE }, verify)
}
if (want('setup') && admin.email) {
const api = await adminApi()
const editor = { email: `shots-editor-${Date.now()}@example.com`, password: `shots-${Date.now()}-Qm48xZr` }
const created = await (await api.post('/api/users', { data: { ...editor, roles: ['editor'] } })).json()
const id = created?.doc?.id
try {
const setup = async (page) => {
await signIn(page, editor)
await page.waitForURL(/setup-totp/, { timeout: 20_000 })
}
await shot('2fa-setup-light', {}, setup)
await shot('2fa-setup-dark', { colorScheme: 'dark' }, setup)
await shot('2fa-setup-phone', { viewport: PHONE }, setup)
} finally {
if (id) {await api.delete(`/api/users/${id}`)}
}
}
if (only?.includes('first-user')) {
const first = async (page) => {
await page.goto('/admin/create-first-user')
await page.locator('#field-confirm-password').waitFor({ timeout: 20_000 })
}
await shot('first-user-light', {}, first)
await shot('first-user-dark', { colorScheme: 'dark' }, first)
await shot('first-user-phone', { viewport: PHONE }, first)
}
} finally {
await restoreLogo?.()
await session?.dispose()
await browser.close()
}
+1
View File
@@ -71,6 +71,7 @@ export const DESCRIPTIONS = {
'e2e/mail-relay-setup.ts': 'for the mail-service spec: empties the SMTP fields and the stored token, so the next e-mail enrols and goes through the mail service (local database only)',
'e2e/mail-relay.spec.ts': 'the mail service on a built site: the state block in the panel, the first e-mail through the public confirm route, no token in anything the browser receives',
'e2e/smtp-sink.ts': 'a local mail sink for the smoke tests: reads what the site really sent (recipients, attachments)',
'e2e/sign-in-look.spec.ts': 'browser test of the sign-in look (whiteLabel.signIn): the panel comes with the form, sits above it on a phone in both themes, is on forgot / reset / logout too, the language links work, the 2FA code screen keeps its boxes (now named)',
'e2e/two-factor-back.spec.ts': 'browser test of the 2FA screens\' `back` link (twoFactor.safeBack): a prepared link — script or another host — ends on the admin root, an ordinary one is followed',
'e2e/routes.snapshot.json': 'every public route of the site (REST, GraphQL, Next route files) with one line saying who may use it and why — the judged list `routes:check` compares with',
'e2e/routes.ts': '`routes:check`: the site\'s public routes against e2e/routes.snapshot.json (`pnpm payload run e2e/routes.ts [update]`; from the repository `pnpm routes:check`)',