Commit f95ada51 authored by Célande Adrien's avatar Célande Adrien Committed by ntome

[caissedepargne] use TransferInvalidOTP

RecipientInvalidOTP generates a bug when raising it during a transfer
the exception is not adapted
the TransferInvalidOTP is now created and can be used

Closes: 41036@sibi
parent 95cf812d
Pipeline #2673 failed with stages
in 2 minutes and 56 seconds
......@@ -30,7 +30,10 @@ from dateutil import parser
from weboob.browser import LoginBrowser, need_login, StatesMixin
from weboob.browser.switch import SiteSwitch
from weboob.browser.url import URL
from weboob.capabilities.bank import Account, AddRecipientStep, Recipient, TransferBankError, Transaction, TransferStep
from weboob.capabilities.bank import (
Account, AddRecipientStep, Recipient, TransferBankError, Transaction, TransferStep,
TransferInvalidOTP, RecipientInvalidOTP,
)
from weboob.capabilities.base import NotAvailable, find_object
from weboob.capabilities.bill import Subscription
from weboob.capabilities.profile import Profile
......@@ -959,7 +962,7 @@ class CaisseEpargne(LoginBrowser, StatesMixin):
self.is_send_sms = False
assert 'otp_sms' in params, 'OTP SMS is missing'
self.otp_sms_validation(params['otp_sms'])
self.otp_sms_validation(params['otp_sms'], TransferInvalidOTP)
if self.transfer.is_here():
self.page.continue_transfer(transfer.account_label, transfer.recipient_label, transfer.label)
return self.page.update_transfer(transfer)
......@@ -1003,7 +1006,7 @@ class CaisseEpargne(LoginBrowser, StatesMixin):
self.location(self.otp_url, json={'fallback': {}})
self.otp_validation = self.page.validation_unit()
def otp_sms_validation(self, otp_sms):
def otp_sms_validation(self, otp_sms, otp_exception):
key = next(iter(self.otp_validation))
data = {
'validate': {
......@@ -1016,7 +1019,7 @@ class CaisseEpargne(LoginBrowser, StatesMixin):
}
self.location(self.otp_url, json=data)
saml = self.page.get_saml()
saml = self.page.get_saml(otp_exception)
action = self.page.get_action()
self.location(action, data={'SAMLResponse': saml})
......@@ -1051,7 +1054,7 @@ class CaisseEpargne(LoginBrowser, StatesMixin):
return self.end_sms_recipient(recipient, **params)
if 'otp_sms' in params:
self.otp_sms_validation(params['otp_sms'])
self.otp_sms_validation(params['otp_sms'], RecipientInvalidOTP)
if self.authent.is_here():
self.page.go_on()
......
......@@ -38,7 +38,7 @@ from weboob.browser.filters.html import Link, Attr, TableCell
from weboob.capabilities import NotAvailable
from weboob.capabilities.bank import (
Account, Investment, Recipient, TransferBankError, Transfer,
AddRecipientBankError, Loan, RecipientInvalidOTP,
AddRecipientBankError, Loan,
)
from weboob.capabilities.bill import DocumentTypes, Subscription, Document
from weboob.tools.capabilities.bank.investments import is_isin_valid
......@@ -1673,12 +1673,12 @@ class SmsRequest(LoggedPage, JsonPage):
return self.doc['step']['validationUnits'][0]
return self.doc['validationUnits'][0]
def get_saml(self):
def get_saml(self, otp_exception):
if not 'response' in self.doc:
error = self.doc['phase']['previousResult']
if error == 'FAILED_AUTHENTICATION':
raise RecipientInvalidOTP()
raise otp_exception()
assert not error, 'Error during recipient validation: %s' % error
return self.doc['response']['saml2_post']['samlResponse']
......
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