Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion fints/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -1579,7 +1579,9 @@ def send_tan(self, challenge: NeedTANResponse, tan: str):
def _process_response(self, dialog, segment, response):
if response.code == '3920' and not self.bank_identifier == ING_BANK_IDENTIFIER:
self.allowed_security_functions = list(response.parameters)
if self.selected_security_function is None or not self.selected_security_function in self.allowed_security_functions:
# '999' counts as "not chosen yet": fetch_tan_mechanisms() sets it as a placeholder, and some banks
# (e.g. Commerzbank photoTAN) list '999' among the allowed functions next to a two-step one (#212).
if self.selected_security_function in (None, '999') or self.selected_security_function not in self.allowed_security_functions:
# Select the first available twostep security_function that we support
for security_function, parameter in self.get_tan_mechanisms().items():
if security_function == '999':
Expand Down
2 changes: 1 addition & 1 deletion fints/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ def minimal_interactive_cli_bootstrap(client):
"""
# Fetch available TAN mechanisms by the bank, if we don't know it already. If the client was created with cached data,
# the function is already set.
if not client.get_current_tan_mechanism():
if client.get_current_tan_mechanism() in (None, '999'):
client.fetch_tan_mechanisms()
mechanisms = list(client.get_tan_mechanisms().items())
if len(mechanisms) > 1:
Expand Down
41 changes: 41 additions & 0 deletions tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,3 +227,44 @@ def test_get_transactions(fints_client):

assert len(transactions) == 3
assert transactions[0].data['amount'].amount == Decimal('182.34')


class _ClosedDialog:
open = False


def _response_3920(*security_functions):
from fints.formals import Response
return Response(code='3920', reference_element=None,
text='Zugelassene Ein- und Zwei-Schritt-Verfahren für den Benutzer.',
parameters=list(security_functions))


def test_3920_replaces_onestep_placeholder(fints_client):
# Commerzbank photoTAN (#212): fetch_tan_mechanisms() sets '999' as a placeholder,
# then the bank allows a two-step method *and* '999'. The client must not stay at '999'.
fints_client.fetch_tan_mechanisms()
fints_client.set_tan_mechanism('999')

fints_client._process_response(_ClosedDialog(), None, _response_3920('942', '999'))

assert fints_client.get_current_tan_mechanism() == '942'
assert fints_client.is_challenge_structured() in (True, False)


def test_3920_keeps_onestep_if_only_onestep_allowed(fints_client):
fints_client.fetch_tan_mechanisms()
fints_client.set_tan_mechanism('999')

fints_client._process_response(_ClosedDialog(), None, _response_3920('999'))

assert fints_client.get_current_tan_mechanism() == '999'


def test_3920_keeps_explicitly_chosen_twostep(fints_client):
fints_client.fetch_tan_mechanisms()
fints_client.set_tan_mechanism('962')

fints_client._process_response(_ClosedDialog(), None, _response_3920('942', '962', '999'))

assert fints_client.get_current_tan_mechanism() == '962'