2FA setup required: the window of existing accounts starts once, at the first start after the upgrade
Owner's decision: for accounts that exist before the upgrade the 72 hours count from the first start after it. The code already stamped them then; this adds the tests that the moment is written once per account (a restart, two instances starting at once, edits and logins do not move it; 71 h after it setup is open, 73 h after it the account is blocked) and says so in the docs. After the rebase on 1.16.5: tests that the setup-required notice and the stale import-map notice both stand above the screen and never replace the code form, and that requireSetup, safeBack and guard switch independently. Co-Authored-By: Claude Fable 5.2 <[email protected]>
This commit is contained in:
co-authored by
Claude Fable 5.2
parent
5d44ac3135
commit
9d2ab43438
@@ -306,6 +306,35 @@ describe('SafeTotpView', () => {
|
||||
})
|
||||
})
|
||||
|
||||
// "Setup required" (requireSetup), the back-link check (safeBack) and ipal-kit's own check (guard) are separate
|
||||
// switches: each combination builds, and each part is on exactly when its own switch says so.
|
||||
describe('requireSetup x safeBack x guard', () => {
|
||||
const combos = [undefined, false].flatMap((requireSetup) => [undefined, false].flatMap((safeBack) => [undefined, false].map((guard) => ({ guard, requireSetup, safeBack }))))
|
||||
|
||||
test.each(combos)('requireSetup: $requireSetup, safeBack: $safeBack, guard: $guard', async (options) => {
|
||||
const config = await ipalKit({ access: { authCollection: 'users' }, i18n, twoFactor: { issuer: 'E', plugin: payloadTotpBeta7, ...options } as never })({ collections: [], secret: 'x' } as unknown as Config)
|
||||
const views = Object.values(config.admin?.components?.views ?? {}) as { Component: { path?: string } | string; path: string }[]
|
||||
const totpViews = views.filter((v) => /(?:setup|verify)-totp$/.test(v.path))
|
||||
expect(totpViews).toHaveLength(4)
|
||||
// the back-link check follows safeBack alone
|
||||
const wrapped = totpViews.filter((v) => typeof v.Component === 'object' && v.Component.path === '@intecion/ipal-kit/admin#SafeTotpView').length
|
||||
expect(wrapped).toBe(options.safeBack === false ? 0 : 4)
|
||||
|
||||
// setup required needs ipal-kit's own check; with either off there is no window field and no notice
|
||||
const setupOn = options.requireSetup !== false && options.guard !== false
|
||||
const users = config.collections?.find((c) => c.slug === 'users')
|
||||
expect(Boolean(users?.fields.some((f) => 'name' in f && f.name === 'totpSetupFrom'))).toBe(setupOn)
|
||||
// the administrator's reset (a lost phone) comes with ipal-kit's own check, also when setup is not required
|
||||
expect(Boolean(config.endpoints?.some((e) => e.path === '/ipal/two-factor/reset'))).toBe(options.guard !== false)
|
||||
const provider = JSON.stringify(config.admin?.components?.providers ?? [])
|
||||
expect(provider.includes('"requireSetup":true')).toBe(setupOn)
|
||||
expect(provider).toContain('TotpRedirectProvider')
|
||||
const guardConfig = (config.custom as { ipal?: { twoFactor?: { requireSetup?: boolean } } } | undefined)?.ipal?.twoFactor
|
||||
expect(Boolean(guardConfig)).toBe(options.guard !== false)
|
||||
if (guardConfig) {expect(Boolean(guardConfig.requireSetup)).toBe(setupOn)}
|
||||
})
|
||||
})
|
||||
|
||||
describe('a 2FA factory that hands back the same view objects on every call', () => {
|
||||
const views = {
|
||||
SetupTOTP: { Component: { path: 'pkg/rsc#TOTPSetup' }, path: 'setup-totp' },
|
||||
|
||||
Reference in New Issue
Block a user