def test_fetch_mfa_token_from_shell__command_succeedes_token_has_spaces(self, m_shell): m_shell.run = Mock() m_shell.run.return_value = ' 123456 ' self.assertEqual('123456', mfa.fetch_mfa_token_from_shell('success_command')) expected = [call('success_command')] self.assertEqual(expected, m_shell.run.mock_calls)
def test_fetch_mfa_token_from_shell__command_succeedes_but_no_valid_token(self, m_shell): m_shell.run = Mock() m_shell.run.return_value = 'Some Token 123456' self.assertEqual(None, mfa.fetch_mfa_token_from_shell('success_command')) expected = [call('success_command')] self.assertEqual(expected, m_shell.run.mock_calls)
def test_fetch_mfa_token_from_shell__command_succeedes_but_None_instead_of_token(self, m_shell): m_shell.run = Mock() m_shell.run.return_value = None self.assertEqual(None, mfa.fetch_mfa_token_from_shell('success_command')) expected = [call('success_command')] self.assertEqual(expected, m_shell.run.mock_calls)
def test_fetch_mfa_token_from_shell__command_failes(self, m_shell): m_shell.run = Mock() m_shell.run.side_effect = shell self.assertEqual(None, mfa.fetch_mfa_token_from_shell('fail_command')) expected = [call('fail_command')] self.assertEqual(expected, m_shell.run.mock_calls)
def _renew_session(self, mfa_callback: Callable) -> Result: logger.info('renew session') logger.info('get mfa from console') token = mfa.fetch_mfa_token_from_shell(self.config.mfa_shell_command) if not token: logger.info('get mfa from user') token = mfa_callback() if not token: result = Result() result.error('invalid mfa token') return result session_result = credentials.fetch_session_token(token) return session_result
def check_command(self): token = mfa.fetch_mfa_token_from_shell(self.mfa_command_input.text()) if token: self.set_success_text('command successful') else: self.set_error_text('command failed')
def test_fetch_mfa_token_from_shell__no_command(self, m_shell): self.assertEqual(None, mfa.fetch_mfa_token_from_shell('')) expected = [] self.assertEqual(expected, m_shell.run.mock_calls)