SPB Git

Repository Public

admin.spec.ts 12.2 KB 234 lines typescript

1/**2 * =============================================================================3 *                  SP BOUCHER | SOFTWARE & RESEARCH4 *             ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING5 * =============================================================================6 *7 * Project          : ORIX App Universe8 * File             : e2e/admin.spec.ts9 * Module           : e2e10 * Repository       : https://git.spboucher.ai/orix-spboucher-ai11 * Project Website  : https://www.orixlab.dev12 * Created          : 2026-11-2113 * Last Modified    : 2026-11-2114 *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: support@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 { readFileSync } from "node:fs";44import { expect, test, type BrowserContext, type Page } from "@playwright/test";45import { PUBLIC_REPOS } from "./catalog";4647const state = () => JSON.parse(readFileSync("e2e/.tmp/state.json", "utf8")) as { enroll: string };48test.describe.configure({ mode: "serial" });4950let ctx: BrowserContext, page: Page;5152test.beforeAll(async ({ browser }) => {53  ctx = await browser.newContext();54  page = await ctx.newPage();55  // A virtual platform authenticator with user verification: stands in for Touch ID / Face ID.56  const cdp = await ctx.newCDPSession(page);57  await cdp.send("WebAuthn.enable");58  await cdp.send("WebAuthn.addVirtualAuthenticator", { options: { protocol: "ctap2", transport: "internal", hasResidentKey: true, hasUserVerification: true, isUserVerified: true, automaticPresenceSimulation: true } });59});60test.afterAll(async () => { await ctx.close(); });6162test("the admin area is closed without a session", async () => {63  await page.goto("/admin");64  await expect(page).toHaveURL(/\/admin\/login$/);65  await expect(page.getByText("No passkey is enrolled yet")).toBeVisible();66  await expect(page.getByTestId("passkey-login")).toHaveCount(0);67  await page.goto("/admin/releases"); await expect(page).toHaveURL(/\/admin\/login$/);68  await page.goto("/apps/scan?preview=1"); await expect(page.getByTestId("preview-banner")).toHaveCount(0);69});7071test("an invalid enrolment link is refused", async () => {72  await page.goto("/admin/enroll?token=not-a-real-token");73  await expect(page.getByTestId("enroll-invalid")).toBeVisible();74  const r = await page.request.post("/api/auth/register/options", { data: { token: "not-a-real-token" }, headers: { origin: "http://localhost:8841" } });75  expect(r.status()).toBe(403);76});7778test("one-time enrolment creates a passkey and opens a session", async () => {79  await page.goto(`/admin/enroll?token=${state().enroll}`);80  await page.getByTestId("passkey-enroll").click();81  await expect(page.getByTestId("admin-dashboard")).toBeVisible();82  const cookie = (await ctx.cookies()).find((c) => c.name === "orix_admin")!;83  expect(cookie.httpOnly).toBe(true); expect(cookie.sameSite).toBe("Strict");84});8586test("the enrolment link cannot be used twice", async ({ browser }) => {87  const other = await browser.newContext(); const p = await other.newPage();88  await p.goto(`/admin/enroll?token=${state().enroll}`);89  await expect(p.getByTestId("enroll-invalid")).toBeVisible();90  await other.close();91});9293test("sign out, then sign in with the passkey", async () => {94  await page.getByRole("button", { name: "Sign out" }).click();95  await expect(page).toHaveURL(/\/admin\/login$/);96  await page.goto("/admin"); await expect(page).toHaveURL(/\/admin\/login$/);97  await page.getByTestId("passkey-login").click();98  await expect(page.getByTestId("admin-dashboard")).toBeVisible();99});100101test("a browser without the passkey cannot sign in", async ({ browser }) => {102  const other = await browser.newContext(); const p = await other.newPage();103  const cdp = await other.newCDPSession(p);104  await cdp.send("WebAuthn.enable");105  await cdp.send("WebAuthn.addVirtualAuthenticator", { options: { protocol: "ctap2", transport: "internal", hasResidentKey: true, hasUserVerification: true, isUserVerified: true } });106  await p.goto("/admin/login");107  await p.getByTestId("passkey-login").click();108  await expect(p.getByTestId("passkey-error")).toBeVisible({ timeout: 20_000 });109  await p.goto("/admin"); await expect(p).toHaveURL(/\/admin\/login$/);110  await other.close();111});112113test("writes need the CSRF token even with a session", async () => {114  const r = await page.request.post("/api/admin/apps/scan/unpublish", { data: {} });115  expect(r.status()).toBe(403);116  expect((await page.request.get("/apps/scan")).status()).toBe(200);117});118119test("edit → draft → preview → publish", async () => {120  await page.goto("/admin/apps/sheet");121  await page.getByTestId("field-name").fill("ORIX Sheet (edited)");122  await page.getByTestId("save-draft").click();123  await expect(page.getByTestId("editor-note")).toContainText("Draft saved");124  const pub = await ctx.newPage();125  await pub.goto("/apps/sheet");126  await expect(pub.getByRole("heading", { level: 1 })).toHaveText("ORIX Sheet"); // public page unchanged127  await pub.goto("/apps/sheet?preview=1");128  await expect(pub.getByTestId("preview-banner")).toBeVisible();129  await expect(pub.getByRole("heading", { level: 1 })).toHaveText("ORIX Sheet (edited)");130  await page.getByTestId("publish").click();131  await expect(page.getByTestId("editor-note")).toContainText("Published");132  await pub.goto("/apps/sheet");133  await expect(pub.getByRole("heading", { level: 1 })).toHaveText("ORIX Sheet (edited)");134  await page.getByTestId("field-name").fill("ORIX Sheet");135  await page.getByTestId("publish").click();136  await expect(page.getByTestId("editor-note")).toContainText("Published");137  await pub.close();138});139140test("the editor refuses an invalid document", async () => {141  await page.goto("/admin/apps/sheet");142  await page.getByTestId("field-advanced").fill('{ "features": "not a list" }');143  await page.getByTestId("save-draft").click();144  await expect(page.getByTestId("editor-note")).toContainText("invalid");145});146147test("screenshot upload: stored, listed, published in the gallery", async () => {148  await page.goto("/admin/apps/fixture-ios");149  await page.getByTestId("upload-screenshot").setInputFiles("public/apps/calc/standard.png");150  await expect(page.getByTestId("shot-row")).toHaveCount(1);151  await page.getByTestId("shot-row").getByLabel("Caption (en)").fill("Fixture caption");152  await page.getByTestId("shot-row").getByLabel("Légende (fr)").fill("Légende d’essai");153  await page.getByTestId("publish").click();154  await expect(page.getByTestId("editor-note")).toContainText("Published");155  const pub = await ctx.newPage();156  await pub.goto("/apps/fixture-ios");157  const img = pub.getByTestId("gallery").locator("img").first();158  await expect(img).toHaveAttribute("alt", "Fixture caption");159  expect(await img.evaluate((i: HTMLImageElement) => i.complete && i.naturalWidth > 0)).toBe(true);160  await pub.close();161  await page.getByTestId("shot-row").getByRole("button", { name: "Remove" }).click();162  await page.getByTestId("publish").click();163  await expect(page.getByTestId("editor-note")).toContainText("Published");164});165166test("a TestFlight link is never shown publicly before it is verified", async () => {167  await page.goto("/admin/apps/camera");168  await page.getByTestId("field-testflight").fill("https://testflight.apple.com/join/Unverif1");169  await page.getByTestId("field-testflight-state").selectOption("public");170  await page.getByTestId("publish").click();171  await expect(page.getByTestId("editor-note")).toContainText("Published");172  const pub = await ctx.newPage();173  await pub.goto("/apps/camera");174  expect(await pub.locator("article > header, #downloads").locator('a[href*="testflight.apple.com"]').count()).toBe(0);175  await expect(pub.getByTestId("tf-unavailable")).toBeVisible();176  await pub.close();177  await page.getByTestId("field-testflight").fill("https://example.com/join/abc");178  await page.getByTestId("publish").click();179  await expect(page.getByTestId("editor-note")).toContainText("not a public invitation URL");180});181182test("release review: approval of an unreachable asset fails closed; withdrawal stops the download", async () => {183  await page.goto("/admin/releases");184  await expect(page.getByTestId("release-row")).toHaveCount(3);185  const pending = page.locator('[data-testid="release-row"][data-state="validated"]');186  page.once("dialog", (d) => d.accept());187  await pending.getByRole("button", { name: "Approve & publish" }).click();188  await expect(page.locator('[data-testid="release-row"][data-state="invalid"]')).toHaveCount(1, { timeout: 20_000 });189  expect((await page.request.get("/download/fixture-review/2.1.0/ORIXReview.dmg")).status()).toBe(404);190  expect((await page.request.get("/download/fixture-review/2.0.0/ORIXReview.dmg")).status()).toBe(200);191  page.once("dialog", (d) => d.accept());192  await page.locator('[data-testid="release-row"][data-state="published"]').filter({ hasText: "fixture-review" }).getByRole("button", { name: "Withdraw" }).click();193  await expect(page.locator('[data-testid="release-row"][data-state="withdrawn"]')).toHaveCount(1);194  expect((await page.request.get("/download/fixture-review/2.0.0/ORIXReview.dmg")).status()).toBe(404);195  const pub = await ctx.newPage();196  await pub.goto("/apps/fixture-review");197  await expect(pub.getByTestId("dl-mac-none")).toBeVisible();198  expect(await pub.locator("article > header, #downloads, #changelog").locator('a[href^="/download/"]').count()).toBe(0);199  await pub.close();200});201202test("manual synchronization reports an unreachable forge instead of hiding it", async () => {203  // Every public repository is tried in turn, each with its bounded retries (about 3.5 s of back-off): the wait grows with the catalogue.204  const wait = PUBLIC_REPOS * 4_500 + 15_000;205  test.setTimeout(wait + 30_000);206  await page.goto("/admin");207  await page.getByTestId("sync-now").click();208  await expect(page.getByTestId("action-note")).toContainText(`0 repositories read, 0 new release record(s), ${PUBLIC_REPOS} error(s).`, { timeout: wait });209  await expect(page.getByTestId("sync-health")).toContainText("stale");210});211212test("announcement: draft stays private, published appears on What's New", async () => {213  await page.goto("/admin/announcements");214  const form = page.getByTestId("announcement-form").first();215  await form.getByLabel("Title (English)").fill("E2E announcement");216  await form.getByLabel("Titre (français)").fill("Annonce E2E");217  await form.getByLabel("Text (English)").fill("Body."); await form.getByLabel("Texte (français)").fill("Corps.");218  await form.getByRole("button", { name: "Create" }).click();219  await expect(form.getByTestId("action-note")).toContainText("Saved");220  expect(await (await page.request.get("/whats-new")).text()).not.toContain("E2E announcement");221  const saved = page.getByTestId("announcement-form").nth(1);222  await saved.getByLabel("State").selectOption("published");223  await saved.getByRole("button", { name: "Save" }).click();224  await expect(saved.getByTestId("action-note")).toContainText("Saved");225  expect(await (await page.request.get("/whats-new")).text()).toContain("E2E announcement");226  expect(await (await page.request.get("/fr/whats-new")).text()).toContain("Annonce E2E");227});228229test("the audit trail records what was done", async () => {230  await page.goto("/admin");231  const trail = page.getByText("Audit trail").locator("..").locator("..");232  for (const a of ["passkey.enrolled.setup", "login.ok", "app.publish", "media.uploaded", "release.rejected", "release.withdrawn", "sync.manual"]) await expect(trail).toContainText(a);233});234
Files main
Menu

Theme