def test_is_token_valid_keystone_v2_invalid_location(self, mock_get): client_backup = tokens.v2_client.Client tokens.v2_client.Client = mock.MagicMock() self.assertRaises(ValueError, tokens.is_token_valid, 'a', 'b', tokens.TokenConf('a', 'b', 'c', 'd', '2.0'), 'test', {'domain': 'test'}) tokens.v2_client.Client = client_backup
def test_is_token_valid_token_not_found(self, mock_get): client_backup = tokens.v3_client.Client tokens.v3_client.Client = mock.MagicMock(return_value=MyClient()) self.assertFalse( tokens.is_token_valid('a', 'b', tokens.TokenConf('a', 'b', 'c', 'd', '3'))) tokens.v3_client.Client = client_backup
def test_is_token_valid_sanity_role_required(self, mock_get, mock_client): user = {'user': {'id': 'test_id', 'domain': {'id': 'test'}}} mock_client.tokens.validate = mock.MagicMock(return_value=user) self.assertTrue( tokens.is_token_valid('a', 'b', tokens.TokenConf('a', 'b', 'c', 'd', '3'), 'test', {'domain': 'test'}))
def test_is_token_valid_keystone_v2(self, mock_get): client_backup = tokens.v2_client.Client tokens.v2_client.Client = mock.MagicMock() self.assertFalse( tokens.is_token_valid('a', 'b', tokens.TokenConf('a', 'b', 'c', 'd', '2.0'), 'test', {'tenant': 'test'})) tokens.v2_client.Client = client_backup
def _get_token_conf(app_conf): mech_id = app_conf.authentication.mech_id mech_password = app_conf.authentication.mech_pass rms_url = app_conf.authentication.rms_url tenant_name = app_conf.authentication.tenant_name keystone_version = app_conf.authentication.keystone_version conf = tokens.TokenConf(mech_id, mech_password, rms_url, tenant_name, keystone_version) return conf
def get_token_conf(app_conf): mech_id = app_conf.authentication.mech_id mech_password = app_conf.authentication.mech_pass # RMS URL is not necessary since this service is RMS rms_url = '' tenant_name = app_conf.authentication.tenant_name keystone_version = app_conf.authentication.keystone_version conf = tokens.TokenConf(mech_id, mech_password, rms_url, tenant_name, keystone_version) return conf
def test_get_token_user_success(self, mock_get_keystone_client): token_info = mock.MagicMock() token_info.token = 'a' token_info.user = '******' ks = mock.MagicMock() ks.tokens.validate.return_value = token_info mock_get_keystone_client.return_value = ks conf = tokens.TokenConf(*('2.0', ) * 5) result = tokens.get_token_user('a', conf, 'c', 'd') self.assertEqual(result.token, 'a') self.assertEqual(result.user, 'test_user')
def _get_token_conf(): conf = tokens.TokenConf(mech_id, mech_password, rms_url, tenant_name) return conf
def test_get_token_user_token_not_found(self, mock_get_keystone_client): ks = mock.MagicMock() ks.tokens.validate.side_effect = exceptions.NotFound() mock_get_keystone_client.return_value = ks conf = tokens.TokenConf(*('3', ) * 5) self.assertIsNone(tokens.get_token_user('a', conf, 'c', 'd'))
def test_get_token_user_invalid_keystone_version(self): conf = tokens.TokenConf(*(None, ) * 5) self.assertRaises(ValueError, tokens.get_token_user, 'a', conf, 'c', 'd')
def test_is_token_valid_role_does_not_exist(self, mock_get): tokens.v3_client.Client = mock.MagicMock(return_value=MyClient(False)) self.assertRaises(ValueError, tokens.is_token_valid, 'a', 'b', tokens.TokenConf('a', 'b', 'c', 'd', '3'), 'test', {'domain': 'test'})
def test_is_token_valid_no_role_location(self, mock_get): tokens.v3_client.Client = mock.MagicMock() self.assertRaises(ValueError, tokens.is_token_valid, 'a', 'b', tokens.TokenConf('a', 'b', 'c', 'd', '3'), 'test')
def test_is_token_valid_keystone_ep_not_found(self, mock_get): self.assertRaises(tokens.KeystoneNotFoundError, tokens.is_token_valid, 'a', 'b', tokens.TokenConf('a', 'b', 'c', 'd', '3'))
def test_is_token_valid_invalid_version(self, mock_get): client_backup = tokens.v3_client.Client tokens.v3_client.Client = mock.MagicMock(return_value=MyClient()) self.assertRaises(ValueError, tokens.is_token_valid, 'a', 'b', tokens.TokenConf('a', 'b', 'c', 'd', '4')) tokens.v3_client.Client = client_backup
def test_is_token_valid_sanity(self, mock_get, mock_client): self.assertTrue( tokens.is_token_valid('a', 'b', tokens.TokenConf('a', 'b', 'c', 'd', '3')))