aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorFlorian Dold <florian.dold@gmail.com>2020-01-18 23:32:03 +0100
committerFlorian Dold <florian.dold@gmail.com>2020-01-18 23:32:14 +0100
commitaf57a404d070500ce63ed9ed0dfce721e82e4801 (patch)
tree39e97aefffe61c568b64c1d71d66b48e26c905ce /src
parentfcb0565323d3134ec2dc376700ef85a2c7b7becd (diff)
downloadwallet-core-af57a404d070500ce63ed9ed0dfce721e82e4801.tar.xz
fix and test case for "insecure" taler://refund URIs
Diffstat (limited to 'src')
-rw-r--r--src/headless/integrationtest.ts2
-rw-r--r--src/operations/pay.ts1
-rw-r--r--src/operations/refund.ts4
-rw-r--r--src/util/taleruri-test.ts15
-rw-r--r--src/util/taleruri.ts17
-rw-r--r--src/wallet.ts25
6 files changed, 53 insertions, 11 deletions
diff --git a/src/headless/integrationtest.ts b/src/headless/integrationtest.ts
index b00fa5ccb..ee52c4c46 100644
--- a/src/headless/integrationtest.ts
+++ b/src/headless/integrationtest.ts
@@ -171,6 +171,8 @@ export async function runIntegrationTest(args: IntegrationTestArgs) {
Amounts.toString(refundAmount),
);
+ console.log("refund URI", refundUri);
+
await myWallet.applyRefund(refundUri);
// Wait until the refund is done
diff --git a/src/operations/pay.ts b/src/operations/pay.ts
index 098e6e18c..c5a344186 100644
--- a/src/operations/pay.ts
+++ b/src/operations/pay.ts
@@ -1093,6 +1093,7 @@ export async function confirmPay(
);
logger.trace("confirmPay: submitting payment after creating purchase record");
+ logger.trace("purchaseRecord:", purchase);
return submitPay(ws, proposalId);
}
diff --git a/src/operations/refund.ts b/src/operations/refund.ts
index 6a96868a3..27d83230a 100644
--- a/src/operations/refund.ts
+++ b/src/operations/refund.ts
@@ -271,7 +271,7 @@ export async function applyRefund(
): Promise<string> {
const parseResult = parseRefundUri(talerRefundUri);
- console.log("applying refund");
+ console.log("applying refund", parseResult);
if (!parseResult) {
throw Error("invalid refund URI");
@@ -283,7 +283,7 @@ export async function applyRefund(
]);
if (!purchase) {
- throw Error("no purchase for the taler://refund/ URI was found");
+ throw Error(`no purchase for the taler://refund/ URI (${talerRefundUri}) was found`);
}
console.log("processing purchase for refund");
diff --git a/src/util/taleruri-test.ts b/src/util/taleruri-test.ts
index de4a90697..052581a91 100644
--- a/src/util/taleruri-test.ts
+++ b/src/util/taleruri-test.ts
@@ -96,7 +96,7 @@ test("taler pay url parsing: complex path prefix", t => {
t.is(r1.sessionId, undefined);
});
-test("taler pay url parsing: complex path prefix and instance", t => {
+test("taler pay uri parsing: complex path prefix and instance", t => {
const url1 = "taler://pay/example.com/mypfx%2Fpublic/foo/myorder";
const r1 = parsePayUri(url1);
if (!r1) {
@@ -107,7 +107,18 @@ test("taler pay url parsing: complex path prefix and instance", t => {
t.is(r1.orderId, "myorder");
});
-test("taler pay url parsing: non-https #1", t => {
+test("taler refund uri parsing: non-https #1", t => {
+ const url1 = "taler://refund/example.com/-/-/myorder?insecure=1";
+ const r1 = parseRefundUri(url1);
+ if (!r1) {
+ t.fail();
+ return;
+ }
+ t.is(r1.merchantBaseUrl, "http://example.com/public/");
+ t.is(r1.orderId, "myorder")
+});
+
+test("taler pay uri parsing: non-https #1", t => {
const url1 = "taler://pay/example.com/-/-/myorder?insecure=1";
const r1 = parsePayUri(url1);
if (!r1) {
diff --git a/src/util/taleruri.ts b/src/util/taleruri.ts
index 1b4e4352b..8ad79669f 100644
--- a/src/util/taleruri.ts
+++ b/src/util/taleruri.ts
@@ -95,13 +95,12 @@ export function classifyTalerUri(s: string): TalerUriType {
return TalerUriType.TalerNotifyReserve;
}
return TalerUriType.Unknown;
-
}
export function getOrderDownloadUrl(merchantBaseUrl: string, orderId: string) {
const u = new URL("proposal", merchantBaseUrl);
u.searchParams.set("order_id", orderId);
- return u.href
+ return u.href;
}
export function parsePayUri(s: string): PayUriResult | undefined {
@@ -208,7 +207,7 @@ export function parseRefundUri(s: string): RefundUriResult | undefined {
return undefined;
}
- const path = s.slice(pfx.length);
+ const [path, search] = s.slice(pfx.length).split("?");
let [host, maybePath, maybeInstance, orderId] = path.split("/");
@@ -236,10 +235,14 @@ export function parseRefundUri(s: string): RefundUriResult | undefined {
maybeInstancePath = `instances/${maybeInstance}/`;
}
- const merchantBaseUrl = "https://" + host +
- "/" +
- maybePath +
- maybeInstancePath
+ let protocol = "https";
+ const searchParams = new URLSearchParams(search);
+ if (searchParams.get("insecure") === "1") {
+ protocol = "http";
+ }
+
+ const merchantBaseUrl =
+ `${protocol}://${host}/` + maybePath + maybeInstancePath;
return {
merchantBaseUrl,
diff --git a/src/wallet.ts b/src/wallet.ts
index a89d2d567..32a92cee0 100644
--- a/src/wallet.ts
+++ b/src/wallet.ts
@@ -248,6 +248,31 @@ export class Wallet {
n.type === NotificationType.WaitingForRetry &&
n.numGivingLiveness == 0
) {
+ logger.trace("no liveness-giving operations left, returning");
+ resolve();
+ }
+ });
+ this.runRetryLoop().catch(e => {
+ console.log("exception in wallet retry loop");
+ reject(e);
+ });
+ });
+ await p;
+ }
+
+ /**
+ * Run the wallet until there are no more pending operations that give
+ * liveness left. The wallet will be in a stopped state when this function
+ * returns without resolving to an exception.
+ */
+ public async runUntilDoneAndStop(): Promise<void> {
+ const p = new Promise((resolve, reject) => {
+ // Run this asynchronously
+ this.addNotificationListener(n => {
+ if (
+ n.type === NotificationType.WaitingForRetry &&
+ n.numGivingLiveness == 0
+ ) {
logger.trace("no liveness-giving operations left, stopping");
this.stop();
}