taler-typescript-core

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

commit c10a1701d0845316aca13192d9f83cadce934ec4
parent 423273dc5190dba9e46fcce6538ca827367f7655
Author: Florian Dold <dold@taler.net>
Date:   Fri, 25 Sep 2026 00:10:09 +0200

harness: exercise wallet fountain imports and collection in Chromium

Diffstat:
Apackages/taler-harness/src/integrationtests/test-wallet-web-ui-fountains.ts | 358+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mpackages/taler-harness/src/integrationtests/test-wallet-web-ui-pwa-payment-inputs.ts | 2+-
Mpackages/taler-harness/src/integrationtests/testrunner.ts | 2++
3 files changed, 361 insertions(+), 1 deletion(-)

diff --git a/packages/taler-harness/src/integrationtests/test-wallet-web-ui-fountains.ts b/packages/taler-harness/src/integrationtests/test-wallet-web-ui-fountains.ts @@ -0,0 +1,358 @@ +/* + 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 { + AbsoluteTime, + Duration, + HostPortPath, + LibtoolVersion, + OrderInputType, + OrderOutputType, + Result, + succeedOrThrow, + TalerProtocolTimestamp, + TalerUriAction, + TalerUris, + TokenFamilyKind, +} from "@gnu-taler/taler-util"; +import { GlobalTestState } from "../harness/harness.js"; +import { withFundedWallet } from "./test-wallet-web-ui-pwa-payment-inputs.js"; + +export async function runWalletWebUiFountainsTest(t: GlobalTestState) { + await withFundedWallet( + t, + "wallet-web-ui-fountains", + async ({ + stage, + pwaUrl, + merchant, + merchantClient: api, + merchantAdminAccessToken: token, + }) => { + const expiry = AbsoluteTime.toProtocolTimestamp( + AbsoluteTime.addDuration( + AbsoluteTime.now(), + Duration.fromSpec({ days: 30 }), + ), + ); + const kinds = [TokenFamilyKind.Discount, TokenFamilyKind.Subscription]; + for (const kind of kinds) + succeedOrThrow( + await api.createTokenFamily(token, { + kind, + slug: kind, + name: kind, + description: `Fountain ${kind}`, + valid_after: TalerProtocolTimestamp.now(), + valid_before: expiry, + duration: { d_us: 86400_000_000 }, + validity_granularity: { d_us: 86400_000_000 }, + }), + ); + const grants = kinds.map((kind) => ({ + token_family_slug: kind, + tokens_per_period_limit: 3, + tokens_per_period_stash: 2, + key_window_size: 0, + })); + const created = succeedOrThrow( + await api.createFountain(token, { + description: "Member benefits", + name: "Member offers", + poll_freq: { d_us: 3600_000_000 }, + grants, + }), + ); + const uri = TalerUris.stringify({ + type: TalerUriAction.Fountain, + merchantBaseUrl: merchant.makeInstanceBaseUrl() as HostPortPath, + fountainId: created.fountain_id, + fountainSecret: created.fountain_secret, + }); + const parsed = TalerUris.parse(uri); + assert( + Result.isOk(parsed), + `Fountain URI parsing failed: ${Result.isError(parsed) ? JSON.stringify(parsed.detail) : ""}; credential length ${created.fountain_secret.length}`, + ); + await stage.step("opt in, review and import fountain", async (page) => { + await page.goto(`${pwaUrl}?talerUri=${encodeURIComponent(uri)}#/`); + await page + .getByRole("button", { name: "Review developer settings" }) + .click(); + await page + .getByRole("checkbox", { name: "Enable fountains", exact: true }) + .click(); + await page + .getByRole("button", { name: "Import fountain", exact: true }) + .waitFor(); + assert( + !(await page.locator("body").innerText()).includes( + created.fountain_secret, + ), + ); + assert(!page.url().includes(created.fountain_secret)); + await page + .getByRole("button", { name: "Import fountain", exact: true }) + .click(); + await page + .getByRole("heading", { name: "Fountains", exact: true }) + .waitFor(); + const version = succeedOrThrow(await api.getConfig()).version; + const name = LibtoolVersion.isCompatible(version, "46:0:0") + ? "Member offers" + : created.fountain_id; + await page.getByRole("heading", { name, exact: true }).waitFor(); + await page + .getByRole("heading", { name: "discount · Discounts", exact: true }) + .waitFor(); + await page + .getByRole("heading", { name: "subscription · Passes", exact: true }) + .waitFor(); + const receipt = page.locator("article dl div").filter({ + has: page.getByText("Received from this fountain", { exact: true }), + }); + await receipt + .first() + .locator("dd") + .filter({ hasText: /^2$/ }) + .waitFor(); + await receipt.last().locator("dd").filter({ hasText: /^2$/ }).waitFor(); + await page.screenshot({ + path: `${t.testDir}/fountains-mobile.png`, + fullPage: true, + }); + await page.setViewportSize({ width: 1280, height: 900 }); + await page.screenshot({ + path: `${t.testDir}/fountains-desktop.png`, + fullPage: true, + }); + // Reimporting the same credential stays idempotent. + await page.goto(`${pwaUrl}?talerUri=${encodeURIComponent(uri)}#/`); + await page + .getByRole("button", { name: "Import fountain", exact: true }) + .click(); + await page + .getByRole("heading", { name: "Fountains", exact: true }) + .waitFor(); + await page.locator("article").first().waitFor(); + assert.equal(await page.locator("article").count(), 1); + }); + for (const kind of kinds) + await stage.step(`spend fountain ${kind}`, async (page) => { + const order = succeedOrThrow( + await api.createOrder(token, { + order: { + version: 1, + summary: `Use fountain ${kind}`, + timestamp: TalerProtocolTimestamp.now(), + pay_deadline: expiry, + choices: [ + { + amount: "TESTKUDOS:1", + inputs: [ + { type: OrderInputType.Token, token_family_slug: kind }, + ], + outputs: + kind === TokenFamilyKind.Subscription + ? [ + { + type: OrderOutputType.Token, + token_family_slug: kind, + }, + ] + : [], + }, + ], + }, + }), + ); + const details = succeedOrThrow( + await api.getOrderDetails(token, order.order_id), + ); + assert.equal(details.order_status, "unpaid"); + await page.goto( + `${pwaUrl}?talerUri=${encodeURIComponent(details.taler_pay_uri)}#/`, + ); + await page.getByText("TESTKUDOS:1", { exact: true }).waitFor(); + const [total] = await page + .getByText(/^Total including fees: /) + .allTextContents(); + const debit = + total?.replace("Total including fees: ", "") ?? "TESTKUDOS:1"; + await page + .getByRole("button", { name: `Pay ${debit}`, exact: true }) + .click(); + await page + .getByRole("heading", { name: "Payment complete", exact: true }) + .waitFor(); + }); + await stage.step("refresh counts and merchant edits", async (page) => { + await page.goto(`${pwaUrl}#/fountains`); + await page + .getByRole("button", { name: "Refresh", exact: true }) + .click(); + const discount = page.locator("article section").filter({ + has: page.getByRole("heading", { + name: "discount · Discounts", + exact: true, + }), + }); + const pass = page.locator("article section").filter({ + has: page.getByRole("heading", { + name: "subscription · Passes", + exact: true, + }), + }); + const count = (section: typeof discount, label: string) => + section + .locator("dl div") + .filter({ has: page.getByText(label, { exact: true }) }) + .locator("dd"); + await count(discount, "Received from this fountain") + .filter({ hasText: /^3$/ }) + .waitFor(); + await count(discount, "Available in wallet") + .filter({ hasText: /^2$/ }) + .waitFor(); + await count(pass, "Received from this fountain") + .filter({ hasText: /^2$/ }) + .waitFor(); + await count(pass, "Available in wallet") + .filter({ hasText: /^2$/ }) + .waitFor(); + succeedOrThrow( + await api.updateFountain(token, created.fountain_id, { + grants: [grants[0]], + }), + ); + await page + .getByRole("button", { name: "Refresh", exact: true }) + .click(); + await page.locator("summary").filter({ hasText: "Details" }).click(); + await page + .getByRole("heading", { name: "Previous grants", exact: true }) + .waitFor(); + }); + await stage.step( + "recover a signed withdrawal before removing the fountain", + async (page) => { + succeedOrThrow( + await api.updateFountain(token, created.fountain_id, { + grants: [ + { + ...grants[0], + tokens_per_period_limit: 4, + tokens_per_period_stash: 3, + }, + ], + }), + ); + const path = "**/fountain/withdraw"; + const context = page.context(); + let signed = false; + await context.route(path, async (route) => { + if (route.request().method() !== "POST") return route.continue(); + const response = await route.fetch(); + signed ||= response.ok(); + // The merchant processed the request, but the wallet cannot use its truncated reply. + return route.fulfill({ response, body: "{" }); + }); + try { + await page + .getByRole("button", { name: "Refresh", exact: true }) + .click(); + await page + .getByText( + "Collection failed. Check your connection and refresh to retry.", + ) + .waitFor(); + assert.ok(signed); + await page + .getByRole("button", { name: "Remove", exact: true }) + .click(); + await page + .getByRole("dialog") + .getByRole("button", { name: "Remove fountain" }) + .click(); + await page + .getByRole("dialog", { name: "Withdrawal pending" }) + .waitFor(); + } finally { + await context.unroute(path); + } + await page.getByRole("button", { name: "Retry collection" }).click(); + await page.getByRole("dialog").waitFor({ state: "hidden" }); + const discount = page.locator("article section").filter({ + has: page.getByRole("heading", { + name: "discount · Discounts", + exact: true, + }), + }); + await discount + .locator("dl div") + .filter({ + has: page.getByText("Received from this fountain", { + exact: true, + }), + }) + .locator("dd") + .filter({ hasText: /^4$/ }) + .waitFor(); + }, + ); + await stage.step( + "revoke and remove without deleting issued tokens", + async (page) => { + succeedOrThrow(await api.deleteFountain(token, created.fountain_id)); + await page + .getByRole("button", { name: "Refresh", exact: true }) + .click(); + await page.getByText("Access revoked", { exact: true }).waitFor(); + assert( + await page + .getByRole("button", { name: "Refresh", exact: true }) + .isDisabled(), + ); + await page + .getByRole("button", { name: "Remove", exact: true }) + .click(); + await page + .getByRole("dialog") + .getByRole("button", { name: "Remove fountain", exact: true }) + .click(); + await page + .getByText( + "You have no fountains. Scan a merchant's QR code or enter its Taler link to import one.", + { exact: true }, + ) + .waitFor(); + await page.goto(`${pwaUrl}#/discounts`); + await page + .getByRole("heading", { name: "discount", exact: true }) + .waitFor(); + assert( + !(await page.locator("body").innerText()).includes( + created.fountain_secret, + ), + ); + }, + ); + }, + ); +} +runWalletWebUiFountainsTest.suites = ["web", "wallet", "merchant"]; +runWalletWebUiFountainsTest.timeoutMs = 180_000; diff --git a/packages/taler-harness/src/integrationtests/test-wallet-web-ui-pwa-payment-inputs.ts b/packages/taler-harness/src/integrationtests/test-wallet-web-ui-pwa-payment-inputs.ts @@ -94,7 +94,7 @@ function payButton(page: Page, amount: string) { } /** Each scenario gets its own funded browser wallet and real merchant. */ -async function withFundedWallet( +export async function withFundedWallet( t: GlobalTestState, name: string, scenario: (context: PaymentScenario) => Promise<void>, diff --git a/packages/taler-harness/src/integrationtests/testrunner.ts b/packages/taler-harness/src/integrationtests/testrunner.ts @@ -332,6 +332,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 { runWalletWebUiFountainsTest } from "./test-wallet-web-ui-fountains.js"; import { runMerchantWebuiFountainsTest, runMerchantWebuiFountainPagesTest, @@ -539,6 +540,7 @@ const allTests: TestMainFunction[] = [ runMerchantWebuiFountainsTest, runMerchantWebuiFountainPagesTest, runMerchantWebuiChallengeDevicesTest, + runWalletWebUiFountainsTest, runMerchantSelfProvisionInactiveAccountPermissionsTest, runWithdrawalExternalTest, runWithdrawalIdempotentTest,