From e8e03c49f716f426e11728abe9d753e7aec6f290 Mon Sep 17 00:00:00 2001 From: Thibault Douge Date: Tue, 2 Feb 2021 18:39:14 +0100 Subject: [PATCH] [amazon] handle form when we have different device choice --- modules/amazon/browser.py | 4 ++-- modules/amazon/pages.py | 10 ++++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/modules/amazon/browser.py b/modules/amazon/browser.py index 5880b03631..e9f8f7a9ce 100644 --- a/modules/amazon/browser.py +++ b/modules/amazon/browser.py @@ -95,7 +95,7 @@ def locate_browser(self, state): self.location(state['url']) def check_interactive(self): - if not self.config['request_information'].get(): + if self.config['request_information'].get() is None: raise NeedInteractiveFor2FA() def send_notification_interactive_mode(self): @@ -131,7 +131,7 @@ def handle_security(self): # we don't raise an error because for the seller account 2FA is mandatory self.logger.warning('2FA is enabled, all connections send an OTP') - if self.page.has_form_verify() or self.page.has_form_auth_mfa(): + if self.page.has_form_verify() or self.page.has_form_auth_mfa() or self.page.has_form_select_device(): self.check_interactive() self.page.send_code() captcha = self.page.get_captcha_url() diff --git a/modules/amazon/pages.py b/modules/amazon/pages.py index 11f17cad87..4025b4c3f6 100644 --- a/modules/amazon/pages.py +++ b/modules/amazon/pages.py @@ -47,6 +47,8 @@ def get_sub_link(self): class SecurityPage(HTMLPage): def get_otp_type(self): + if self.doc.xpath('//form[@id="auth-select-device-form"]'): + return 'auth-select-device-form' # amazon send us otp in two cases: # - if it's the first time we connect to this account for an ip => manage it normally # - if user has activated otp in his options => raise ActionNeeded, an ask user to deactivate it @@ -63,6 +65,11 @@ def get_otp_message(self): def send_code(self): form = self.get_form() + if form.el.attrib.get('id') == 'auth-select-device-form': + # the first is sms, second email, third application + # the first item is automatically selected + form.submit() + if form.el.attrib.get('id') == 'auth-mfa-form': # when code is sent by sms, server send it automatically, nothing to do here return @@ -95,6 +102,9 @@ def has_form_verify(self): def has_form_auth_mfa(self): return bool(self.doc.xpath('//form[@id="auth-mfa-form"]')) + def has_form_select_device(self): + return bool(self.doc.xpath('//form[@id="auth-select-device-form"]')) + class ApprovalPage(HTMLPage, LoggedPage): def get_msg_app_validation(self): -- GitLab