- Turnstile is on only when both keys are set (panel or env); then submitForm requires a valid token, so a bot can no longer skip the check by omitting it. Not configured -> no widget, no check. New getTurnstileConfig() for layouts. - /api/ipal/test-email now requires the admin role (403 for other users). - roles field: create access is admin-only, so open sign-up can't self-assign admin. - clientIp reads X-Forwarded-For from the right, accepts Headers, can be pinned via option or IPAL_IP_HEADER; exposed on search/MCP routes. - Pluggable shared rate-limit store (setRateLimitStore) for multi-instance setups. - Replace the template int.spec with real unit tests in test/ (44 tests). Co-Authored-By: Claude Opus 5.5 <[email protected]>
26 lines
840 B
TypeScript
26 lines
840 B
TypeScript
import type { BasePayload } from 'payload'
|
|
|
|
import { vi } from 'vitest'
|
|
|
|
type FakeOptions = {
|
|
forms?: Record<string, { fields: Record<string, unknown>[] }>
|
|
integrations?: Record<string, unknown>
|
|
}
|
|
|
|
/** The slice of the Local API the form/Turnstile code touches. */
|
|
export function fakePayload({ forms = {}, integrations = {} }: FakeOptions = {}) {
|
|
const create = vi.fn(async () => ({ id: 'sub-1' }))
|
|
const payload = {
|
|
create,
|
|
findByID: vi.fn(async ({ id }: { id: string }) => {
|
|
const form = forms[id]
|
|
if (!form) {throw new Error('Not Found')}
|
|
return { id, ...form }
|
|
}),
|
|
findGlobal: vi.fn(async () => integrations),
|
|
logger: { error: vi.fn(), info: vi.fn(), warn: vi.fn() },
|
|
updateGlobal: vi.fn(async () => integrations),
|
|
}
|
|
return { create, payload: payload as unknown as BasePayload }
|
|
}
|