[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[taler-bank] branch master updated: Improve Payto parser
From: |
gnunet |
Subject: |
[taler-bank] branch master updated: Improve Payto parser |
Date: |
Tue, 17 Nov 2020 15:53:00 +0100 |
This is an automated email from the git hooks/post-receive script.
ms pushed a commit to branch master
in repository bank.
The following commit(s) were added to refs/heads/master by this push:
new 354f6f6 Improve Payto parser
354f6f6 is described below
commit 354f6f6608eb14e8fd27669f08d8eabacd35098f
Author: MS <ms@taler.net>
AuthorDate: Tue Nov 17 15:52:51 2020 +0100
Improve Payto parser
---
talerbank/app/static/web-common | 2 +-
talerbank/app/tests.py | 29 ++++++++++++++++++++---------
talerbank/app/views.py | 24 +++++++++++++-----------
3 files changed, 34 insertions(+), 21 deletions(-)
diff --git a/talerbank/app/static/web-common b/talerbank/app/static/web-common
index 2457613..eaefc57 160000
--- a/talerbank/app/static/web-common
+++ b/talerbank/app/static/web-common
@@ -1 +1 @@
-Subproject commit 2457613ecc8b8971bd47119b1a02a2f290bb4830
+Subproject commit eaefc57f2ea5434ad6b7f1c11ee4daa0fc92c76c
diff --git a/talerbank/app/tests.py b/talerbank/app/tests.py
index b5c926e..86e5998 100644
--- a/talerbank/app/tests.py
+++ b/talerbank/app/tests.py
@@ -336,17 +336,28 @@ class ReservePubExtractionTestCase(TestCase):
class PaytoParseTestCase(TestCase):
- def test_payto_parse(self):
+ def test_payto_wrong_protocol(self):
+ self.assertRaises(Exception, PaytoParse, "http://foo/bar")
+ def test_payto_with_port_number(self):
+ parsed = PaytoParse("payto://iban/localhost:1234/account")
+ self.assertEqual(parsed.bank, "localhost:1234")
+ def test_payto_malformed(self):
+ self.assertRaises(Exception, PaytoParse, "payto:foo/bar")
+ def test_payto_noamount(self):
parsed = PaytoParse(
-
"payto://x-taler-bank/bank.int.taler.net/Exchange?subject=0T096A11M57GWGG0P6ZM9Z8G5829BFJFH2AN9R5T80FJ931DX7GG&amount=EUR:1"
- )
- self.assertTrue("Exchange" == parsed.account)
- self.assertTrue(
- "0T096A11M57GWGG0P6ZM9Z8G5829BFJFH2AN9R5T80FJ931DX7GG" ==
parsed.subject
+
"payto://x-taler-bank/bank.int.taler.net/Exchange?message=0T096A11M57GWGG0P6ZM9Z8G5829BFJFH2AN9R5T80FJ931DX7GG"
)
- self.assertTrue(parsed.amount.value == 1)
- self.assertTrue(parsed.amount.fraction == 0)
- self.assertTrue(parsed.amount.currency == "EUR")
+ def test_payto_parse(self):
+ parsed = PaytoParse(
+
"payto://x-taler-bank/bank.int.taler.net/Exchange?message=0T096A11M57GWGG0P6ZM9Z8G5829BFJFH2AN9R5T80FJ931DX7GG&amount=EUR:1"
+ )
+ self.assertEqual("Exchange", parsed.target)
+
self.assertEqual("0T096A11M57GWGG0P6ZM9Z8G5829BFJFH2AN9R5T80FJ931DX7GG",
parsed.message)
+ self.assertEqual(parsed.amount.value, 1)
+ self.assertEqual(parsed.amount.fraction, 0)
+ self.assertEqual(parsed.amount.currency, "EUR")
+ self.assertEqual(parsed.authority, "x-taler-bank")
+ self.assertEqual(parsed.bank, "bank.int.taler.net")
class PublicAccountsTestCase(TestCase):
diff --git a/talerbank/app/views.py b/talerbank/app/views.py
index fc1eb54..1ac0c99 100644
--- a/talerbank/app/views.py
+++ b/talerbank/app/views.py
@@ -102,17 +102,19 @@ def allow_origin_star(view_func):
class PaytoParse:
def __init__(self, payto_uri):
- parsed_payto = urlparse(payto_uri)
- if parsed_payto.scheme != "payto":
- raise Exception("Bad Payto URI: '%s'" % payto_uri)
- path_as_list = parsed_payto.path.split("/")
- if len(path_as_list) == 0:
- raise Exception("No account/user name found: '%s'" % payto_uri)
- self.account = path_as_list[-1]
- params = dict(parse_qsl(parsed_payto.query))
- self.subject = params.get("subject")
- self.amount = Amount.parse(params.get("amount"))
-
+ obj = urlparse(payto_uri)
+ path = obj.path.split("/")
+ if obj.scheme != "payto" or \
+ len(path) != 3 or \
+ not obj.netloc or \
+ not re.match("^payto://", payto_uri):
+ raise Exception(f"Bad Payto URI: {payto_uri}")
+ self.target = path.pop()
+ self.bank = path.pop()
+ self.authority = obj.netloc
+ params = dict(parse_qsl(obj.query))
+ self.message = params.get("message")
+ self.amount = Amount.parse(params.get("amount")) if "amount" in params
else None
##
# Exception raised upon failing login.
--
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [taler-bank] branch master updated: Improve Payto parser,
gnunet <=