]> git.ipfire.org Git - thirdparty/python-fints.git/commitdiff
Test wrong authentication data
authorHenryk Plötz <henryk@ploetzli.ch>
Mon, 10 Sep 2018 17:31:07 +0000 (19:31 +0200)
committerRaphael Michel <mail@raphaelmichel.de>
Mon, 3 Dec 2018 18:34:29 +0000 (19:34 +0100)
tests/conftest.py
tests/test_client.py

index 509a524907d0389d515e78168f723cd8c5c9e578..0beb196951ca501bba2e3c23e856ef93f2b70cbd 100644 (file)
@@ -34,6 +34,18 @@ def fints_server():
         def make_answer(self, dialog_id, message):
             datadict = dialogs[dialog_id]
 
+            pin = None
+            tan = None
+            pinmatch = re.search(rb"HNSHA:\d+:\d+\+[^+]*\+[^+]*\+([^:+?']+)(?::([^:+?']+))?'", message)
+            if pinmatch:
+                pin = pinmatch.group(1).decode('us-ascii')
+
+                if pinmatch.group(2):
+                    tan = pinmatch.group(2).decode('us-ascii')
+
+            if pin != '1234':
+                return "HIRMG::2+9910::Pin ungültig'".encode('utf-8')
+
             result = []
 
             result.append(b"HIRMG::2+0010::Nachricht entgegengenommen'")
@@ -90,7 +102,7 @@ def fints_server():
                                 'amount': amountmatch.group(1),
                             }
                             result.append("HIRMS::2:{}+0030::Auftragsfreigabe erforderlich'".format(hktan.group(1).decode('us-ascii')).encode('us-ascii'))
-                            result.append("HITAN::{}:{}+2++{}+Geben Sie die TAN an'".format(hktan.group(2).decode('us-ascii'), hktan.group(1).decode('us-ascii'), ref).encode('us-ascii'))
+                            result.append("HITAN::{}:{}+2++{}+Geben Sie TAN 123456 an'".format(hktan.group(2).decode('us-ascii'), hktan.group(1).decode('us-ascii'), ref).encode('us-ascii'))
 
             hktan = re.search(rb"'HKTAN:(\d+):(\d+)\+2\+\+\+\+([^+]+)\+", message)
             if hktan:
@@ -100,7 +112,10 @@ def fints_server():
 
                 task = datadict.setdefault('pending', {}).get(ref, None)
                 if task:
-                    result.append("HIRMS::2:{}+0010::Transfer {} to {} re {}'".format(segno, task['amount'], task['recv'], repr(task['memo']).replace("'", "?'")).encode('iso-8859-1'))
+                    if tan == '123456':
+                        result.append("HIRMS::2:{}+0010::Transfer {} to {} re {}'".format(segno, task['amount'], task['recv'], repr(task['memo']).replace("'", "?'")).encode('iso-8859-1'))
+                    else:
+                        result.append("HIRMS::2:{}+9941::TAN ungültig'".format(segno).encode('iso-8859-1'))
 
                 datadict['pending'].pop(ref, None)
 
index 8fd1f48ef4ab6c261baef4bba30d688fd89e1b65..4570d3469223320851f5d3066f2a5177864bf8a7 100644 (file)
@@ -1,4 +1,5 @@
 from fints.client import FinTS3PinTanClient, TransactionResponse, NeedTANResponse, ResponseStatus
+from fints.exceptions import FinTSClientPINError
 from decimal import Decimal
 import pytest
 
@@ -23,6 +24,26 @@ def test_get_information(fints_client):
 
     assert information["bank"]["name"] == 'Test Bank'
 
+def test_pin_wrong(fints_server):
+    client = FinTS3PinTanClient(
+        '12345678',
+        'test1',
+        '99999',
+        fints_server,
+    )
+    with pytest.raises(FinTSClientPINError):
+        with client:
+            pass
+
+    assert client.pin.blocked
+
+    with pytest.raises(Exception):
+        with client:
+            pass
+
+    with pytest.raises(Exception, match="Refusing"):
+        str(client.pin)
+
 def test_resume(fints_client, fints_server):
     with fints_client:
         system_id = fints_client.system_id
@@ -103,3 +124,19 @@ def test_transfer_2step(fints_client):
         b = fints_client.send_tan(a, '123456')
         assert b.status == ResponseStatus.SUCCESS
         assert b.responses[0].text == "Transfer 2.34 to DE111234567800000002 re 'Test transfer 2step'"
+
+def test_tan_wrong(fints_client):
+    with fints_client:
+        accounts = fints_client.get_sepa_accounts()
+        a = fints_client.simple_sepa_transfer(
+            accounts[0],
+            'DE111234567800000002',
+            'GENODE00TES',
+            'Test Receiver',
+            Decimal('2.34'),
+            'Test Sender',
+            'Test transfer 2step'
+        )
+
+        b = fints_client.send_tan(a, '99881')
+        assert b.status == ResponseStatus.ERROR