From 0de604b23831335397eeefe8da471b0173ed0344 Mon Sep 17 00:00:00 2001 From: Romain Bignon Date: Mon, 19 Nov 2018 17:11:27 +0100 Subject: [PATCH] bnporc: add parameter to disable password rotation --- modules/bnporc/enterprise/browser.py | 4 ++-- modules/bnporc/module.py | 11 +++-------- modules/bnporc/pp/browser.py | 9 ++++----- modules/bnporc/pp/pages.py | 3 +++ 4 files changed, 12 insertions(+), 15 deletions(-) diff --git a/modules/bnporc/enterprise/browser.py b/modules/bnporc/enterprise/browser.py index e7b752d27b..b644d67022 100644 --- a/modules/bnporc/enterprise/browser.py +++ b/modules/bnporc/enterprise/browser.py @@ -65,8 +65,8 @@ class BNPEnterprise(LoginBrowser): renew_pass = URL('/sommaire/PseRedirectPasswordConnect', ActionNeededPage) - def __init__(self, *args, **kwargs): - super(BNPEnterprise, self).__init__(*args, **kwargs) + def __init__(self, config, *args, **kwargs): + super(BNPEnterprise, self).__init__(config['login'].get(), config['password'].get(), *args, **kwargs) def do_login(self): self.login.go() diff --git a/modules/bnporc/module.py b/modules/bnporc/module.py index 26046535ce..803e513825 100644 --- a/modules/bnporc/module.py +++ b/modules/bnporc/module.py @@ -32,7 +32,7 @@ from weboob.capabilities.profile import CapProfile from weboob.capabilities.base import find_object from weboob.tools.backend import Module, BackendConfig -from weboob.tools.value import ValueBackendPassword, Value +from weboob.tools.value import ValueBackendPassword, Value, ValueBool from .enterprise.browser import BNPEnterprise from .company.browser import BNPCompany @@ -52,9 +52,7 @@ class BNPorcModule(Module, CapBankWealth, CapBankTransferAddRecipient, CapMessag CONFIG = BackendConfig( ValueBackendPassword('login', label=u'Numéro client', masked=False), ValueBackendPassword('password', label=u'Code secret', regexp='^(\d{6})$'), - #ValueBackendPassword('rotating_password', default='', - # label='Password to set when the allowed uses are exhausted (6 digits)', - # regexp='^(\d{6}|)$'), + ValueBool('rotating_password', label=u'Automatically renew password every 100 connections', default=False), Value('website', label='Type de compte', default='pp', choices={'pp': 'Particuliers/Professionnels', 'hbank': 'HelloBank', @@ -73,10 +71,7 @@ def __init__(self, *args, **kwargs): def create_default_browser(self): b = {'ent': BNPEnterprise, 'ent2': BNPCompany, 'pp': BNPPartPro, 'hbank': HelloBank} self.BROWSER = b[self.config['website'].get()] - if self.BROWSER is BNPPartPro: - return self.create_browser(self.config) - return self.create_browser(self.config['login'].get(), - self.config['password'].get()) + return self.create_browser(self.config) def iter_accounts(self): for account in self.browser.get_accounts_list(): diff --git a/modules/bnporc/pp/browser.py b/modules/bnporc/pp/browser.py index d6643120d2..b67ab73142 100644 --- a/modules/bnporc/pp/browser.py +++ b/modules/bnporc/pp/browser.py @@ -114,10 +114,11 @@ class BNPParibasBrowser(JsonBrowserMixin, LoginBrowser): profile = URL(r'/kyc-wspl/rest/informationsClient', ProfilePage) list_detail_card = URL(r'/udcarte-wspl/rest/listeDetailCartes', ListDetailCardPage) - def __init__(self, *args, **kwargs): - super(BNPParibasBrowser, self).__init__(*args, **kwargs) + def __init__(self, config, *args, **kwargs): + super(BNPParibasBrowser, self).__init__(config['login'].get(), config['password'].get(), *args, **kwargs) self.accounts_list = None self.card_to_transaction_type = {} + self.rotating_password = config['rotating_password'] @retry(ConnectionError, tries=3) def open(self, *args, **kwargs): @@ -406,9 +407,7 @@ class BNPPartPro(BNPParibasBrowser): def __init__(self, config=None, *args, **kwargs): self.config = config - kwargs['username'] = self.config['login'].get() - kwargs['password'] = self.config['password'].get() - super(BNPPartPro, self).__init__(*args, **kwargs) + super(BNPPartPro, self).__init__(self.config, *args, **kwargs) def switch(self, subdomain): self.BASEURL = self.BASEURL_TEMPLATE % subdomain diff --git a/modules/bnporc/pp/pages.py b/modules/bnporc/pp/pages.py index 6d1b7bfbee..1d460b3551 100644 --- a/modules/bnporc/pp/pages.py +++ b/modules/bnporc/pp/pages.py @@ -102,6 +102,9 @@ def on_load(self): msg = CleanText('//div[@class="confirmation"]//span[span]')(self.doc) self.logger.warning('Password expired.') + if not self.browser.rotating_password: + raise BrowserPasswordExpired(msg) + if not self.looks_legit(self.browser.password): # we may not be able to restore the password, so reject it self.logger.warning('Unable to restore it, it is not legit.') -- GitLab