gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] [taler-wallet-core] branch master updated: taler URI parsin


From: gnunet
Subject: [GNUnet-SVN] [taler-wallet-core] branch master updated: taler URI parsing
Date: Wed, 02 Oct 2019 10:52:44 +0200

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 3f6d3d18 taler URI parsing
3f6d3d18 is described below

commit 3f6d3d186bf6960951b16eb1ffac160c5d02195d
Author: Florian Dold <address@hidden>
AuthorDate: Wed Oct 2 14:21:31 2019 +0530

    taler URI parsing
    
    * add support for non-https taler://pay URIs
    * implement path prefix properly
---
 src/taleruri-test.ts | 44 ++++++++++++++++++++++++++++++++++++++++++--
 src/taleruri.ts      | 10 ++++++++--
 2 files changed, 50 insertions(+), 4 deletions(-)

diff --git a/src/taleruri-test.ts b/src/taleruri-test.ts
index 8b5828b7..bf4e9d49 100644
--- a/src/taleruri-test.ts
+++ b/src/taleruri-test.ts
@@ -86,7 +86,7 @@ test("taler pay url parsing: instance", (t) => {
     t.fail();
     return;
   }
-  t.is(r1.downloadUrl, 
"https://example.com/instances/myinst/public/proposal?order_id=myorder";);
+  t.is(r1.downloadUrl, 
"https://example.com/public/instances/myinst/proposal?order_id=myorder";);
 });
 
 
@@ -97,7 +97,47 @@ test("taler pay url parsing: path prefix and instance", (t) 
=> {
     t.fail();
     return;
   }
-  t.is(r1.downloadUrl, 
"https://example.com/mypfx/instances/myinst/public/proposal?order_id=myorder";);
+  t.is(r1.downloadUrl, 
"https://example.com/mypfx/instances/myinst/proposal?order_id=myorder";);
+});
+
+test("taler pay url parsing: complex path prefix", (t) => {
+  const url1 = "taler://pay/example.com/mypfx%2Fpublic/-/myorder";
+  const r1 = parsePayUri(url1);
+  if (!r1) {
+    t.fail();
+    return;
+  }
+  t.is(r1.downloadUrl, 
"https://example.com/mypfx/public/proposal?order_id=myorder";);
+});
+
+test("taler pay url parsing: complex path prefix and instance", (t) => {
+  const url1 = "taler://pay/example.com/mypfx%2Fpublic/foo/myorder";
+  const r1 = parsePayUri(url1);
+  if (!r1) {
+    t.fail();
+    return;
+  }
+  t.is(r1.downloadUrl, 
"https://example.com/mypfx/public/instances/foo/proposal?order_id=myorder";);
+});
+
+test("taler pay url parsing: non-https #1", (t) => {
+  const url1 = "taler://pay/example.com/-/-/myorder?insecure=1";
+  const r1 = parsePayUri(url1);
+  if (!r1) {
+    t.fail();
+    return;
+  }
+  t.is(r1.downloadUrl, "http://example.com/public/proposal?order_id=myorder";);
+});
+
+test("taler pay url parsing: non-https #2", (t) => {
+  const url1 = "taler://pay/example.com/-/-/myorder?insecure=2";
+  const r1 = parsePayUri(url1);
+  if (!r1) {
+    t.fail();
+    return;
+  }
+  t.is(r1.downloadUrl, "https://example.com/public/proposal?order_id=myorder";);
 });
 
 
diff --git a/src/taleruri.ts b/src/taleruri.ts
index 0d68621b..0af5c4c9 100644
--- a/src/taleruri.ts
+++ b/src/taleruri.ts
@@ -61,6 +61,7 @@ export function parseWithdrawUri(s: string): 
WithdrawUriResult | undefined {
 
 export function parsePayUri(s: string): PayUriResult | undefined {
   const parsedUri = new URI(s);
+  const query: any = parsedUri.query(true);
   if (parsedUri.scheme() === "http" || parsedUri.scheme() === "https") {
     return {
       downloadUrl: s,
@@ -96,7 +97,7 @@ export function parsePayUri(s: string): PayUriResult | 
undefined {
   }
 
   if (maybePath === "-") {
-    maybePath = "";
+    maybePath = "public/";
   } else {
     maybePath = decodeURIComponent(maybePath) + "/";
   }
@@ -105,8 +106,13 @@ export function parsePayUri(s: string): PayUriResult | 
undefined {
     maybeInstancePath = `instances/${maybeInstance}/`;
   }
 
+  let protocol = "https";
+  if (query["insecure"] === "1") {
+    protocol = "http";
+  }
+
   const downloadUrl = new URI(
-    "https://"; + host + "/" + decodeURIComponent(maybePath) + 
maybeInstancePath + "public/proposal",
+    protocol + "://" + host + "/" + decodeURIComponent(maybePath) + 
maybeInstancePath + "proposal",
   )
     .addQuery({ order_id: orderId })
     .href();

-- 
To stop receiving notification emails like this one, please contact
address@hidden.



reply via email to

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