commit c457c55e50b7cee6c3a1a77feac5f4c46af6755f
parent 510a87fe34e9d435af480458ab9e22be5ad64c56
Author: Florian Dold <dold@taler.net>
Date: Tue, 21 Jul 2026 11:08:03 +0200
util: test the documented merchant auth methods
Diffstat:
1 file changed, 71 insertions(+), 0 deletions(-)
diff --git a/packages/taler-util/src/types-taler-merchant.test.ts b/packages/taler-util/src/types-taler-merchant.test.ts
@@ -0,0 +1,71 @@
+/*
+ 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";
+import { test } from "node:test";
+import {
+ codecForLoginTokenSuccessResponse,
+ codecForQueryInstancesResponse,
+} from "./types-taler-merchant.js";
+
+function instancesResponse(method: string): any {
+ return {
+ name: "Default",
+ user_type: "business",
+ merchant_pub: "M".repeat(52),
+ address: {},
+ jurisdiction: {},
+ use_stefan: false,
+ default_wire_transfer_delay: { d_us: 1000 },
+ default_pay_delay: { d_us: 1000 },
+ default_refund_delay: { d_us: 1000 },
+ auth: { method },
+ };
+}
+
+test("an instance without an auth token decodes", (t) => {
+ // The backend reports "external" whenever the instance's auth hash is
+ // unset, which is every deployment that authenticates at an API gateway.
+ for (const method of ["token", "external"]) {
+ assert.doesNotThrow(
+ () => codecForQueryInstancesResponse().decode(instancesResponse(method)),
+ method,
+ );
+ }
+});
+
+test("every login token scope the SPA can request decodes", (t) => {
+ for (const scope of [
+ "readonly",
+ "all",
+ "order-simple",
+ "order-pos",
+ "order-mgmt",
+ "order-full",
+ "readonly:refreshable",
+ ]) {
+ assert.doesNotThrow(
+ () =>
+ codecForLoginTokenSuccessResponse().decode({
+ scope,
+ access_token: "secret-token:abc",
+ expiration: { t_s: 1 },
+ refreshable: true,
+ }),
+ scope,
+ );
+ }
+});