Merge "Use native override of RequestContext.from_environ"

This commit is contained in:
Zuul 2025-12-15 10:15:34 +00:00 committed by Gerrit Code Review
commit bdbb371ecd
3 changed files with 11 additions and 12 deletions

View file

@ -106,17 +106,13 @@ class ContextHook(hooks.PecanHook):
super(ContextHook, self).__init__()
def before(self, state):
is_public_api = state.request.environ.get('is_public_api', False)
auth_token_info = state.request.environ.get('keystone.token_info')
# set the global_request_id if we have an inbound request id
gr_id = state.request.headers.get(INBOUND_HEADER, "")
if re.match(ID_FORMAT, gr_id):
state.request.environ[GLOBAL_REQ_ID] = gr_id
ctx = context.RequestContext.from_environ(
state.request.environ,
is_public_api=is_public_api,
auth_token_info=auth_token_info)
state.request.environ)
# Do not pass any token with context for noauth mode
if cfg.CONF.auth_strategy != 'keystone':
ctx.auth_token = None

View file

@ -77,9 +77,15 @@ class RequestContext(context.RequestContext):
:param environ: The environment dictionary associated with a request.
:type environ: dict
"""
context = super().from_environ(environ)
context.is_public_api = environ.get('is_public_api', False)
context.auth_token_info = environ.get('keystone.token_info')
is_public_api = environ.get('is_public_api', False)
auth_token_info = environ.get('keystone.token_info')
context = super().from_environ(
environ,
is_public_api=is_public_api,
auth_token_info=auth_token_info,
**kwargs
)
return context
def to_dict(self):

View file

@ -225,11 +225,8 @@ class TestContextHook(base.BaseApiTest):
ctx.to_policy_values.return_value = policy_dict
mock_policy.return_value = False
context_hook.before(reqstate)
creds_dict = {'is_public_api': is_public_api}
if auth_token_info:
creds_dict['auth_token_info'] = auth_token_info
mock_ctx.from_environ.assert_called_once_with(
environ, **creds_dict)
mock_ctx.from_environ.assert_called_once_with(environ)
mock_policy.assert_not_called()
if auth_strategy == 'noauth':
self.assertIsNone(ctx.auth_token)