31 lines
1.1 KiB
TypeScript
31 lines
1.1 KiB
TypeScript
import { readFileSync } from "node:fs";
|
|
import path from "node:path";
|
|
import type { BrowserContext, Page } from "@playwright/test";
|
|
|
|
export const DATA = process.env.LUNCH_DATA ?? path.join(process.cwd(), ".data");
|
|
|
|
/** Ein virtueller Passkey für diesen Kontext (Chromium, CDP) — wie Face ID am iPhone. */
|
|
export async function passkey(context: BrowserContext, page: Page): Promise<void> {
|
|
const cdp = await context.newCDPSession(page);
|
|
await cdp.send("WebAuthn.enable");
|
|
await cdp.send("WebAuthn.addVirtualAuthenticator", {
|
|
options: {
|
|
protocol: "ctap2",
|
|
transport: "internal",
|
|
hasResidentKey: true,
|
|
hasUserVerification: true,
|
|
isUserVerified: true,
|
|
automaticPresenceSimulation: true,
|
|
},
|
|
});
|
|
}
|
|
|
|
/** Der Code aus einer Datei im Datenordner (Einrichtung, Rückweg). */
|
|
export function codeFrom(file: string): string {
|
|
const line = readFileSync(path.join(DATA, file), "utf8")
|
|
.split("\n")
|
|
.find((l) => /^[A-Z2-9]{4}(-[A-Z2-9]{4}){3}$/.test(l));
|
|
if (!line) throw new Error(`kein Code in ${file}`);
|
|
return line;
|
|
}
|