From e75a218a7e90ccaddacbacf7e5fe888ab0874332 Mon Sep 17 00:00:00 2001 From: Damien Mat Date: Fri, 22 May 2020 11:59:18 +0200 Subject: [PATCH] [caissedepargne] Manage BrowserUnavailable at login MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit First step for login is to submit login without password and get the authentification method type before proceeding to it. For some connections, response JSON returns no auth method, and an 'AUTHENTICATION_FAILED' status right at this step. While there is a message 'Confirmez votre authentification à votre banque à distance', it is deceitful. When attempting the connection in a navigator the same reponse is given but a JS message 'erreur technique, Ce service est temporairement indisponible' is displayed as well. Hence the BrowserUnavailable error to be raised. --- modules/caissedepargne/browser.py | 7 +++++++ modules/caissedepargne/pages.py | 11 +++++++++++ 2 files changed, 18 insertions(+) diff --git a/modules/caissedepargne/browser.py b/modules/caissedepargne/browser.py index 25298febf7..65ba427bb4 100644 --- a/modules/caissedepargne/browser.py +++ b/modules/caissedepargne/browser.py @@ -705,6 +705,13 @@ def do_new_login(self, data): if self.response.headers.get('Page_Erreur', '') == 'INDISPO': raise BrowserUnavailable() + pre_login_status = self.page.get_wrong_pre_login_status() + if pre_login_status == 'AUTHENTICATION_FAILED': + # failing at this step means no password has been submitted yet + # and no auth method type cannot be recovered + # corresponding to 'erreur technique' on website + raise BrowserUnavailable() + authentication_method = self.page.get_authentication_method_type() self.do_authentication_validation( authentication_method=authentication_method, diff --git a/modules/caissedepargne/pages.py b/modules/caissedepargne/pages.py index 153f78dc76..dee24d0320 100644 --- a/modules/caissedepargne/pages.py +++ b/modules/caissedepargne/pages.py @@ -120,6 +120,17 @@ class AuthenticationMethodPage(JsonPage): def get_validation_id(self): return Dict('id')(self.doc) + def get_wrong_pre_login_status(self): + if ( + not Dict('step/validationUnits', default=None)(self.doc) + and not Dict('validationUnits', default=None)(self.doc) + ): + # 'validationUnits' informs about auth method + # not having any is faulty for the connection + status = self.doc['response']['status'] + assert status in ('AUTHENTICATION_FAILED',), 'Unhandled status when checking if authentication method is informed: %s' % status + return status + @property def validation_units(self): units = Coalesce( -- GitLab