fix(editor): e2e setup retries a GoTrue 500 step-up, drops late replays
This commit is contained in:
1 parent
dca80cb006
commit
0ea94602d1
5 files changed
+110
-11
No files matched your search
@@ -15,7 +15,7 @@ import {
|
||||
} from '../../../../packages/supabase/tests/sandbox/mfa'
|
||||
import { sql, stack } from '../../../../packages/supabase/tests/sandbox/stack'
|
||||
import { currentCode } from '../../../../packages/supabase/tests/sandbox/totp'
|
||||
import { expect } from './browser'
|
||||
import { expect, test } from './browser'
|
||||
import type { SandboxAccount } from './sandbox'
|
||||
|
||||
export type GrantKind =
|
||||
@@ -68,7 +68,10 @@ export async function enrolVerifiedFactor(
|
||||
const token = await passwordToken(account)
|
||||
const enrolment = await enrolTotp(token, name)
|
||||
if (!enrolment.factor) throw new Error(`sandbox enrol: ${refusal(enrolment)}`)
|
||||
const verified = await verifyTotp(token, enrolment.factor)
|
||||
let verified = await verifyTotp(token, enrolment.factor)
|
||||
// The HTTP 500 of the sweep (see `STEP_UP_ATTEMPTS`) is tried once more.
|
||||
if (verified.status >= 500)
|
||||
verified = await verifyTotp(token, enrolment.factor)
|
||||
if (verified.status !== 200)
|
||||
throw new Error(`sandbox verify: ${refusal(verified)}`)
|
||||
return enrolment.factor.secret
|
||||
@@ -111,12 +114,48 @@ export const stepUpHeading = (page: Page, dict: Dict) =>
|
||||
.getByRole('main')
|
||||
.getByRole('heading', { level: 1, name: dict['admin.step_up.title'] })
|
||||
|
||||
/** Completes the administration step-up; the page behind it then renders. */
|
||||
export async function stepUpAdmin(page: Page, dict: Dict, secret: string) {
|
||||
/**
|
||||
* GoTrue answers some TOTP verifies HTTP 500 `unexpected_failure` under the eight-worker
|
||||
* sweep (gate final.log, BLK-015 family): the step-up then shows the network or the
|
||||
* unavailable failure (supabase-js reads that 500 as a retryable fetch error). The setup
|
||||
* tries again from a reloaded page, at most this many times in all; a refused code
|
||||
* (`invalid_code`) is never retried.
|
||||
*/
|
||||
const STEP_UP_ATTEMPTS = 3
|
||||
|
||||
/** The failures of the step-up form that a server or transport fault shows. */
|
||||
const transientFailure = (main: Locator, dict: Dict) =>
|
||||
main
|
||||
.getByText(dict['mfa.failure.unavailable'])
|
||||
.or(main.getByText(dict['mfa.failure.network']))
|
||||
|
||||
/** One code sent; resolves once the gate opened (false) or said the server failed (true). */
|
||||
async function sendStepUpCode(page: Page, dict: Dict, secret: string) {
|
||||
const heading = stepUpHeading(page, dict)
|
||||
const main = page.getByRole('main')
|
||||
const unavailable = transientFailure(main, dict)
|
||||
await expect(heading).toBeVisible()
|
||||
// The gate settles its reads before the code is typed (a re-check remounts the form).
|
||||
await page.waitForLoadState('networkidle')
|
||||
await enterCode(page.getByRole('main'), dict, secret)
|
||||
await expect(heading).toBeHidden()
|
||||
await enterCode(main, dict, secret)
|
||||
await expect(async () => {
|
||||
const settled =
|
||||
(await heading.isHidden()) || (await unavailable.isVisible())
|
||||
expect(settled).toBe(true)
|
||||
}).toPass({ timeout: 10_000 })
|
||||
return unavailable.isVisible()
|
||||
}
|
||||
|
||||
/** Completes the administration step-up; the page behind it then renders. */
|
||||
export async function stepUpAdmin(page: Page, dict: Dict, secret: string) {
|
||||
for (let attempt = 1; ; attempt += 1) {
|
||||
const unavailable = await sendStepUpCode(page, dict, secret)
|
||||
if (!unavailable || attempt === STEP_UP_ATTEMPTS) break
|
||||
test.info().annotations.push({
|
||||
type: 'step-up retried',
|
||||
description: `attempt ${attempt}: GoTrue verify failed on the server`,
|
||||
})
|
||||
await page.reload()
|
||||
}
|
||||
await expect(stepUpHeading(page, dict)).toBeHidden()
|
||||
}
|
||||
Reference in new issue
Block a user