taler-typescript-core

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

commit fa5a0d1464eb5d70ad8924ae374164cf126ebb5d
parent eefcce641c302de2b8580fdf3fa579d138f1b4a3
Author: Florian Dold <dold@taler.net>
Date:   Thu, 20 Aug 2026 19:06:48 +0200

wallet-core: retain all development response blockers

Diffstat:
Apackages/taler-wallet-core/src/dev-experiments.test.ts | 69+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mpackages/taler-wallet-core/src/dev-experiments.ts | 6++++--
2 files changed, 73 insertions(+), 2 deletions(-)

diff --git a/packages/taler-wallet-core/src/dev-experiments.test.ts b/packages/taler-wallet-core/src/dev-experiments.test.ts @@ -0,0 +1,69 @@ +/* + 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 { + HeadersImpl, + HttpRequestLibrary, + HttpResponse, +} from "@gnu-taler/taler-util/http"; +import assert from "node:assert"; +import { test } from "node:test"; +import { DevExperimentHttpLib } from "./dev-experiments.js"; + +function okResponse(url: string): HttpResponse { + return { + requestMethod: "POST", + requestUrl: url, + status: 200, + headers: new HeadersImpl(), + async bytes() { + return new Uint8Array(); + }, + async json() { + return {}; + }, + async text() { + return "{}"; + }, + }; +} + +test("fake protocol versions do not disable payment response blockers", async () => { + let underlyingCalls = 0; + const underlying: HttpRequestLibrary = { + async fetch(url) { + underlyingCalls++; + return okResponse(url); + }, + }; + const http = new DevExperimentHttpLib(underlying, { + fakeProtoVer: new Map(), + blockPayResponse: true, + blockClaimResponse: true, + }); + + const payResponse = await http.fetch("https://merchant.example/order/pay", { + method: "POST", + }); + const claimResponse = await http.fetch( + "https://merchant.example/order/claim", + { method: "POST" }, + ); + + assert.strictEqual(payResponse.status, 500); + assert.strictEqual(claimResponse.status, 500); + assert.strictEqual(underlyingCalls, 1); +}); diff --git a/packages/taler-wallet-core/src/dev-experiments.ts b/packages/taler-wallet-core/src/dev-experiments.ts @@ -943,7 +943,8 @@ export class DevExperimentHttpLib implements HttpRequestLibrary { return mockResponseReplacementJson(resp, respJson); } } - } else if (this.devExperimentState.blockPayResponse) { + } + if (this.devExperimentState.blockPayResponse) { logger.warn(`have blockPayResponse`); logger.info(`endsWithPay: ${url.endsWith("/pay")}`); if (method === "post" && url.endsWith("/pay")) { @@ -951,7 +952,8 @@ export class DevExperimentHttpLib implements HttpRequestLibrary { const realResp = await this.underlyingLib.fetch(url, opt); return mockInternalServerError(realResp); } - } else if (this.devExperimentState.blockClaimResponse) { + } + if (this.devExperimentState.blockClaimResponse) { if (method === "post" && url.endsWith("/claim")) { logger.warn(`blocking /claim response`); // The claim is not sent on at all: the merchant would hand the order