aboutsummaryrefslogtreecommitdiff
path: root/packages
diff options
context:
space:
mode:
authorFlorian Dold <florian@dold.me>2021-02-08 13:02:12 +0100
committerFlorian Dold <florian@dold.me>2021-02-08 13:02:55 +0100
commit883637d3f287e5026de5bcafb559ff3e6ba1f3bb (patch)
treecac64b97186a18c071c3e51e2ae74e74802d8235 /packages
parent48fa2ccea16e1d0e11d5ac93049bc33df8d47119 (diff)
allow fault injection callbacks to run async code
Diffstat (limited to 'packages')
-rw-r--r--packages/taler-wallet-cli/src/integrationtests/faultInjection.ts19
-rw-r--r--packages/taler-wallet-cli/src/integrationtests/test-exchange-management.ts4
-rw-r--r--packages/taler-wallet-cli/src/integrationtests/test-pay-abort.ts6
-rw-r--r--packages/taler-wallet-cli/src/integrationtests/test-pay-paid.ts2
-rw-r--r--packages/taler-wallet-cli/src/integrationtests/test-payment-fault.ts6
-rw-r--r--packages/taler-wallet-cli/src/integrationtests/test-payment-transient.ts2
6 files changed, 16 insertions, 23 deletions
diff --git a/packages/taler-wallet-cli/src/integrationtests/faultInjection.ts b/packages/taler-wallet-cli/src/integrationtests/faultInjection.ts
index a2d4836d9..60549154b 100644
--- a/packages/taler-wallet-cli/src/integrationtests/faultInjection.ts
+++ b/packages/taler-wallet-cli/src/integrationtests/faultInjection.ts
@@ -28,17 +28,10 @@ import { URL } from "url";
import {
GlobalTestState,
ExchangeService,
- BankService,
ExchangeServiceInterface,
MerchantServiceInterface,
MerchantService,
- PrivateOrderStatusQuery,
} from "./harness";
-import {
- PostOrderRequest,
- PostOrderResponse,
- MerchantOrderPrivateStatusResponse,
-} from "./merchantApiTypes";
export interface FaultProxyConfig {
inboundPort: number;
@@ -65,8 +58,8 @@ export interface FaultInjectionResponseContext {
}
export interface FaultSpec {
- modifyRequest?: (ctx: FaultInjectionRequestContext) => void;
- modifyResponse?: (ctx: FaultInjectionResponseContext) => void;
+ modifyRequest?: (ctx: FaultInjectionRequestContext) => Promise<void>;
+ modifyResponse?: (ctx: FaultInjectionResponseContext) => Promise<void>;
}
export class FaultProxy {
@@ -85,7 +78,7 @@ export class FaultProxy {
req.on("data", (chunk) => {
requestChunks.push(chunk);
});
- req.on("end", () => {
+ req.on("end", async () => {
console.log("end of data");
let requestBuffer: Buffer | undefined;
if (requestChunks.length > 0) {
@@ -103,7 +96,7 @@ export class FaultProxy {
for (const faultSpec of this.currentFaultSpecs) {
if (faultSpec.modifyRequest) {
- faultSpec.modifyRequest(faultReqContext);
+ await faultSpec.modifyRequest(faultReqContext);
}
}
@@ -138,7 +131,7 @@ export class FaultProxy {
proxyResp.on("data", (proxyRespData) => {
respChunks.push(proxyRespData);
});
- proxyResp.on("end", () => {
+ proxyResp.on("end", async () => {
console.log("end of target response");
let responseBuffer: Buffer | undefined;
if (respChunks.length > 0) {
@@ -154,7 +147,7 @@ export class FaultProxy {
for (const faultSpec of this.currentFaultSpecs) {
const modResponse = faultSpec.modifyResponse;
if (modResponse) {
- modResponse(faultRespContext);
+ await modResponse(faultRespContext);
}
}
if (faultRespContext.dropResponse) {
diff --git a/packages/taler-wallet-cli/src/integrationtests/test-exchange-management.ts b/packages/taler-wallet-cli/src/integrationtests/test-exchange-management.ts
index 6fc8bf3c1..1b7deefc5 100644
--- a/packages/taler-wallet-cli/src/integrationtests/test-exchange-management.ts
+++ b/packages/taler-wallet-cli/src/integrationtests/test-exchange-management.ts
@@ -155,7 +155,7 @@ export async function runExchangeManagementTest(t: GlobalTestState) {
t.assertTrue(exchangesList.exchanges.length === 0);
faultyExchange.faultProxy.addFault({
- modifyResponse(ctx: FaultInjectionResponseContext) {
+ async modifyResponse(ctx: FaultInjectionResponseContext) {
const url = new URL(ctx.request.requestUrl);
if (url.pathname === "/keys") {
const body = {
@@ -193,7 +193,7 @@ export async function runExchangeManagementTest(t: GlobalTestState) {
faultyExchange.faultProxy.clearAllFaults();
faultyExchange.faultProxy.addFault({
- modifyResponse(ctx: FaultInjectionResponseContext) {
+ async modifyResponse(ctx: FaultInjectionResponseContext) {
const url = new URL(ctx.request.requestUrl);
if (url.pathname === "/keys") {
const keys = ctx.responseBody?.toString("utf-8");
diff --git a/packages/taler-wallet-cli/src/integrationtests/test-pay-abort.ts b/packages/taler-wallet-cli/src/integrationtests/test-pay-abort.ts
index 90a0edf09..44a81b516 100644
--- a/packages/taler-wallet-cli/src/integrationtests/test-pay-abort.ts
+++ b/packages/taler-wallet-cli/src/integrationtests/test-pay-abort.ts
@@ -91,7 +91,7 @@ export async function runPayAbortTest(t: GlobalTestState) {
let firstDepositUrl: string | undefined;
faultyExchange.faultProxy.addFault({
- modifyRequest(ctx: FaultInjectionRequestContext) {
+ async modifyRequest(ctx: FaultInjectionRequestContext) {
const url = new URL(ctx.requestUrl);
if (url.pathname.endsWith("/deposit")) {
if (!firstDepositUrl) {
@@ -104,7 +104,7 @@ export async function runPayAbortTest(t: GlobalTestState) {
}
}
},
- modifyResponse(ctx: FaultInjectionResponseContext) {
+ async modifyResponse(ctx: FaultInjectionResponseContext) {
const url = new URL(ctx.request.requestUrl);
if (url.pathname.endsWith("/deposit") && url.href != firstDepositUrl) {
ctx.responseBody = Buffer.from("{}");
@@ -114,7 +114,7 @@ export async function runPayAbortTest(t: GlobalTestState) {
});
faultyMerchant.faultProxy.addFault({
- modifyResponse(ctx: FaultInjectionResponseContext) {
+ async modifyResponse(ctx: FaultInjectionResponseContext) {
const url = new URL(ctx.request.requestUrl);
if (url.pathname.endsWith("/pay") && url.href != firstDepositUrl) {
ctx.responseBody = Buffer.from("{}");
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 b0253b449..f826bdc6d 100644
--- a/packages/taler-wallet-cli/src/integrationtests/test-pay-paid.ts
+++ b/packages/taler-wallet-cli/src/integrationtests/test-pay-paid.ts
@@ -167,7 +167,7 @@ export async function runPayPaidTest(t: GlobalTestState) {
let numPaidRequested = 0;
faultyMerchant.faultProxy.addFault({
- modifyRequest(ctx: FaultInjectionRequestContext) {
+ async modifyRequest(ctx: FaultInjectionRequestContext) {
const url = new URL(ctx.requestUrl);
if (url.pathname.endsWith("/pay")) {
numPayRequested++;
diff --git a/packages/taler-wallet-cli/src/integrationtests/test-payment-fault.ts b/packages/taler-wallet-cli/src/integrationtests/test-payment-fault.ts
index 4462b4ff9..713f7162f 100644
--- a/packages/taler-wallet-cli/src/integrationtests/test-payment-fault.ts
+++ b/packages/taler-wallet-cli/src/integrationtests/test-payment-fault.ts
@@ -83,10 +83,10 @@ export async function runPaymentFaultTest(t: GlobalTestState) {
// Print all requests to the exchange
faultyExchange.faultProxy.addFault({
- modifyRequest(ctx: FaultInjectionRequestContext) {
+ async modifyRequest(ctx: FaultInjectionRequestContext) {
console.log("got request", ctx);
},
- modifyResponse(ctx: FaultInjectionResponseContext) {
+ async modifyResponse(ctx: FaultInjectionResponseContext) {
console.log("got response", ctx);
},
});
@@ -180,7 +180,7 @@ export async function runPaymentFaultTest(t: GlobalTestState) {
// Drop 3 responses from the exchange.
let faultCount = 0;
faultyExchange.faultProxy.addFault({
- modifyResponse(ctx: FaultInjectionResponseContext) {
+ async modifyResponse(ctx: FaultInjectionResponseContext) {
if (!ctx.request.requestUrl.endsWith("/deposit")) {
return;
}
diff --git a/packages/taler-wallet-cli/src/integrationtests/test-payment-transient.ts b/packages/taler-wallet-cli/src/integrationtests/test-payment-transient.ts
index b059625aa..b9e5670d8 100644
--- a/packages/taler-wallet-cli/src/integrationtests/test-payment-transient.ts
+++ b/packages/taler-wallet-cli/src/integrationtests/test-payment-transient.ts
@@ -116,7 +116,7 @@ export async function runPaymentTransientTest(t: GlobalTestState) {
let faultInjected = false;
faultyMerchant.faultProxy.addFault({
- modifyResponse(ctx: FaultInjectionResponseContext) {
+ async modifyResponse(ctx: FaultInjectionResponseContext) {
console.log("in modifyResponse");
const url = new URL(ctx.request.requestUrl);
console.log("pathname is", url.pathname);