test(supabase): TOTP step guard in the sandbox verify helper
This commit is contained in:
1 parent
697cefa2dd
commit
2b10471b0a
4 files changed
+39
-34
No files matched your search
@@ -10,13 +10,11 @@ import type { Dict } from '@/i18n/types'
|
||||
import type { Locator, Page } from '@playwright/test'
|
||||
import {
|
||||
enrolTotp,
|
||||
refusal,
|
||||
verifyTotp,
|
||||
} from '../../../../packages/supabase/tests/sandbox/mfa'
|
||||
import { sql, stack } from '../../../../packages/supabase/tests/sandbox/stack'
|
||||
import {
|
||||
totpCode,
|
||||
TOTP_STEP_SECONDS,
|
||||
} from '../../../../packages/supabase/tests/sandbox/totp'
|
||||
import { currentCode } from '../../../../packages/supabase/tests/sandbox/totp'
|
||||
import { expect } from './browser'
|
||||
import type { SandboxAccount } from './sandbox'
|
||||
|
||||
@@ -69,25 +67,14 @@ export async function enrolVerifiedFactor(
|
||||
): Promise<string> {
|
||||
const token = await passwordToken(account)
|
||||
const enrolment = await enrolTotp(token, name)
|
||||
if (!enrolment.factor)
|
||||
throw new Error(`sandbox enrol: HTTP ${enrolment.status}`)
|
||||
if (!enrolment.factor) throw new Error(`sandbox enrol: ${refusal(enrolment)}`)
|
||||
const verified = await verifyTotp(token, enrolment.factor)
|
||||
if (verified.status !== 200)
|
||||
throw new Error(`sandbox verify: HTTP ${verified.status}`)
|
||||
throw new Error(`sandbox verify: ${refusal(verified)}`)
|
||||
return enrolment.factor.secret
|
||||
}
|
||||
|
||||
/**
|
||||
* A code the authenticator would show now, never one about to change: a code
|
||||
* typed in its last seconds may reach GoTrue in the next step.
|
||||
*/
|
||||
export async function currentCode(secret: string): Promise<string> {
|
||||
const step = TOTP_STEP_SECONDS * 1000
|
||||
const left = step - (Date.now() % step)
|
||||
if (left < 3000)
|
||||
await new Promise((resolve) => setTimeout(resolve, left + 200))
|
||||
return totpCode(secret)
|
||||
}
|
||||
export { currentCode }
|
||||
|
||||
/** Types a code from `secret` into the TOTP form inside `scope` and sends it. */
|
||||
export async function enterCode(
|
||||
|
||||
@@ -12,6 +12,7 @@ import type { Dict } from '@/i18n/types'
|
||||
import type { Browser, BrowserContext, Page } from '@playwright/test'
|
||||
import {
|
||||
enrolTotp,
|
||||
refusal,
|
||||
verifyTotp,
|
||||
} from '../../../../packages/supabase/tests/sandbox/mfa'
|
||||
import {
|
||||
@@ -50,10 +51,12 @@ export async function makeActor(
|
||||
for (const kind of grants) await seedGrant(account, kind)
|
||||
const token = await passwordToken(account)
|
||||
const enrolment = await enrolTotp(token, 'Téléphone')
|
||||
if (!enrolment.factor) throw new Error('editor fixture: enrol refused')
|
||||
if (!enrolment.factor)
|
||||
throw new Error(`editor fixture: enrol ${refusal(enrolment)}`)
|
||||
const verified = await verifyTotp(token, enrolment.factor)
|
||||
const aal2 = verified.body.access_token
|
||||
if (typeof aal2 !== 'string') throw new Error('editor fixture: no aal2')
|
||||
if (typeof aal2 !== 'string')
|
||||
throw new Error(`editor fixture: no aal2 ${refusal(verified)}`)
|
||||
return { account, secret: enrolment.factor.secret, aal2 }
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user