From: Henryk Plötz Date: Mon, 10 Sep 2018 17:31:07 +0000 (+0200) Subject: Test wrong authentication data X-Git-Tag: v2.0.0~1^2~38 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=aee0a5876d820f9b6f575ccc89886030bc754699;p=thirdparty%2Fpython-fints.git Test wrong authentication data --- diff --git a/tests/conftest.py b/tests/conftest.py index 509a524..0beb196 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -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) diff --git a/tests/test_client.py b/tests/test_client.py index 8fd1f48..4570d34 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -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