PROGRAMISTA §6 rows 83–87 now 1.18.0 (1.17.2 was never released alone) and new rows 88–94; iapl-upgrade blocks for speed and growth and for drafts in related documents, the 1.17.2 blocks as "→ 1.18.0 (from 1.17.2)"; every "since 1.17.2" in docs, comments and tests reads 1.18.0; reference skills, AGENTS.md and the reference index on 1.18.0. Co-Authored-By: Claude Opus 5.5 <[email protected]>
63 lines
3.7 KiB
TypeScript
63 lines
3.7 KiB
TypeScript
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.18.0 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 })
|
|
// the site reads the client address from IAPL_IP_HEADER (reference/.env: x-forwarded-for, one proxy)
|
|
const login = async (address: string, pass: string, ip = '203.0.113.150') => {
|
|
const res = await anon.post('/api/users/login', { data: { email: address, password: pass }, headers: { 'x-forwarded-for': ip } })
|
|
return { body: await res.text(), status: res.status() }
|
|
}
|
|
// 1.18.0 (accounts.signInLimit): one IP fails at most 5 times per address and Payload locks a staff account at 50
|
|
// failures — a spray from 50 IPs, one failure each, locks it
|
|
for (let i = 0; i < 50; i++) {await login(email, 'a-wrong-password-1', `198.51.100.${i + 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 { name: error?.extensions?.name, message: error?.message }
|
|
}
|
|
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)
|
|
})
|