Commit 7d821176 authored by Maxime Gasselin's avatar Maxime Gasselin Committed by Vincent A

[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.
parent bf57938a
......@@ -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 @@ class BanquePopulaire(LoginBrowser):
'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 @@ class BanquePopulaire(LoginBrowser):
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']},
......
......@@ -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):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment