()
| 15 | const email = `csrf-${randomUUID()}@e2e.test`; |
| 16 | yield* browser.session({ label: "anonymous" }, async ({ page, step }) => { |
| 17 | const interceptCallback = async (): Promise<string> => { |
| 18 | let callback: string | undefined; |
| 19 | // Pause the real provider response before its redirect reaches the app. |
| 20 | // Playwright does not route subsequent hops of a redirect chain. |
| 21 | await page.route("**/user_management/authorize/submit", async (route) => { |
| 22 | const response = await route.fetch({ maxRedirects: 0 }); |
| 23 | expect(response.status()).toBe(302); |
| 24 | callback = response.headers().location; |
| 25 | await route.fulfill({ |
| 26 | status: 200, |
| 27 | contentType: "text/plain", |
| 28 | body: "Authorization ready for callback validation", |
| 29 | }); |
| 30 | }); |
| 31 | await page.goto(new URL("/api/auth/login", target.baseUrl).toString()); |
| 32 | await page.getByPlaceholder("new-user@example.com").fill(email); |
| 33 | await page.getByRole("button", { name: /Continue/ }).click(); |
| 34 | await expect.poll(() => callback).toBeDefined(); |
| 35 | await page.unroute("**/user_management/authorize/submit"); |
| 36 | if (!callback) throw new Error("AuthKit did not return a callback"); |
| 37 | return callback; |
| 38 | }; |
| 39 | await step("Discard a valid code without state and restart login", async () => { |
| 40 | const callback = new URL(await interceptCallback()); |
| 41 | callback.searchParams.delete("state"); |
no test coverage detected