Replaced by an explicit list of forms only (ten exported names, runtime env names, project file names and marks, commands, skill names, the log prefix, the brand in prose). Package name, import paths, routes, CSS tokens, data attributes, custom keys, context flags, the cookie and kv keys are not touched. package.json keeps the five old bin names beside the five new ones. The old names stop working in this commit and come back as aliases in the next; docs follow. Co-Authored-By: Claude Fable 5.2 <[email protected]>
46 lines
1.9 KiB
TypeScript
46 lines
1.9 KiB
TypeScript
import type { Config, TextField } from 'payload'
|
|
|
|
import { payloadTotp } from '@clocklimited/payload-2fa'
|
|
import { realpathSync } from 'node:fs'
|
|
import { createRequire } from 'node:module'
|
|
import { describe, expect, test } from 'vitest'
|
|
|
|
import type { I18nConfig } from '../src/modules/i18n/types.js'
|
|
|
|
import { iapl } from '../src/plugin.js'
|
|
|
|
const i18n: I18nConfig = { defaultLocale: 'en', locales: [{ code: 'en', label: 'English' }] }
|
|
|
|
const require = createRequire(import.meta.url)
|
|
/** Real path of the `payload` entry that `fromFile` would load. */
|
|
const payloadSeenFrom = (fromFile: string) => realpathSync(createRequire(fromFile).resolve('payload'))
|
|
|
|
describe('@clocklimited/payload-2fa with the real plugin', () => {
|
|
test('uses the same payload as the project (peer dependency, no second copy)', () => {
|
|
const twoFactorEntry = realpathSync(require.resolve('@clocklimited/payload-2fa'))
|
|
expect(payloadSeenFrom(twoFactorEntry)).toBe(payloadSeenFrom(import.meta.url))
|
|
})
|
|
|
|
test('iapl wraps the auth collection with TOTP: secret field, strategy and setup view', async () => {
|
|
const config = await iapl({
|
|
access: { authCollection: 'users' },
|
|
i18n,
|
|
twoFactor: { issuer: 'Example', plugin: payloadTotp },
|
|
})({ collections: [], secret: 'x' } as unknown as Config)
|
|
|
|
const users = config.collections?.find((c) => c.slug === 'users')
|
|
const secret = users?.fields.find(
|
|
(f): f is TextField => 'name' in f && f.name === 'totpSecret' && f.type === 'text',
|
|
)
|
|
expect(secret).toBeDefined()
|
|
expect(secret?.admin?.hidden).toBe(true)
|
|
// The TOTP secret is never readable over the API.
|
|
expect((secret?.access?.read as () => boolean)()).toBe(false)
|
|
|
|
const auth = users?.auth
|
|
expect(typeof auth === 'object' && auth.strategies?.length).toBeGreaterThan(0)
|
|
expect(config.admin?.components?.views?.SetupTOTP).toBeDefined()
|
|
expect(config.admin?.components?.views?.VerifyTOTP).toBeDefined()
|
|
})
|
|
})
|