Exemplo n.º 1
0
    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)
Exemplo n.º 2
0
    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)
Exemplo n.º 3
0
    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)
Exemplo n.º 4
0
    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)
Exemplo n.º 5
0
 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
Exemplo n.º 6
0
 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')
Exemplo n.º 7
0
    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)