diff --git a/fints/client.py b/fints/client.py index 213972a..09a701c 100644 --- a/fints/client.py +++ b/fints/client.py @@ -1273,6 +1273,14 @@ def __init__(self, bank_identifier, user_id, pin, server, customer_id=None, tan_ self._bootstrap_mode = True super().__init__(bank_identifier=bank_identifier, user_id=user_id, customer_id=customer_id, *args, **kwargs) + def __enter__(self): + retval = super().__enter__() + # The bootstrap (fetch_tan_mechanisms(), get_tan_media()) is done + # without a standing dialog: errors like 9075 are not expected anymore + # once the standing dialog has been initialized + self._bootstrap_mode = False + return retval + def _new_dialog(self, lazy_init=False): if self.pin is None: enc = None diff --git a/tests/conftest.py b/tests/conftest.py index d584e8f..1856bbb 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -50,6 +50,18 @@ def make_answer(self, dialog_id, message): result = [] + hkidn_user = re.search(rb"'HKIDN:\d+:2\+280:12345678\+([^+]+)\+", message) + if hkidn_user: + datadict['user'] = hkidn_user.group(1) + + # Some banks require a strong customer authentication for fetching + # the transactions + hkkaz_sca = re.search(rb"'HKKAZ:(\d+):\d+\+", message) + if hkkaz_sca and datadict.get('user') == b'test-sca': + result.append(b"HIRMG::2+9050::Nachricht teilweise fehlerhaft.'") + result.append("HIRMS::2:{}+9075::Starke Authentifizierung erforderlich.'".format(hkkaz_sca.group(1).decode('us-ascii')).encode('us-ascii')) + return b"".join(result) + result.append(b"HIRMG::2+0010::Nachricht entgegengenommen'") hkvvb = re.search(rb"'HKVVB:(\d+):3\+(\d+)\+(\d+)", message) diff --git a/tests/test_client.py b/tests/test_client.py index f602e4f..98e4d4d 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -1,5 +1,6 @@ from fints.client import FinTS3PinTanClient, TransactionResponse, NeedTANResponse, ResponseStatus, NeedRetryResponse -from fints.exceptions import FinTSClientPINError, FinTSClientTemporaryAuthError +from fints.exceptions import FinTSClientPINError, FinTSClientTemporaryAuthError, FinTSSCARequiredError +from datetime import date from decimal import Decimal import pytest @@ -29,6 +30,22 @@ def test_get_information(fints_client): assert information["bank"]["name"] == 'Test Bank' +def test_sca_required(fints_server): + """A 9075 response to a command raises FinTSSCARequiredError, also for a + client that never called get_tan_media()""" + client = FinTS3PinTanClient( + '12345678', + 'test-sca', + '1234', + fints_server, + product_id="TEST-123", product_version="1.2.3", + ) + with pytest.raises(FinTSSCARequiredError): + with client: + accounts = client.get_sepa_accounts() + client.get_transactions(accounts[0], date(2026, 10, 1), date(2026, 10, 2)) + + def test_pin_wrong(fints_server): client = FinTS3PinTanClient( '12345678',