2FA back link: the stale import-map notice never replaces the screen
R2-1: the notice was rendered instead of the 2FA screen, and its flag is a text search of the importMap.js on disk — not the map in the build. A false alarm (map generated in the build with the repository's file in the running image, a re-exporting map) hid a working code form and locked everyone out. The notice is now rendered above the screen, the log line says "may be", and the flag goes to ipal-kit's own provider only. R2-2: views are compared against copies, so a factory that reuses its view objects is guarded too; copyViews, changedViewKeys, SAFE_TOTP_VIEW, totpViewImportKey, findImportMapFile and missingImportMapEntries are exported; ipal-doctor warns when the config registers the 2FA package's own view; docs wording and a misplaced comment fixed. Co-Authored-By: Claude Fable 5.2 <[email protected]>
This commit is contained in:
co-authored by
Claude Fable 5.2
parent
ad51456eaa
commit
b2c1dca5da
@@ -51,6 +51,35 @@ afterEach(() => {
|
||||
vi.unstubAllEnvs()
|
||||
})
|
||||
|
||||
describe('importmap rule and the 2FA back-link check', () => {
|
||||
const MAP = 'src/app/(payload)/admin/importMap.js'
|
||||
const entries = (...names: string[]) => `export const importMap = { ${names.map((n) => `"${n}": X`).join(', ')} }`
|
||||
const withPlugin = (admin: string) => ({ ...base(), ...installed('@clocklimited/payload-2fa', '3.0.0'), 'node_modules/@intecion/ipal-kit/dist/exports/admin.js': admin })
|
||||
const messages = (report: DoctorReport) => report.findings.filter((f) => f.rule === 'importmap').map((f) => `${f.severity}: ${f.message}`)
|
||||
|
||||
test('expects SafeTotpView when the installed plugin has it; not with safeBack: false; not for an older plugin', async () => {
|
||||
const map = entries('@clocklimited/payload-2fa/rsc#TOTPSetup', '@intecion/ipal-kit/admin#TotpRedirectProvider')
|
||||
const admin = 'export { SafeTotpView } from "./x.js"; export { TotpRedirectProvider } from "./y.js"'
|
||||
const lacking = await doctor(project({ ...withPlugin(admin), [MAP]: map, 'src/payload.config.ts': 'twoFactor: { plugin: payloadTotp }' }), ['importmap'])
|
||||
expect(messages(lacking).join()).toContain('import map lacks @intecion/ipal-kit/admin#SafeTotpView')
|
||||
const off = await doctor(project({ ...withPlugin(admin), [MAP]: map, 'src/payload.config.ts': 'twoFactor: { plugin: payloadTotp, safeBack: false }' }), ['importmap'])
|
||||
expect(messages(off).join()).not.toContain('SafeTotpView')
|
||||
const older = await doctor(project({ ...withPlugin('export { TotpRedirectProvider } from "./y.js"'), [MAP]: map, 'src/payload.config.ts': 'twoFactor: { plugin: payloadTotp }' }), ['importmap'])
|
||||
expect(messages(older).join()).not.toContain('SafeTotpView')
|
||||
})
|
||||
|
||||
test("warns when the config registers the 2FA package's own view itself", async () => {
|
||||
const map = entries('@clocklimited/payload-2fa/rsc#TOTPSetup', '@intecion/ipal-kit/admin#TotpRedirectProvider', '@intecion/ipal-kit/admin#SafeTotpView')
|
||||
const admin = 'export { SafeTotpView } from "./x.js"; export { TotpRedirectProvider } from "./y.js"'
|
||||
const own = "twoFactor: { plugin: payloadTotp }, admin: { components: { views: { Mine: { Component: '@clocklimited/payload-2fa/rsc#TOTPVerify', path: '/my-verify' } } } }"
|
||||
const raw = await doctor(project({ ...withPlugin(admin), [MAP]: map, 'src/payload.config.ts': own }), ['importmap'])
|
||||
const NOTE = /^warning: the config names the 2FA package's own setup \/ verify view/
|
||||
expect(messages(raw).filter((m) => NOTE.test(m))).toHaveLength(1)
|
||||
const plain = await doctor(project({ ...withPlugin(admin), [MAP]: map, 'src/payload.config.ts': 'twoFactor: { plugin: payloadTotp }' }), ['importmap'])
|
||||
expect(messages(plain).filter((m) => NOTE.test(m))).toEqual([])
|
||||
})
|
||||
})
|
||||
|
||||
describe('helpers', () => {
|
||||
test('parseEnvFile reads KEY=value, strips quotes, skips comments', () => {
|
||||
expect(parseEnvFile('# c\nA=1\nexport B="two"\n C = \'3\'\nbad line')).toEqual({ A: '1', B: 'two', C: '3' })
|
||||
|
||||
Reference in New Issue
Block a user