Form attachments: reference smoke test with a mail sink, Turnstile reset fix, docs
Co-Authored-By: Claude Fable 5.2 <[email protected]>
This commit is contained in:
co-authored by
Claude Fable 5.2
parent
387debc88c
commit
fdb6140c09
@@ -46,6 +46,11 @@ once there are more than 20.
|
||||
whether the mail server takes a file of that size.
|
||||
|
||||
### Fixed
|
||||
- **A form can be sent again after the server refused it.** After a refused submission (a field error from the
|
||||
server, a failed e-mail) `useTurnstile().reset()` cleared the token but never asked the widget for a new one, so
|
||||
with Turnstile on, the next click on Send answered "The form could not be sent" without sending anything.
|
||||
`reset()` now makes the widget issue a new token (`Turnstile` takes a `resetSignal` prop for your own wiring).
|
||||
No project change.
|
||||
- **The honeypot of `BuilderForm` / `RenderForm` now reaches the server.** The hidden field was rendered, but its
|
||||
value was not part of what the form sent, so a bot that filled it was not dropped. It is now sent with the
|
||||
submission (`createSubmitAction` checks and strips it, as before). A hand-written action that calls `submitForm`
|
||||
|
||||
@@ -911,6 +911,11 @@ export const formClasses: BuilderFormClassNames = {
|
||||
fields: 'grid grid-cols-12 gap-4',
|
||||
form: 'grid gap-6',
|
||||
formError: 'rounded-control bg-danger-surface p-3 text-danger',
|
||||
file: 'block w-full text-fg file:mr-3 file:rounded-control file:border-0 file:bg-surface-muted file:px-3 file:py-2 file:text-fg-strong',
|
||||
fileItem: 'flex flex-wrap items-center gap-2',
|
||||
fileList: 'mt-2 grid gap-1 text-sm',
|
||||
fileRemove: 'underline underline-offset-2',
|
||||
help: 'mt-1 text-sm text-fg-muted',
|
||||
input: control,
|
||||
label: 'mb-1 block font-medium text-fg-strong',
|
||||
legend: 'mb-1 font-medium text-fg-strong',
|
||||
@@ -1154,6 +1159,7 @@ Rules: AGENT.md §8a.
|
||||
|---|---|
|
||||
| `e2e/create-test-admin.ts` | a test admin with a known TOTP secret (local / CI database only) (below) |
|
||||
| `e2e/smoke.spec.ts` | the smoke tests every release must pass: pages, showcase, forms, sitemap, SEO/GEO, headers, consent, 2FA |
|
||||
| `e2e/smtp-sink.ts` | — |
|
||||
| `e2e/totp.ts` | RFC 6238 code generator for the 2FA sign-in in the smoke test (below) |
|
||||
|
||||
### `e2e/create-test-admin.ts`
|
||||
@@ -1164,7 +1170,8 @@ Rules: AGENT.md §8a.
|
||||
* the real 2FA screen instead of skipping it. LOCAL / CI database only:
|
||||
* pnpm payload run e2e/create-test-admin.ts
|
||||
* Values come from E2E_ADMIN_EMAIL / E2E_ADMIN_PASSWORD / E2E_TOTP_SECRET (.env.example). Not a seed: seeds
|
||||
* never create users (docs/seeding.md).
|
||||
* never create users (docs/seeding.md). It also points e-mail sending at the tests' local mail sink
|
||||
* (E2E_SMTP_PORT, default 2526).
|
||||
*/
|
||||
import config from '@payload-config'
|
||||
import { isLocalDatabase } from '@intecion/ipal-kit/seed'
|
||||
@@ -1184,6 +1191,16 @@ if (found.docs[0]) {
|
||||
await payload.create({ collection: 'users', data: data as never, overrideAccess: true })
|
||||
}
|
||||
console.log(`[e2e] test admin ready: ${email}`)
|
||||
|
||||
// E-mail for the smoke tests goes to a local sink the test itself starts (e2e/smtp-sink.ts), so the test can
|
||||
// read what the site sent — the form file as an attachment. Without the sink running, sends simply fail.
|
||||
const smtpPort = Number(process.env.E2E_SMTP_PORT ?? 2526)
|
||||
await payload.updateGlobal({
|
||||
slug: 'site-integrations',
|
||||
data: { emailTransport: 'smtp', smtpFromAddress: 'site@example-studio.test', smtpHost: '127.0.0.1', smtpPassword: 'e2e-sink', smtpPort, smtpUser: 'e2e' } as never,
|
||||
overrideAccess: true,
|
||||
})
|
||||
console.log(`[e2e] e-mail sending points at the local sink 127.0.0.1:${smtpPort}`)
|
||||
process.exit(0)
|
||||
```
|
||||
|
||||
|
||||
+5
-3
@@ -188,9 +188,10 @@ function ContactForm() {
|
||||
`reset()` → after submitting. `enabled` → false when the provider got `siteKey: null` (the widget does not
|
||||
render; server-side verification is decided by `getTurnstileConfig` anyway).
|
||||
|
||||
`reset()` only **clears `token` in React state** — it does not call `turnstile.reset()` on the
|
||||
Cloudflare widget. A new token appears only when the widget generates one again
|
||||
(e.g. after expiry, about 300 s) or is mounted again.
|
||||
`reset()` clears `token` **and makes the widget run its challenge again**, so a new token arrives a moment later
|
||||
— a token is single-use, and a form the server refused can be sent again. (Up to 1.15.5 it only cleared the
|
||||
React state, and the next send had no token until the old one expired.) Your own `<Turnstile>` outside the
|
||||
provider: change its `resetSignal` prop to get the same.
|
||||
|
||||
`useTurnstile()` outside `<TurnstileProvider>` throws. `useOptionalTurnstile()`
|
||||
(also from `/client`) returns `enabled: false` there instead of throwing — `BuilderForm` uses it.
|
||||
@@ -202,6 +203,7 @@ Cloudflare widget. A new token appears only when the widget generates one again
|
||||
| `siteKey` | `string` | — | empty → renders nothing |
|
||||
| `onToken` | `(token: string \| null) => void` | — | token once solved; `null` on expiry / error / theme change |
|
||||
| `theme` | `'page' \| 'auto' \| 'light' \| 'dark'` | `'page'` | `'page'` = the site's theme (`data-theme`, ThemeScript), no theme → `'auto'` |
|
||||
| `resetSignal` | `number` | `0` | change the value → the widget issues a new token (what `reset()` does for the provider's widget) |
|
||||
|
||||
### Why Turnstile is NOT fully "drop in and forget" like CookieBanner
|
||||
|
||||
|
||||
Reference in New Issue
Block a user