summaryrefslogtreecommitdiff
path: root/packages/taler-wallet-core
diff options
context:
space:
mode:
authorFlorian Dold <florian@dold.me>2021-02-04 17:13:31 +0100
committerFlorian Dold <florian@dold.me>2021-02-04 17:13:31 +0100
commitf262b288123d4198223274a3382b9a1110d3ca33 (patch)
treec94f505c0e4f3a4695f23138ed3b6a76c5befb1d /packages/taler-wallet-core
parent83937a7198c17b267714b159f0e616a2536264d3 (diff)
downloadwallet-core-f262b288123d4198223274a3382b9a1110d3ca33.tar.gz
wallet-core-f262b288123d4198223274a3382b9a1110d3ca33.tar.bz2
wallet-core-f262b288123d4198223274a3382b9a1110d3ca33.zip
use new auth token for merchant in integration tests
Diffstat (limited to 'packages/taler-wallet-core')
-rw-r--r--packages/taler-wallet-core/src/headless/NodeHttpLib.ts1
-rw-r--r--packages/taler-wallet-core/src/operations/testing.ts29
-rw-r--r--packages/taler-wallet-core/src/types/walletTypes.ts8
3 files changed, 20 insertions, 18 deletions
diff --git a/packages/taler-wallet-core/src/headless/NodeHttpLib.ts b/packages/taler-wallet-core/src/headless/NodeHttpLib.ts
index 95626cc4d..dc649a65e 100644
--- a/packages/taler-wallet-core/src/headless/NodeHttpLib.ts
+++ b/packages/taler-wallet-core/src/headless/NodeHttpLib.ts
@@ -32,6 +32,7 @@ import { TalerErrorCode } from "../TalerErrorCode";
import { URL } from "../util/url";
import { Logger } from "../util/logging";
import { bytesToString } from "../crypto/talerCrypto";
+import { j2s } from "../util/helpers";
const logger = new Logger("NodeHttpLib.ts");
diff --git a/packages/taler-wallet-core/src/operations/testing.ts b/packages/taler-wallet-core/src/operations/testing.ts
index 0a83773ab..162e23b31 100644
--- a/packages/taler-wallet-core/src/operations/testing.ts
+++ b/packages/taler-wallet-core/src/operations/testing.ts
@@ -31,8 +31,6 @@ import { createTalerWithdrawReserve } from "./reserves";
import { URL } from "../util/url";
import { Wallet } from "../wallet";
import { Amounts } from "../util/amounts";
-import { NodeHttpLib } from "../headless/NodeHttpLib";
-import { getDefaultNodeWallet } from "../headless/helpers";
import {
TestPayArgs,
PreparePayResultType,
@@ -53,7 +51,7 @@ interface BankWithdrawalResponse {
interface MerchantBackendInfo {
baseUrl: string;
- apikey: string;
+ authToken?: string;
}
/**
@@ -109,6 +107,15 @@ export async function withdrawTestBalance(
);
}
+function getMerchantAuthHeader(m: MerchantBackendInfo): Record<string, string> {
+ if (m.authToken) {
+ return {
+ "Authorization": `Bearer ${m.authToken}`,
+ }
+ }
+ return {};
+}
+
async function createBankWithdrawalUri(
http: HttpRequestLibrary,
bankBaseUrl: string,
@@ -190,9 +197,7 @@ async function refund(
refund: refundAmount,
};
const resp = await http.postJson(reqUrl.href, refundReq, {
- headers: {
- Authorization: `ApiKey ${merchantBackend.apikey}`,
- },
+ headers: getMerchantAuthHeader(merchantBackend),
});
const r = await readSuccessResponseJsonOrThrow(resp, codecForAny());
const refundUri = r.taler_refund_uri;
@@ -221,9 +226,7 @@ async function createOrder(
},
};
const resp = await http.postJson(reqUrl, orderReq, {
- headers: {
- Authorization: `ApiKey ${merchantBackend.apikey}`,
- },
+ headers: getMerchantAuthHeader(merchantBackend),
});
const r = await readSuccessResponseJsonOrThrow(resp, codecForAny());
const orderId = r.order_id;
@@ -241,9 +244,7 @@ async function checkPayment(
const reqUrl = new URL(`/private/orders/${orderId}`, merchantBackend.baseUrl);
reqUrl.searchParams.set("order_id", orderId);
const resp = await http.get(reqUrl.href, {
- headers: {
- Authorization: `ApiKey ${merchantBackend.apikey}`,
- },
+ headers: getMerchantAuthHeader(merchantBackend),
});
return readSuccessResponseJsonOrThrow(resp, codecForCheckPaymentResponse());
}
@@ -337,7 +338,7 @@ export async function runIntegrationTest(
const myMerchant: MerchantBackendInfo = {
baseUrl: args.merchantBaseUrl,
- apikey: args.merchantApiKey,
+ authToken: args.merchantAuthToken,
};
await makePayment(
@@ -415,7 +416,7 @@ export async function testPay(
) {
logger.trace("creating order");
const merchant = {
- apikey: args.merchantApiKey,
+ authToken: args.merchantAuthToken,
baseUrl: args.merchantBaseUrl,
};
const orderResp = await createOrder(
diff --git a/packages/taler-wallet-core/src/types/walletTypes.ts b/packages/taler-wallet-core/src/types/walletTypes.ts
index f195918ac..1b98df276 100644
--- a/packages/taler-wallet-core/src/types/walletTypes.ts
+++ b/packages/taler-wallet-core/src/types/walletTypes.ts
@@ -689,7 +689,7 @@ export interface GetExchangeTosResult {
export interface TestPayArgs {
merchantBaseUrl: string;
- merchantApiKey: string;
+ merchantAuthToken: string;
amount: string;
summary: string;
}
@@ -697,7 +697,7 @@ export interface TestPayArgs {
export const codecForTestPayArgs = (): Codec<TestPayArgs> =>
buildCodecForObject<TestPayArgs>()
.property("merchantBaseUrl", codecForString())
- .property("merchantApiKey", codecForString())
+ .property("merchantAuthToken", codecForString())
.property("amount", codecForString())
.property("summary", codecForString())
.build("TestPayArgs");
@@ -706,7 +706,7 @@ export interface IntegrationTestArgs {
exchangeBaseUrl: string;
bankBaseUrl: string;
merchantBaseUrl: string;
- merchantApiKey: string;
+ merchantAuthToken: string;
amountToWithdraw: string;
amountToSpend: string;
}
@@ -716,7 +716,7 @@ export const codecForIntegrationTestArgs = (): Codec<IntegrationTestArgs> =>
.property("exchangeBaseUrl", codecForString())
.property("bankBaseUrl", codecForString())
.property("merchantBaseUrl", codecForString())
- .property("merchantApiKey", codecForString())
+ .property("merchantAuthToken", codecForString())
.property("amountToSpend", codecForAmountString())
.property("amountToWithdraw", codecForAmountString())
.build("IntegrationTestArgs");