From 05824e24787620905a8184ef6f02ed89d3f704a9 Mon Sep 17 00:00:00 2001 From: Jerome Berthier Date: Fri, 5 Jul 2019 15:22:04 +0200 Subject: [PATCH] [banquepopulaire] rework previous patch, raise BrowserIncorrectPassword only in a specific case The current source code leads to false positive BrowserIncorrectPassword. Some accounts got an exception when fetching history or cards coming, which is correctly handled by the module using ErrorPage. This patch restricts the BrowserIncorrectPassword 'hack' to the login stage, as it is the only case we want to catch. --- modules/banquepopulaire/browser.py | 16 ++++++++++------ modules/banquepopulaire/pages.py | 4 ---- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/modules/banquepopulaire/browser.py b/modules/banquepopulaire/browser.py index 11261dd7f3..1c9e7835db 100644 --- a/modules/banquepopulaire/browser.py +++ b/modules/banquepopulaire/browser.py @@ -187,10 +187,6 @@ def __init__(self, website, *args, **kwargs): self.investments = {} - # HACK, the website may crash with legacy passwords (legacy means not only digits) - # If the website crashes and if we have a legacy password, we raise WrongPass instead of BrowserUnavailable - self.is_password_only_digits = None - def deinit(self): super(BanquePopulaire, self).deinit() self.linebourse.deinit() @@ -218,9 +214,17 @@ def do_login(self): if self.home_page.is_here(): return - self.is_password_only_digits = self.password.isdigit() + try: + self.page.login(self.username, self.password) + except BrowserUnavailable as ex: + # HACK: some accounts with legacy password fails (legacy means not only digits). + # The website crashes, even on a web browser. + # So, if we get a specific exception AND if we have a legacy password, + # we raise WrongPass instead of BrowserUnavailable. + if 'Cette page est indisponible' in ex.message and not self.password.isdigit(): + raise BrowserIncorrectPassword() + raise - self.page.login(self.username, self.password) if self.login_page.is_here(): raise BrowserIncorrectPassword() if 'internetRescuePortal' in self.url: diff --git a/modules/banquepopulaire/pages.py b/modules/banquepopulaire/pages.py index afa9ef4e52..9186fc040c 100644 --- a/modules/banquepopulaire/pages.py +++ b/modules/banquepopulaire/pages.py @@ -271,10 +271,6 @@ def on_load(self): class ErrorPage(LoggedPage, MyHTMLPage): def on_load(self): - # HACK: some accounts with legacy password fails, people needs to update it - if not self.browser.is_password_only_digits: - raise BrowserIncorrectPassword() - if CleanText('//script[contains(text(), "momentanément indisponible")]')(self.doc): raise BrowserUnavailable(u"Le service est momentanément indisponible") elif CleanText('//h1[contains(text(), "Cette page est indisponible")]')(self.doc): -- GitLab