Files
serverAppConfigs/tests/e2e/lib/login.ts
T

36 lines
1.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 });
await uid.fill(user);
await page.locator('button[type="submit"]').first().click();
const pwd = page.locator('input[name="password"]');
await pwd.waitFor({ state: "visible", timeout: 30_000 });
await pwd.fill(pass);
await page.locator('button[type="submit"]').first().click();
// Back on the homepage with panels rendered.
await page.waitForURL(/:\/\/www\.franksdank\.cloud\//, { timeout: 60_000 });
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 },
};
}