def test_main_keyboard_interrupt(self, _config_mock): keyman = Keyman(["foo", "-o", "foo", "-u", "bar", "-a", "baz"]) keyman.handle_appid_selection = mock.MagicMock() keyman.user_password = mock.MagicMock() keyman.user_password.side_effect = KeyboardInterrupt with self.assertRaises(SystemExit): keyman.main()
def test_main_unhandled_exception(self, _config_mock): keyman = Keyman(["foo", "-o", "foo", "-u", "bar", "-a", "baz"]) keyman.handle_appid_selection = mock.MagicMock() keyman.user_password = mock.MagicMock() keyman.user_password.side_effect = Exception() with self.assertRaises(SystemExit): keyman.main()
def test_main_keyboard_interrupt(self, _config_mock): keyman = Keyman(['foo', '-o', 'foo', '-u', 'bar', '-a', 'baz']) keyman.handle_appid_selection = mock.MagicMock() keyman.user_password = mock.MagicMock() keyman.user_password.side_effect = KeyboardInterrupt with self.assertRaises(SystemExit): keyman.main()
def test_main_unhandled_exception(self, _config_mock): keyman = Keyman(['foo', '-o', 'foo', '-u', 'bar', '-a', 'baz']) keyman.handle_appid_selection = mock.MagicMock() keyman.user_password = mock.MagicMock() keyman.user_password.side_effect = Exception() with self.assertRaises(SystemExit): keyman.main()
def test_user_password_cache_get_success(self, pass_mock, _config_mock, keyring_kr_mock, keyring_pw_mock): keyman = Keyman('') keyman.config.password_cache = True keyman.config.password_reset = False keyring_pw_mock.return_value = 'test' self.assertEqual('test', keyman.user_password()) assert not pass_mock.called
def test_user_password_cache_unavailable(self, pass_mock, _config_mock, keyring_kr_mock, keyring_pw_mock): keyman = Keyman('') keyman.config.password_cache = True keyman.config.password_reset = False keyring_kr_mock.side_effect = keyring.errors.InitError pass_mock.getpass.return_value = 'test' self.assertEqual('test', keyman.user_password()) assert not keyring_pw_mock.called
def test_main_aws_auth_error(self, _config_mock): keyman = Keyman(["foo", "-o", "foo", "-u", "bar", "-a", "baz"]) keyman.handle_appid_selection = mock.MagicMock() keyman.handle_appid_selection.side_effect = NoAWSAccounts() keyman.user_password = mock.MagicMock() keyman.user_password.return_value = "foo" keyman.init_okta = mock.MagicMock() keyman.auth_okta = mock.MagicMock() keyman.aws_auth_loop = mock.MagicMock() with self.assertRaises(SystemExit): keyman.main()
def test_user_password_cache_get_empty(self, pass_mock, _config_mock, keyring_kr_mock, keyring_pw_mock, keyring_setpw_mock): keyman = Keyman('') keyman.config.password_cache = True keyman.config.password_reset = False keyring_pw_mock.return_value = None pass_mock.getpass.return_value = 'test' self.assertEqual('test', keyman.user_password()) keyring_setpw_mock.assert_has_calls( [mock.call('aws_okta_keyman', mock.ANY, 'test')])
def test_main_no_aws_accounts(self, _config_mock): keyman = Keyman(['foo', '-o', 'foo', '-u', 'bar', '-a', 'baz']) keyman.handle_appid_selection = mock.MagicMock() keyman.user_password = mock.MagicMock() keyman.user_password.return_value = 'foo' keyman.init_okta = mock.MagicMock() keyman.auth_okta = mock.MagicMock() keyman.aws_auth_loop = mock.MagicMock() keyman.aws_auth_loop.return_value = 1 with self.assertRaises(SystemExit): keyman.main()
def test_main_update(self, config_mock): config_mock().update = True keyman = Keyman(["foo", "-o", "foo", "-u", "bar", "-a", "baz"]) keyman.update = mock.MagicMock() keyman.handle_appid_selection = mock.MagicMock() keyman.user_password = mock.MagicMock() keyman.user_password.return_value = "foo" keyman.init_okta = mock.MagicMock() keyman.auth_okta = mock.MagicMock() keyman.aws_auth_loop = mock.MagicMock() with self.assertRaises(SystemExit): keyman.main() keyman.update.assert_has_calls([mock.call(__version__)])
def test_main_post_okta_appid_selection(self, _config_mock): keyman = Keyman(['foo', '-o', 'foo', '-u', 'bar']) keyman.handle_appid_selection = mock.MagicMock() keyman.config.appid = None keyman.user_password = mock.MagicMock() keyman.user_password.return_value = 'foo' keyman.init_okta = mock.MagicMock() keyman.auth_okta = mock.MagicMock() keyman.aws_auth_loop = mock.MagicMock() keyman.aws_auth_loop.return_value = None keyman.handle_appid_selection = mock.MagicMock() keyman.main() keyman.handle_appid_selection.assert_has_calls( [mock.call(), mock.call(okta_ready=True)])
def test_main(self, _config_mock): keyman = Keyman(['foo', '-o', 'foo', '-u', 'bar', '-a', 'baz']) keyman.handle_appid_selection = mock.MagicMock() keyman.user_password = mock.MagicMock() keyman.user_password.return_value = 'foo' keyman.init_okta = mock.MagicMock() keyman.auth_okta = mock.MagicMock() keyman.aws_auth_loop = mock.MagicMock() keyman.main() assert keyman.handle_appid_selection.called assert keyman.user_password.called keyman.init_okta.assert_called_with('foo') assert keyman.auth_okta.called assert keyman.aws_auth_loop.called
def test_main(self, _config_mock): keyman = Keyman(["foo", "-o", "foo", "-u", "bar", "-a", "baz"]) keyman.handle_appid_selection = mock.MagicMock() keyman.user_password = mock.MagicMock() keyman.user_password.return_value = "foo" keyman.init_okta = mock.MagicMock() keyman.auth_okta = mock.MagicMock() keyman.aws_auth_loop = mock.MagicMock() keyman.aws_auth_loop.return_value = None keyman.main() assert keyman.handle_appid_selection.called assert keyman.user_password.called keyman.init_okta.assert_called_with("foo") assert keyman.auth_okta.called assert keyman.aws_auth_loop.called
def test_user_password_cache_get_empty( self, pass_mock, _config_mock, keyring_kr_mock, keyring_pw_mock, keyring_setpw_mock, ): keyman = Keyman("") keyman.config.password_cache = True keyman.config.password_reset = False keyring_pw_mock.return_value = None pass_mock.getpass.return_value = "test" self.assertEqual("test", keyman.user_password()) keyring_setpw_mock.assert_has_calls( [ mock.call("aws_okta_keyman", mock.ANY, "test"), ], )
def test_user_password_no_cache(self, pass_mock, _config_mock): keyman = Keyman("") keyman.config.password_cache = False pass_mock.getpass.return_value = "test" self.assertEqual("test", keyman.user_password())
def test_user_password(self, pass_mock): pass_mock.getpass.return_value = 'test' self.assertEqual('test', Keyman.user_password())