Skip to content

Commit 3444b1b

Browse files
committed
test(platform): wait out the sign-in rate limit in the live suite
Better Auth keys it on client IP and path, so every phase's fresh sign-ins chain into one budget whoever signs in. The zone-5xx phase's first test was refused with a 429 at its fourth sign-in in 15 seconds, and the zone had no part in it.
1 parent d48787f commit 3444b1b

1 file changed

Lines changed: 21 additions & 3 deletions

File tree

‎apps/sim/platform/checks/live/session.ts‎

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,20 +35,38 @@ function readSessions(): Record<string, Cookies> {
3535
}
3636
}
3737

38+
const SIGN_IN_PATH = '/api/auth/sign-in/email'
39+
/**
40+
* Better Auth refuses a fourth sign-in from one client IP while each came within ten seconds of the
41+
* last. This suite is one client whoever it signs in as, and each phase of a job starts its sessions
42+
* over, so a refusal here is the limiter's and says nothing about the page under test. It waits out
43+
* the window; any other answer is left to the assertion after it.
44+
*/
45+
const RATE_LIMIT_WINDOW_MS = 10_000
46+
3847
/** Types the credentials into the login page `target` redirected to, as a person would. */
3948
export async function signInThroughForm(page: Page, email: string, target: string) {
4049
await page.goto(target)
4150
await expect(page).toHaveURL(/\/login(?:\?|$)/)
4251
await page.locator('#email').fill(email)
4352
await page.locator('#password').fill(requireEnv('PLATFORM_LIVE_PASSWORD'))
44-
await page.getByRole('button', { name: 'Sign in', exact: true }).click()
53+
await expect(async () => {
54+
const [response] = await Promise.all([
55+
page.waitForResponse(
56+
(candidate) =>
57+
candidate.request().method() === 'POST' &&
58+
new URL(candidate.url()).pathname === SIGN_IN_PATH
59+
),
60+
page.getByRole('button', { name: 'Sign in', exact: true }).click(),
61+
])
62+
expect(response.status(), 'refused by the sign-in rate limit').not.toBe(429)
63+
}).toPass({ timeout: 45_000, intervals: [RATE_LIMIT_WINDOW_MS + 1_000] })
4564
await expect(page).not.toHaveURL(/\/login(?:\?|$)/, { timeout: 30_000 })
4665
}
4766

4867
/**
4968
* Opens `target` as `email`. The first sign-in per person goes through the form, and later ones
50-
* restore its session: Better Auth allows three sign-ins per address in ten seconds, far fewer than
51-
* a suite this size needs.
69+
* restore its session: the sign-in rate limit allows far fewer than a suite this size needs.
5270
*/
5371
export async function signIn(page: Page, email: string, target: string) {
5472
const known = readSessions()[email]

0 commit comments

Comments
 (0)