summaryrefslogtreecommitdiff
path: root/src/util
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/util
parentfcb0565323d3134ec2dc376700ef85a2c7b7becd (diff)
downloadwallet-core-af57a404d070500ce63ed9ed0dfce721e82e4801.tar.gz
wallet-core-af57a404d070500ce63ed9ed0dfce721e82e4801.tar.bz2
wallet-core-af57a404d070500ce63ed9ed0dfce721e82e4801.zip
fix and test case for "insecure" taler://refund URIs
Diffstat (limited to 'src/util')
-rw-r--r--src/util/taleruri-test.ts15
-rw-r--r--src/util/taleruri.ts17
2 files changed, 23 insertions, 9 deletions
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,