- nodemailer ^8.0.1 -> ^10.2.1 (advisories up to 10.1.3); drop @types/nodemailer, nodemailer 10 ships its own types. Node engines >=20.9.0 (nodemailer 10 needs 20+). - pnpm.overrides (repo only, not passed to projects) for packages in payload 3.90.2's tree: undici and dompurify are exact-pinned upstream; fast-uri, js-yaml, browserslist, source-map-js, fast-copy, baseline-browser-mapping raised to fixed minimums. pnpm audit --prod: 19 high / 35 moderate / 11 low -> 0. - Tests: SMTP over a local SMTP socket with real nodemailer (panelSmtpAdapter, sendEmail, unreachable server status), Microsoft Graph and Graph->SMTP fallback via mailAdapter; real payloadTotp through ipalKit, plus a check that payload-2fa resolves the project's payload. - Docs: email.md, AGENT.md §4 item 12, ipal-setup, ipal-upgrade, README. Co-Authored-By: Claude Opus 5.5 <[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 { ipalKit } 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('ipalKit wraps the auth collection with TOTP: secret field, strategy and setup view', async () => {
|
|
const config = await ipalKit({
|
|
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()
|
|
})
|
|
})
|