From deaf9692432bb6a9353fe56cecb6cddf0401a78c Mon Sep 17 00:00:00 2001 From: Jhon Honce Date: Thu, 9 Sep 2021 10:13:06 -0700 Subject: Refacter API server emphasis on logging * To aid in debugging log API request and response bodies at trace level. Events can be correlated using the X-Reference-Id. * Server now echos X-Reference-Id from client if set, otherwise generates an unique id. * Move logic for X-Reference-Id into middleware * Change uses of Header.Add() to Set() when setting Content-Type * Log API operations in Apache format using gorilla middleware * Port server code to use BaseContext and ConnContext Fixes #10053 Signed-off-by: Jhon Honce --- test/apiv2/python/rest_api/test_v2_0_0_system.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'test') diff --git a/test/apiv2/python/rest_api/test_v2_0_0_system.py b/test/apiv2/python/rest_api/test_v2_0_0_system.py index 3dfd08525..2d3935c9c 100644 --- a/test/apiv2/python/rest_api/test_v2_0_0_system.py +++ b/test/apiv2/python/rest_api/test_v2_0_0_system.py @@ -1,5 +1,6 @@ import json import unittest +import uuid import requests from .fixtures import APITestCase @@ -92,6 +93,18 @@ class SystemTestCase(APITestCase): r = requests.get(self.uri("/system/df")) self.assertEqual(r.status_code, 200, r.text) + def test_reference_id(self): + rid = str(uuid.uuid4()) + r = requests.get(self.uri("/info"), headers={"X-Reference-Id": rid}) + self.assertEqual(r.status_code, 200, r.text) + + self.assertIn("X-Reference-Id", r.headers) + self.assertEqual(r.headers["X-Reference-Id"], rid) + + r = requests.get(self.uri("/info")) + self.assertIn("X-Reference-Id", r.headers) + self.assertNotEqual(r.headers["X-Reference-Id"], rid) + if __name__ == "__main__": unittest.main() -- cgit v1.2.3-54-g00ecf