gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[taler-wallet-core] branch master updated (98d205ba -> f262b288)


From: gnunet
Subject: [taler-wallet-core] branch master updated (98d205ba -> f262b288)
Date: Thu, 04 Feb 2021 17:13:36 +0100

This is an automated email from the git hooks/post-receive script.

dold pushed a change to branch master
in repository wallet-core.

    from 98d205ba also report test results when parent gets killed
     new aa6cba15 remove bogus argument
     new 83937a71 per-test timeout
     new f262b288 use new auth token for merchant in integration tests

The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../src/integrationtests/harness.ts                |  4 +-
 .../src/integrationtests/test-tipping.ts           |  2 +-
 .../src/integrationtests/test-wallettesting.ts     | 98 +++++++++++++++++++---
 .../src/integrationtests/testrunner.ts             |  6 +-
 .../taler-wallet-core/src/headless/NodeHttpLib.ts  |  1 +
 .../taler-wallet-core/src/operations/testing.ts    | 29 +++----
 .../taler-wallet-core/src/types/walletTypes.ts     |  8 +-
 7 files changed, 115 insertions(+), 33 deletions(-)

diff --git a/packages/taler-wallet-cli/src/integrationtests/harness.ts 
b/packages/taler-wallet-cli/src/integrationtests/harness.ts
index 9a1136bc..ba02776e 100644
--- a/packages/taler-wallet-cli/src/integrationtests/harness.ts
+++ b/packages/taler-wallet-cli/src/integrationtests/harness.ts
@@ -98,13 +98,11 @@ import {
 import { ApplyRefundResponse } from "@gnu-taler/taler-wallet-core";
 import { PendingOperationsResponse } from "@gnu-taler/taler-wallet-core";
 import { CoinConfig } from "./denomStructures";
-import CancellationToken from "cancellationtoken";
 
 const exec = util.promisify(require("child_process").exec);
 
 export async function delayMs(
   ms: number,
-  cancellationToken?: CancellationToken,
 ): Promise<void> {
   return new Promise((resolve, reject) => {
     setTimeout(() => resolve(), ms);
@@ -1429,6 +1427,7 @@ export class MerchantService implements 
MerchantServiceInterface {
     console.log("adding instance");
     const url = 
`http://localhost:${this.merchantConfig.httpPort}/private/instances`;
     await axios.post(url, {
+      auth_token: instanceConfig.authToken,
       payto_uris: instanceConfig.paytoUris,
       id: instanceConfig.id,
       name: instanceConfig.name,
@@ -1464,6 +1463,7 @@ export class MerchantService implements 
MerchantServiceInterface {
 }
 
 export interface MerchantInstanceConfig {
+  authToken?: string;
   id: string;
   name: string;
   paytoUris: string[];
diff --git a/packages/taler-wallet-cli/src/integrationtests/test-tipping.ts 
b/packages/taler-wallet-cli/src/integrationtests/test-tipping.ts
index 21422c42..a8947331 100644
--- a/packages/taler-wallet-cli/src/integrationtests/test-tipping.ts
+++ b/packages/taler-wallet-cli/src/integrationtests/test-tipping.ts
@@ -18,7 +18,7 @@
  * Imports.
  */
 import { GlobalTestState, MerchantPrivateApi, BankApi } from "./harness";
-import { createSimpleTestkudosEnvironment, withdrawViaBank } from "./helpers";
+import { createSimpleTestkudosEnvironment } from "./helpers";
 
 /**
  * Run test for basic, bank-integrated withdrawal.
diff --git 
a/packages/taler-wallet-cli/src/integrationtests/test-wallettesting.ts 
b/packages/taler-wallet-cli/src/integrationtests/test-wallettesting.ts
index cdb95485..65d8aea2 100644
--- a/packages/taler-wallet-cli/src/integrationtests/test-wallettesting.ts
+++ b/packages/taler-wallet-cli/src/integrationtests/test-wallettesting.ts
@@ -22,26 +22,104 @@
 /**
  * Imports.
  */
-import { GlobalTestState } from "./harness";
-import { createSimpleTestkudosEnvironment, withdrawViaBank } from "./helpers";
+import { CoinConfig, defaultCoinConfig } from "./denomStructures";
+import {
+  BankService,
+  ExchangeService,
+  GlobalTestState,
+  MerchantService,
+  setupDb,
+  WalletCli,
+} from "./harness";
+import { SimpleTestEnvironment } from "./helpers";
+
+const merchantAuthToken = "secret-token:sandbox";
 
 /**
- * Run test for basic, bank-integrated withdrawal.
+ * Run a test case with a simple TESTKUDOS Taler environment, consisting
+ * of one exchange, one bank and one merchant.
  */
-export async function runWallettestingTest(t: GlobalTestState) {
-  const {
-    wallet,
-    bank,
+export async function createMyEnvironment(
+  t: GlobalTestState,
+  coinConfig: CoinConfig[] = defaultCoinConfig.map((x) => x("TESTKUDOS")),
+): Promise<SimpleTestEnvironment> {
+  const db = await setupDb(t);
+
+  const bank = await BankService.create(t, {
+    allowRegistrations: true,
+    currency: "TESTKUDOS",
+    database: db.connStr,
+    httpPort: 8082,
+  });
+
+  const exchange = ExchangeService.create(t, {
+    name: "testexchange-1",
+    currency: "TESTKUDOS",
+    httpPort: 8081,
+    database: db.connStr,
+  });
+
+  const merchant = await MerchantService.create(t, {
+    name: "testmerchant-1",
+    currency: "TESTKUDOS",
+    httpPort: 8083,
+    database: db.connStr,
+  });
+
+  const exchangeBankAccount = await bank.createExchangeAccount(
+    "MyExchange",
+    "x",
+  );
+  exchange.addBankAccount("1", exchangeBankAccount);
+
+  bank.setSuggestedExchange(exchange, exchangeBankAccount.accountPaytoUri);
+
+  await bank.start();
+
+  await bank.pingUntilAvailable();
+
+  exchange.addCoinConfigList(coinConfig);
+
+  await exchange.start();
+  await exchange.pingUntilAvailable();
+
+  merchant.addExchange(exchange);
+
+  await merchant.start();
+  await merchant.pingUntilAvailable();
+
+  await merchant.addInstance({
+    id: "default",
+    name: "Default Instance",
+    paytoUris: [`payto://x-taler-bank/merchant-default`],
+  });
+
+  console.log("setup done!");
+
+  const wallet = new WalletCli(t);
+
+  return {
+    commonDb: db,
     exchange,
     merchant,
-  } = await createSimpleTestkudosEnvironment(t);
+    wallet,
+    bank,
+    exchangeBankAccount,
+  };
+}
+
+/**
+ * Run test for basic, bank-integrated withdrawal.
+ */
+export async function runWallettestingTest(t: GlobalTestState) {
+  const { wallet, bank, exchange, merchant } = await createMyEnvironment(t);
 
   await wallet.runIntegrationTest({
     amountToSpend: "TESTKUDOS:5",
     amountToWithdraw: "TESTKUDOS:10",
     bankBaseUrl: bank.baseUrl,
     exchangeBaseUrl: exchange.baseUrl,
-    merchantApiKey: "sandbox",
+    merchantAuthToken: merchantAuthToken,
     merchantBaseUrl: merchant.makeInstanceBaseUrl(),
   });
 
@@ -70,7 +148,7 @@ export async function runWallettestingTest(t: 
GlobalTestState) {
 
   await wallet.testPay({
     amount: "TESTKUDOS:5",
-    merchantApiKey: "sandbox",
+    merchantAuthToken: merchantAuthToken,
     merchantBaseUrl: merchant.makeInstanceBaseUrl(),
     summary: "foo",
   });
diff --git a/packages/taler-wallet-cli/src/integrationtests/testrunner.ts 
b/packages/taler-wallet-cli/src/integrationtests/testrunner.ts
index 0d591573..455d8f45 100644
--- a/packages/taler-wallet-cli/src/integrationtests/testrunner.ts
+++ b/packages/taler-wallet-cli/src/integrationtests/testrunner.ts
@@ -68,6 +68,7 @@ import CancellationToken from "cancellationtoken";
  */
 interface TestMainFunction {
   (t: GlobalTestState): Promise<void>;
+  timeoutMs?: number;
 }
 
 const allTests: TestMainFunction[] = [
@@ -199,9 +200,10 @@ export async function runTests(spec: TestRunSpec) {
     currentChild.stdout?.pipe(harnessLogStream);
     currentChild.stderr?.pipe(harnessLogStream);
 
-    const testTimeoutMs = 60000;
+    const defaultTimeout = 60000;
+    const testTimeoutMs = testCase.timeoutMs ?? defaultTimeout;
 
-    const { token } = CancellationToken.timeout(60000);
+    const { token } = CancellationToken.timeout(testTimeoutMs);
 
     const resultPromise: Promise<TestRunResult> = new Promise(
       (resolve, reject) => {
diff --git a/packages/taler-wallet-core/src/headless/NodeHttpLib.ts 
b/packages/taler-wallet-core/src/headless/NodeHttpLib.ts
index 95626cc4..dc649a65 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 0a83773a..162e23b3 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 f195918a..1b98df27 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");

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]