taler-typescript-core

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

commit 0b413324524a9cc0165addbc429681091e60f8e9
parent a9892b9e8c6c5b38b7383aee2a8089c376a115ce
Author: Florian Dold <dold@taler.net>
Date:   Tue, 21 Jul 2026 03:02:02 +0200

util: test that the access-token list is fetched authenticated from /tokens

Diffstat:
Apackages/taler-util/src/http-client/bank-core.test.ts | 69+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 69 insertions(+), 0 deletions(-)

diff --git a/packages/taler-util/src/http-client/bank-core.test.ts b/packages/taler-util/src/http-client/bank-core.test.ts @@ -0,0 +1,69 @@ +/* + This file is part of GNU Taler + (C) 2024 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 { test } from "node:test"; +import assert from "node:assert"; +import { + HeadersImpl, + HttpRequestLibrary, + HttpRequestOptions, + HttpResponse, +} from "../http-common.js"; +import { TalerCoreBankHttpClient } from "./bank-core.js"; + +class Recorder implements HttpRequestLibrary { + lastUrl?: string; + lastOpt?: HttpRequestOptions; + async fetch(url: string, opt?: HttpRequestOptions): Promise<HttpResponse> { + this.lastUrl = url; + this.lastOpt = opt; + return { + requestUrl: url, + requestMethod: opt?.method ?? "GET", + status: 204, + headers: new HeadersImpl(), + async json() { + return {}; + }, + async text() { + return ""; + }, + async bytes() { + return new Uint8Array(); + }, + }; + } +} + +test("getAccessTokenList requests /tokens with an Authorization header", async (t) => { + const rec = new Recorder(); + const client = new TalerCoreBankHttpClient( + "https://bank.example.com/api/", + rec, + ); + await client + .getAccessTokenList("alice", "secret-token" as any) + .catch(() => undefined); + assert.ok( + rec.lastUrl?.includes("/accounts/alice/tokens"), + `expected the plural /tokens endpoint, got: ${rec.lastUrl}`, + ); + const auth = (rec.lastOpt?.headers as any)?.Authorization; + assert.ok( + typeof auth === "string" && auth.length > 0, + `expected an Authorization header, got: ${auth}`, + ); +});