From 7d8211763e93461066d425ca96855096e9adeb38 Mon Sep 17 00:00:00 2001 From: Maxime Gasselin Date: Wed, 13 May 2020 11:02:50 +0200 Subject: [PATCH] [banquepopulaire] try with and without phase param New subwebistes don't need phase 1 param anymore. We think more subwebistes would have this behaviour so we decide to try the login twice without and with phase param. --- modules/banquepopulaire/browser.py | 18 +++++++++++++----- modules/banquepopulaire/pages.py | 6 +++++- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/modules/banquepopulaire/browser.py b/modules/banquepopulaire/browser.py index 98ad0db25f..e3544c1766 100644 --- a/modules/banquepopulaire/browser.py +++ b/modules/banquepopulaire/browser.py @@ -208,6 +208,7 @@ class BanquePopulaire(LoginBrowser): documents_page = URL(r'/api-bp/wapi/2.0/abonnes/current/documents/recherche-avancee', DocumentsPage) def __init__(self, website, *args, **kwargs): + self.retry_login_without_phase = False self.website = website self.BASEURL = 'https://%s' % website # this url is required because the creditmaritime abstract uses an other url @@ -357,12 +358,12 @@ def do_new_login(self): 'last_login': None, }, } - # We need to avoid to add "phase":"1" for part in bpaca website - # Maybe it will be the case for other websites + # We need to avoid to add "phase":"1" for some sub-websites # The phase information seems to be in js file and the value is not hardcode - if self.website not in ('www.ibps.bpaca.banquepopulaire.fr', ) or self.user_type != 'part': - # Here if we don't add phase":"1" we would get false wrongpass - bpcesta['phase'] = "1" + # Consequently we try the login twice with and without phase param + # Because the problem occurs during do_redirect + if not self.retry_login_without_phase: + bpcesta['phase'] = '1' params={ 'nonce': nonce, @@ -449,6 +450,13 @@ def do_new_login(self): def do_redirect(self, headers): redirect_data = self.page.get_redirect_data() + if not redirect_data and self.page.is_new_login(): + # assert to avoid infinite loop + assert not self.retry_login_without_phase, 'the login failed with and without phase 1 param' + self.retry_login_without_phase = True + self.session.cookies.clear() + return self.do_login() + self.location( redirect_data['action'], data={'SAMLResponse': redirect_data['samlResponse']}, diff --git a/modules/banquepopulaire/pages.py b/modules/banquepopulaire/pages.py index ec8b29c7cf..d5888069f8 100644 --- a/modules/banquepopulaire/pages.py +++ b/modules/banquepopulaire/pages.py @@ -368,7 +368,11 @@ class AuthenticationMethodPage(AbstractPage): BROWSER_ATTR = 'package.browser.CaisseEpargne' def get_redirect_data(self): - return Dict('response/saml2_post')(self.doc) + return Dict('response/saml2_post', default=NotAvailable)(self.doc) + + def is_new_login(self): + # We check here if we are doing a new login + return bool(Dict('step/phase/state', default=NotAvailable)(self.doc)) class AuthenticationStepPage(AbstractPage): -- GitLab