[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[taler-wallet-core] branch master updated: merchant exchange confusion t
From: |
gnunet |
Subject: |
[taler-wallet-core] branch master updated: merchant exchange confusion test |
Date: |
Thu, 14 Jan 2021 01:48:01 +0100 |
This is an automated email from the git hooks/post-receive script.
dold pushed a commit to branch master
in repository wallet-core.
The following commit(s) were added to refs/heads/master by this push:
new 657c4b63 merchant exchange confusion test
657c4b63 is described below
commit 657c4b6377d405640d353a8c5e15dbb6ac59800b
Author: Florian Dold <florian@dold.me>
AuthorDate: Thu Jan 14 01:47:56 2021 +0100
merchant exchange confusion test
---
.../src/integrationtests/harness.ts | 4 -
...paid.ts => test-merchant-exchange-confusion.ts} | 204 ++++++++++++---------
.../src/integrationtests/test-pay-paid.ts | 9 +-
.../src/integrationtests/test-revocation.ts | 5 -
.../integrationtests/test-timetravel-withdraw.ts | 2 +-
.../src/integrationtests/testrunner.ts | 4 +-
6 files changed, 125 insertions(+), 103 deletions(-)
diff --git a/packages/taler-wallet-cli/src/integrationtests/harness.ts
b/packages/taler-wallet-cli/src/integrationtests/harness.ts
index 3bfe8570..6a9d694e 100644
--- a/packages/taler-wallet-cli/src/integrationtests/harness.ts
+++ b/packages/taler-wallet-cli/src/integrationtests/harness.ts
@@ -1000,7 +1000,6 @@ export class ExchangeService implements
ExchangeServiceInterface {
[
"-c",
this.configFilename,
- ...this.timetravelArgArr,
"download",
"sign",
"upload",
@@ -1026,7 +1025,6 @@ export class ExchangeService implements
ExchangeServiceInterface {
[
"-c",
this.configFilename,
- ...this.timetravelArgArr,
"enable-account",
acc,
"upload",
@@ -1043,7 +1041,6 @@ export class ExchangeService implements
ExchangeServiceInterface {
[
"-c",
this.configFilename,
- ...this.timetravelArgArr,
"wire-fee",
`${i}`,
"x-taler-bank",
@@ -1066,7 +1063,6 @@ export class ExchangeService implements
ExchangeServiceInterface {
[
"-c",
this.configFilename,
- ...this.timetravelArgArr,
"revoke-denomination",
denomPubHash,
"upload",
diff --git a/packages/taler-wallet-cli/src/integrationtests/test-pay-paid.ts
b/packages/taler-wallet-cli/src/integrationtests/test-merchant-exchange-confusion.ts
similarity index 54%
copy from packages/taler-wallet-cli/src/integrationtests/test-pay-paid.ts
copy to
packages/taler-wallet-cli/src/integrationtests/test-merchant-exchange-confusion.ts
index 4d270660..ed070dc9 100644
--- a/packages/taler-wallet-cli/src/integrationtests/test-pay-paid.ts
+++
b/packages/taler-wallet-cli/src/integrationtests/test-merchant-exchange-confusion.ts
@@ -17,10 +17,19 @@
/**
* Imports.
*/
-import { GlobalTestState, MerchantPrivateApi } from "./harness";
+import {
+ BankService,
+ ExchangeService,
+ GlobalTestState,
+ MerchantPrivateApi,
+ MerchantService,
+ setupDb,
+ WalletCli,
+} from "./harness";
import {
withdrawViaBank,
createFaultInjectedMerchantTestkudosEnvironment,
+ FaultyMerchantTestEnvironment,
} from "./helpers";
import {
PreparePayResultType,
@@ -29,29 +38,122 @@ import {
URL,
} from "taler-wallet-core";
import axios from "axios";
-import { FaultInjectionRequestContext } from "./faultInjection";
+import {
+ FaultInjectedExchangeService,
+ FaultInjectedMerchantService,
+ FaultInjectionRequestContext,
+} from "./faultInjection";
+import { defaultCoinConfig } from "./denomStructures";
/**
- * Run test for the wallets repurchase detection mechanism
- * based on the fulfillment URL.
- *
- * FIXME: This test is now almost the same as test-paywall-flow,
- * since we can't initiate payment via a "claimed" private order status
- * response.
+ * Run a test case with a simple TESTKUDOS Taler environment, consisting
+ * of one exchange, one bank and one merchant.
*/
-export async function runPayPaidTest(t: GlobalTestState) {
+export async function createConfusedMerchantTestkudosEnvironment(
+ t: GlobalTestState,
+): Promise<FaultyMerchantTestEnvironment> {
+ 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 faultyMerchant = new FaultInjectedMerchantService(t, merchant, 9083);
+ const faultyExchange = new FaultInjectedExchangeService(t, exchange, 9081);
+
+ const exchangeBankAccount = await bank.createExchangeAccount(
+ "MyExchange",
+ "x",
+ );
+ exchange.addBankAccount("1", exchangeBankAccount);
+
+ bank.setSuggestedExchange(
+ faultyExchange,
+ exchangeBankAccount.accountPaytoUri,
+ );
+
+ await bank.start();
+
+ await bank.pingUntilAvailable();
+
+ exchange.addOfferedCoins(defaultCoinConfig);
+
+ await exchange.start();
+ await exchange.pingUntilAvailable();
+
+ // Confuse the merchant by adding the non-proxied exchange.
+ merchant.addExchange(exchange);
+
+ await merchant.start();
+ await merchant.pingUntilAvailable();
+
+ await merchant.addInstance({
+ id: "minst1",
+ name: "minst1",
+ paytoUris: ["payto://x-taler-bank/minst1"],
+ });
+
+ 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,
+ wallet,
+ bank,
+ exchangeBankAccount,
+ faultyMerchant,
+ faultyExchange,
+ };
+}
+
+/**
+ * Confuse the merchant by having one URL for the same exchange in the config,
+ * but sending coins from the same exchange with a different URL.
+ */
+export async function runMerchantExchangeConfusionTest(t: GlobalTestState) {
// Set up test environment
const {
wallet,
bank,
- exchange,
+ faultyExchange,
faultyMerchant,
- } = await createFaultInjectedMerchantTestkudosEnvironment(t);
+ } = await createConfusedMerchantTestkudosEnvironment(t);
// Withdraw digital cash into the wallet.
- await withdrawViaBank(t, { wallet, bank, exchange, amount: "TESTKUDOS:20" });
+ await withdrawViaBank(t, {
+ wallet,
+ bank,
+ exchange: faultyExchange,
+ amount: "TESTKUDOS:20",
+ });
/**
* =========================================================================
@@ -125,82 +227,4 @@ export async function runPayPaidTest(t: GlobalTestState) {
});
t.assertTrue(confirmPayRes.type === ConfirmPayResultType.Done);
-
- publicOrderStatusResp = await axios.get(publicOrderStatusUrl, {
- validateStatus: () => true,
- });
-
- console.log(publicOrderStatusResp.data);
-
- if (publicOrderStatusResp.status != 202) {
- console.log(publicOrderStatusResp.data);
- throw Error(
- `expected status 202 (after paying), but got
${publicOrderStatusResp.status}`,
- );
- }
-
- /**
- * =========================================================================
- * Now change up the session ID and do payment re-play!
- * =========================================================================
- */
-
- orderStatus = await MerchantPrivateApi.queryPrivateOrderStatus(merchant, {
- orderId: orderResp.order_id,
- sessionId: "mysession-two",
- });
-
- console.log(
- "order status under mysession-two:",
- JSON.stringify(orderStatus, undefined, 2),
- );
-
- // Should be claimed (not paid!) because of a new session ID
- t.assertTrue(orderStatus.order_status === "claimed");
-
- let numPayRequested = 0;
- let numPaidRequested = 0;
-
- faultyMerchant.faultProxy.addFault({
- modifyRequest(ctx: FaultInjectionRequestContext) {
- const url = new URL(ctx.requestUrl);
- if (url.pathname.endsWith("/pay")) {
- numPayRequested++;
- } else if (url.pathname.endsWith("/paid")) {
- numPaidRequested++;
- }
- },
- });
-
- let orderRespTwo = await MerchantPrivateApi.createOrder(merchant, "default",
{
- order: {
- summary: "Buy me!",
- amount: "TESTKUDOS:5",
- fulfillment_url: "https://example.com/article42",
- },
- });
-
- let orderStatusTwo = await MerchantPrivateApi.queryPrivateOrderStatus(
- merchant,
- {
- orderId: orderRespTwo.order_id,
- sessionId: "mysession-two",
- },
- );
-
- t.assertTrue(orderStatusTwo.order_status === "unpaid");
-
- // Pay with new taler://pay URI, which should
- // have the new session ID!
- // Wallet should now automatically re-play payment.
- preparePayResp = await wallet.preparePay({
- talerPayUri: orderStatusTwo.taler_pay_uri,
- });
-
- t.assertTrue(preparePayResp.status ===
PreparePayResultType.AlreadyConfirmed);
- t.assertTrue(preparePayResp.paid);
-
- // Make sure the wallet is actually doing the replay properly.
- t.assertTrue(numPaidRequested == 1);
- t.assertTrue(numPayRequested == 0);
}
diff --git a/packages/taler-wallet-cli/src/integrationtests/test-pay-paid.ts
b/packages/taler-wallet-cli/src/integrationtests/test-pay-paid.ts
index 4d270660..136400d9 100644
--- a/packages/taler-wallet-cli/src/integrationtests/test-pay-paid.ts
+++ b/packages/taler-wallet-cli/src/integrationtests/test-pay-paid.ts
@@ -45,13 +45,18 @@ export async function runPayPaidTest(t: GlobalTestState) {
const {
wallet,
bank,
- exchange,
+ faultyExchange,
faultyMerchant,
} = await createFaultInjectedMerchantTestkudosEnvironment(t);
// Withdraw digital cash into the wallet.
- await withdrawViaBank(t, { wallet, bank, exchange, amount: "TESTKUDOS:20" });
+ await withdrawViaBank(t, {
+ wallet,
+ bank,
+ exchange: faultyExchange,
+ amount: "TESTKUDOS:20",
+ });
/**
* =========================================================================
diff --git a/packages/taler-wallet-cli/src/integrationtests/test-revocation.ts
b/packages/taler-wallet-cli/src/integrationtests/test-revocation.ts
index ac989855..0fcf7a93 100644
--- a/packages/taler-wallet-cli/src/integrationtests/test-revocation.ts
+++ b/packages/taler-wallet-cli/src/integrationtests/test-revocation.ts
@@ -42,16 +42,11 @@ async function revokeAllWalletCoins(req: {
for (const coin of coinDump.coins) {
usedDenomHashes.add(coin.denom_pub_hash);
}
-
- await exchange.stop();
-
for (const x of usedDenomHashes.values()) {
await exchange.revokeDenomination(x);
}
await exchange.keyup();
-
- await exchange.start();
await exchange.pingUntilAvailable();
await merchant.stop();
await merchant.start();
diff --git
a/packages/taler-wallet-cli/src/integrationtests/test-timetravel-withdraw.ts
b/packages/taler-wallet-cli/src/integrationtests/test-timetravel-withdraw.ts
index e74a49c9..54b507bc 100644
--- a/packages/taler-wallet-cli/src/integrationtests/test-timetravel-withdraw.ts
+++ b/packages/taler-wallet-cli/src/integrationtests/test-timetravel-withdraw.ts
@@ -51,9 +51,9 @@ export async function runTimetravelWithdrawTest(t:
GlobalTestState) {
await exchange.stop();
exchange.setTimetravel(timetravelDuration);
- await exchange.keyup();
await exchange.start();
await exchange.pingUntilAvailable();
+ await exchange.keyup();
await merchant.stop();
merchant.setTimetravel(timetravelDuration);
diff --git a/packages/taler-wallet-cli/src/integrationtests/testrunner.ts
b/packages/taler-wallet-cli/src/integrationtests/testrunner.ts
index 3b1ea496..fbc25168 100644
--- a/packages/taler-wallet-cli/src/integrationtests/testrunner.ts
+++ b/packages/taler-wallet-cli/src/integrationtests/testrunner.ts
@@ -47,6 +47,7 @@ import { runTestWithdrawalManualTest } from
"./test-withdrawal-manual";
import { runWithdrawalAbortBankTest } from "./test-withdrawal-abort-bank";
import { runWithdrawalBankIntegratedTest } from
"./test-withdrawal-bank-integrated";
import M from "minimatch";
+import { runMerchantExchangeConfusionTest } from
"./test-merchant-exchange-confusion";
/**
* Test runner.
@@ -87,6 +88,7 @@ const allTests: TestMainFunction[] = [
runTestWithdrawalManualTest,
runWithdrawalAbortBankTest,
runWithdrawalBankIntegratedTest,
+ runMerchantExchangeConfusionTest,
];
export interface TestRunSpec {
@@ -118,7 +120,7 @@ export function getTestName(tf: TestMainFunction): string {
throw Error("invalid test name, must be 'run${NAME}Test'");
}
return res[1]
- .replace(/[a-z0-9][A-Z]/, (x) => {
+ .replace(/[a-z0-9][A-Z]/g, (x) => {
return x[0] + "-" + x[1];
})
.toLowerCase();
--
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [taler-wallet-core] branch master updated: merchant exchange confusion test,
gnunet <=