def validate_client_impersonation(redis_client, url, tenant, admintoken): """Validate Client Token :param redis_client: redis.Redis object connected to the redis cache :param url: Keystone Identity URL to authenticate against :param admintoken: admin token object for Keystone Identity authentication :param tenant: tenant id of user data to retrieve :returns: True, the auth token, and the cachekey on success, : otherwise False, None, and None """ user_token = UserToken(url=url, tenant=tenant, admintoken=admintoken) if user_token.token_data is None: LOG.debug(('Unable to get Access information for ' '%(s_tenant)s') % { 's_tenant': tenant }) return False, None, None # cache the data so it is easier to access next time retval, cache_key = _send_data_to_cache(redis_client, url=url, token_data=user_token) return True, user_token.token_data, cache_key
def test_send_data_to_cache(self, m): test_redis = get_auth_redis_client() m.post('http://mockurl/tokens', text='{"access": \ {"token": {"id": "the-token", "expires": \ "2125-09-04T14:09:20.236Z"}}}') token_data = AdminToken(url='http://mockurl', tenant='\ tenant-id', passwd='passwd', token='thetoken') self.assertIsNotNone(token_data) self.assertIsNone(token_data.token_data) # _send_data_to_cache() retval, key = _send_data_to_cache(test_redis, '', token_data) self.assertTrue(retval) self.assertIsNotNone(key) self.assertIsInstance(key, str) with mock.patch.object(test_redis, 'set', side_effect=side_effect_exception): retval, key = _send_data_to_cache(test_redis, '', token_data) self.assertFalse(retval) self.assertIsNone(key)