test(supabase): TOTP step guard in the sandbox verify helper

This commit is contained in:
bchanot committed 2026-11-04 18:55:47 +01:00
1 parent 697cefa2dd
commit 2b10471b0a
4 files changed
+39 -34

No files matched your search

+5 -18
View File
@@ -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(