Staff check (userMeetsRole): the 'no roles field = every account passes' rule applied to the account's own collection, so an account of a second auth collection (customers) passed every staff check. It now applies only to staff collections: the panel's login collection plus the new access.staffCollections. The injected auth collection uses the new adminOrSelfIn(slug), so an account of another collection with the same numeric id is not 'self'. 2FA: @clocklimited/payload-2fa wraps the collections and globals present when it runs; ipalKit's own globals and collections were added later and stayed unwrapped, so a password without the TOTP code opened them over REST and GraphQL. ipal-kit now has its own second-factor check (secondFactorPassed / requireSecondFactor): applied to every collection and global at the end of ipalKit, again in onInit for entities added by plugins listed after it, and inside userMeetsRole and the endpoints that take a project access function. It fails closed: an unrecognised user shape is refused, and startup stops when the injected 2FA plugin lacks the parts the check reads (twoFactor.guard: false opts out). Tests through real HTTP requests (REST and GraphQL) against Payload's route handlers, plus the reference smoke test. Docs, agent guide, skills and the reference skills copy updated; changelog entry without a version. Co-Authored-By: Claude Fable 5.2 <[email protected]>
57 lines
2.1 KiB
TypeScript
57 lines
2.1 KiB
TypeScript
import type { BasePayload, Config } from 'payload'
|
|
|
|
import { buildConfig } from 'payload'
|
|
import { vi } from 'vitest'
|
|
|
|
/**
|
|
* The only way a test builds a real Payload config. Outside production
|
|
* getPayload() spawns a detached `payload generate:types` child; with no
|
|
* PAYLOAD_CONFIG_PATH it never finds a config (tsconfig rootDir "./" makes
|
|
* Payload's findUpSync loop forever) and is left spinning after vitest exits.
|
|
* test/testConfig.test.ts fails when a test calls buildConfig directly.
|
|
*/
|
|
export const buildTestConfig = (config: Config) =>
|
|
buildConfig({ ...config, typescript: { ...config.typescript, autoGenerate: false } })
|
|
|
|
/**
|
|
* The parts of @clocklimited/payload-2fa that ipalKit checks for after the injected factory ran
|
|
* (missingTotpParts): the two fields and the `totp` strategy on the target collection.
|
|
* A fake 2FA factory in a test wraps its config in this.
|
|
*/
|
|
export function withTotpParts(config: Config, collection: string): Config {
|
|
return {
|
|
...config,
|
|
collections: (config.collections ?? []).map((c) =>
|
|
c.slug === collection
|
|
? {
|
|
...c,
|
|
auth: { ...(typeof c.auth === 'object' ? c.auth : {}), strategies: [{ name: 'totp', authenticate: () => ({ user: null }) }] },
|
|
fields: [...c.fields, { name: 'totpSecret', type: 'text' }, { name: 'hasTotp', type: 'checkbox', virtual: true }],
|
|
}
|
|
: c,
|
|
),
|
|
}
|
|
}
|
|
|
|
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 }
|
|
}
|