taler-typescript-core

Wallet core logic and WebUIs for various components
Log | Files | Refs | Submodules | README | LICENSE

commit 1fc5430520c72ec14e47c464ec9fe948f06a9f6a
parent 1332484f91551aa724512c439b5c5d57b3fee08a
Author: Florian Dold <dold@taler.net>
Date:   Mon, 23 Nov 2026 17:35:46 +0100

harness: exercise challenge-device provisioning in Chromium

Diffstat:
Apackages/taler-harness/src/integrationtests/merchant-webui-environment.ts | 93+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Apackages/taler-harness/src/integrationtests/test-merchant-webui-challenge-devices.ts | 97+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mpackages/taler-harness/src/integrationtests/testrunner.ts | 2++
3 files changed, 192 insertions(+), 0 deletions(-)

diff --git a/packages/taler-harness/src/integrationtests/merchant-webui-environment.ts b/packages/taler-harness/src/integrationtests/merchant-webui-environment.ts @@ -0,0 +1,93 @@ +/* + This file is part of GNU Taler + (C) 2026 Taler Systems S.A. + + GNU Taler is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> + */ + +import { + type AccessToken, + TalerMerchantInstanceHttpClient, +} from "@gnu-taler/taler-util"; +import type { Page } from "playwright-core"; +import { createSimpleTestkudosEnvironmentV3 } from "../harness/environments.js"; +import { + harnessLongpollQueue, + harnessHttpLib, + GlobalTestState, +} from "../harness/harness.js"; +import { launchMerchantWebuiBrowser } from "../harness/merchant-webui-browser.js"; +import { startStaticServerMerchantWebui } from "../harness/webui-server.js"; + +interface MerchantPortal { + api: TalerMerchantInstanceHttpClient; + token: AccessToken; + page: Page; + webuiUrl: string; + walletClient: Awaited< + ReturnType<typeof createSimpleTestkudosEnvironmentV3> + >["walletClient"]; +} + +export async function withMerchantPortal( + t: GlobalTestState, + run: (portal: MerchantPortal) => Promise<void>, +): Promise<void> { + t.allowLogs({ + file: "merchant-httpd-testmerchant-1-stderr.log", + level: "WARNING", + messages: [ + ["Failed to find required permissions for scope 0", 1], + ["Permission check failed: scope 0 not understood", 1], + [ + "Credentials provided are 0 which are insufficient for access to `instances-write'", + 1, + ], + ], + justification: + "The unauthenticated portal checks whether merchant account setup is available before sign-in.", + }); + const { + merchant, + walletClient, + merchantAdminAccessToken: token, + } = await createSimpleTestkudosEnvironmentV3(t); + const api = new TalerMerchantInstanceHttpClient( + merchant.makeInstanceBaseUrl(), + { httpClient: harnessHttpLib, longpollQueue: harnessLongpollQueue }, + ); + const server = await startStaticServerMerchantWebui( + merchant.makeInstanceBaseUrl(), + { buildSource: "workspace" }, + ); + let browser: + | Awaited<ReturnType<typeof launchMerchantWebuiBrowser>> + | undefined; + try { + browser = await launchMerchantWebuiBrowser(); + const page: Page = browser.page; + page.setDefaultTimeout(15_000); + await page.goto(`${server.url}#/signin`); + await page.getByRole("textbox", { name: "Merchant Account" }).fill("admin"); + await page.getByLabel("Password", { exact: true }).fill("123"); + await page.getByRole("button", { name: "Sign in", exact: true }).click(); + const sidebar = page.getByRole("complementary"); + await sidebar.waitFor({ state: "visible" }); + await run({ api, token, walletClient, webuiUrl: server.url, page }); + } finally { + try { + await browser?.close(); + } finally { + await server.close(); + } + } +} diff --git a/packages/taler-harness/src/integrationtests/test-merchant-webui-challenge-devices.ts b/packages/taler-harness/src/integrationtests/test-merchant-webui-challenge-devices.ts @@ -0,0 +1,97 @@ +/* + This file is part of GNU Taler + (C) 2026 Taler Systems S.A. + + GNU Taler is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> + */ + +import assert from "node:assert/strict"; +import { succeedOrThrow } from "@gnu-taler/taler-util"; +import type { GlobalTestState } from "../harness/harness.js"; +import { assertNoUnexpectedErrorBanner } from "../harness/merchant-webui-browser.js"; +import { withMerchantPortal } from "./merchant-webui-environment.js"; + +export async function runMerchantWebuiChallengeDevicesTest(t: GlobalTestState) { + await withMerchantPortal(t, async ({ api, token, webuiUrl, page }) => { + for (const algorithm of [3, 4]) { + const name = `Door ${algorithm}`; + const deviceId = `otp_door_${algorithm}`; + await page.goto(`${webuiUrl}#/authenticators/new`); + await page.locator("#auth_name").fill(name); + await page.locator(`#auth_method_${algorithm}`).check(); + assert.equal(await page.locator("#auth_secret_gen").count(), 0); + const [creation] = await Promise.all([ + page.waitForResponse( + (r) => + r.request().method() === "POST" && + new URL(r.url()).pathname.endsWith("/private/otp-devices"), + ), + page.getByRole("button", { name: "Add device", exact: true }).click(), + ]); + assert.equal(creation.status(), 200); + assert.equal("otp_key" in creation.request().postDataJSON(), false); + const publicKey = (await creation.json()).otp_device_pub; + assert.ok(publicKey); + const keyField = page.getByLabel("Public verification key"); + assert.equal(await keyField.inputValue(), publicKey); + await page.getByRole("button", { name: "Copy key" }).click(); + await page.getByRole("button", { name: "✓ Copied" }).waitFor(); + await page.getByRole("button", { name: "Done", exact: true }).click(); + await page.getByRole("link", { name, exact: true }).click(); + assert.equal(await keyField.inputValue(), publicKey); + assert.equal(await page.getByRole("radio").count(), 1); + await page.locator("#auth_name").fill(name + " renamed"); + await page.getByRole("button", { name: "Save Changes" }).click(); + await page + .getByRole("link", { name: name + " renamed", exact: true }) + .waitFor(); + assert.equal( + succeedOrThrow(await api.getOtpDeviceDetails(token, deviceId)) + .otp_device_pub, + publicKey, + ); + + await page.goto(`${webuiUrl}#/templates/new`); + await page.getByRole("textbox", { name: "Template Name" }).fill(name); + await page.getByRole("textbox", { name: /Order Summary/i }).fill(name); + await page.getByRole("spinbutton", { name: "Fixed Amount" }).fill("1"); + await page + .getByRole("button", { name: /Show advanced options/i }) + .click(); + await page.getByRole("combobox", { name: /OTP device/i }).fill(deviceId); + await page.getByRole("option", { name: new RegExp(deviceId) }).click(); + const templateId = await page.locator("#tmpl_id_input").inputValue(); + const [saved] = await Promise.all([ + page.waitForResponse( + (r) => + r.request().method() === "POST" && + new URL(r.url()).pathname.endsWith("/private/templates"), + ), + page + .getByRole("button", { name: "Create Template", exact: true }) + .click(), + ]); + assert.ok(saved.ok()); + assert.equal( + succeedOrThrow(await api.getTemplateDetails(token, templateId)).otp_id, + deviceId, + ); + } + await assertNoUnexpectedErrorBanner(page); + }); +} +runMerchantWebuiChallengeDevicesTest.suites = [ + "web", + "merchant", + "merchant-webui", +]; +runMerchantWebuiChallengeDevicesTest.timeoutMs = 120_000; diff --git a/packages/taler-harness/src/integrationtests/testrunner.ts b/packages/taler-harness/src/integrationtests/testrunner.ts @@ -331,6 +331,7 @@ import { } from "./test-merchant-webui-mfa.js"; import { runMerchantWebuiKycSwapTest } from "./test-merchant-webui-kyc-swap.js"; import { runMerchantWebuiBootstrapTest } from "./test-merchant-webui-bootstrap.js"; +import { runMerchantWebuiChallengeDevicesTest } from "./test-merchant-webui-challenge-devices.js"; import { runMerchantWebuiSimpleTest } from "./test-merchant-webui-simple.js"; import { runWireMetadataTest } from "./test-wire-metadata.js"; import { runWithdrawalAbortBankTest } from "./test-withdrawal-abort-bank.js"; @@ -529,6 +530,7 @@ const allTests: TestMainFunction[] = [ runMerchantWebuiPasswordResetMfaTest, runMerchantWebuiKycSwapTest, runMerchantWebuiSimpleTest, + runMerchantWebuiChallengeDevicesTest, runMerchantSelfProvisionInactiveAccountPermissionsTest, runWithdrawalExternalTest, runWithdrawalIdempotentTest,