Commit 74cf825f authored by Stephane Sobucki's avatar Stephane Sobucki Committed by Vincent A

[hsbc] Handle more login errors

Handle more login error messages, updated XPath for errors in
LoginPage's `on_load()` method.

Additionaly, added login errors check in `end_login()` to avoid
FormNotFound exception due to a blocked account access.
parent 4f22e3e4
......@@ -32,7 +32,10 @@
from woob.tools.capabilities.bank.transactions import sorted_transactions, keep_only_card_transactions
from woob.tools.compat import parse_qsl, urlparse
from woob.tools.value import Value
from woob.exceptions import ActionNeeded, BrowserIncorrectPassword, BrowserUnavailable, BrowserQuestion
from woob.exceptions import (
BrowserIncorrectPassword, BrowserPasswordExpired, BrowserUnavailable,
BrowserUserBanned, BrowserQuestion,
)
from woob.browser import URL, need_login, TwoFactorBrowser
from woob.browser.exceptions import HTTPNotFound
from woob.capabilities.base import find_object
......@@ -170,6 +173,18 @@ def handle_otp(self):
self.page.login_with_secure_key(self.secret, otp)
self.end_login()
def check_login_error(self):
error_msg = self.page.get_error()
if error_msg:
if 'Please click Reset Credentials' in error_msg or 'Please reset your HSBC Secure Key' in error_msg:
raise BrowserPasswordExpired(error_msg)
elif 'Please retry in 30 minutes' in error_msg:
raise BrowserUserBanned(error_msg)
raise AssertionError('Unhandled error at login: %s' % error_msg)
def init_login(self):
self.session.cookies.clear()
......@@ -192,12 +207,7 @@ def init_login(self):
if no_secure_key_link:
self.location(no_secure_key_link)
else:
error = self.page.get_error()
if error and 'Please click Reset Credentials' in error:
raise ActionNeeded(error)
elif error:
raise AssertionError('Unhandled error at login: %s' % error)
self.check_login_error()
self.check_interactive()
raise BrowserQuestion(
Value(
......@@ -211,6 +221,7 @@ def init_login(self):
def end_login(self):
for _ in range(3):
if self.login.is_here():
self.check_login_error()
self.page.useless_form()
# This wonderful website has 2 baseurl with only one difference: the 's' at the end of 'client'
......
......@@ -559,17 +559,18 @@ def logged(self):
return False
def on_load(self):
for message in self.doc.xpath('//div[has-class("csPanelErrors")]'):
for message in self.doc.xpath('//div[@class="mainBloc"]/*[@class="error"]'): # Sometimes <p>, sometimes <div>
error_msg = CleanText('.')(message)
if any(
msg in error_msg
for msg in [
'Please enter valid credentials for memorable answer and password.',
'Please enter a valid Username.',
'mot de passe invalide',
'Log on error', # wrong otp
]
):
error_at_login_regex = re.compile(
'Please enter valid credentials for memorable answer and password.'
+ '|Please enter a valid Username.'
+ '|mot de passe invalide'
+ '|Log on error' # wrong otp
)
if error_at_login_regex.search(error_msg):
raise BrowserIncorrectPassword(error_msg)
else:
raise BrowserUnavailable(error_msg)
......
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