Merge "Noauth should also use request_id from compute_req_id.py"
This commit is contained in:
commit
df58289fa1
2 files changed
+55
-4
No files matched your search
@@ -14,6 +14,7 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from oslo_middleware import request_id
|
||||
import webob.dec
|
||||
import webob.exc
|
||||
|
||||
@@ -53,10 +54,10 @@ class NoAuthMiddlewareBase(base_wsgi.Middleware):
|
||||
if CONF.api.use_forwarded_for:
|
||||
remote_address = req.headers.get('X-Forwarded-For', remote_address)
|
||||
is_admin = always_admin or (user_id == 'admin')
|
||||
ctx = context.RequestContext(user_id,
|
||||
project_id,
|
||||
is_admin=is_admin,
|
||||
remote_address=remote_address)
|
||||
ctx = context.RequestContext(
|
||||
user_id, project_id, is_admin=is_admin,
|
||||
remote_address=remote_address,
|
||||
request_id=req.environ.get(request_id.ENV_REQUEST_ID))
|
||||
|
||||
req.environ['nova.context'] = ctx
|
||||
return self.application
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
# 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)
|
||||
Reference in new issue
Block a user