dbca8153e3
When using noauth midlleware, the context is generated here: https://github.com/openstack/nova/blob/ef6f4e4c8ec82e2c9f9988fe2e04591ee01220e6/nova/api/openstack/auth.py#L56 as the openstack.request_id from req.environ, previously created in: https://github.com/openstack/oslo.middleware/blob/master/oslo_middleware/request_id.py#L57 was not included in the initialize of the context obj, oslo_context.context.Context.__init__ will generate a new request_id for context obj. As the req.environ['openstack.request_id'] will later be returned to the user as the 'x-openstack-request-id' field in the response header, users may use this for searching etc. But the Nova workflow will all use the context.request_id, which will lead to an inconsistency problem. Change-Id: I047b5f66b33ac89b2b5e9170c12bc87d76d0946b Closes-Bug: #1758031
51 lines
1.8 KiB
Python
51 lines
1.8 KiB
Python
# Copyright (c) 2018 OpenStack Foundation
|
|
#
|
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
|
# not use this file except in compliance with the License. You may obtain
|
|
# a copy of the License at
|
|
#
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
#
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
# License for the specific language governing permissions and limitations
|
|
# under the License.
|
|
|
|
from oslo_middleware import request_id
|
|
from oslo_serialization import jsonutils
|
|
import webob
|
|
import webob.exc
|
|
|
|
import nova.api.openstack.auth
|
|
import nova.conf
|
|
from nova import test
|
|
|
|
CONF = nova.conf.CONF
|
|
|
|
|
|
class NoAuthMiddleware(test.NoDBTestCase):
|
|
|
|
def setUp(self):
|
|
super(NoAuthMiddleware, self).setUp()
|
|
|
|
@webob.dec.wsgify()
|
|
def fake_app(req):
|
|
self.context = req.environ['nova.context']
|
|
return webob.Response()
|
|
|
|
self.context = None
|
|
self.middleware = nova.api.openstack.auth.NoAuthMiddleware(fake_app)
|
|
self.request = webob.Request.blank('/')
|
|
self.request.headers['X_TENANT_ID'] = 'testtenantid'
|
|
self.request.headers['X_AUTH_TOKEN'] = 'testauthtoken'
|
|
self.request.headers['X_SERVICE_CATALOG'] = jsonutils.dumps({})
|
|
|
|
def test_request_id_extracted_from_env(self):
|
|
req_id = 'dummy-request-id'
|
|
self.request.headers['X_PROJECT_ID'] = 'testtenantid'
|
|
self.request.headers['X_USER_ID'] = 'testuserid'
|
|
self.request.environ[request_id.ENV_REQUEST_ID] = req_id
|
|
self.request.get_response(self.middleware)
|
|
self.assertEqual(req_id, self.context.request_id)
|