Repository Public
1/**2 * =============================================================================3 * SP BOUCHER | SOFTWARE & RESEARCH4 * ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING5 * =============================================================================6 *7 * Project : Note SPBoucher AI8 * File : tests/e2e/global-setup.ts9 * Module : tests10 * Repository : https://git.spboucher.ai/note-spboucher-ai11 * Project Website : https://note.spboucher.ai12 * Created : 2026-11-1713 * Last Modified : 2026-11-1914 *15 * Author : Simon-Pierre Boucher16 * Position : Professor of Finance17 * Institution : Université du Québec en Outaouais (UQO)18 * Organization : SP Boucher19 * Website : https://spboucher.ai20 * Git : https://git.spboucher.ai21 *22 * Preferred Contact: contact@spboucher.ai23 * Development : dev@spboucher.ai24 * Support : support@spboucher.ai25 * Security/Admin : admin@spboucher.ai26 *27 * Copyright (c) 202628 * Simon-Pierre Boucher29 * All rights reserved where applicable. This file is governed by the30 * applicable project license, copyright notices and relevant law.31 * Existing third-party rights and notices remain unaffected.32 *33 * License : None specified (no license file in this repository)34 *35 * Do not embed credentials, private keys, access tokens,36 * certificates or confidential personal information.37 *38 * =============================================================================39 * END OF SP BOUCHER SOURCE HEADER40 * =============================================================================41 */4243import fs from "node:fs";44import { chromium } from "@playwright/test";45import { AUTH_DIR, cli, enrollmentToken, saveCredential, saveState, sql, virtualAuthenticator } from "./helpers";4647/**48 * Start from a known access state on the TEST database: no passkey, no session, no window. Then perform the real first-enrollment49 * journey once (CLI window → /enroll → virtual authenticator) and keep the resulting session + passkey for the other specs.50 */51export default async function globalSetup() {52 process.env.E2E_STARTED = String(Date.now() - 2000); // read by global-teardown.ts53 const base = process.env.E2E_BASE_URL ?? "http://localhost:8481";54 await sql`delete from webauthn_credentials`; await sql`update sessions set revoked_at = now(), revoked_reason = 'e2e-reset' where revoked_at is null`;55 await sql`delete from login_attempts`; await sql`delete from webauthn_challenges`; await sql`update auth_enrollments set closed_reason = 'e2e-reset' where consumed_at is null and closed_reason is null`;56 fs.rmSync(AUTH_DIR, { recursive: true, force: true });57 const token = enrollmentToken(cli("open-enrollment", "5"));58 const browser = await chromium.launch(); const ctx = await browser.newContext({ baseURL: base, viewport: { width: 390, height: 844 }, hasTouch: true, isMobile: true });59 const page = await ctx.newPage(); const a = await virtualAuthenticator(page);60 await page.goto(`/enroll#${token}`);61 await page.getByLabel("Name of this device").fill("E2E phone");62 await page.getByRole("button", { name: /Create passkey/ }).click();63 await page.getByText("Passkey registered").waitFor();64 await page.waitForURL(/\/settings/);65 await saveCredential(a.cdp, a.id); await saveState(ctx);66 await browser.close(); await sql.end();67}68