def test_safe_rstrip(self): value = '/test/' rstripped_value = '/test' not_rstripped = '/' self.assertEqual(rstripped_value, utils.safe_rstrip(value, '/')) self.assertEqual(not_rstripped, utils.safe_rstrip(not_rstripped, '/'))
def test_safe_rstrip(self): value = "/test/" rstripped_value = "/test" not_rstripped = "/" self.assertEqual(rstripped_value, utils.safe_rstrip(value, "/")) self.assertEqual(not_rstripped, utils.safe_rstrip(not_rstripped, "/"))
def __call__(self, env, start_response): path = utils.safe_rstrip(env.get('PATH_INFO'), '/') if path in self.public_api_routes: return self.app(env, start_response) return super(AuthTokenMiddleware, self).__call__(env, start_response)
def test_safe_rstrip_not_raises_exceptions(self): # Supplying an integer should normally raise an exception because it # does not save the rstrip() method. value = 10 # In the case of raising an exception safe_rstrip() should return the # original value. self.assertEqual(value, utils.safe_rstrip(value))
def __call__(self, env, start_response): path = utils.safe_rstrip(env.get("PATH_INFO"), "/") # The information whether the API call is being performed against the # public API is required for some other components. Saving it to the # WSGI environment is reasonable thereby. env["is_public_api"] = any(map(lambda pattern: re.match(pattern, path), self.public_api_routes)) if env["is_public_api"]: return self.app(env, start_response) return super(AuthTokenMiddleware, self).__call__(env, start_response)
def __call__(self, env, start_response): path = utils.safe_rstrip(env.get('PATH_INFO'), '/') # The information whether the API call is being performed against the # public API is required for some other components. Saving it to the # WSGI environment is reasonable thereby. env['is_public_api'] = any(map(lambda pattern: re.match(pattern, path), self.public_api_routes)) if env['is_public_api']: return self._ironic_app(env, start_response) return super(AuthTokenMiddleware, self).__call__(env, start_response)
def before(self, state): user_id = state.request.headers.get('X-User-Id') user_id = state.request.headers.get('X-User', user_id) tenant = state.request.headers.get('X-Tenant-Id') tenant = state.request.headers.get('X-Tenant', tenant) domain_id = state.request.headers.get('X-User-Domain-Id') domain_name = state.request.headers.get('X-User-Domain-Name') auth_token = state.request.headers.get('X-Auth-Token', None) creds = {'roles': state.request.headers.get('X-Roles', '').split(',')} is_admin = policy.check('admin', state.request.headers, creds) path = utils.safe_rstrip(state.request.path, '/') is_public_api = path in self.public_api_routes state.request.context = context.RequestContext( auth_token=auth_token, user=user_id, tenant=tenant, domain_id=domain_id, domain_name=domain_name, is_admin=is_admin, is_public_api=is_public_api)