mirror of
https://github.com/iflytek/skillhub.git
synced 2026-09-10 22:41:02 +00:00
test(e2e): isolate password reset rate limits
This commit is contained in:
parent
b9579ae377
commit
6650369cc4
2 changed files with 12 additions and 12 deletions
|
|
@ -5,3 +5,12 @@ export async function setEnglishLocale(page: Page) {
|
|||
window.localStorage.setItem('i18nextLng', 'en')
|
||||
})
|
||||
}
|
||||
|
||||
export async function setUniqueClientIp(page: Page, seed: string) {
|
||||
const suffix = Date.now() + Math.floor(Math.random() * 1000)
|
||||
const thirdOctet = seed.split('').reduce((sum, char) => sum + char.charCodeAt(0), 0) % 250
|
||||
const fourthOctet = suffix % 250
|
||||
await page.context().setExtraHTTPHeaders({
|
||||
'X-Forwarded-For': `10.0.${thirdOctet}.${fourthOctet}`,
|
||||
})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,25 +1,18 @@
|
|||
import { expect, test } from '@playwright/test'
|
||||
import { setEnglishLocale } from './helpers/auth-fixtures'
|
||||
import { setEnglishLocale, setUniqueClientIp } from './helpers/auth-fixtures'
|
||||
|
||||
test.describe('Password Reset (Real API)', () => {
|
||||
function uniqueResetEmail(seed: string) {
|
||||
return `nonexistent_${seed}_${Date.now()}@example.com`
|
||||
}
|
||||
|
||||
function forwardedIp(seed: string) {
|
||||
const hash = Array.from(seed).reduce((value, char) => value + char.charCodeAt(0), 0)
|
||||
return `198.51.${(hash % 200) + 1}.${(Date.now() % 200) + 1}`
|
||||
}
|
||||
|
||||
test.beforeEach(async ({ page }) => {
|
||||
await setEnglishLocale(page)
|
||||
})
|
||||
|
||||
test('sends verification code from reset-password page', async ({ page }) => {
|
||||
const email = uniqueResetEmail('request')
|
||||
await page.context().setExtraHTTPHeaders({
|
||||
'X-Forwarded-For': forwardedIp('request'),
|
||||
})
|
||||
await setUniqueClientIp(page, 'password-reset-request')
|
||||
|
||||
await page.goto('/reset-password')
|
||||
|
||||
|
|
@ -32,9 +25,7 @@ test.describe('Password Reset (Real API)', () => {
|
|||
|
||||
test('shows backend validation error for an invalid reset code', async ({ page }) => {
|
||||
const email = uniqueResetEmail('invalid-code')
|
||||
await page.context().setExtraHTTPHeaders({
|
||||
'X-Forwarded-For': forwardedIp('invalid-code'),
|
||||
})
|
||||
await setUniqueClientIp(page, 'password-reset-invalid-code')
|
||||
|
||||
await page.goto('/reset-password')
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue