summaryrefslogtreecommitdiff
path: root/oslo_middleware/tests/test_request_id.py
diff options
context:
space:
mode:
Diffstat (limited to 'oslo_middleware/tests/test_request_id.py')
-rw-r--r--oslo_middleware/tests/test_request_id.py41
1 files changed, 41 insertions, 0 deletions
diff --git a/oslo_middleware/tests/test_request_id.py b/oslo_middleware/tests/test_request_id.py
index 5c79c21..5374fa2 100644
--- a/oslo_middleware/tests/test_request_id.py
+++ b/oslo_middleware/tests/test_request_id.py
@@ -13,6 +13,7 @@
# License for the specific language governing permissions and limitations
# under the License.
+import uuid
from oslotest import base as test_base
from testtools import matchers
@@ -63,3 +64,43 @@ class RequestIdTest(test_base.BaseTestCase):
self.assertEqual(res.headers.get("x-compute-req-id"), res_req_id)
self.assertEqual(res.headers.get("x-silly-id"), res_req_id)
+
+ def test_global_request_id_set(self):
+ """Test that global request_id is set."""
+ @webob.dec.wsgify
+ def application(req):
+ return req.environ[request_id.GLOBAL_REQ_ID]
+
+ global_req = "req-%s" % uuid.uuid4()
+ app = request_id.RequestId(application)
+ req = webob.Request.blank(
+ '/test',
+ headers={"X-OpenStack-Request-ID": global_req})
+ res = req.get_response(app)
+ res_req_id = res.headers.get(request_id.HTTP_RESP_HEADER_REQUEST_ID)
+ if isinstance(res_req_id, bytes):
+ res_req_id = res_req_id.decode('utf-8')
+ # global-request-id in request environ is returned as response body
+ self.assertEqual(res.body.decode('utf-8'), global_req)
+ self.assertNotEqual(res.body.decode('utf-8'), res_req_id)
+
+ def test_global_request_id_drop(self):
+ """Test that bad format ids are dropped.
+
+ This ensures that badly formatted ids are dropped entirely.
+ """
+ @webob.dec.wsgify
+ def application(req):
+ return req.environ.get(request_id.GLOBAL_REQ_ID)
+
+ global_req = "req-%s-bad" % uuid.uuid4()
+ app = request_id.RequestId(application)
+ req = webob.Request.blank(
+ '/test',
+ headers={"X-OpenStack-Request-ID": global_req})
+ res = req.get_response(app)
+ res_req_id = res.headers.get(request_id.HTTP_RESP_HEADER_REQUEST_ID)
+ if isinstance(res_req_id, bytes):
+ res_req_id = res_req_id.decode('utf-8')
+ # global-request-id in request environ is returned as response body
+ self.assertEqual(res.body.decode('utf-8'), '')