SPB Git

Repository Public

browser-check.mjs 9.2 KB 173 lines javascript

1/**2 * =============================================================================3 *                  SP BOUCHER | INFRASTRUCTURE & AUTOMATION4 *             ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING5 * =============================================================================6 *7 * Project          : MacLustr Identity8 * File             : integrations/browser-check.mjs9 * Module           : integrations10 * Repository       : https://git.spboucher.ai/maclustr-identity11 * Project Website  : https://identity.spboucher.ai12 * Created          : 2026-12-0113 * Last Modified    : 2026-12-0114 *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: admin@spboucher.ai23 * Technical Contact: dev@spboucher.ai24 * Security/Admin   : admin@spboucher.ai25 *26 * Copyright (c) 202627 * Simon-Pierre Boucher28 * All rights reserved where applicable. This file is governed by the29 * applicable project license, copyright notices and relevant law.30 * Existing third-party rights and notices remain unaffected.31 *32 * License          : None specified (no license file in this repository)33 *34 * Do not embed credentials, private keys, access tokens,35 * certificates or confidential personal information.36 *37 * =============================================================================38 * END OF SP BOUCHER SOURCE HEADER39 * =============================================================================40 */4142/**43 * Optional real-browser check of the marketplace modal flow (not part of e2e.sh, which is HTTP only).44 * Needs Playwright with Chromium; it is loaded from PLAYWRIGHT_FROM (default: apps/web, which already has it).45 *46 *   ./demo-marketplace/setup.sh && (cd demo-marketplace && node server.mjs &)47 *   ./demo-wallet/setup.sh && (cd demo-wallet && .venv/bin/python app.py &)48 *   MK_URL=http://localhost:8881 WL_URL=http://localhost:8882 node browser-check.mjs      (WL_URL is optional)49 *50 * Use fresh state files (DEMO_STATE_FILE) so that the demo users start unverified.51 */52import { createRequire } from "node:module";53import { dirname, join, resolve } from "node:path";54import { fileURLToPath } from "node:url";5556const HERE = dirname(fileURLToPath(import.meta.url));57const require = createRequire(join(resolve(process.env.PLAYWRIGHT_FROM ?? join(HERE, "..", "apps", "web")), "package.json"));58let chromium;59try {60  ({ chromium } = require("playwright"));61} catch {62  ({ chromium } = require("@playwright/test"));63}64const MK_URL = process.env.MK_URL ?? "http://localhost:8881";65const SHOTS = process.env.SHOTS_DIR;6667let failed = 0;68const check = (ok, label, detail) => {69  if (!ok) failed += 1;70  console.log(`  ${ok ? "ok  " : "FAIL"} ${label}${!ok && detail !== undefined ? ` -> ${JSON.stringify(detail)}` : ""}`);71};7273const browser = await chromium.launch();74try {75  const page = await browser.newPage({ viewport: { width: 1100, height: 800 } });76  const consoleErrors = [];77  page.on("console", (m) => m.type() === "error" && consoleErrors.push(m.text()));78  await page.goto(MK_URL);79  await page.getByRole("button", { name: /Ana/ }).click();80  await page.getByText("Identity not verified").waitFor();81  if (SHOTS) await page.screenshot({ path: join(SHOTS, "marketplace.png"), fullPage: true });82  await page.locator('input[name="title"]').fill("Oak writing desk");83  await page.locator('input[name="price"]').fill("240");84  await page.getByRole("button", { name: "Save draft" }).click();85  await page.getByRole("button", { name: "Publish" }).click();86  await page.getByText("Publishing is reserved for sellers with a verified identity").waitFor();87  check(true, "publishing a draft is refused with an explanation");8889  const verify = page.getByRole("button", { name: "Verify my identity" });90  await verify.focus();91  await verify.click();92  const dialog = page.getByRole("dialog", { name: "Identity verification for Brocante" });93  await dialog.waitFor();94  const frame = dialog.locator("iframe");95  check((await frame.getAttribute("allow")) === "camera", "the modal iframe delegates the camera only");96  check((await dialog.getAttribute("aria-modal")) === "true", "the dialog is modal for assistive technologies");97  check(await page.evaluate(() => document.activeElement?.hasAttribute("data-mlid-close")), "focus moved into the dialog");9899  // The hosted page must be allowed to render in the frame (frame-ancestors lists the marketplace origin).100  const handle = await frame.elementHandle();101  const inner = await handle.contentFrame();102  await inner.waitForLoadState("domcontentloaded");103  const innerUrl = inner.url();104  const bodyLength = await inner.evaluate(() => document.body?.innerText?.length ?? 0).catch(() => -1);105  check(/\/verify\/vs_/.test(innerUrl), "the hosted verification page is loaded in the frame", innerUrl);106  check(!consoleErrors.some((e) => /frame-ancestors|Refused to (frame|display)/i.test(e)), "the browser did not block the frame (CSP frame-ancestors)", consoleErrors);107  console.log(`  info hosted page text length inside the frame: ${bodyLength}`);108  if (SHOTS) await page.screenshot({ path: join(SHOTS, "marketplace-modal.png") });109110  await page.keyboard.press("Tab");111  await page.keyboard.press("Tab");112  check(await page.evaluate(() => Boolean(document.activeElement?.closest('[data-maclustr-identity="modal"]'))), "Tab keeps focus inside the dialog");113  await page.locator("[data-mlid-close]").focus();114  await page.keyboard.press("Escape");115  await dialog.waitFor({ state: "detached" });116  await page.getByText("Verification was not completed").waitFor();117  check(await page.evaluate(() => document.activeElement?.id === "verify"), "Escape closes the dialog and focus returns to the button");118119  // Full flow inside the frame, as a person would do it in sandbox: method, consent, simulated result.120  // These selectors follow the hosted page (apps/web); adjust them here if its wording changes.121  await verify.click();122  await dialog.waitFor();123  const hosted = page.frameLocator('[data-maclustr-identity="modal"] iframe');124  await hosted.getByRole("button", { name: "Get started" }).click();125  await hosted.locator("input[type=radio]").nth(1).check();126  await hosted.getByRole("button", { name: "Continue" }).click();127  await hosted.locator("input[type=checkbox]").first().check();128  await hosted.getByRole("button", { name: "I consent and continue" }).click();129  await hosted.getByRole("button", { name: /^Verified/ }).click();130  await dialog.waitFor({ state: "detached" });131  check(true, "the hosted page reported 'completed' and the dialog closed by itself");132  await page.locator("#status-line", { hasText: "Identity verified" }).waitFor({ timeout: 15000 });133  check(true, "the seller status became 'Identity verified' from the server record");134  await page.getByRole("button", { name: "Publish" }).click();135  await page.locator("#public .badge", { hasText: "Identity verified" }).waitFor();136  check(true, "the draft is published and the public listing shows the badge");137  await page.getByText('What does "Identity verified" mean?').click();138  check(await page.getByText("What it does not certify.").isVisible(), "the badge explanation states what it does not certify");139  if (SHOTS) await page.screenshot({ path: join(SHOTS, "marketplace-verified.png"), fullPage: true });140141  // Wallet: full-page redirect to the hosted page, then back through return_url.142  if (process.env.WL_URL) {143    const WL_URL = process.env.WL_URL;144    const w = await browser.newPage({ viewport: { width: 1000, height: 800 } });145    await w.goto(WL_URL);146    await w.getByRole("button", { name: "Dana" }).click();147    await w.getByRole("button", { name: /Raise the transfer limit/ }).click();148    await w.getByText("Raising the limit requires a verified identity").waitFor();149    check(true, "wallet: raising the limit is refused with an explanation, the request is saved");150    await w.getByRole("button", { name: "Verify my identity" }).click();151    await w.waitForURL(/\/verify\/vs_/);152    check(new URL(w.url()).origin !== new URL(WL_URL).origin, "wallet: the browser was redirected to the hosted page");153    await w.getByRole("button", { name: "Get started" }).click();154    await w.locator("input[type=radio]").nth(1).check();155    await w.getByRole("button", { name: "Continue" }).click();156    await w.locator("input[type=checkbox]").first().check();157    await w.getByRole("button", { name: "I consent and continue" }).click();158    await w.getByRole("button", { name: /^Verified/ }).click();159    await w.getByText(/^Return to /).click();160    await w.waitForURL(/\/verify\/return/);161    await w.getByText("Identity verified").waitFor();162    check(true, "wallet: the hosted page sent the person back to return_url, the server looked the result up");163    await w.getByRole("button", { name: /Confirm: raise the limit/ }).click();164    await w.getByText("$10,000.00").waitFor();165    check(true, "wallet: the saved request is applied after verification");166    if (SHOTS) await w.screenshot({ path: join(SHOTS, "wallet-verified.png"), fullPage: true });167  }168} finally {169  await browser.close();170}171console.log(failed ? `${failed} check(s) failed` : "browser check passed");172process.exit(failed ? 1 : 0);173
Files main
Menu

Theme