fill-verify-Enter with a single inputValue read per stage (identification and password); the toHaveValue assertion hard-failed every attempt when the re-render wipe landed inside its 5s window (00-auth.setup failure 2026-09-24)
60 lines
2.5 KiB
TypeScript
60 lines
2.5 KiB
TypeScript
import { expect, type Page } from "@playwright/test";
|
|
import { REAL_UA } from "./env";
|
|
|
|
// Authentik's default login flow is two stages (identification -> password),
|
|
// both rendered inside open shadow roots. Playwright's CSS engine pierces
|
|
// open shadow roots, so plain input[name=...] locators work. Each login runs
|
|
// in a FRESH browser context: reusing a half-finished flow poisons authentik's
|
|
// pending_user stage and the second login hangs (see the
|
|
// authentik-flow-ui-automation skill). Anubis sits in front and solves its
|
|
// proof-of-work automatically in a real Chromium, which is why the
|
|
// uidField wait can legitimately take a while on a cold challenge.
|
|
export async function akLogin(page: Page, baseUrl: string, user: string, pass: string): Promise<void> {
|
|
await page.goto(baseUrl + "/");
|
|
const uid = page.locator('input[name="uidField"]');
|
|
await uid.waitFor({ state: "visible", timeout: 90_000 });
|
|
|
|
// The flow executor (Lit) re-renders a stage right after mount and can wipe
|
|
// a programmatic fill; a submit then POSTs an empty form ("This field is
|
|
// required") and the stage never advances. Both stages share the race:
|
|
// fill, VERIFY the value survived with a single read (a toHaveValue
|
|
// assertion hard-fails the attempt when the wipe lands inside its window),
|
|
// submit via Enter (native form path; the button can be re-created between
|
|
// snapshot and click), and retry if the stage reset under us.
|
|
for (let attempt = 0; attempt < 3; attempt++) {
|
|
await uid.fill(user);
|
|
if ((await uid.inputValue()) !== user) continue;
|
|
await uid.press("Enter");
|
|
try {
|
|
await page.locator('input[name="password"]').waitFor({ state: "visible", timeout: 15_000 });
|
|
break;
|
|
} catch {
|
|
if (attempt === 2) throw new Error("identification stage never advanced after 3 attempts");
|
|
}
|
|
}
|
|
|
|
const pwd = page.locator('input[name="password"]');
|
|
for (let attempt = 0; attempt < 3; attempt++) {
|
|
await pwd.fill(pass);
|
|
if ((await pwd.inputValue()) !== pass) continue;
|
|
await pwd.press("Enter");
|
|
try {
|
|
await page.waitForURL(/:\/\/www\.franksdank\.cloud\//, { timeout: 20_000 });
|
|
break;
|
|
} catch {
|
|
if (attempt === 2) throw new Error("password stage never advanced after 3 attempts");
|
|
}
|
|
}
|
|
|
|
// Back on the homepage with panels rendered.
|
|
await expect(page.locator("#grid .panel").first()).toBeVisible({ timeout: 30_000 });
|
|
}
|
|
|
|
export function launchOptions() {
|
|
return {
|
|
userAgent: REAL_UA,
|
|
ignoreHTTPSErrors: true,
|
|
viewport: { width: 1440, height: 900 },
|
|
};
|
|
}
|