Commit 5a2f6012 authored by Jerome Berthier's avatar Jerome Berthier Committed by Romain Bignon

[creditdunord] Refactor wrong/expired password management

The code was handling authentication problems in different places.
parent 175c1fca
......@@ -36,6 +36,7 @@ class CreditDuNordBrowser(LoginBrowser):
login = URL('$',
redirect = URL('/swm/redirectCDN.html', RedirectPage)
entrypage = URL('/icd/zco/#zco', EntryPage)
......@@ -64,37 +65,25 @@ class CreditDuNordBrowser(LoginBrowser):
def do_login(self):
self.login.go().login(self.username, self.password)
if self.redirect.is_here():
if self.accounts.is_here():
expired_error =
if expired_error:
raise BrowserPasswordExpired(expired_error)
if self.login.is_here():
# Force redirection to entry page if the redirect page does not contain an url
if self.redirect.is_here():
if self.entrypage.is_here() or self.login.is_here():
error =
if error:
if 'code confidentiel à la première connexion' in error:
raise BrowserPasswordExpired(error)
raise BrowserIncorrectPassword(error)
# in case we are still on login without error message
# we'll check what's happening.
assert False, "Still on login page."
if not self.logged:
raise BrowserIncorrectPassword()
# The redirection page may contain a message
if'//head[title="Authentification"]/script[contains(text(), "_pageLabel=reinitialisation_mot_de_passe")]'):
raise BrowserPasswordExpired()
if not self.entrypage.is_here():
# The main page may contain a message as well
msg = 'vous devez modifier votre code confidentiel à la première connexion puis tous les 12 mois'
if'//b[contains(text(), "%s")]' % msg):
raise BrowserPasswordExpired(msg.capitalize())
def _iter_accounts(self):, loans_page_label=self.loans_page_label)
for a in
......@@ -97,23 +97,26 @@ class CDNVirtKeyboard(GridVirtKeyboard):
return ','.join(res)
class HTMLErrorPage(HTMLPage):
def get_error(self):
# No Coalesce here as both can be empty
return CleanText('//b[has-class("x-attentionErreurLigneHaut")]')(self.doc) or \
class RedirectPage(HTMLPage):
def check_error(self):
error = CleanText(self.doc.xpath('//script[contains(text(), "erreur")]'))(self)
if error:
error_link ='href="(.*)"', error).group(1)
error_page = self.browser.location(error_link)
err_message = CleanText('//div/b[contains(@class, "attentionErreur")]'))(self)
if err_message == "Nous n'avons pas pu vous authentifier.":
raise BrowserIncorrectPassword("Nous n'avons pas pu vous authentifier.")
assert False, 'Never seen this error message before: %s' % err_message
class EntryPage(LoggedPage, HTMLPage):
def on_load(self):
link = Regexp(CleanText('//script'), 'href="(.*)"', default='')(self.doc)
if link:
class EntryPage(LoggedPage, HTMLErrorPage):
class LoginPage(HTMLPage):
class LoginPage(HTMLErrorPage):
def login(self, username, password):
......@@ -155,9 +158,6 @@ class LoginPage(HTMLPage):
self.browser.location('/saga/authentification', data=data)
def get_error(self):
return CleanText('//b[has-class("x-attentionErreurLigneHaut")]', default="")(self.doc)
class AccountTypePage(LoggedPage, JsonPage):
def get_account_type(self):
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