[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] [taler-bank] branch master updated (c68833b -> 477f3bc)
From: |
gnunet |
Subject: |
[GNUnet-SVN] [taler-bank] branch master updated (c68833b -> 477f3bc) |
Date: |
Wed, 15 Nov 2017 12:19:58 +0100 |
This is an automated email from the git hooks/post-receive script.
marcello pushed a change to branch master
in repository bank.
from c68833b document extra steps I had to take
new 89a3315 withdraw testcase -- missing exchange interaction mocking
new 477f3bc check withdrawing POSTs the expected data to exchange
The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
talerbank/app/tests.py | 59 +++++++++++++++++++++++++++++++++++++++++---------
talerbank/app/views.py | 15 +++----------
2 files changed, 52 insertions(+), 22 deletions(-)
diff --git a/talerbank/app/tests.py b/talerbank/app/tests.py
index 84ab430..55bea32 100644
--- a/talerbank/app/tests.py
+++ b/talerbank/app/tests.py
@@ -19,6 +19,7 @@ from django.test import TestCase, Client
from django.core.urlresolvers import reverse
from django.conf import settings
from django.contrib.auth.models import User
+from mock import patch, MagicMock, Mock
from .models import BankAccount, BankTransaction
from . import urls
from .views import wire_transfer
@@ -30,28 +31,39 @@ def clear_db():
BankTransaction.objects.all().delete()
class WithdrawTestCase(TestCase):
- # FIXME tbd
def setUp(self):
user_bankaccount = BankAccount(
user=User.objects.create_user(username="test_user",
- password="test_password"))
+ password="test_password"),
+ account_no=100)
user_bankaccount.save()
+
+ exchange_bankaccount = BankAccount(
+ user=User.objects.create_user(username="test_exchange",
+ password=""),
+ account_no=99)
+ exchange_bankaccount.save()
- def test_withdraw(self):
+ @patch('hashlib.new') # Need to patch update() and hexdigest() methods.
+ @patch('requests.post')
+ @patch('time.time')
+ def test_withdraw(self, mocked_time, mocked_post, mocked_hashlib):
client = Client()
+ wire_details = '''{
+ "test": {
+ "type":"test",
+ "account_number":99,
+ "bank_uri":"http://bank.example/";,
+ "name":"example"
+ }
+ }'''
params = {
"amount_value": "0",
"amount_fraction": "1",
"amount_currency": settings.TALER_CURRENCY,
"exchange": "http://exchange.example/";,
"reserve_pub": "UVZ789",
- "wire_details": '''{
- "test":
- {"type":"test"},
- {"account_number":"99"},
- {"bank_uri":"http://bank.example/"},
- {"name":"example"}
- }'''
+ "wire_details": wire_details.replace("\n", "").replace(" ", "")
}
client.post(reverse("login", urlconf=urls),
{"username": "test_user",
@@ -59,6 +71,33 @@ class WithdrawTestCase(TestCase):
response = client.get(reverse("pin-question", urlconf=urls),
params)
+ # We mock hashlib in order to fake the CAPTCHA.
+ hasher = MagicMock()
+ hasher.hexdigest = MagicMock()
+ hasher.hexdigest.return_value = "0"
+ mocked_hashlib.return_value = hasher
+ post = MagicMock()
+ post.status_code = 200
+ mocked_post.return_value = post
+ mocked_time.return_value = 0
+ response = client.post(reverse("pin-verify", urlconf=urls),
+ {"pin_1": "0"})
+ expected_json = {
+ "reserve_pub": "UVZ789",
+ "execution_date": "/Date(0)/",
+ "sender_account_details": {
+ "type": "test",
+ "bank_uri": "http://testserver/";,
+ "account_number": 100
+ },
+ "transfer_details": {"timestamp": 0},
+ "amount": {
+ "value": 0,
+ "fraction": 1,
+ "currency": settings.TALER_CURRENCY}
+ }
+
mocked_post.assert_called_with("http://exchange.example/admin/add/incoming";,
+ json=expected_json)
class RegisterTestCase(TestCase):
"""User registration"""
diff --git a/talerbank/app/views.py b/talerbank/app/views.py
index 58580af..8900c87 100644
--- a/talerbank/app/views.py
+++ b/talerbank/app/views.py
@@ -15,16 +15,6 @@
# @author Marcello Stanisci
# @author Florian Dold
-# wire_transfer() needs to be wrapped in such a way that
-# any possible exception is caught in *one* place. It is used when:
-#
-# 1. withdrawing is finalized (pin_tan_verify())
-# 2. a new user is registered (register())
-# 3. the exchange moves money to account X (add_incoming())
-#
-# NOTE: this abstracting function needs _sometimes_ to update the
-# session, depending on the situation.
-
from urllib.parse import urljoin
from functools import wraps
import json
@@ -178,9 +168,10 @@ def pin_tan_verify(request):
hasher = hashlib.new("sha1")
hasher.update(settings.SECRET_KEY.encode("utf-8"))
# pin_0 is the answer given by the user
- hasher.update(request.POST.get("pin_0").encode("utf-8"))
+ hasher.update(request.POST.get("pin_0" ,"").encode("utf-8"))
hashed_attempt = hasher.hexdigest()
if hashed_attempt != request.POST.get("pin_1"):
+ LOGGER.warning("Wrong CAPTCHA answer: %s vs %s" %
(type(hashed_attempt), type(request.POST.get("pin_1"))))
request.session["captcha_failed"] = True
return redirect(request.POST.get("question_url", "profile"))
# Check the session is a "pin tan" one
@@ -193,7 +184,7 @@ def pin_tan_verify(request):
BankAccount.objects.get(user=request.user),
exchange_bank_account,
request.session["reserve_pub"],
- request,
+ request=request,
session_expand=dict(debt_limit=True))
except (FVE, RFVE) as exc:
LOGGER.warning("Not a withdrawing session")
--
To stop receiving notification emails like this one, please contact
address@hidden
- [GNUnet-SVN] [taler-bank] branch master updated (c68833b -> 477f3bc),
gnunet <=