summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorian Dold <florian@dold.me>2023-08-29 09:02:16 +0200
committerFlorian Dold <florian@dold.me>2023-08-29 09:03:19 +0200
commitb13bd85215ad64e7a2764ac7e7fee5945ffa1c07 (patch)
tree70643c7e76baeb9f61857add603dc381b6f03766
parent8941f29cb457f86235b73f125e77a88cb762f353 (diff)
downloadwallet-core-b13bd85215ad64e7a2764ac7e7fee5945ffa1c07.tar.gz
wallet-core-b13bd85215ad64e7a2764ac7e7fee5945ffa1c07.tar.bz2
wallet-core-b13bd85215ad64e7a2764ac7e7fee5945ffa1c07.zip
taler-harness: remove axios usage, renovate some tests
-rw-r--r--packages/taler-harness/package.json1
-rw-r--r--packages/taler-harness/src/bench1.ts9
-rw-r--r--packages/taler-harness/src/harness/harness.ts396
-rw-r--r--packages/taler-harness/src/harness/libeufin-apis.ts519
-rw-r--r--packages/taler-harness/src/harness/libeufin.ts177
-rw-r--r--packages/taler-harness/src/index.ts6
-rw-r--r--packages/taler-harness/src/integrationtests/test-libeufin-api-bankaccount.ts2
-rw-r--r--packages/taler-harness/src/integrationtests/test-libeufin-api-bankconnection.ts4
-rw-r--r--packages/taler-harness/src/integrationtests/test-libeufin-api-facade-bad-request.ts25
-rw-r--r--packages/taler-harness/src/integrationtests/test-libeufin-api-facade.ts10
-rw-r--r--packages/taler-harness/src/integrationtests/test-libeufin-api-permissions.ts5
-rw-r--r--packages/taler-harness/src/integrationtests/test-libeufin-api-sandbox-transactions.ts2
-rw-r--r--packages/taler-harness/src/integrationtests/test-libeufin-api-scheduling.ts12
-rw-r--r--packages/taler-harness/src/integrationtests/test-libeufin-api-users.ts4
-rw-r--r--packages/taler-harness/src/integrationtests/test-libeufin-c5x.ts18
-rw-r--r--packages/taler-harness/src/integrationtests/test-libeufin-facade-anastasis.ts4
-rw-r--r--packages/taler-harness/src/integrationtests/test-libeufin-refund.ts2
-rw-r--r--packages/taler-harness/src/integrationtests/test-libeufin-sandbox-wire-transfer-cli.ts4
-rw-r--r--packages/taler-harness/src/integrationtests/test-merchant-exchange-confusion.ts16
-rw-r--r--packages/taler-harness/src/integrationtests/test-merchant-instances-delete.ts22
-rw-r--r--packages/taler-harness/src/integrationtests/test-merchant-instances-urls.ts9
-rw-r--r--packages/taler-harness/src/integrationtests/test-merchant-instances.ts48
-rw-r--r--packages/taler-harness/src/integrationtests/test-merchant-longpolling.ts33
-rw-r--r--packages/taler-harness/src/integrationtests/test-merchant-refund-api.ts34
-rw-r--r--packages/taler-harness/src/integrationtests/test-merchant-spec-public-orders.ts9
-rw-r--r--packages/taler-harness/src/integrationtests/test-pay-paid.ts24
-rw-r--r--packages/taler-harness/src/integrationtests/test-payment-abort.ts21
-rw-r--r--packages/taler-harness/src/integrationtests/test-payment-claim.ts4
-rw-r--r--packages/taler-harness/src/integrationtests/test-payment-idempotency.ts4
-rw-r--r--packages/taler-harness/src/integrationtests/test-payment-template.ts3
-rw-r--r--packages/taler-harness/src/integrationtests/test-payment-transient.ts37
-rw-r--r--packages/taler-harness/src/integrationtests/test-paywall-flow.ts20
-rw-r--r--packages/taler-harness/src/integrationtests/test-refund-auto.ts4
-rw-r--r--packages/taler-harness/src/integrationtests/test-refund-incremental.ts4
-rw-r--r--packages/taler-harness/src/integrationtests/test-wallet-balance.ts19
-rw-r--r--packages/taler-harness/src/integrationtests/test-wallet-dbless.ts8
-rw-r--r--packages/taler-util/src/http-common.ts29
-rw-r--r--packages/taler-wallet-core/package.json1
-rw-r--r--packages/web-util/package.json1
-rw-r--r--pnpm-lock.yaml35
40 files changed, 666 insertions, 919 deletions
diff --git a/packages/taler-harness/package.json b/packages/taler-harness/package.json
index 6dfe9b74b..435ff8a59 100644
--- a/packages/taler-harness/package.json
+++ b/packages/taler-harness/package.json
@@ -40,7 +40,6 @@
"dependencies": {
"@gnu-taler/taler-util": "workspace:*",
"@gnu-taler/taler-wallet-core": "workspace:*",
- "axios": "^0.27.2",
"tslib": "^2.5.3"
}
} \ No newline at end of file
diff --git a/packages/taler-harness/src/bench1.ts b/packages/taler-harness/src/bench1.ts
index 6aa444e0a..618eb683e 100644
--- a/packages/taler-harness/src/bench1.ts
+++ b/packages/taler-harness/src/bench1.ts
@@ -26,13 +26,13 @@ import {
j2s,
Logger,
} from "@gnu-taler/taler-util";
-import { createPlatformHttpLib } from "@gnu-taler/taler-util/http";
import {
AccessStats,
createNativeWalletHost2,
Wallet,
WalletApiOperation,
} from "@gnu-taler/taler-wallet-core";
+import { harnessHttpLib } from "./harness/harness.js";
/**
* Entry point for the benchmark.
@@ -46,11 +46,6 @@ export async function runBench1(configJson: any): Promise<void> {
// Validate the configuration file for this benchmark.
const b1conf = codecForBench1Config().decode(configJson);
- const myHttpLib = createPlatformHttpLib({
- enableThrottling: false,
- allowHttp: true,
- });
-
const numIter = b1conf.iterations ?? 1;
const numDeposits = b1conf.deposits ?? 5;
const restartWallet = b1conf.restartAfter ?? 20;
@@ -85,7 +80,7 @@ export async function runBench1(configJson: any): Promise<void> {
const res = await createNativeWalletHost2({
// No persistent DB storage.
persistentStoragePath: undefined,
- httpLib: myHttpLib,
+ httpLib: harnessHttpLib,
config: {
testing: {
insecureTrustExchange: trustExchange,
diff --git a/packages/taler-harness/src/harness/harness.ts b/packages/taler-harness/src/harness/harness.ts
index 926a0c93b..7db9d82bd 100644
--- a/packages/taler-harness/src/harness/harness.ts
+++ b/packages/taler-harness/src/harness/harness.ts
@@ -55,9 +55,11 @@ import {
RewardCreateRequest,
TippingReserveStatus,
WalletNotification,
+ codecForAny,
} from "@gnu-taler/taler-util";
import {
createPlatformHttpLib,
+ expectSuccessResponseOrThrow,
readSuccessResponseJsonOrThrow,
} from "@gnu-taler/taler-util/http";
import {
@@ -78,7 +80,6 @@ import {
WalletNotificationWaiter,
} from "@gnu-taler/taler-wallet-core/remote";
import { deepStrictEqual } from "assert";
-import axiosImp, { AxiosError } from "axios";
import { ChildProcess, spawn } from "child_process";
import * as fs from "fs";
import * as http from "http";
@@ -87,12 +88,9 @@ import * as path from "path";
import * as readline from "readline";
import { URL } from "url";
import { CoinConfig } from "./denomStructures.js";
-import { LibeufinNexusApi, LibeufinSandboxApi } from "./libeufin-apis.js";
const logger = new Logger("harness.ts");
-const axios = axiosImp.default;
-
export async function delayMs(ms: number): Promise<void> {
return new Promise((resolve, reject) => {
setTimeout(() => resolve(), ms);
@@ -322,12 +320,6 @@ export class GlobalTestState {
);
}
- assertAxiosError(e: any): asserts e is AxiosError {
- if (!e.isAxiosError) {
- throw Error("expected axios error");
- }
- }
-
assertTrue(b: boolean): asserts b {
if (!b) {
throw Error("test assertion failed");
@@ -558,7 +550,10 @@ export async function pingProc(
while (true) {
try {
logger.trace(`pinging ${serviceName} at ${url}`);
- const resp = await axios.get(url);
+ const resp = await harnessHttpLib.fetch(url);
+ if (resp.status !== 200) {
+ throw Error("non-200 status code");
+ }
logger.trace(`service ${serviceName} available`);
return;
} catch (e: any) {
@@ -584,289 +579,6 @@ class BankServiceBase {
}
/**
- * Work in progress. The key point is that both Sandbox and Nexus
- * will be configured and started by this class.
- */
-class LibEuFinBankService extends BankServiceBase implements BankServiceHandle {
- sandboxProc: ProcessWrapper | undefined;
- nexusProc: ProcessWrapper | undefined;
-
- http = createPlatformHttpLib({
- allowHttp: true,
- enableThrottling: false,
- });
-
- static async create(
- gc: GlobalTestState,
- bc: BankConfig,
- ): Promise<LibEuFinBankService> {
- return new LibEuFinBankService(gc, bc, "foo");
- }
-
- get port() {
- return this.bankConfig.httpPort;
- }
- get nexusPort() {
- return this.bankConfig.httpPort + 1000;
- }
-
- get nexusDbConn(): string {
- return `jdbc:sqlite:${this.globalTestState.testDir}/libeufin-nexus.sqlite3`;
- }
-
- get sandboxDbConn(): string {
- return `jdbc:sqlite:${this.globalTestState.testDir}/libeufin-sandbox.sqlite3`;
- }
-
- get nexusBaseUrl(): string {
- return `http://localhost:${this.nexusPort}`;
- }
-
- get baseUrlDemobank(): string {
- let url = new URL("demobanks/default/", this.baseUrlNetloc);
- return url.href;
- }
-
- get bankAccessApiBaseUrl(): string {
- let url = new URL("access-api/", this.baseUrlDemobank);
- return url.href;
- }
-
- get baseUrlNetloc(): string {
- return `http://localhost:${this.bankConfig.httpPort}/`;
- }
-
- get baseUrl(): string {
- return this.bankAccessApiBaseUrl;
- }
-
- async setSuggestedExchange(
- e: ExchangeServiceInterface,
- exchangePayto: string,
- ) {
- await sh(
- this.globalTestState,
- "libeufin-sandbox-set-default-exchange",
- `libeufin-sandbox default-exchange ${e.baseUrl} ${exchangePayto}`,
- {
- ...process.env,
- LIBEUFIN_SANDBOX_DB_CONNECTION: this.sandboxDbConn,
- },
- );
- }
-
- // Create one at both sides: Sandbox and Nexus.
- async createExchangeAccount(
- accountName: string,
- password: string,
- ): Promise<HarnessExchangeBankAccount> {
- logger.info("Create Exchange account(s)!");
- /**
- * Many test cases try to create a Exchange account before
- * starting the bank; that's because the Pybank did it entirely
- * via the configuration file.
- */
- await this.start();
- await this.pingUntilAvailable();
- await LibeufinSandboxApi.createDemobankAccount(accountName, password, {
- baseUrl: this.bankAccessApiBaseUrl,
- });
- let bankAccountLabel = accountName;
- await LibeufinSandboxApi.createDemobankEbicsSubscriber(
- {
- hostID: "talertestEbicsHost",
- userID: "exchangeEbicsUser",
- partnerID: "exchangeEbicsPartner",
- },
- bankAccountLabel,
- { baseUrl: this.baseUrlDemobank },
- );
-
- await LibeufinNexusApi.createUser(
- { baseUrl: this.nexusBaseUrl },
- {
- username: accountName,
- password: password,
- },
- );
- await LibeufinNexusApi.createEbicsBankConnection(
- { baseUrl: this.nexusBaseUrl },
- {
- name: "ebics-connection", // connection name.
- ebicsURL: new URL("ebicsweb", this.baseUrlNetloc).href,
- hostID: "talertestEbicsHost",
- userID: "exchangeEbicsUser",
- partnerID: "exchangeEbicsPartner",
- },
- );
- await LibeufinNexusApi.connectBankConnection(
- { baseUrl: this.nexusBaseUrl },
- "ebics-connection",
- );
- await LibeufinNexusApi.fetchAccounts(
- { baseUrl: this.nexusBaseUrl },
- "ebics-connection",
- );
- await LibeufinNexusApi.importConnectionAccount(
- { baseUrl: this.nexusBaseUrl },
- "ebics-connection", // connection name
- accountName, // offered account label
- `${accountName}-nexus-label`, // bank account label at Nexus
- );
- await LibeufinNexusApi.createTwgFacade(
- { baseUrl: this.nexusBaseUrl },
- {
- name: "exchange-facade",
- connectionName: "ebics-connection",
- accountName: `${accountName}-nexus-label`,
- currency: "EUR",
- reserveTransferLevel: "report",
- },
- );
- await LibeufinNexusApi.postPermission(
- { baseUrl: this.nexusBaseUrl },
- {
- action: "grant",
- permission: {
- subjectId: accountName,
- subjectType: "user",
- resourceType: "facade",
- resourceId: "exchange-facade", // facade name
- permissionName: "facade.talerWireGateway.transfer",
- },
- },
- );
- await LibeufinNexusApi.postPermission(
- { baseUrl: this.nexusBaseUrl },
- {
- action: "grant",
- permission: {
- subjectId: accountName,
- subjectType: "user",
- resourceType: "facade",
- resourceId: "exchange-facade", // facade name
- permissionName: "facade.talerWireGateway.history",
- },
- },
- );
- // Set fetch task.
- await LibeufinNexusApi.postTask(
- { baseUrl: this.nexusBaseUrl },
- `${accountName}-nexus-label`,
- {
- name: "wirewatch-task",
- cronspec: "* * *",
- type: "fetch",
- params: {
- level: "all",
- rangeType: "all",
- },
- },
- );
- await LibeufinNexusApi.postTask(
- { baseUrl: this.nexusBaseUrl },
- `${accountName}-nexus-label`,
- {
- name: "aggregator-task",
- cronspec: "* * *",
- type: "submit",
- params: {},
- },
- );
- let facadesResp = await LibeufinNexusApi.getAllFacades({
- baseUrl: this.nexusBaseUrl,
- });
- let accountInfoResp = await LibeufinSandboxApi.demobankAccountInfo(
- "admin",
- "secret",
- { baseUrl: this.bankAccessApiBaseUrl },
- accountName, // bank account label.
- );
- return {
- accountName: accountName,
- accountPassword: password,
- accountPaytoUri: accountInfoResp.data.paytoUri,
- wireGatewayApiBaseUrl: facadesResp.data.facades[0].baseUrl,
- };
- }
-
- async start(): Promise<void> {
- /**
- * Because many test cases try to create a Exchange bank
- * account _before_ starting the bank (Pybank did it only via
- * the config), it is possible that at this point Sandbox and
- * Nexus are already running. Hence, this method only launches
- * them if they weren't launched earlier.
- */
-
- // Only go ahead if BOTH aren't running.
- if (this.sandboxProc || this.nexusProc) {
- logger.info("Nexus or Sandbox already running, not taking any action.");
- return;
- }
- await sh(
- this.globalTestState,
- "libeufin-sandbox-config-demobank",
- `libeufin-sandbox config --currency=${this.bankConfig.currency} default`,
- {
- ...process.env,
- LIBEUFIN_SANDBOX_DB_CONNECTION: this.sandboxDbConn,
- LIBEUFIN_SANDBOX_ADMIN_PASSWORD: "secret",
- },
- );
- this.sandboxProc = this.globalTestState.spawnService(
- "libeufin-sandbox",
- ["serve", "--port", `${this.port}`],
- "libeufin-sandbox",
- {
- ...process.env,
- LIBEUFIN_SANDBOX_DB_CONNECTION: this.sandboxDbConn,
- LIBEUFIN_SANDBOX_ADMIN_PASSWORD: "secret",
- },
- );
- await runCommand(
- this.globalTestState,
- "libeufin-nexus-superuser",
- "libeufin-nexus",
- ["superuser", "admin", "--password", "test"],
- {
- ...process.env,
- LIBEUFIN_NEXUS_DB_CONNECTION: this.nexusDbConn,
- },
- );
- this.nexusProc = this.globalTestState.spawnService(
- "libeufin-nexus",
- ["serve", "--port", `${this.nexusPort}`],
- "libeufin-nexus",
- {
- ...process.env,
- LIBEUFIN_NEXUS_DB_CONNECTION: this.nexusDbConn,
- },
- );
- // need to wait here, because at this point
- // a Ebics host needs to be created (RESTfully)
- await this.pingUntilAvailable();
- LibeufinSandboxApi.createEbicsHost(
- { baseUrl: this.baseUrlNetloc },
- "talertestEbicsHost",
- );
- }
-
- async pingUntilAvailable(): Promise<void> {
- await pingProc(
- this.sandboxProc,
- `http://localhost:${this.bankConfig.httpPort}`,
- "libeufin-sandbox",
- );
- await pingProc(
- this.nexusProc,
- `${this.nexusBaseUrl}/config`,
- "libeufin-nexus",
- );
- }
-}
-
-/**
* Implementation of the bank service using the "taler-fakebank-run" tool.
*/
export class FakebankService
@@ -1152,6 +864,9 @@ export class ExchangeService implements ExchangeServiceInterface {
"currency_round_unit",
e.roundUnit ?? `${e.currency}:0.01`,
);
+ // Set to a high value to not break existing test cases where the merchant
+ // would cover all fees.
+ config.setString("exchange", "STEFAN_ABS", `${e.currency}:1`);
config.setString(
"exchange",
"revocation_dir",
@@ -1636,20 +1351,30 @@ export interface DeleteTippingReserveArgs {
purge?: boolean;
}
+/**
+ * Default HTTP client handle for the integration test harness.
+ */
+export const harnessHttpLib = createPlatformHttpLib({
+ allowHttp: true,
+ enableThrottling: false,
+});
+
export class MerchantApiClient {
constructor(
private baseUrl: string,
public readonly auth: MerchantAuthConfiguration,
) {}
- // FIXME: Migrate everything to this in favor of axios
- http = createPlatformHttpLib({ allowHttp: true, enableThrottling: false });
+ httpClient = createPlatformHttpLib({ allowHttp: true, enableThrottling: false });
async changeAuth(auth: MerchantAuthConfiguration): Promise<void> {
const url = new URL("private/auth", this.baseUrl);
- await axios.post(url.href, auth, {
+ const res = await this.httpClient.fetch(url.href, {
+ method: "POST",
+ body: auth,
headers: this.makeAuthHeader(),
});
+ await expectSuccessResponseOrThrow(res);
}
async deleteTippingReserve(req: DeleteTippingReserveArgs): Promise<void> {
@@ -1657,7 +1382,8 @@ export class MerchantApiClient {
if (req.purge) {
url.searchParams.set("purge", "YES");
}
- const resp = await axios.delete(url.href, {
+ const resp = await this.httpClient.fetch(url.href, {
+ method: "DELETE",
headers: this.makeAuthHeader(),
});
logger.info(`delete status: ${resp.status}`);
@@ -1668,7 +1394,7 @@ export class MerchantApiClient {
req: CreateMerchantTippingReserveRequest,
): Promise<MerchantReserveCreateConfirmation> {
const url = new URL("private/reserves", this.baseUrl);
- const resp = await this.http.fetch(url.href, {
+ const resp = await this.httpClient.fetch(url.href, {
method: "POST",
body: req,
headers: this.makeAuthHeader(),
@@ -1684,7 +1410,7 @@ export class MerchantApiClient {
console.log(this.makeAuthHeader());
const url = new URL("private", this.baseUrl);
logger.info(`request url ${url.href}`);
- const resp = await this.http.fetch(url.href, {
+ const resp = await this.httpClient.fetch(url.href, {
method: "GET",
headers: this.makeAuthHeader(),
});
@@ -1694,7 +1420,7 @@ export class MerchantApiClient {
async getPrivateTipReserves(): Promise<TippingReserveStatus> {
console.log(this.makeAuthHeader());
const url = new URL("private/reserves", this.baseUrl);
- const resp = await this.http.fetch(url.href, {
+ const resp = await this.httpClient.fetch(url.href, {
method: "GET",
headers: this.makeAuthHeader(),
});
@@ -1704,33 +1430,37 @@ export class MerchantApiClient {
async deleteInstance(instanceId: string) {
const url = new URL(`management/instances/${instanceId}`, this.baseUrl);
- await axios.delete(url.href, {
+ const resp = await this.httpClient.fetch(url.href, {
+ method: "DELETE",
headers: this.makeAuthHeader(),
});
+ await expectSuccessResponseOrThrow(resp);
}
async createInstance(req: MerchantInstanceConfig): Promise<void> {
const url = new URL("management/instances", this.baseUrl);
- await axios.post(url.href, req, {
+ await this.httpClient.fetch(url.href, {
+ method: "POST",
+ body: req,
headers: this.makeAuthHeader(),
});
}
async getInstances(): Promise<MerchantInstancesResponse> {
const url = new URL("management/instances", this.baseUrl);
- const resp = await axios.get(url.href, {
+ const resp = await this.httpClient.fetch(url.href, {
headers: this.makeAuthHeader(),
});
- return resp.data;
+ return resp.json();
}
async getInstanceFullDetails(instanceId: string): Promise<any> {
const url = new URL(`management/instances/${instanceId}`, this.baseUrl);
try {
- const resp = await axios.get(url.href, {
+ const resp = await this.httpClient.fetch(url.href, {
headers: this.makeAuthHeader(),
});
- return resp.data;
+ return resp.json();
} catch (e) {
throw e;
}
@@ -1750,6 +1480,8 @@ export class MerchantApiClient {
/**
* FIXME: This should be deprecated in favor of MerchantApiClient
+ *
+ * @deprecated use MerchantApiClient instead
*/
export namespace MerchantPrivateApi {
export async function createOrder(
@@ -1760,10 +1492,15 @@ export namespace MerchantPrivateApi {
): Promise<MerchantPostOrderResponse> {
const baseUrl = merchantService.makeInstanceBaseUrl(instanceName);
let url = new URL("private/orders", baseUrl);
- const resp = await axios.post(url.href, req, {
+ const resp = await harnessHttpLib.fetch(url.href, {
+ method: "POST",
+ body: req,
headers: withAuthorization as Record<string, string>,
});
- return codecForMerchantPostOrderResponse().decode(resp.data);
+ return readSuccessResponseJsonOrThrow(
+ resp,
+ codecForMerchantPostOrderResponse(),
+ );
}
export async function createTemplate(
@@ -1774,7 +1511,9 @@ export namespace MerchantPrivateApi {
) {
const baseUrl = merchantService.makeInstanceBaseUrl(instanceName);
let url = new URL("private/templates", baseUrl);
- const resp = await axios.post(url.href, req, {
+ const resp = await harnessHttpLib.fetch(url.href, {
+ method: "POST",
+ body: req,
headers: withAuthorization as Record<string, string>,
});
if (resp.status !== 204) {
@@ -1794,10 +1533,13 @@ export namespace MerchantPrivateApi {
if (query.sessionId) {
reqUrl.searchParams.set("session_id", query.sessionId);
}
- const resp = await axios.get(reqUrl.href, {
+ const resp = await harnessHttpLib.fetch(reqUrl.href, {
headers: withAuthorization as Record<string, string>,
});
- return codecForMerchantOrderPrivateStatusResponse().decode(resp.data);
+ return readSuccessResponseJsonOrThrow(
+ resp,
+ codecForMerchantOrderPrivateStatusResponse(),
+ );
}
export async function giveRefund(
@@ -1813,12 +1555,16 @@ export namespace MerchantPrivateApi {
`private/orders/${r.orderId}/refund`,
merchantService.makeInstanceBaseUrl(r.instance),
);
- const resp = await axios.post(reqUrl.href, {
- refund: r.amount,
- reason: r.justification,
+ const resp = await harnessHttpLib.fetch(reqUrl.href, {
+ method: "POST",
+ body: {
+ refund: r.amount,
+ reason: r.justification,
+ },
});
+ const respBody = await resp.json();
return {
- talerRefundUri: resp.data.taler_refund_uri,
+ talerRefundUri: respBody.taler_refund_uri,
};
}
@@ -1830,9 +1576,9 @@ export namespace MerchantPrivateApi {
`private/reserves`,
merchantService.makeInstanceBaseUrl(instance),
);
- const resp = await axios.get(reqUrl.href);
+ const resp = await harnessHttpLib.fetch(reqUrl.href);
// FIXME: validate
- return resp.data;
+ return resp.json();
}
export async function giveTip(
@@ -1844,9 +1590,12 @@ export namespace MerchantPrivateApi {
`private/tips`,
merchantService.makeInstanceBaseUrl(instance),
);
- const resp = await axios.post(reqUrl.href, req);
+ const resp = await harnessHttpLib.fetch(reqUrl.href, {
+ method: "POST",
+ body: req,
+ });
// FIXME: validate
- return resp.data;
+ return resp.json();
}
}
@@ -2052,7 +1801,12 @@ export class MerchantService implements MerchantServiceInterface {
instanceConfig.defaultPayDelay ??
Duration.toTalerProtocolDuration(Duration.getForever()),
};
- await axios.post(url, body);
+ const httpLib = createPlatformHttpLib({
+ allowHttp: true,
+ enableThrottling: false,
+ });
+ const resp = await httpLib.fetch(url, { method: "POST", body });
+ await expectSuccessResponseOrThrow(resp);
}
makeInstanceBaseUrl(instanceName?: string): string {
diff --git a/packages/taler-harness/src/harness/libeufin-apis.ts b/packages/taler-harness/src/harness/libeufin-apis.ts
index cb9acdaa4..3c57eee07 100644
--- a/packages/taler-harness/src/harness/libeufin-apis.ts
+++ b/packages/taler-harness/src/harness/libeufin-apis.ts
@@ -6,8 +6,21 @@
*/
import { URL } from "@gnu-taler/taler-util";
-import axiosImp from "axios";
-const axios = axiosImp.default;
+import {
+ createPlatformHttpLib,
+ makeBasicAuthHeader,
+} from "@gnu-taler/taler-util/http";
+import {
+ LibeufinNexusTransactions,
+ LibeufinSandboxAdminBankAccountBalance,
+ NexusBankConnections,
+ NexusFacadeListResponse,
+ NexusGetPermissionsResponse,
+ NexusNewTransactionsInfo,
+ NexusTask,
+ NexusTaskCollection,
+ NexusUserResponse,
+} from "./libeufin.js";
export interface LibeufinSandboxServiceInterface {
baseUrl: string;
@@ -163,30 +176,13 @@ export interface LibeufinSandboxAddIncomingRequest {
direction: string;
}
+const libeufinHttpLib = createPlatformHttpLib();
+
/**
* APIs spread across Legacy and Access, it is therefore
* the "base URL" relative to which API every call addresses.
*/
export namespace LibeufinSandboxApi {
- // Need Access API base URL.
- export async function demobankAccountInfo(
- username: string,
- password: string,
- libeufinSandboxService: LibeufinSandboxServiceInterface,
- accountLabel: string,
- ) {
- let url = new URL(
- `accounts/${accountLabel}`,
- libeufinSandboxService.baseUrl,
- );
- return await axios.get(url.href, {
- auth: {
- username: username,
- password: password,
- },
- });
- }
-
// Creates one bank account via the Access API.
// Need the /demobanks/$id/access-api as the base URL
export async function createDemobankAccount(
@@ -194,12 +190,15 @@ export namespace LibeufinSandboxApi {
password: string,
libeufinSandboxService: LibeufinSandboxServiceInterface,
iban: string | null = null,
- ) {
+ ): Promise<void> {
let url = new URL("testing/register", libeufinSandboxService.baseUrl);
- await axios.post(url.href, {
- username: username,
- password: password,
- iban: iban,
+ await libeufinHttpLib.fetch(url.href, {
+ method: "POST",
+ body: {
+ username: username,
+ password: password,
+ iban: iban,
+ },
});
}
// Need /demobanks/$id as the base URL
@@ -209,75 +208,57 @@ export namespace LibeufinSandboxApi {
libeufinSandboxService: LibeufinSandboxServiceInterface,
username: string = "admin",
password: string = "secret",
- ) {
+ ): Promise<void> {
// baseUrl should already be pointed to one demobank.
let url = new URL("ebics/subscribers", libeufinSandboxService.baseUrl);
- await axios.post(
- url.href,
- {
+ await libeufinHttpLib.fetch(url.href, {
+ method: "POST",
+ body: {
userID: req.userID,
hostID: req.hostID,
partnerID: req.partnerID,
demobankAccountLabel: demobankAccountLabel,
},
- {
- auth: {
- username: "admin",
- password: "secret",
- },
- },
- );
+ });
}
export async function rotateKeys(
libeufinSandboxService: LibeufinSandboxServiceInterface,
hostID: string,
- ) {
+ ): Promise<void> {
const baseUrl = libeufinSandboxService.baseUrl;
let url = new URL(`admin/ebics/hosts/${hostID}/rotate-keys`, baseUrl);
- await axios.post(
- url.href,
- {},
- {
- auth: {
- username: "admin",
- password: "secret",
- },
- },
- );
+ await libeufinHttpLib.fetch(url.href, {
+ method: "POST",
+ body: {},
+ });
}
export async function createEbicsHost(
libeufinSandboxService: LibeufinSandboxServiceInterface,
hostID: string,
- ) {
+ ): Promise<void> {
const baseUrl = libeufinSandboxService.baseUrl;
let url = new URL("admin/ebics/hosts", baseUrl);
- await axios.post(
- url.href,
- {
+ await libeufinHttpLib.fetch(url.href, {
+ method: "POST",
+ body: {
hostID,
ebicsVersion: "2.5",
},
- {
- auth: {
- username: "admin",
- password: "secret",
- },
- },
- );
+ headers: { Authorization: makeBasicAuthHeader("admin", "secret") },
+ });
}
export async function createBankAccount(
libeufinSandboxService: LibeufinSandboxServiceInterface,
req: BankAccountInfo,
- ) {
+ ): Promise<void> {
const baseUrl = libeufinSandboxService.baseUrl;
let url = new URL(`admin/bank-accounts/${req.label}`, baseUrl);
- await axios.post(url.href, req, {
- auth: {
- username: "admin",
- password: "secret",
- },
+ await libeufinHttpLib.fetch(url.href, {
+ method: "POST",
+ body: req,
+ headers: { Authorization: makeBasicAuthHeader("admin", "secret") },
});
}
@@ -288,14 +269,13 @@ export namespace LibeufinSandboxApi {
export async function createEbicsSubscriber(
libeufinSandboxService: LibeufinSandboxServiceInterface,
req: CreateEbicsSubscriberRequest,
- ) {
+ ): Promise<void> {
const baseUrl = libeufinSandboxService.baseUrl;
let url = new URL("admin/ebics/subscribers", baseUrl);
- await axios.post(url.href, req, {
- auth: {
- username: "admin",
- password: "secret",
- },
+ await libeufinHttpLib.fetch(url.href, {
+ method: "POST",
+ body: req,
+ headers: { Authorization: makeBasicAuthHeader("admin", "secret") },
});
}
@@ -306,14 +286,13 @@ export namespace LibeufinSandboxApi {
export async function createEbicsBankAccount(
libeufinSandboxService: LibeufinSandboxServiceInterface,
req: CreateEbicsBankAccountRequest,
- ) {
+ ): Promise<void> {
const baseUrl = libeufinSandboxService.baseUrl;
let url = new URL("admin/ebics/bank-accounts", baseUrl);
- await axios.post(url.href, req, {
- auth: {
- username: "admin",
- password: "secret",
- },
+ await libeufinHttpLib.fetch(url.href, {
+ method: "POST",
+ body: req,
+ headers: { Authorization: makeBasicAuthHeader("admin", "secret") },
});
}
@@ -321,17 +300,16 @@ export namespace LibeufinSandboxApi {
libeufinSandboxService: LibeufinSandboxServiceInterface,
accountLabel: string,
req: SimulateIncomingTransactionRequest,
- ) {
+ ): Promise<void> {
const baseUrl = libeufinSandboxService.baseUrl;
let url = new URL(
`admin/bank-accounts/${accountLabel}/simulate-incoming-transaction`,
baseUrl,
);
- await axios.post(url.href, req, {
- auth: {
- username: "admin",
- password: "secret",
- },
+ await libeufinHttpLib.fetch(url.href, {
+ method: "POST",
+ body: req,
+ headers: { Authorization: makeBasicAuthHeader("admin", "secret") },
});
}
@@ -344,13 +322,10 @@ export namespace LibeufinSandboxApi {
`admin/bank-accounts/${accountLabel}/transactions`,
baseUrl,
);
- const res = await axios.get(url.href, {
- auth: {
- username: "admin",
- password: "secret",
- },
+ const res = await libeufinHttpLib.fetch(url.href, {
+ headers: { Authorization: makeBasicAuthHeader("admin", "secret") },
});
- return res.data as SandboxAccountTransactions;
+ return (await res.json()) as SandboxAccountTransactions;
}
export async function getCamt053(
@@ -359,61 +334,50 @@ export namespace LibeufinSandboxApi {
): Promise<any> {
const baseUrl = libeufinSandboxService.baseUrl;
let url = new URL("admin/payments/camt", baseUrl);
- return await axios.post(
- url.href,
- {
+ return await libeufinHttpLib.fetch(url.href, {
+ method: "POST",
+ headers: { Authorization: makeBasicAuthHeader("admin", "secret") },
+ body: {
bankaccount: accountLabel,
type: 53,
},
- {
- auth: {
- username: "admin",
- password: "secret",
- },
- },
- );
+ });
}
export async function getAccountInfoWithBalance(
libeufinSandboxService: LibeufinSandboxServiceInterface,
accountLabel: string,
- ): Promise<any> {
+ ): Promise<LibeufinSandboxAdminBankAccountBalance> {
const baseUrl = libeufinSandboxService.baseUrl;
let url = new URL(`admin/bank-accounts/${accountLabel}`, baseUrl);
- return await axios.get(url.href, {
- auth: {
- username: "admin",
- password: "secret",
- },
+ const res = await libeufinHttpLib.fetch(url.href, {
+ headers: { Authorization: makeBasicAuthHeader("admin", "secret") },
});
+ return res.json();
}
}
export namespace LibeufinNexusApi {
export async function getAllConnections(
nexus: LibeufinNexusServiceInterface,
- ): Promise<any> {
+ ): Promise<NexusBankConnections> {
let url = new URL("bank-connections", nexus.baseUrl);
- const res = await axios.get(url.href, {
- auth: {
- username: "admin",
- password: "test",
- },
+ const res = await libeufinHttpLib.fetch(url.href, {
+ headers: { Authorization: makeBasicAuthHeader("admin", "secret") },
});
- return res;
+ return res.json();
}
export async function deleteBankConnection(
libeufinNexusService: LibeufinNexusServiceInterface,
req: DeleteBankConnectionRequest,
- ): Promise<any> {
+ ): Promise<void> {
const baseUrl = libeufinNexusService.baseUrl;
let url = new URL("bank-connections/delete-connection", baseUrl);
- return await axios.post(url.href, req, {
- auth: {
- username: "admin",
- password: "test",
- },
+ await libeufinHttpLib.fetch(url.href, {
+ method: "POST",
+ headers: { Authorization: makeBasicAuthHeader("admin", "secret") },
+ body: req,
});
}
@@ -423,9 +387,10 @@ export namespace LibeufinNexusApi {
): Promise<void> {
const baseUrl = libeufinNexusService.baseUrl;
let url = new URL("bank-connections", baseUrl);
- await axios.post(
- url.href,
- {
+ await libeufinHttpLib.fetch(url.href, {
+ method: "POST",
+ headers: { Authorization: makeBasicAuthHeader("admin", "secret") },
+ body: {
source: "new",
type: "ebics",
name: req.name,
@@ -437,13 +402,7 @@ export namespace LibeufinNexusApi {
systemID: req.systemID,
},
},
- {
- auth: {
- username: "admin",
- password: "test",
- },
- },
- );
+ });
}
export async function getBankAccount(
@@ -452,12 +411,10 @@ export namespace LibeufinNexusApi {
): Promise<any> {
const baseUrl = libeufinNexusService.baseUrl;
let url = new URL(`bank-accounts/${accountName}`, baseUrl);
- return await axios.get(url.href, {
- auth: {
- username: "admin",
- password: "test",
- },
+ const resp = await libeufinHttpLib.fetch(url.href, {
+ headers: { Authorization: makeBasicAuthHeader("admin", "secret") },
});
+ return resp.json();
}
export async function submitInitiatedPayment(
@@ -470,16 +427,11 @@ export namespace LibeufinNexusApi {
`bank-accounts/${accountName}/payment-initiations/${paymentId}/submit`,
baseUrl,
);
- await axios.post(
- url.href,
- {},
- {
- auth: {
- username: "admin",
- password: "test",
- },
- },
- );
+ await libeufinHttpLib.fetch(url.href, {
+ method: "POST",
+ headers: { Authorization: makeBasicAuthHeader("admin", "secret") },
+ body: {},
+ });
}
export async function fetchAccounts(
@@ -491,16 +443,11 @@ export namespace LibeufinNexusApi {
`bank-connections/${connectionName}/fetch-accounts`,
baseUrl,
);
- await axios.post(
- url.href,
- {},
- {
- auth: {
- username: "admin",
- password: "test",
- },
- },
- );
+ await libeufinHttpLib.fetch(url.href, {
+ method: "POST",
+ headers: { Authorization: makeBasicAuthHeader("admin", "secret") },
+ body: {},
+ });
}
export async function importConnectionAccount(
@@ -514,37 +461,27 @@ export namespace LibeufinNexusApi {
`bank-connections/${connectionName}/import-account`,
baseUrl,
);
- await axios.post(
- url.href,
- {
+ await libeufinHttpLib.fetch(url.href, {
+ method: "POST",
+ headers: { Authorization: makeBasicAuthHeader("admin", "secret") },
+ body: {
offeredAccountId,
nexusBankAccountId,
},
- {
- auth: {
- username: "admin",
- password: "test",
- },
- },
- );
+ });
}
export async function connectBankConnection(
libeufinNexusService: LibeufinNexusServiceInterface,
connectionName: string,
- ) {
+ ): Promise<void> {
const baseUrl = libeufinNexusService.baseUrl;
let url = new URL(`bank-connections/${connectionName}/connect`, baseUrl);
- await axios.post(
- url.href,
- {},
- {
- auth: {
- username: "admin",
- password: "test",
- },
- },
- );
+ await libeufinHttpLib.fetch(url.href, {
+ method: "POST",
+ headers: { Authorization: makeBasicAuthHeader("admin", "secret") },
+ body: {},
+ });
}
export async function getPaymentInitiations(
@@ -558,43 +495,33 @@ export namespace LibeufinNexusApi {
`/bank-accounts/${accountName}/payment-initiations`,
baseUrl,
);
- let response = await axios.get(url.href, {
- auth: {
- username: username,
- password: password,
- },
+ let response = await libeufinHttpLib.fetch(url.href, {
+ headers: { Authorization: makeBasicAuthHeader("admin", "secret") },
});
+ const respJson = await response.json();
console.log(
`Payment initiations of: ${accountName}`,
- JSON.stringify(response.data, null, 2),
+ JSON.stringify(respJson, null, 2),
);
}
- export async function getConfig(
- libeufinNexusService: LibeufinNexusServiceInterface,
- ): Promise<void> {
- const baseUrl = libeufinNexusService.baseUrl;
- let url = new URL(`/config`, baseUrl);
- let response = await axios.get(url.href);
- }
-
// Uses the Anastasis API to get a list of transactions.
export async function getAnastasisTransactions(
libeufinNexusService: LibeufinNexusServiceInterface,
anastasisBaseUrl: string,
+ // FIXME: Nail down type!
params: {}, // of the request: {delta: 5, ..}
username: string = "admin",
password: string = "test",
): Promise<any> {
let url = new URL("history/incoming", anastasisBaseUrl);
- let response = await axios.get(url.href, {
- params: params,
- auth: {
- username: username,
- password: password,
- },
+ for (const [k, v] of Object.entries(params)) {
+ url.searchParams.set(k, String(v));
+ }
+ let response = await libeufinHttpLib.fetch(url.href, {
+ headers: { Authorization: makeBasicAuthHeader("admin", "secret") },
});
- return response;
+ return response.json();
}
// FIXME: this function should return some structured
@@ -604,16 +531,13 @@ export namespace LibeufinNexusApi {
accountName: string,
username: string = "admin",
password: string = "test",
- ): Promise<any> {
+ ): Promise<LibeufinNexusTransactions> {
const baseUrl = libeufinNexusService.baseUrl;
let url = new URL(`/bank-accounts/${accountName}/transactions`, baseUrl);
- let response = await axios.get(url.href, {
- auth: {
- username: username,
- password: password,
- },
+ let response = await libeufinHttpLib.fetch(url.href, {
+ headers: { Authorization: makeBasicAuthHeader("admin", "secret") },
});
- return response;
+ return response.json();
}
export async function fetchTransactions(
@@ -623,25 +547,21 @@ export namespace LibeufinNexusApi {
level: string = "report",
username: string = "admin",
password: string = "test",
- ): Promise<any> {
+ ): Promise<NexusNewTransactionsInfo> {
const baseUrl = libeufinNexusService.baseUrl;
let url = new URL(
`/bank-accounts/${accountName}/fetch-transactions`,
baseUrl,
);
- return await axios.post(
- url.href,
- {
+ const resp = await libeufinHttpLib.fetch(url.href, {
+ method: "POST",
+ headers: { Authorization: makeBasicAuthHeader("admin", "secret") },
+ body: {
rangeType: rangeType,
level: level,
},
- {
- auth: {
- username: username,
- password: password,
- },
- },
- );
+ });
+ return resp.json();
}
export async function changePassword(
@@ -649,97 +569,109 @@ export namespace LibeufinNexusApi {
username: string,
req: UpdateNexusUserRequest,
auth: NexusAuth,
- ) {
+ ): Promise<void> {
const baseUrl = libeufinNexusService.baseUrl;
let url = new URL(`/users/${username}/password`, baseUrl);
- await axios.post(url.href, req, auth);
+ await libeufinHttpLib.fetch(url.href, {
+ method: "POST",
+ headers: { Authorization: makeBasicAuthHeader("admin", "secret") },
+ body: req,
+ });
}
export async function getUser(
libeufinNexusService: LibeufinNexusServiceInterface,
auth: NexusAuth,
- ): Promise<any> {
+ ): Promise<NexusUserResponse> {
const baseUrl = libeufinNexusService.baseUrl;
let url = new URL(`/user`, baseUrl);
- return await axios.get(url.href, auth);
+ const resp = await libeufinHttpLib.fetch(url.href, {
+ headers: { Authorization: makeBasicAuthHeader("admin", "secret") },
+ });
+ return resp.json();
}
export async function createUser(
libeufinNexusService: LibeufinNexusServiceInterface,
req: CreateNexusUserRequest,
- ) {
+ ): Promise<void> {
const baseUrl = libeufinNexusService.baseUrl;
let url = new URL(`/users`, baseUrl);
- await axios.post(url.href, req, {
- auth: {
- username: "admin",
- password: "test",
- },
+ await libeufinHttpLib.fetch(url.href, {
+ method: "POST",
+ headers: { Authorization: makeBasicAuthHeader("admin", "secret") },
+ body: req,
});
}
export async function getAllPermissions(
libeufinNexusService: LibeufinNexusServiceInterface,
- ): Promise<any> {
+ ): Promise<NexusGetPermissionsResponse> {
const baseUrl = libeufinNexusService.baseUrl;
let url = new URL(`/permissions`, baseUrl);
- return await axios.get(url.href, {
- auth: {
- username: "admin",
- password: "test",
- },
+ const resp = await libeufinHttpLib.fetch(url.href, {
+ headers: { Authorization: makeBasicAuthHeader("admin", "secret") },
});
+ return resp.json();
}
export async function postPermission(
libeufinNexusService: LibeufinNexusServiceInterface,
req: PostNexusPermissionRequest,
- ) {
+ ): Promise<void> {
const baseUrl = libeufinNexusService.baseUrl;
let url = new URL(`/permissions`, baseUrl);
- await axios.post(url.href, req, {
- auth: {
- username: "admin",
- password: "test",
- },
+ await libeufinHttpLib.fetch(url.href, {
+ method: "POST",
+ headers: { Authorization: makeBasicAuthHeader("admin", "secret") },
+ body: req,
+ });
+ }
+
+ export async function getAllTasks(
+ libeufinNexusService: LibeufinNexusServiceInterface,
+ bankAccountName: string,
+ ): Promise<NexusTaskCollection> {
+ const baseUrl = libeufinNexusService.baseUrl;
+ let url = new URL(`/bank-accounts/${bankAccountName}/schedule`, baseUrl);
+ const resp = await libeufinHttpLib.fetch(url.href, {
+ headers: { Authorization: makeBasicAuthHeader("admin", "secret") },
});
+ return resp.json();
}
- export async function getTasks(
+ export async function getTask(
libeufinNexusService: LibeufinNexusServiceInterface,
bankAccountName: string,
// When void, the request returns the list of all the
// tasks under this bank account.
- taskName: string | void,
- ): Promise<any> {
+ taskName: string,
+ ): Promise<NexusTask> {
const baseUrl = libeufinNexusService.baseUrl;
- let url = new URL(`/bank-accounts/${bankAccountName}/schedule`, baseUrl);
+ let url = new URL(
+ `/bank-accounts/${bankAccountName}/schedule/${taskName}`,
+ baseUrl,
+ );
if (taskName) url = new URL(taskName, `${url.href}/`);
-
- // It's caller's responsibility to interpret the response.
- return await axios.get(url.href, {
- auth: {
- username: "admin",
- password: "test",
- },
+ const resp = await libeufinHttpLib.fetch(url.href, {
+ headers: { Authorization: makeBasicAuthHeader("admin", "secret") },
});
+ return resp.json();
}
export async function deleteTask(
libeufinNexusService: LibeufinNexusServiceInterface,
bankAccountName: string,
taskName: string,
- ) {
+ ): Promise<void> {
const baseUrl = libeufinNexusService.baseUrl;
let url = new URL(
`/bank-accounts/${bankAccountName}/schedule/${taskName}`,
baseUrl,
);
- await axios.delete(url.href, {
- auth: {
- username: "admin",
- password: "test",
- },
+ await libeufinHttpLib.fetch(url.href, {
+ method: "DELETE",
+ headers: { Authorization: makeBasicAuthHeader("admin", "secret") },
});
}
@@ -747,53 +679,50 @@ export namespace LibeufinNexusApi {
libeufinNexusService: LibeufinNexusServiceInterface,
bankAccountName: string,
req: PostNexusTaskRequest,
- ): Promise<any> {
+ ): Promise<void> {
const baseUrl = libeufinNexusService.baseUrl;
let url = new URL(`/bank-accounts/${bankAccountName}/schedule`, baseUrl);
- return await axios.post(url.href, req, {
- auth: {
- username: "admin",
- password: "test",
- },
+ await libeufinHttpLib.fetch(url.href, {
+ method: "POST",
+ headers: { Authorization: makeBasicAuthHeader("admin", "secret") },
+ body: req,
});
}
export async function deleteFacade(
libeufinNexusService: LibeufinNexusServiceInterface,
facadeName: string,
- ): Promise<any> {
+ ): Promise<void> {
const baseUrl = libeufinNexusService.baseUrl;
let url = new URL(`facades/${facadeName}`, baseUrl);
- return await axios.delete(url.href, {
- auth: {
- username: "admin",
- password: "test",
- },
+ await libeufinHttpLib.fetch(url.href, {
+ method: "DELETE",
+ headers: { Authorization: makeBasicAuthHeader("admin", "secret") },
});
}
export async function getAllFacades(
libeufinNexusService: LibeufinNexusServiceInterface,
- ): Promise<any> {
+ ): Promise<NexusFacadeListResponse> {
const baseUrl = libeufinNexusService.baseUrl;
let url = new URL("facades", baseUrl);
- return await axios.get(url.href, {
- auth: {
- username: "admin",
- password: "test",
- },
+ const resp = await libeufinHttpLib.fetch(url.href, {
+ headers: { Authorization: makeBasicAuthHeader("admin", "secret") },
});
+ // FIXME: Just return validated, typed response here!
+ return resp.json();
}
export async function createAnastasisFacade(
libeufinNexusService: LibeufinNexusServiceInterface,
req: CreateAnastasisFacadeRequest,
- ) {
+ ): Promise<void> {
const baseUrl = libeufinNexusService.baseUrl;
let url = new URL("facades", baseUrl);
- await axios.post(
- url.href,
- {
+ await libeufinHttpLib.fetch(url.href, {
+ method: "POST",
+ headers: { Authorization: makeBasicAuthHeader("admin", "secret") },
+ body: {
name: req.name,
type: "anastasis",
config: {
@@ -803,24 +732,19 @@ export namespace LibeufinNexusApi {
reserveTransferLevel: req.reserveTransferLevel,
},
},
- {
- auth: {
- username: "admin",
- password: "test",
- },
- },
- );
+ });
}
export async function createTwgFacade(
libeufinNexusService: LibeufinNexusServiceInterface,
req: CreateTalerWireGatewayFacadeRequest,
- ) {
+ ): Promise<void> {
const baseUrl = libeufinNexusService.baseUrl;
let url = new URL("facades", baseUrl);
- await axios.post(
- url.href,
- {
+ await libeufinHttpLib.fetch(url.href, {
+ method: "POST",
+ headers: { Authorization: makeBasicAuthHeader("admin", "secret") },
+ body: {
name: req.name,
type: "taler-wire-gateway",
config: {
@@ -830,33 +754,22 @@ export namespace LibeufinNexusApi {
reserveTransferLevel: req.reserveTransferLevel,
},
},
- {
- auth: {
- username: "admin",
- password: "test",
- },
- },
- );
+ });
}
export async function submitAllPaymentInitiations(
libeufinNexusService: LibeufinNexusServiceInterface,
accountId: string,
- ) {
+ ): Promise<void> {
const baseUrl = libeufinNexusService.baseUrl;
let url = new URL(
`/bank-accounts/${accountId}/submit-all-payment-initiations`,
baseUrl,
);
- await axios.post(
- url.href,
- {},
- {
- auth: {
- username: "admin",
- password: "test",
- },
- },
- );
+ await libeufinHttpLib.fetch(url.href, {
+ method: "POST",
+ headers: { Authorization: makeBasicAuthHeader("admin", "secret") },
+ body: {},
+ });
}
}
diff --git a/packages/taler-harness/src/harness/libeufin.ts b/packages/taler-harness/src/harness/libeufin.ts
index 8fd276fad..9f3e7a5a0 100644
--- a/packages/taler-harness/src/harness/libeufin.ts
+++ b/packages/taler-harness/src/harness/libeufin.ts
@@ -26,39 +26,32 @@
/**
* Imports.
*/
-import axios from "axios";
-import { URL, Logger } from "@gnu-taler/taler-util";
+import { AmountString, Logger } from "@gnu-taler/taler-util";
import {
- GlobalTestState,
DbInfo,
- pingProc,
+ GlobalTestState,
ProcessWrapper,
+ getRandomIban,
+ pingProc,
runCommand,
setupDb,
sh,
- getRandomIban,
} from "../harness/harness.js";
import {
- LibeufinSandboxApi,
- LibeufinNexusApi,
+ CreateAnastasisFacadeRequest,
CreateEbicsBankAccountRequest,
- LibeufinSandboxServiceInterface,
- CreateTalerWireGatewayFacadeRequest,
- SimulateIncomingTransactionRequest,
- SandboxAccountTransactions,
- DeleteBankConnectionRequest,
CreateEbicsBankConnectionRequest,
- UpdateNexusUserRequest,
- NexusAuth,
- CreateAnastasisFacadeRequest,
- PostNexusTaskRequest,
- PostNexusPermissionRequest,
CreateNexusUserRequest,
+ CreateTalerWireGatewayFacadeRequest,
+ LibeufinNexusApi,
+ LibeufinSandboxApi,
+ LibeufinSandboxServiceInterface,
+ PostNexusPermissionRequest,
} from "../harness/libeufin-apis.js";
const logger = new Logger("libeufin.ts");
-export { LibeufinSandboxApi, LibeufinNexusApi };
+export { LibeufinNexusApi, LibeufinSandboxApi };
export interface LibeufinServices {
libeufinSandbox: LibeufinSandboxService;
@@ -76,7 +69,7 @@ export interface LibeufinNexusConfig {
databaseJdbcUri: string;
}
-interface LibeufinNexusMoneyMovement {
+export interface LibeufinNexusMoneyMovement {
amount: string;
creditDebitIndicator: string;
details: {
@@ -103,11 +96,11 @@ interface LibeufinNexusMoneyMovement {
};
}
-interface LibeufinNexusBatches {
+export interface LibeufinNexusBatches {
batchTransactions: Array<LibeufinNexusMoneyMovement>;
}
-interface LibeufinNexusTransaction {
+export interface LibeufinNexusTransaction {
amount: string;
creditDebitIndicator: string;
status: string;
@@ -118,7 +111,7 @@ interface LibeufinNexusTransaction {
batches: Array<LibeufinNexusBatches>;
}
-interface LibeufinNexusTransactions {
+export interface LibeufinNexusTransactions {
transactions: Array<LibeufinNexusTransaction>;
}
@@ -182,6 +175,146 @@ export interface LibeufinPreparedPaymentDetails {
nexusBankAccountName: string;
}
+export interface NexusBankConnection {
+ // connection type. For example "ebics".
+ type: string;
+
+ // connection name as given by the user at
+ // the moment of creation.
+ name: string;
+}
+
+export interface NexusBankConnections {
+ bankConnections: NexusBankConnection[];
+}
+
+export interface FacadeShowInfo {
+ // Name of the facade, same as the "fcid" parameter.
+ name: string;
+
+ // Type of the facade.
+ // For example, "taler-wire-gateway".
+ type: string;
+
+ // Bas URL of the facade.
+ baseUrl: string;
+
+ // details depending on the facade type.
+ config: any;
+}
+
+export interface FetchParams {
+ // Because transactions are delivered by banks in "batches",
+ // then every batch can have different qualities. This value
+ // lets the request specify which type of batch ought to be
+ // returned. Currently, the following two type are supported:
+ //
+ // 'report': typically includes only non booked transactions.
+ // 'statement': typically includes only booked transactions.
+ level: "report" | "statement" | "all";
+
+ // This type indicates the time range of the query.
+ // It allows the following values:
+ //
+ // 'latest': retrieves the last transactions from the bank.
+ // If there are older unread transactions, those will *not*
+ // be downloaded.
+ //
+ // 'all': retrieves all the transactions from the bank,
+ // until the oldest.
+ //
+ // 'previous-days': currently *not* implemented, it will allow
+ // the request to download transactions from
+ // today until N days before.
+ //
+ // 'since-last': retrieves all the transactions since the last
+ // time one was downloaded.
+ //
+ rangeType: "latest" | "all" | "previous-days" | "since-last";
+}
+
+export interface NexusTask {
+ // The resource being impacted by this operation.
+ // Typically a (Nexus) bank account being fetched
+ // or whose payments are submitted. In this cases,
+ // this value is the "bank-account" constant.
+ resourceType: string;
+ // Name of the resource. In case of "bank-account", that
+ // is the name under which the bank account was imported
+ // from the bank.
+ resourceId: string;
+ // Task name, equals 'taskId'
+ taskName: string;
+ // Values allowed are "fetch" or "submit".
+ taskType: string;
+ // FIXME: describe.
+ taskCronSpec: string;
+ // Only meaningful for "fetch" types.
+ taskParams: FetchParams;
+ // Timestamp in secons when the next iteration will run.
+ nextScheduledExecutionSec: number;
+ // Timestamp in seconds when the previous iteration ran.
+ prevScheduledExecutionSec: number;
+}
+
+export interface NexusNewTransactionsInfo {
+ // How many transactions are new to Nexus.
+ newTransactions: number;
+ // How many transactions got downloaded by the request.
+ // Note that a transaction can be downloaded multiple
+ // times but only counts as new once.
+ downloadedTransactions: number;
+}
+
+
+export interface NexusUserResponse {
+ // User name
+ username: string;
+
+ // Is this a super user?
+ superuser: boolean;
+}
+
+export interface NexusTaskShortInfo {
+ cronspec: string;
+ type: "fetch" | "submit";
+ params: FetchParams;
+}
+
+export interface NexusTaskCollection {
+ // This field can contain *multiple* objects of the type sampled below.
+ schedule: {
+ [taskName: string]: NexusTaskShortInfo;
+ };
+}
+
+export interface NexusFacadeListResponse {
+ facades: FacadeShowInfo[];
+}
+
+export interface LibeufinSandboxAdminBankAccountBalance {
+ // Balance in the $currency:$amount format.
+ balance: AmountString;
+ // IBAN of the bank account identified by $accountLabel
+ iban: string;
+ // BIC of the bank account identified by $accountLabel
+ bic: string;
+ // Mentions $accountLabel
+ label: string;
+}
+
+export interface LibeufinPermission {
+ subjectType: string;
+ subjectId: string;
+ resourceType: string;
+ resourceId: string;
+ permissionName: string;
+}
+
+export interface NexusGetPermissionsResponse {
+ permissions: LibeufinPermission[];
+}
+
export class LibeufinSandboxService implements LibeufinSandboxServiceInterface {
static async create(
gc: GlobalTestState,
diff --git a/packages/taler-harness/src/index.ts b/packages/taler-harness/src/index.ts
index 0efaea9ad..cd688ed89 100644
--- a/packages/taler-harness/src/index.ts
+++ b/packages/taler-harness/src/index.ts
@@ -191,12 +191,12 @@ configCli
const config = Configuration.load();
let res;
if (args.get.file) {
- res = config.getString(args.get.section, args.get.option);
- } else {
res = config.getPath(args.get.section, args.get.option);
+ } else {
+ res = config.getString(args.get.section, args.get.option);
}
if (res.isDefined()) {
- console.log(res.getValue());
+ console.log(res.required());
} else {
console.warn("not found");
process.exit(1);
diff --git a/packages/taler-harness/src/integrationtests/test-libeufin-api-bankaccount.ts b/packages/taler-harness/src/integrationtests/test-libeufin-api-bankaccount.ts
index f36168301..e5e3dfe64 100644
--- a/packages/taler-harness/src/integrationtests/test-libeufin-api-bankaccount.ts
+++ b/packages/taler-harness/src/integrationtests/test-libeufin-api-bankaccount.ts
@@ -101,7 +101,7 @@ export async function runLibeufinApiBankaccountTest(t: GlobalTestState) {
nexus,
"local-mock",
);
- let el = findNexusPayment("mock subject", transactions.data);
+ let el = findNexusPayment("mock subject", transactions);
t.assertTrue(el instanceof Object);
}
diff --git a/packages/taler-harness/src/integrationtests/test-libeufin-api-bankconnection.ts b/packages/taler-harness/src/integrationtests/test-libeufin-api-bankconnection.ts
index 912b7b2ac..243500dc9 100644
--- a/packages/taler-harness/src/integrationtests/test-libeufin-api-bankconnection.ts
+++ b/packages/taler-harness/src/integrationtests/test-libeufin-api-bankconnection.ts
@@ -45,12 +45,12 @@ export async function runLibeufinApiBankconnectionTest(t: GlobalTestState) {
});
let connections = await LibeufinNexusApi.getAllConnections(nexus);
- t.assertTrue(connections.data["bankConnections"].length == 1);
+ t.assertTrue(connections.bankConnections.length == 1);
await LibeufinNexusApi.deleteBankConnection(nexus, {
bankConnectionId: "bankconnection-api-test-connection",
});
connections = await LibeufinNexusApi.getAllConnections(nexus);
- t.assertTrue(connections.data["bankConnections"].length == 0);
+ t.assertTrue(connections.bankConnections.length == 0);
}
runLibeufinApiBankconnectionTest.suites = ["libeufin"];
diff --git a/packages/taler-harness/src/integrationtests/test-libeufin-api-facade-bad-request.ts b/packages/taler-harness/src/integrationtests/test-libeufin-api-facade-bad-request.ts
index a1da9e0da..27cc81588 100644
--- a/packages/taler-harness/src/integrationtests/test-libeufin-api-facade-bad-request.ts
+++ b/packages/taler-harness/src/integrationtests/test-libeufin-api-facade-bad-request.ts
@@ -18,15 +18,16 @@
* Imports.
*/
import { URL } from "@gnu-taler/taler-util";
-import axiosImp from "axios";
-import { GlobalTestState } from "../harness/harness.js";
+import { GlobalTestState, harnessHttpLib } from "../harness/harness.js";
import {
launchLibeufinServices,
NexusUserBundle,
SandboxUserBundle,
} from "../harness/libeufin.js";
-
-const axios = axiosImp.default;
+import {
+ createPlatformHttpLib,
+ makeBasicAuthHeader,
+} from "@gnu-taler/taler-util/http";
export async function runLibeufinApiFacadeBadRequestTest(t: GlobalTestState) {
/**
@@ -50,21 +51,17 @@ export async function runLibeufinApiFacadeBadRequestTest(t: GlobalTestState) {
console.log("malformed facade");
const baseUrl = libeufinServices.libeufinNexus.baseUrl;
let url = new URL("facades", baseUrl);
- let resp = await axios.post(
- url.href,
- {
+ let resp = await harnessHttpLib.fetch(url.href, {
+ method: "POST",
+ body: {
name: "malformed-facade",
type: "taler-wire-gateway",
config: {}, // malformation here.
},
- {
- auth: {
- username: "admin",
- password: "test",
- },
- validateStatus: () => true,
+ headers: {
+ Authorization: makeBasicAuthHeader("admin", "test"),
},
- );
+ });
t.assertTrue(resp.status == 400);
}
diff --git a/packages/taler-harness/src/integrationtests/test-libeufin-api-facade.ts b/packages/taler-harness/src/integrationtests/test-libeufin-api-facade.ts
index 946c565d4..a819dd481 100644
--- a/packages/taler-harness/src/integrationtests/test-libeufin-api-facade.ts
+++ b/packages/taler-harness/src/integrationtests/test-libeufin-api-facade.ts
@@ -51,20 +51,20 @@ export async function runLibeufinApiFacadeTest(t: GlobalTestState) {
libeufinServices.libeufinNexus,
);
// check that original facade shows up.
- t.assertTrue(resp.data["facades"][0]["name"] == user01nexus.twgReq["name"]);
+ t.assertTrue(resp.facades[0].name == user01nexus.twgReq["name"]);
- const twgBaseUrl: string = resp.data["facades"][0]["baseUrl"];
+ const twgBaseUrl: string = resp.facades[0]["baseUrl"];
t.assertTrue(typeof twgBaseUrl === "string");
t.assertTrue(twgBaseUrl.startsWith("http://"));
t.assertTrue(twgBaseUrl.endsWith("/"));
// delete it.
- resp = await LibeufinNexusApi.deleteFacade(
+ await LibeufinNexusApi.deleteFacade(
libeufinServices.libeufinNexus,
user01nexus.twgReq["name"],
);
- // check that no facades show up.
- t.assertTrue(!resp.data.hasOwnProperty("facades"));
+ resp = await LibeufinNexusApi.getAllFacades(libeufinServices.libeufinNexus);
+ t.assertTrue(!resp.hasOwnProperty("facades"));
}
runLibeufinApiFacadeTest.suites = ["libeufin"];
diff --git a/packages/taler-harness/src/integrationtests/test-libeufin-api-permissions.ts b/packages/taler-harness/src/integrationtests/test-libeufin-api-permissions.ts
index f8f2d7d80..56443c20a 100644
--- a/packages/taler-harness/src/integrationtests/test-libeufin-api-permissions.ts
+++ b/packages/taler-harness/src/integrationtests/test-libeufin-api-permissions.ts
@@ -46,7 +46,8 @@ export async function runLibeufinApiPermissionsTest(t: GlobalTestState) {
user01nexus.twgTransferPermission,
);
let transferPermission = await LibeufinNexusApi.getAllPermissions(nexus);
- let element = transferPermission.data["permissions"].pop();
+ let element = transferPermission["permissions"].pop();
+ t.assertTrue(!!element);
t.assertTrue(
element["permissionName"] == "facade.talerwiregateway.transfer" &&
element["subjectId"] == "username-01",
@@ -58,7 +59,7 @@ export async function runLibeufinApiPermissionsTest(t: GlobalTestState) {
await LibeufinNexusApi.postPermission(nexus, denyTransfer);
transferPermission = await LibeufinNexusApi.getAllPermissions(nexus);
- t.assertTrue(transferPermission.data["permissions"].length == 0);
+ t.assertTrue(transferPermission["permissions"].length == 0);
}
runLibeufinApiPermissionsTest.suites = ["libeufin"];
diff --git a/packages/taler-harness/src/integrationtests/test-libeufin-api-sandbox-transactions.ts b/packages/taler-harness/src/integrationtests/test-libeufin-api-sandbox-transactions.ts
index f1ff69a6d..6cfc55aa6 100644
--- a/packages/taler-harness/src/integrationtests/test-libeufin-api-sandbox-transactions.ts
+++ b/packages/taler-harness/src/integrationtests/test-libeufin-api-sandbox-transactions.ts
@@ -64,6 +64,6 @@ export async function runLibeufinApiSandboxTransactionsTest(
sandbox,
"mock-account",
);
- t.assertAmountEquals(ret.data.balance, "EUR:2.1");
+ t.assertAmountEquals(ret.balance, "EUR:2.1");
}
runLibeufinApiSandboxTransactionsTest.suites = ["libeufin"];
diff --git a/packages/taler-harness/src/integrationtests/test-libeufin-api-scheduling.ts b/packages/taler-harness/src/integrationtests/test-libeufin-api-scheduling.ts
index 95f4bfaa0..15ed2ab78 100644
--- a/packages/taler-harness/src/integrationtests/test-libeufin-api-scheduling.ts
+++ b/packages/taler-harness/src/integrationtests/test-libeufin-api-scheduling.ts
@@ -54,19 +54,19 @@ export async function runLibeufinApiSchedulingTest(t: GlobalTestState) {
rangeType: "all",
},
});
- let resp = await LibeufinNexusApi.getTasks(
+ let resp = await LibeufinNexusApi.getTask(
nexus,
user01nexus.localAccountName,
"test-task",
);
- t.assertTrue(resp.data["taskName"] == "test-task");
+ t.assertTrue(resp.taskName == "test-task");
await LibeufinNexusApi.deleteTask(
nexus,
user01nexus.localAccountName,
"test-task",
);
try {
- await LibeufinNexusApi.getTasks(
+ await LibeufinNexusApi.getTask(
nexus,
user01nexus.localAccountName,
"test-task",
@@ -82,19 +82,19 @@ export async function runLibeufinApiSchedulingTest(t: GlobalTestState) {
type: "submit",
params: {},
});
- resp = await LibeufinNexusApi.getTasks(
+ resp = await LibeufinNexusApi.getTask(
nexus,
user01nexus.localAccountName,
"test-task",
);
- t.assertTrue(resp.data["taskName"] == "test-task");
+ t.assertTrue(resp.taskName == "test-task");
await LibeufinNexusApi.deleteTask(
nexus,
user01nexus.localAccountName,
"test-task",
);
try {
- await LibeufinNexusApi.getTasks(
+ await LibeufinNexusApi.getTask(
nexus,
user01nexus.localAccountName,
"test-task",
diff --git a/packages/taler-harness/src/integrationtests/test-libeufin-api-users.ts b/packages/taler-harness/src/integrationtests/test-libeufin-api-users.ts
index bc3103c7e..662b22bbe 100644
--- a/packages/taler-harness/src/integrationtests/test-libeufin-api-users.ts
+++ b/packages/taler-harness/src/integrationtests/test-libeufin-api-users.ts
@@ -56,8 +56,8 @@ export async function runLibeufinApiUsersTest(t: GlobalTestState) {
password: "got-changed",
},
});
- console.log(resp.data);
- t.assertTrue(resp.data["username"] == "one" && !resp.data["superuser"]);
+ console.log(resp);
+ t.assertTrue(resp["username"] == "one" && !resp["superuser"]);
}
runLibeufinApiUsersTest.suites = ["libeufin"];
diff --git a/packages/taler-harness/src/integrationtests/test-libeufin-c5x.ts b/packages/taler-harness/src/integrationtests/test-libeufin-c5x.ts
index c6dfca99b..5097bc4d3 100644
--- a/packages/taler-harness/src/integrationtests/test-libeufin-c5x.ts
+++ b/packages/taler-harness/src/integrationtests/test-libeufin-c5x.ts
@@ -79,7 +79,7 @@ export async function runLibeufinC5xTest(t: GlobalTestState) {
libeufinServices.libeufinNexus,
user01nexus.localAccountName,
);
- t.assertTrue(nexusTxs.data["transactions"].length == 0);
+ t.assertTrue(nexusTxs["transactions"].length == 0);
// Addressing one payment to user 01
await libeufinServices.libeufinSandbox.makeTransaction(
@@ -95,8 +95,8 @@ export async function runLibeufinC5xTest(t: GlobalTestState) {
"all", // range
"report", // C52
);
- t.assertTrue(expectOne.data.newTransactions == 1);
- t.assertTrue(expectOne.data.downloadedTransactions == 1);
+ t.assertTrue(expectOne.newTransactions == 1);
+ t.assertTrue(expectOne.downloadedTransactions == 1);
/* Expect zero payments being downloaded because the
* previous request consumed already the one pending
@@ -108,8 +108,8 @@ export async function runLibeufinC5xTest(t: GlobalTestState) {
"all", // range
"report", // C52
);
- t.assertTrue(expectZero.data.newTransactions == 0);
- t.assertTrue(expectZero.data.downloadedTransactions == 0);
+ t.assertTrue(expectZero.newTransactions == 0);
+ t.assertTrue(expectZero.downloadedTransactions == 0);
/**
* A statement should still account zero payments because
@@ -121,8 +121,8 @@ export async function runLibeufinC5xTest(t: GlobalTestState) {
"all", // range
"statement", // C53
);
- t.assertTrue(expectZero.data.newTransactions == 0);
- t.assertTrue(expectZero.data.downloadedTransactions == 0);
+ t.assertTrue(expectZero.newTransactions == 0);
+ t.assertTrue(expectZero.downloadedTransactions == 0);
/**
* Ticking now. That books any pending transaction.
@@ -141,7 +141,7 @@ export async function runLibeufinC5xTest(t: GlobalTestState) {
"all", // range
"statement", // C53
);
- t.assertTrue(expectOne.data.downloadedTransactions == 1);
- t.assertTrue(expectOne.data.newTransactions == 0);
+ t.assertTrue(expectOne.downloadedTransactions == 1);
+ t.assertTrue(expectOne.newTransactions == 0);
}
runLibeufinC5xTest.suites = ["libeufin"];
diff --git a/packages/taler-harness/src/integrationtests/test-libeufin-facade-anastasis.ts b/packages/taler-harness/src/integrationtests/test-libeufin-facade-anastasis.ts
index 10c73fed5..0efd55f44 100644
--- a/packages/taler-harness/src/integrationtests/test-libeufin-facade-anastasis.ts
+++ b/packages/taler-harness/src/integrationtests/test-libeufin-facade-anastasis.ts
@@ -53,9 +53,9 @@ export async function runLibeufinAnastasisFacadeTest(t: GlobalTestState) {
);
// check that original facade shows up.
t.assertTrue(
- resp.data["facades"][0]["name"] == user01nexus.anastasisReq["name"],
+ resp["facades"][0]["name"] == user01nexus.anastasisReq["name"],
);
- const anastasisBaseUrl: string = resp.data["facades"][0]["baseUrl"];
+const anastasisBaseUrl: string = resp["facades"][0]["baseUrl"];
t.assertTrue(typeof anastasisBaseUrl === "string");
t.assertTrue(anastasisBaseUrl.startsWith("http://"));
t.assertTrue(anastasisBaseUrl.endsWith("/"));
diff --git a/packages/taler-harness/src/integrationtests/test-libeufin-refund.ts b/packages/taler-harness/src/integrationtests/test-libeufin-refund.ts
index 9d90121a0..d37363bab 100644
--- a/packages/taler-harness/src/integrationtests/test-libeufin-refund.ts
+++ b/packages/taler-harness/src/integrationtests/test-libeufin-refund.ts
@@ -77,7 +77,7 @@ export async function runLibeufinRefundTest(t: GlobalTestState) {
libeufinServices.libeufinNexus,
user01nexus.localAccountName,
);
- t.assertTrue(nexusTxs.data["transactions"].length == 1);
+ t.assertTrue(nexusTxs["transactions"].length == 1);
// Submit the reimbursement
await LibeufinNexusApi.submitInitiatedPayment(
diff --git a/packages/taler-harness/src/integrationtests/test-libeufin-sandbox-wire-transfer-cli.ts b/packages/taler-harness/src/integrationtests/test-libeufin-sandbox-wire-transfer-cli.ts
index e6b074d3f..be467e2f1 100644
--- a/packages/taler-harness/src/integrationtests/test-libeufin-sandbox-wire-transfer-cli.ts
+++ b/packages/taler-harness/src/integrationtests/test-libeufin-sandbox-wire-transfer-cli.ts
@@ -79,7 +79,7 @@ export async function runLibeufinSandboxWireTransferCliTest(
sandbox,
"mock-account-2",
);
- console.log(ret.data.balance);
- t.assertTrue(ret.data.balance == "EUR:1.89");
+ console.log(ret.balance);
+ t.assertTrue(ret.balance == "EUR:1.89");
}
runLibeufinSandboxWireTransferCliTest.suites = ["libeufin"];
diff --git a/packages/taler-harness/src/integrationtests/test-merchant-exchange-confusion.ts b/packages/taler-harness/src/integrationtests/test-merchant-exchange-confusion.ts
index 2fccd0b97..e18cd7a0f 100644
--- a/packages/taler-harness/src/integrationtests/test-merchant-exchange-confusion.ts
+++ b/packages/taler-harness/src/integrationtests/test-merchant-exchange-confusion.ts
@@ -23,8 +23,6 @@ import {
PreparePayResultType,
} from "@gnu-taler/taler-util";
import { WalletApiOperation } from "@gnu-taler/taler-wallet-core";
-import axiosImp from "axios";
-const axios = axiosImp.default;
import { URL } from "url";
import { defaultCoinConfig } from "../harness/denomStructures.js";
import {
@@ -36,6 +34,7 @@ import {
ExchangeService,
getPayto,
GlobalTestState,
+ harnessHttpLib,
MerchantPrivateApi,
MerchantService,
setupDb,
@@ -45,6 +44,7 @@ import {
FaultyMerchantTestEnvironment,
withdrawViaBank,
} from "../harness/helpers.js";
+import { createPlatformHttpLib } from "@gnu-taler/taler-util/http";
/**
* Run a test case with a simple TESTKUDOS Taler environment, consisting
@@ -186,9 +186,7 @@ export async function runMerchantExchangeConfusionTest(t: GlobalTestState) {
t.assertTrue(orderStatus.already_paid_order_id === undefined);
let publicOrderStatusUrl = orderStatus.order_status_url;
- let publicOrderStatusResp = await axios.get(publicOrderStatusUrl, {
- validateStatus: () => true,
- });
+ let publicOrderStatusResp = await harnessHttpLib.fetch(publicOrderStatusUrl);
if (publicOrderStatusResp.status != 402) {
throw Error(
@@ -197,7 +195,7 @@ export async function runMerchantExchangeConfusionTest(t: GlobalTestState) {
}
let pubUnpaidStatus = codecForMerchantOrderStatusUnpaid().decode(
- publicOrderStatusResp.data,
+ await publicOrderStatusResp.json(),
);
console.log(pubUnpaidStatus);
@@ -221,9 +219,7 @@ export async function runMerchantExchangeConfusionTest(t: GlobalTestState) {
console.log("requesting", orderUrlWithHash.href);
- publicOrderStatusResp = await axios.get(orderUrlWithHash.href, {
- validateStatus: () => true,
- });
+ publicOrderStatusResp = await harnessHttpLib.fetch(orderUrlWithHash.href);
if (publicOrderStatusResp.status != 402) {
throw Error(
@@ -232,7 +228,7 @@ export async function runMerchantExchangeConfusionTest(t: GlobalTestState) {
}
pubUnpaidStatus = codecForMerchantOrderStatusUnpaid().decode(
- publicOrderStatusResp.data,
+ await publicOrderStatusResp.json(),
);
const confirmPayRes = await wallet.client.call(
diff --git a/packages/taler-harness/src/integrationtests/test-merchant-instances-delete.ts b/packages/taler-harness/src/integrationtests/test-merchant-instances-delete.ts
index 09231cdd8..e6e5bff76 100644
--- a/packages/taler-harness/src/integrationtests/test-merchant-instances-delete.ts
+++ b/packages/taler-harness/src/integrationtests/test-merchant-instances-delete.ts
@@ -17,9 +17,7 @@
/**
* Imports.
*/
-import { URL } from "@gnu-taler/taler-util";
-import axiosImp from "axios";
-const axios = axiosImp.default;
+import { TalerError, URL } from "@gnu-taler/taler-util";
import {
ExchangeService,
GlobalTestState,
@@ -27,7 +25,9 @@ import {
MerchantService,
setupDb,
getPayto,
+ harnessHttpLib,
} from "../harness/harness.js";
+import { createPlatformHttpLib } from "@gnu-taler/taler-util/http";
/**
* Test instance deletion and authentication for it
@@ -61,15 +61,17 @@ export async function runMerchantInstancesDeleteTest(t: GlobalTestState) {
const baseUrl = merchant.makeInstanceBaseUrl();
{
- const r = await axios.get(new URL("config", baseUrl).href);
- console.log(r.data);
- t.assertDeepEqual(r.data.currency, "TESTKUDOS");
+ const r = await harnessHttpLib.fetch(new URL("config", baseUrl).href);
+ const data = await r.json();
+ console.log(data);
+ t.assertDeepEqual(data.currency, "TESTKUDOS");
}
// Instances should initially be empty
{
- const r = await axios.get(new URL("management/instances", baseUrl).href);
- t.assertDeepEqual(r.data.instances, []);
+ const r = await harnessHttpLib.fetch(new URL("management/instances", baseUrl).href);
+ const data = await r.json();
+ t.assertDeepEqual(data.instances, []);
}
// Add an instance, no auth!
@@ -121,8 +123,8 @@ export async function runMerchantInstancesDeleteTest(t: GlobalTestState) {
await unauthMerchantClient.deleteInstance("myinst");
});
console.log("Got expected exception", exc);
- t.assertAxiosError(exc);
- t.assertDeepEqual(exc.response?.status, 401);
+ t.assertTrue(exc instanceof TalerError);
+ t.assertDeepEqual(exc.errorDetail.httpStatusCode, 401);
}
}
diff --git a/packages/taler-harness/src/integrationtests/test-merchant-instances-urls.ts b/packages/taler-harness/src/integrationtests/test-merchant-instances-urls.ts
index 534b35278..18a09c76b 100644
--- a/packages/taler-harness/src/integrationtests/test-merchant-instances-urls.ts
+++ b/packages/taler-harness/src/integrationtests/test-merchant-instances-urls.ts
@@ -18,8 +18,6 @@
* Imports.
*/
import { Duration } from "@gnu-taler/taler-util";
-import axiosImp from "axios";
-const axios = axiosImp.default;
import {
ExchangeService,
GlobalTestState,
@@ -27,14 +25,14 @@ import {
MerchantService,
setupDb,
getPayto,
+ harnessHttpLib,
} from "../harness/harness.js";
+import { createPlatformHttpLib } from "@gnu-taler/taler-util/http";
/**
* Do basic checks on instance management and authentication.
*/
export async function runMerchantInstancesUrlsTest(t: GlobalTestState) {
- // Set up test environment
-
const db = await setupDb(t);
const exchange = ExchangeService.create(t, {
@@ -111,11 +109,10 @@ export async function runMerchantInstancesUrlsTest(t: GlobalTestState) {
});
async function check(url: string, token: string, expectedStatus: number) {
- const resp = await axios.get(url, {
+ const resp = await harnessHttpLib.fetch(url, {
headers: {
Authorization: `Bearer ${token}`,
},
- validateStatus: () => true,
});
console.log(
`checking ${url}, expected ${expectedStatus}, got ${resp.status}`,
diff --git a/packages/taler-harness/src/integrationtests/test-merchant-instances.ts b/packages/taler-harness/src/integrationtests/test-merchant-instances.ts
index 78626ea3d..f7d89c543 100644
--- a/packages/taler-harness/src/integrationtests/test-merchant-instances.ts
+++ b/packages/taler-harness/src/integrationtests/test-merchant-instances.ts
@@ -18,8 +18,6 @@
* Imports.
*/
import { URL } from "@gnu-taler/taler-util";
-import axiosImp from "axios";
-const axios = axiosImp.default;
import {
ExchangeService,
GlobalTestState,
@@ -27,7 +25,9 @@ import {
MerchantService,
setupDb,
getPayto,
+ harnessHttpLib,
} from "../harness/harness.js";
+import { createPlatformHttpLib } from "@gnu-taler/taler-util/http";
/**
* Do basic checks on instance management and authentication.
@@ -61,15 +61,19 @@ export async function runMerchantInstancesTest(t: GlobalTestState) {
const baseUrl = merchant.makeInstanceBaseUrl();
{
- const r = await axios.get(new URL("config", baseUrl).href);
- console.log(r.data);
- t.assertDeepEqual(r.data.currency, "TESTKUDOS");
+ const r = await harnessHttpLib.fetch(new URL("config", baseUrl).href);
+ const data = await r.json();
+ console.log(data);
+ t.assertDeepEqual(data.currency, "TESTKUDOS");
}
// Instances should initially be empty
{
- const r = await axios.get(new URL("management/instances", baseUrl).href);
- t.assertDeepEqual(r.data.instances, []);
+ const r = await harnessHttpLib.fetch(
+ new URL("management/instances", baseUrl).href,
+ );
+ const data = await r.json();
+ t.assertDeepEqual(data.instances, []);
}
// Add an instance, no auth!
@@ -104,11 +108,14 @@ export async function runMerchantInstancesTest(t: GlobalTestState) {
// Check that a "malformed" bearer Authorization header gets ignored
{
const url = merchant.makeInstanceBaseUrl();
- const resp = await axios.get(new URL("management/instances", url).href, {
- headers: {
- Authorization: "foo bar-baz",
+ const resp = await harnessHttpLib.fetch(
+ new URL("management/instances", url).href,
+ {
+ headers: {
+ Authorization: "foo bar-baz",
+ },
},
- });
+ );
t.assertDeepEqual(resp.status, 200);
}
@@ -130,9 +137,7 @@ export async function runMerchantInstancesTest(t: GlobalTestState) {
});
console.log(exc);
-
- t.assertAxiosError(exc);
- t.assertTrue(exc.response?.status === 401);
+ t.assertTrue(exc.errorDetail.httpStatusCode === 401);
merchantClient = new MerchantApiClient(merchant.makeInstanceBaseUrl(), {
method: "token",
@@ -145,12 +150,15 @@ export async function runMerchantInstancesTest(t: GlobalTestState) {
// Now, try some variations.
{
const url = merchant.makeInstanceBaseUrl();
- const resp = await axios.get(new URL("management/instances", url).href, {
- headers: {
- // Note the spaces
- Authorization: "Bearer secret-token:foobar",
+ const resp = await harnessHttpLib.fetch(
+ new URL("management/instances", url).href,
+ {
+ headers: {
+ // Note the spaces
+ Authorization: "Bearer secret-token:foobar",
+ },
},
- });
+ );
t.assertDeepEqual(resp.status, 200);
}
@@ -176,7 +184,7 @@ export async function runMerchantInstancesTest(t: GlobalTestState) {
await unauthMerchantClient.deleteInstance("myinst");
});
console.log(exc);
- t.assertAxiosError(exc);
+ t.assertTrue(exc.errorDetail.httpStatusCode === 401);
t.assertDeepEqual(exc.response?.status, 401);
}
}
diff --git a/packages/taler-harness/src/integrationtests/test-merchant-longpolling.ts b/packages/taler-harness/src/integrationtests/test-merchant-longpolling.ts
index 59f23fe5d..8d271c5d1 100644
--- a/packages/taler-harness/src/integrationtests/test-merchant-longpolling.ts
+++ b/packages/taler-harness/src/integrationtests/test-merchant-longpolling.ts
@@ -24,20 +24,18 @@ import {
codecForMerchantOrderStatusUnpaid,
} from "@gnu-taler/taler-util";
import { WalletApiOperation } from "@gnu-taler/taler-wallet-core";
-import axiosImp from "axios";
-import { GlobalTestState, MerchantPrivateApi } from "../harness/harness.js";
+import { GlobalTestState, MerchantPrivateApi, harnessHttpLib } from "../harness/harness.js";
import {
createSimpleTestkudosEnvironmentV2,
- withdrawViaBankV2
+ withdrawViaBankV2,
} from "../harness/helpers.js";
-const axios = axiosImp.default;
+import { createPlatformHttpLib } from "@gnu-taler/taler-util/http";
/**
* Run test for basic, bank-integrated withdrawal.
*/
export async function runMerchantLongpollingTest(t: GlobalTestState) {
// Set up test environment
-
const { walletClient, bank, exchange, merchant } =
await createSimpleTestkudosEnvironmentV2(t);
@@ -83,9 +81,7 @@ export async function runMerchantLongpollingTest(t: GlobalTestState) {
// First, request order status without longpolling
{
console.log("requesting", publicOrderStatusUrl.href);
- let publicOrderStatusResp = await axios.get(publicOrderStatusUrl.href, {
- validateStatus: () => true,
- });
+ let publicOrderStatusResp = await harnessHttpLib.fetch(publicOrderStatusUrl.href);
if (publicOrderStatusResp.status != 402) {
throw Error(
@@ -98,9 +94,7 @@ export async function runMerchantLongpollingTest(t: GlobalTestState) {
publicOrderStatusUrl.searchParams.set("timeout_ms", "500");
console.log("requesting", publicOrderStatusUrl.href);
- let publicOrderStatusResp = await axios.get(publicOrderStatusUrl.href, {
- validateStatus: () => true,
- });
+ let publicOrderStatusResp = await harnessHttpLib.fetch(publicOrderStatusUrl.href);
if (publicOrderStatusResp.status != 402) {
throw Error(
@@ -109,7 +103,7 @@ export async function runMerchantLongpollingTest(t: GlobalTestState) {
}
let pubUnpaidStatus = codecForMerchantOrderStatusUnpaid().decode(
- publicOrderStatusResp.data,
+ await publicOrderStatusResp.json(),
);
console.log(pubUnpaidStatus);
@@ -135,9 +129,7 @@ export async function runMerchantLongpollingTest(t: GlobalTestState) {
preparePayResp.contractTermsHash,
);
- let publicOrderStatusPromise = axios.get(publicOrderStatusUrl.href, {
- validateStatus: () => true,
- });
+ let publicOrderStatusPromise = harnessHttpLib.fetch(publicOrderStatusUrl.href);
t.assertTrue(preparePayResp.status === PreparePayResultType.PaymentPossible);
@@ -152,15 +144,12 @@ export async function runMerchantLongpollingTest(t: GlobalTestState) {
}
pubUnpaidStatus = codecForMerchantOrderStatusUnpaid().decode(
- publicOrderStatusResp.data,
+ await publicOrderStatusResp.json(),
);
- const confirmPayRes = await walletClient.call(
- WalletApiOperation.ConfirmPay,
- {
- proposalId: proposalId,
- },
- );
+ const confirmPayRes = await walletClient.call(WalletApiOperation.ConfirmPay, {
+ proposalId: proposalId,
+ });
t.assertTrue(confirmPayRes.type === ConfirmPayResultType.Done);
}
diff --git a/packages/taler-harness/src/integrationtests/test-merchant-refund-api.ts b/packages/taler-harness/src/integrationtests/test-merchant-refund-api.ts
index 5d9b23fa7..8efac1fc1 100644
--- a/packages/taler-harness/src/integrationtests/test-merchant-refund-api.ts
+++ b/packages/taler-harness/src/integrationtests/test-merchant-refund-api.ts
@@ -17,12 +17,14 @@
/**
* Imports.
*/
+import { createPlatformHttpLib } from "@gnu-taler/taler-util/http";
import {
GlobalTestState,
MerchantPrivateApi,
MerchantServiceInterface,
WalletCli,
ExchangeServiceInterface,
+ harnessHttpLib,
} from "../harness/harness.js";
import {
createSimpleTestkudosEnvironment,
@@ -34,8 +36,6 @@ import {
PreparePayResultType,
Duration,
} from "@gnu-taler/taler-util";
-import axiosImp from "axios";
-const axios = axiosImp.default;
import {
WalletApiOperation,
BankServiceHandle,
@@ -136,23 +136,19 @@ async function testRefundApiWithFulfillmentUrl(
preparePayResult.contractTermsHash,
);
- let publicOrderStatusResp = await axios.get(publicOrderStatusUrl.href, {
- validateStatus: () => true,
- });
- console.log(publicOrderStatusResp.data);
+ let publicOrderStatusResp = await harnessHttpLib.fetch(publicOrderStatusUrl.href);
+ const respData = await publicOrderStatusResp.json();
t.assertTrue(publicOrderStatusResp.status === 200);
- t.assertAmountEquals(publicOrderStatusResp.data.refund_amount, "TESTKUDOS:5");
+ t.assertAmountEquals(respData.refund_amount, "TESTKUDOS:5");
publicOrderStatusUrl = new URL(
`orders/${orderId}`,
merchant.makeInstanceBaseUrl(),
);
console.log(`requesting order status via '${publicOrderStatusUrl.href}'`);
- publicOrderStatusResp = await axios.get(publicOrderStatusUrl.href, {
- validateStatus: () => true,
- });
+ publicOrderStatusResp = await harnessHttpLib.fetch(publicOrderStatusUrl.href);
console.log(publicOrderStatusResp.status);
- console.log(publicOrderStatusResp.data);
+ console.log(await publicOrderStatusResp.json());
// We didn't give any authentication, so we should get a fulfillment URL back
t.assertTrue(publicOrderStatusResp.status === 403);
}
@@ -252,22 +248,20 @@ async function testRefundApiWithFulfillmentMessage(
preparePayResult.contractTermsHash,
);
- let publicOrderStatusResp = await axios.get(publicOrderStatusUrl.href, {
- validateStatus: () => true,
- });
- console.log(publicOrderStatusResp.data);
+ let publicOrderStatusResp = await harnessHttpLib.fetch(publicOrderStatusUrl.href);
+ let respData = await publicOrderStatusResp.json();
+ console.log(respData);
t.assertTrue(publicOrderStatusResp.status === 200);
- t.assertAmountEquals(publicOrderStatusResp.data.refund_amount, "TESTKUDOS:5");
+ t.assertAmountEquals(respData.refund_amount, "TESTKUDOS:5");
publicOrderStatusUrl = new URL(
`orders/${orderId}`,
merchant.makeInstanceBaseUrl(),
);
- publicOrderStatusResp = await axios.get(publicOrderStatusUrl.href, {
- validateStatus: () => true,
- });
- console.log(publicOrderStatusResp.data);
+ publicOrderStatusResp = await harnessHttpLib.fetch(publicOrderStatusUrl.href);
+ respData = await publicOrderStatusResp.json();
+ console.log(respData);
// We didn't give any authentication, so we should get a fulfillment URL back
t.assertTrue(publicOrderStatusResp.status === 403);
}
diff --git a/packages/taler-harness/src/integrationtests/test-merchant-spec-public-orders.ts b/packages/taler-harness/src/integrationtests/test-merchant-spec-public-orders.ts
index 975ba707b..fca368dad 100644
--- a/packages/taler-harness/src/integrationtests/test-merchant-spec-public-orders.ts
+++ b/packages/taler-harness/src/integrationtests/test-merchant-spec-public-orders.ts
@@ -24,7 +24,6 @@ import {
encodeCrock,
getRandomBytes,
} from "@gnu-taler/taler-util";
-import { createPlatformHttpLib } from "@gnu-taler/taler-util/http";
import { WalletApiOperation } from "@gnu-taler/taler-wallet-core";
import {
BankService,
@@ -33,17 +32,13 @@ import {
MerchantPrivateApi,
MerchantService,
WalletCli,
+ harnessHttpLib,
} from "../harness/harness.js";
import {
createSimpleTestkudosEnvironment,
withdrawViaBank,
} from "../harness/helpers.js";
-const httpLib = createPlatformHttpLib({
- allowHttp: true,
- enableThrottling: false,
-});
-
interface Context {
merchant: MerchantService;
merchantBaseUrl: string;
@@ -51,6 +46,8 @@ interface Context {
exchange: ExchangeService;
}
+const httpLib = harnessHttpLib;
+
async function testWithClaimToken(
t: GlobalTestState,
c: Context,
diff --git a/packages/taler-harness/src/integrationtests/test-pay-paid.ts b/packages/taler-harness/src/integrationtests/test-pay-paid.ts
index 2ef91e4a8..a377b7237 100644
--- a/packages/taler-harness/src/integrationtests/test-pay-paid.ts
+++ b/packages/taler-harness/src/integrationtests/test-pay-paid.ts
@@ -17,7 +17,7 @@
/**
* Imports.
*/
-import { GlobalTestState, MerchantPrivateApi } from "../harness/harness.js";
+import { GlobalTestState, MerchantPrivateApi, harnessHttpLib } from "../harness/harness.js";
import {
withdrawViaBank,
createFaultInjectedMerchantTestkudosEnvironment,
@@ -28,8 +28,6 @@ import {
ConfirmPayResultType,
URL,
} from "@gnu-taler/taler-util";
-import axiosImp from "axios";
-const axios = axiosImp.default;
import { FaultInjectionRequestContext } from "../harness/faultInjection.js";
import { WalletApiOperation } from "@gnu-taler/taler-wallet-core";
@@ -86,9 +84,7 @@ export async function runPayPaidTest(t: GlobalTestState) {
t.assertTrue(orderStatus.already_paid_order_id === undefined);
let publicOrderStatusUrl = orderStatus.order_status_url;
- let publicOrderStatusResp = await axios.get(publicOrderStatusUrl, {
- validateStatus: () => true,
- });
+ let publicOrderStatusResp = await harnessHttpLib.fetch(publicOrderStatusUrl);
if (publicOrderStatusResp.status != 402) {
throw Error(
@@ -97,7 +93,7 @@ export async function runPayPaidTest(t: GlobalTestState) {
}
let pubUnpaidStatus = codecForMerchantOrderStatusUnpaid().decode(
- publicOrderStatusResp.data,
+ publicOrderStatusResp.json(),
);
console.log(pubUnpaidStatus);
@@ -113,9 +109,7 @@ export async function runPayPaidTest(t: GlobalTestState) {
const proposalId = preparePayResp.proposalId;
- publicOrderStatusResp = await axios.get(publicOrderStatusUrl, {
- validateStatus: () => true,
- });
+ publicOrderStatusResp = await harnessHttpLib.fetch(publicOrderStatusUrl);
if (publicOrderStatusResp.status != 402) {
throw Error(
@@ -124,7 +118,7 @@ export async function runPayPaidTest(t: GlobalTestState) {
}
pubUnpaidStatus = codecForMerchantOrderStatusUnpaid().decode(
- publicOrderStatusResp.data,
+ publicOrderStatusResp.json(),
);
const confirmPayRes = await wallet.client.call(
@@ -136,14 +130,12 @@ export async function runPayPaidTest(t: GlobalTestState) {
t.assertTrue(confirmPayRes.type === ConfirmPayResultType.Done);
- publicOrderStatusResp = await axios.get(publicOrderStatusUrl, {
- validateStatus: () => true,
- });
+ publicOrderStatusResp = await harnessHttpLib.fetch(publicOrderStatusUrl);
- console.log(publicOrderStatusResp.data);
+ console.log(publicOrderStatusResp.json());
if (publicOrderStatusResp.status != 200) {
- console.log(publicOrderStatusResp.data);
+ console.log(publicOrderStatusResp.json());
throw Error(
`expected status 200 (after paying), but got ${publicOrderStatusResp.status}`,
);
diff --git a/packages/taler-harness/src/integrationtests/test-payment-abort.ts b/packages/taler-harness/src/integrationtests/test-payment-abort.ts
index 40438c583..05ca7a543 100644
--- a/packages/taler-harness/src/integrationtests/test-payment-abort.ts
+++ b/packages/taler-harness/src/integrationtests/test-payment-abort.ts
@@ -17,14 +17,12 @@
/**
* Imports.
*/
-import { GlobalTestState, MerchantPrivateApi } from "../harness/harness.js";
+import { GlobalTestState, MerchantPrivateApi, harnessHttpLib } from "../harness/harness.js";
import {
withdrawViaBank,
createFaultInjectedMerchantTestkudosEnvironment,
} from "../harness/helpers.js";
-import {
- FaultInjectionRequestContext,
-} from "../harness/faultInjection.js";
+import { FaultInjectionRequestContext } from "../harness/faultInjection.js";
import {
codecForMerchantOrderStatusUnpaid,
ConfirmPayResultType,
@@ -35,9 +33,6 @@ import {
URL,
} from "@gnu-taler/taler-util";
import { WalletApiOperation } from "@gnu-taler/taler-wallet-core";
-import axiosImp from "axios";
-
-const axios = axiosImp.default;
export async function runPaymentAbortTest(t: GlobalTestState) {
// Set up test environment
@@ -75,9 +70,7 @@ export async function runPaymentAbortTest(t: GlobalTestState) {
t.assertTrue(orderStatus.already_paid_order_id === undefined);
let publicOrderStatusUrl = orderStatus.order_status_url;
- let publicOrderStatusResp = await axios.get(publicOrderStatusUrl, {
- validateStatus: () => true,
- });
+ let publicOrderStatusResp = await harnessHttpLib.fetch(publicOrderStatusUrl);
if (publicOrderStatusResp.status != 402) {
throw Error(
@@ -86,7 +79,7 @@ export async function runPaymentAbortTest(t: GlobalTestState) {
}
let pubUnpaidStatus = codecForMerchantOrderStatusUnpaid().decode(
- publicOrderStatusResp.data,
+ publicOrderStatusResp.json(),
);
console.log(pubUnpaidStatus);
@@ -102,9 +95,7 @@ export async function runPaymentAbortTest(t: GlobalTestState) {
const proposalId = preparePayResp.proposalId;
- publicOrderStatusResp = await axios.get(publicOrderStatusUrl, {
- validateStatus: () => true,
- });
+ publicOrderStatusResp = await harnessHttpLib.fetch(publicOrderStatusUrl);
if (publicOrderStatusResp.status != 402) {
throw Error(
@@ -113,7 +104,7 @@ export async function runPaymentAbortTest(t: GlobalTestState) {
}
pubUnpaidStatus = codecForMerchantOrderStatusUnpaid().decode(
- publicOrderStatusResp.data,
+ publicOrderStatusResp.json(),
);
faultyMerchant.faultProxy.addFault({
diff --git a/packages/taler-harness/src/integrationtests/test-payment-claim.ts b/packages/taler-harness/src/integrationtests/test-payment-claim.ts
index eb219c1e7..3e52cb5dd 100644
--- a/packages/taler-harness/src/integrationtests/test-payment-claim.ts
+++ b/packages/taler-harness/src/integrationtests/test-payment-claim.ts
@@ -42,13 +42,15 @@ export async function runPaymentClaimTest(t: GlobalTestState) {
// Withdraw digital cash into the wallet.
- await withdrawViaBankV2(t, {
+ const wres = await withdrawViaBankV2(t, {
walletClient,
bank,
exchange,
amount: "TESTKUDOS:20",
});
+ await wres.withdrawalFinishedCond;
+
// Set up order.
const orderResp = await MerchantPrivateApi.createOrder(merchant, "default", {
diff --git a/packages/taler-harness/src/integrationtests/test-payment-idempotency.ts b/packages/taler-harness/src/integrationtests/test-payment-idempotency.ts
index e16cf9dd1..6373c2393 100644
--- a/packages/taler-harness/src/integrationtests/test-payment-idempotency.ts
+++ b/packages/taler-harness/src/integrationtests/test-payment-idempotency.ts
@@ -37,13 +37,15 @@ export async function runPaymentIdempotencyTest(t: GlobalTestState) {
// Withdraw digital cash into the wallet.
- await withdrawViaBankV2(t, {
+ const wres = await withdrawViaBankV2(t, {
walletClient,
bank,
exchange,
amount: "TESTKUDOS:20",
});
+ await wres.withdrawalFinishedCond;
+
// Set up order.
const orderResp = await MerchantPrivateApi.createOrder(merchant, "default", {
diff --git a/packages/taler-harness/src/integrationtests/test-payment-template.ts b/packages/taler-harness/src/integrationtests/test-payment-template.ts
index 172791648..707be52e1 100644
--- a/packages/taler-harness/src/integrationtests/test-payment-template.ts
+++ b/packages/taler-harness/src/integrationtests/test-payment-template.ts
@@ -50,7 +50,8 @@ export async function runPaymentTemplateTest(t: GlobalTestState) {
// Withdraw digital cash into the wallet.
- await withdrawViaBankV2(t, { walletClient, bank, exchange, amount: "TESTKUDOS:20" });
+ const wres = await withdrawViaBankV2(t, { walletClient, bank, exchange, amount: "TESTKUDOS:20" });
+ await wres.withdrawalFinishedCond;
// Request a template payment
diff --git a/packages/taler-harness/src/integrationtests/test-payment-transient.ts b/packages/taler-harness/src/integrationtests/test-payment-transient.ts
index 33a9716d5..c2a8e37c5 100644
--- a/packages/taler-harness/src/integrationtests/test-payment-transient.ts
+++ b/packages/taler-harness/src/integrationtests/test-payment-transient.ts
@@ -17,23 +17,22 @@
/**
* Imports.
*/
-import { GlobalTestState, MerchantPrivateApi } from "../harness/harness.js";
import {
- withdrawViaBank,
- createFaultInjectedMerchantTestkudosEnvironment,
-} from "../harness/helpers.js";
-import { FaultInjectionResponseContext } from "../harness/faultInjection.js";
-import {
- codecForMerchantOrderStatusUnpaid,
ConfirmPayResultType,
PreparePayResultType,
TalerErrorCode,
TalerErrorDetail,
URL,
+ codecForMerchantOrderStatusUnpaid,
} from "@gnu-taler/taler-util";
import { WalletApiOperation } from "@gnu-taler/taler-wallet-core";
-import axiosImp from "axios";
-const axios = axiosImp.default;
+import { FaultInjectionResponseContext } from "../harness/faultInjection.js";
+import { GlobalTestState, MerchantPrivateApi, harnessHttpLib } from "../harness/harness.js";
+import {
+ createFaultInjectedMerchantTestkudosEnvironment,
+ withdrawViaBank,
+} from "../harness/helpers.js";
+
/**
* Run test for a payment where the merchant has a transient
@@ -75,9 +74,7 @@ export async function runPaymentTransientTest(t: GlobalTestState) {
t.assertTrue(orderStatus.already_paid_order_id === undefined);
let publicOrderStatusUrl = orderStatus.order_status_url;
- let publicOrderStatusResp = await axios.get(publicOrderStatusUrl, {
- validateStatus: () => true,
- });
+ let publicOrderStatusResp = await harnessHttpLib.fetch(publicOrderStatusUrl);
if (publicOrderStatusResp.status != 402) {
throw Error(
@@ -86,7 +83,7 @@ export async function runPaymentTransientTest(t: GlobalTestState) {
}
let pubUnpaidStatus = codecForMerchantOrderStatusUnpaid().decode(
- publicOrderStatusResp.data,
+ publicOrderStatusResp.json(),
);
console.log(pubUnpaidStatus);
@@ -102,9 +99,7 @@ export async function runPaymentTransientTest(t: GlobalTestState) {
const proposalId = preparePayResp.proposalId;
- publicOrderStatusResp = await axios.get(publicOrderStatusUrl, {
- validateStatus: () => true,
- });
+ publicOrderStatusResp = await harnessHttpLib.fetch(publicOrderStatusUrl);
if (publicOrderStatusResp.status != 402) {
throw Error(
@@ -113,7 +108,7 @@ export async function runPaymentTransientTest(t: GlobalTestState) {
}
pubUnpaidStatus = codecForMerchantOrderStatusUnpaid().decode(
- publicOrderStatusResp.data,
+ publicOrderStatusResp.json(),
);
let faultInjected = false;
@@ -165,14 +160,12 @@ export async function runPaymentTransientTest(t: GlobalTestState) {
// Now ask the merchant if paid
console.log("requesting", publicOrderStatusUrl);
- publicOrderStatusResp = await axios.get(publicOrderStatusUrl, {
- validateStatus: () => true,
- });
+ publicOrderStatusResp = await harnessHttpLib.fetch(publicOrderStatusUrl);
- console.log(publicOrderStatusResp.data);
+ console.log(publicOrderStatusResp.json());
if (publicOrderStatusResp.status != 200) {
- console.log(publicOrderStatusResp.data);
+ console.log(publicOrderStatusResp.json());
throw Error(
`expected status 200 (after paying), but got ${publicOrderStatusResp.status}`,
);
diff --git a/packages/taler-harness/src/integrationtests/test-paywall-flow.ts b/packages/taler-harness/src/integrationtests/test-paywall-flow.ts
index b0477a049..5f63d4fac 100644
--- a/packages/taler-harness/src/integrationtests/test-paywall-flow.ts
+++ b/packages/taler-harness/src/integrationtests/test-paywall-flow.ts
@@ -17,7 +17,7 @@
/**
* Imports.
*/
-import { GlobalTestState, MerchantPrivateApi } from "../harness/harness.js";
+import { GlobalTestState, MerchantPrivateApi, harnessHttpLib } from "../harness/harness.js";
import {
PreparePayResultType,
codecForMerchantOrderStatusUnpaid,
@@ -29,12 +29,6 @@ import {
createSimpleTestkudosEnvironmentV2,
withdrawViaBankV2,
} from "../harness/helpers.js";
-import { createPlatformHttpLib } from "@gnu-taler/taler-util/http";
-
-const httpLib = createPlatformHttpLib({
- allowHttp: true,
- enableThrottling: false,
-});
/**
* Run test for basic, bank-integrated withdrawal.
@@ -47,13 +41,15 @@ export async function runPaywallFlowTest(t: GlobalTestState) {
// Withdraw digital cash into the wallet.
- await withdrawViaBankV2(t, {
+ const wres = await withdrawViaBankV2(t, {
walletClient,
bank,
exchange,
amount: "TESTKUDOS:20",
});
+ await wres.withdrawalFinishedCond;
+
/**
* =========================================================================
* Create an order and let the wallet pay under a session ID
@@ -86,7 +82,7 @@ export async function runPaywallFlowTest(t: GlobalTestState) {
t.assertTrue(orderStatus.already_paid_order_id === undefined);
let publicOrderStatusUrl = new URL(orderStatus.order_status_url);
- let publicOrderStatusResp = await httpLib.fetch(publicOrderStatusUrl.href);
+ let publicOrderStatusResp = await harnessHttpLib.fetch(publicOrderStatusUrl.href);
if (publicOrderStatusResp.status != 402) {
throw Error(
@@ -112,7 +108,7 @@ export async function runPaywallFlowTest(t: GlobalTestState) {
const proposalId = preparePayResp.proposalId;
console.log("requesting", publicOrderStatusUrl.href);
- publicOrderStatusResp = await httpLib.fetch(publicOrderStatusUrl.href);
+ publicOrderStatusResp = await harnessHttpLib.fetch(publicOrderStatusUrl.href);
console.log("response body", publicOrderStatusResp.json());
if (publicOrderStatusResp.status != 402) {
throw Error(
@@ -129,7 +125,7 @@ export async function runPaywallFlowTest(t: GlobalTestState) {
});
t.assertTrue(confirmPayRes.type === ConfirmPayResultType.Done);
- publicOrderStatusResp = await httpLib.fetch(publicOrderStatusUrl.href);
+ publicOrderStatusResp = await harnessHttpLib.fetch(publicOrderStatusUrl.href);
console.log(publicOrderStatusResp.json());
@@ -231,7 +227,7 @@ export async function runPaywallFlowTest(t: GlobalTestState) {
console.log("requesting public status", publicOrderStatusUrl);
// Ask the order status of the claimed-but-unpaid order
- publicOrderStatusResp = await httpLib.fetch(publicOrderStatusUrl.href);
+ publicOrderStatusResp = await harnessHttpLib.fetch(publicOrderStatusUrl.href);
if (publicOrderStatusResp.status != 402) {
throw Error(`expected status 402, but got ${publicOrderStatusResp.status}`);
diff --git a/packages/taler-harness/src/integrationtests/test-refund-auto.ts b/packages/taler-harness/src/integrationtests/test-refund-auto.ts
index 607080e68..5648835d5 100644
--- a/packages/taler-harness/src/integrationtests/test-refund-auto.ts
+++ b/packages/taler-harness/src/integrationtests/test-refund-auto.ts
@@ -36,13 +36,15 @@ export async function runRefundAutoTest(t: GlobalTestState) {
// Withdraw digital cash into the wallet.
- await withdrawViaBankV2(t, {
+ const wres = await withdrawViaBankV2(t, {
walletClient,
bank,
exchange,
amount: "TESTKUDOS:20",
});
+ await wres.withdrawalFinishedCond;
+
// Set up order.
const orderResp = await MerchantPrivateApi.createOrder(merchant, "default", {
order: {
diff --git a/packages/taler-harness/src/integrationtests/test-refund-incremental.ts b/packages/taler-harness/src/integrationtests/test-refund-incremental.ts
index 8e7e38b71..8ac0948f2 100644
--- a/packages/taler-harness/src/integrationtests/test-refund-incremental.ts
+++ b/packages/taler-harness/src/integrationtests/test-refund-incremental.ts
@@ -45,13 +45,15 @@ export async function runRefundIncrementalTest(t: GlobalTestState) {
// Withdraw digital cash into the wallet.
- await withdrawViaBankV2(t, {
+ const wres = await withdrawViaBankV2(t, {
walletClient,
bank,
exchange,
amount: "TESTKUDOS:20",
});
+ await wres.withdrawalFinishedCond;
+
// Set up order.
const orderResp = await MerchantPrivateApi.createOrder(merchant, "default", {
diff --git a/packages/taler-harness/src/integrationtests/test-wallet-balance.ts b/packages/taler-harness/src/integrationtests/test-wallet-balance.ts
index 0f75bd96e..15b0fd427 100644
--- a/packages/taler-harness/src/integrationtests/test-wallet-balance.ts
+++ b/packages/taler-harness/src/integrationtests/test-wallet-balance.ts
@@ -17,22 +17,11 @@
/**
* Imports.
*/
-import { Amounts, Duration, PreparePayResultType } from "@gnu-taler/taler-util";
+import { Amounts, PreparePayResultType } from "@gnu-taler/taler-util";
import { WalletApiOperation } from "@gnu-taler/taler-wallet-core";
-import { CoinConfig, defaultCoinConfig } from "../harness/denomStructures.js";
-import {
- ExchangeService,
- FakebankService,
- getRandomIban,
- GlobalTestState,
- MerchantPrivateApi,
- MerchantService,
- setupDb,
- WalletCli,
-} from "../harness/harness.js";
+import { GlobalTestState, MerchantPrivateApi } from "../harness/harness.js";
import {
createSimpleTestkudosEnvironmentV2,
- withdrawViaBank,
withdrawViaBankV2,
} from "../harness/helpers.js";
@@ -50,13 +39,15 @@ export async function runWalletBalanceTest(t: GlobalTestState) {
// Withdraw digital cash into the wallet.
- await withdrawViaBankV2(t, {
+ const wres = await withdrawViaBankV2(t, {
walletClient,
bank,
exchange,
amount: "TESTKUDOS:20",
});
+ await wres.withdrawalFinishedCond;
+
const order = {
summary: "Buy me!",
amount: "TESTKUDOS:5",
diff --git a/packages/taler-harness/src/integrationtests/test-wallet-dbless.ts b/packages/taler-harness/src/integrationtests/test-wallet-dbless.ts
index 58f564f34..153ae93d8 100644
--- a/packages/taler-harness/src/integrationtests/test-wallet-dbless.ts
+++ b/packages/taler-harness/src/integrationtests/test-wallet-dbless.ts
@@ -23,7 +23,6 @@ import {
j2s,
TalerError,
} from "@gnu-taler/taler-util";
-import { createPlatformHttpLib } from "@gnu-taler/taler-util/http";
import {
checkReserve,
CryptoDispatcher,
@@ -36,7 +35,7 @@ import {
Wallet,
withdrawCoin,
} from "@gnu-taler/taler-wallet-core";
-import { GlobalTestState } from "../harness/harness.js";
+import { GlobalTestState, harnessHttpLib } from "../harness/harness.js";
import { createSimpleTestkudosEnvironmentV2 } from "../harness/helpers.js";
/**
@@ -47,10 +46,7 @@ export async function runWalletDblessTest(t: GlobalTestState) {
const { bank, exchange } = await createSimpleTestkudosEnvironmentV2(t);
- const http = createPlatformHttpLib({
- allowHttp: true,
- enableThrottling: false,
- });
+ const http = harnessHttpLib;
const cryptiDisp = new CryptoDispatcher(
new SynchronousCryptoWorkerFactoryPlain(),
);
diff --git a/packages/taler-util/src/http-common.ts b/packages/taler-util/src/http-common.ts
index 4f6aaaf44..93cf9bba0 100644
--- a/packages/taler-util/src/http-common.ts
+++ b/packages/taler-util/src/http-common.ts
@@ -19,7 +19,12 @@
import { CancellationToken } from "./CancellationToken.js";
import { Codec } from "./codec.js";
import { j2s } from "./helpers.js";
-import { TalerError, makeErrorDetail } from "./index.js";
+import {
+ TalerError,
+ base64FromArrayBuffer,
+ makeErrorDetail,
+ stringToBytes,
+} from "./index.js";
import { Logger } from "./logging.js";
import { TalerErrorCode } from "./taler-error-codes.js";
import { Duration, AbsoluteTime } from "./time.js";
@@ -306,6 +311,16 @@ export async function readSuccessResponseJsonOrThrow<T>(
throwUnexpectedRequestError(httpResponse, r.talerErrorResponse);
}
+export async function expectSuccessResponseOrThrow<T>(
+ httpResponse: HttpResponse,
+): Promise<void> {
+ if (httpResponse.status >= 200 && httpResponse.status <= 299) {
+ return;
+ }
+ const errResp = await readTalerErrorResponse(httpResponse);
+ throwUnexpectedRequestError(httpResponse, errResp);
+}
+
export async function readSuccessResponseTextOrErrorCode<T>(
httpResponse: HttpResponse,
): Promise<ResponseOrError<string>> {
@@ -452,3 +467,15 @@ export function getDefaultHeaders(method: string): Record<string, string> {
return headers;
}
+
+/**
+ * Helper function to generate the "Authorization" HTTP header.
+ */
+export function makeBasicAuthHeader(
+ username: string,
+ password: string,
+): string {
+ const auth = `${username}:${password}`;
+ const authEncoded: string = base64FromArrayBuffer(stringToBytes(auth));
+ return `Basic ${authEncoded}`;
+}
diff --git a/packages/taler-wallet-core/package.json b/packages/taler-wallet-core/package.json
index 25e7c2eb2..c471770de 100644
--- a/packages/taler-wallet-core/package.json
+++ b/packages/taler-wallet-core/package.json
@@ -72,7 +72,6 @@
"@gnu-taler/idb-bridge": "workspace:*",
"@gnu-taler/taler-util": "workspace:*",
"@types/node": "^18.11.17",
- "axios": "^0.27.2",
"big-integer": "^1.6.51",
"fflate": "^0.7.4",
"tslib": "^2.5.3"
diff --git a/packages/web-util/package.json b/packages/web-util/package.json
index 9661b3f87..6cfe19258 100644
--- a/packages/web-util/package.json
+++ b/packages/web-util/package.json
@@ -44,7 +44,6 @@
"@types/web": "^0.0.82",
"@types/ws": "^8.5.3",
"autoprefixer": "^10.4.14",
- "axios": "^1.2.2",
"chokidar": "^3.5.3",
"esbuild": "^0.17.7",
"express": "^4.18.2",
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 7fd6f7619..5b733353b 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -579,9 +579,6 @@ importers:
'@gnu-taler/taler-wallet-core':
specifier: workspace:*
version: link:../taler-wallet-core
- axios:
- specifier: ^0.27.2
- version: 0.27.2
tslib:
specifier: ^2.5.3
version: 2.5.3
@@ -678,9 +675,6 @@ importers:
'@types/node':
specifier: ^18.11.17
version: 18.11.17
- axios:
- specifier: ^0.27.2
- version: 0.27.2
big-integer:
specifier: ^1.6.51
version: 1.6.51
@@ -925,9 +919,6 @@ importers:
autoprefixer:
specifier: ^10.4.14
version: 10.4.14(postcss@8.4.23)
- axios:
- specifier: ^1.2.2
- version: 1.2.2
chokidar:
specifier: ^3.5.3
version: 3.5.3
@@ -6804,6 +6795,7 @@ packages:
/asynckit@0.4.0:
resolution: {integrity: sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==}
+ dev: true
/at-least-node@1.0.0:
resolution: {integrity: sha512-+q/t7Ekv1EDY2l6Gda6LLiX14rU9TV20Wa3ofeQmwPFZbOMo9DXrLbOjFaaclkXKWidIaopwAObQDqwWtGUjqg==}
@@ -6969,15 +6961,6 @@ packages:
- debug
dev: true
- /axios@0.27.2:
- resolution: {integrity: sha512-t+yRIyySRTp/wua5xEr+z1q60QmLq8ABsS5O9Me1AsE5dfKqgnCFzwiCZZ/cGNd1lq4/7akDWMxdhVlucjmnOQ==}
- dependencies:
- follow-redirects: 1.15.2
- form-data: 4.0.0
- transitivePeerDependencies:
- - debug
- dev: false
-
/axios@1.1.3:
resolution: {integrity: sha512-00tXVRwKx/FZr/IDVFt4C+f9FYairX517WoGCL6dpOntqLkZofjhu43F/Xl44UOpqa+9sLFDrG/XAnFsUYgkDA==}
dependencies:
@@ -6988,16 +6971,6 @@ packages:
- debug
dev: true
- /axios@1.2.2:
- resolution: {integrity: sha512-bz/J4gS2S3I7mpN/YZfGFTqhXTYzRho8Ay38w2otuuDR322KzFIWm/4W2K6gIwvWaws5n+mnb7D1lN9uD+QH6Q==}
- dependencies:
- follow-redirects: 1.15.2
- form-data: 4.0.0
- proxy-from-env: 1.1.0
- transitivePeerDependencies:
- - debug
- dev: true
-
/axobject-query@2.2.0:
resolution: {integrity: sha512-Td525n+iPOOyUQIeBfcASuG6uJsDOITl7Mds5gFyerkWiX7qhUTdYUBlSgNMyVqtSJqwpt1kXGLdUt6SykLMRA==}
dev: true
@@ -8069,6 +8042,7 @@ packages:
engines: {node: '>= 0.8'}
dependencies:
delayed-stream: 1.0.0
+ dev: true
/commander@2.17.1:
resolution: {integrity: sha512-wPMUt6FnH2yzG95SA6mzjQOEKUU3aLaDEmzs1ti+1E9h+CsrZghRlqEM/EJ4KscsQVG8uNN4uVreUeT8+drlgg==}
@@ -8918,6 +8892,7 @@ packages:
/delayed-stream@1.0.0:
resolution: {integrity: sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==}
engines: {node: '>=0.4.0'}
+ dev: true
/depd@1.1.2:
resolution: {integrity: sha512-7emPTl6Dpo6JRXOXjLRxck+FlLRX5847cLKEn00PLAgc3g2hTZZgr+e4c2v6QpSmLeFP3n5yUo7ft6avBK/5jQ==}
@@ -10528,6 +10503,7 @@ packages:
peerDependenciesMeta:
debug:
optional: true
+ dev: true
/for-each@0.3.3:
resolution: {integrity: sha512-jqYfLp7mo9vIyQf8ykW2v7A+2N4QjeCeI5+Dz9XraiO1ign81wjiH7Fb9vSOWvQfNtmSa4H2RoQTrrXivdUZmw==}
@@ -10604,6 +10580,7 @@ packages:
asynckit: 0.4.0
combined-stream: 1.0.8
mime-types: 2.1.35
+ dev: true
/forwarded@0.2.0:
resolution: {integrity: sha512-buRG0fpBtRHSTCOASe6hD258tEubFoRLb4ZNA6NxMVHNw2gOcwHo9wyablzMzOA5z9xA9L1KNjk/Nt6MT9aYow==}
@@ -12669,12 +12646,14 @@ packages:
/mime-db@1.52.0:
resolution: {integrity: sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==}
engines: {node: '>= 0.6'}
+ dev: true
/mime-types@2.1.35:
resolution: {integrity: sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==}
engines: {node: '>= 0.6'}
dependencies:
mime-db: 1.52.0
+ dev: true
/mime@1.6.0:
resolution: {integrity: sha512-x0Vn8spI+wuJ1O6S7gnbaQg8Pxh4NNHb7KSINmEWKiPE4RKOplvijn+NkmYmmRgP68mc70j2EbeTFRsrswaQeg==}