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('$',
'/.*\?.*_pageLabel=page_erreur_connexion',
'/.*\?.*_pageLabel=reinitialisation_mot_de_passe',
LoginPage)
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():
self.page.check_error()
if self.accounts.is_here():
expired_error = self.page.get_password_expired()
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():
self.entrypage.go()
if self.entrypage.is_here() or self.login.is_here():
error = self.page.get_error()
if error:
if 'code confidentiel à la première connexion' in error:
raise BrowserPasswordExpired(error)
raise BrowserIncorrectPassword(error)
else:
# 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 self.page.doc.xpath('//head[title="Authentification"]/script[contains(text(), "_pageLabel=reinitialisation_mot_de_passe")]'):
raise BrowserPasswordExpired()
if not self.entrypage.is_here():
self.entrypage.go()
# 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 self.page.doc.xpath('//b[contains(text(), "%s")]' % msg):
raise BrowserPasswordExpired(msg.capitalize())
def _iter_accounts(self):
self.loans.go(account_type=self.account_type, loans_page_label=self.loans_page_label)
for a in self.page.get_list():
......
......@@ -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 \
CleanText('//div[has-class("x-attentionErreur")]/b')(self.doc)
class RedirectPage(HTMLPage):
def check_error(self):
error = CleanText(self.doc.xpath('//script[contains(text(), "erreur")]'))(self)
if error:
error_link = re.search(r'href="(.*)"', error).group(1)
error_page = self.browser.location(error_link)
err_message = CleanText(error_page.page.doc.xpath('//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:
self.browser.location(link)
class EntryPage(LoggedPage, HTMLErrorPage):
pass
class LoginPage(HTMLPage):
class LoginPage(HTMLErrorPage):
VIRTUALKEYBOARD = CDNVirtKeyboard
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