From b27e1cbefc2a12a838de209decb7e22b5ba1b2c0 Mon Sep 17 00:00:00 2001 From: Carson Labrado Date: Fri, 17 Mar 2023 20:27:00 +0000 Subject: Aggregation: Prefix fix HttpHeaders property The "HttpHeaders" property in a response is an array of HTTP headers. We perform prefix fixing on the "Location" header from responses so we should also fix any "Location" headers which are contained by "HttpHeaders" in an aggregated response. This requires special handling since each header is represented as a single string in the response. Added testcase for HttpHeaders property Tested: All unit tests pass Signed-off-by: Carson Labrado Change-Id: I3040c4ea52b2bebcb6e206bb50585c6a75538f0a --- .../include/redfish_aggregator_test.cpp | 33 ++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'test/redfish-core') diff --git a/test/redfish-core/include/redfish_aggregator_test.cpp b/test/redfish-core/include/redfish_aggregator_test.cpp index 838e5edf6b..2fdd784d3b 100644 --- a/test/redfish-core/include/redfish_aggregator_test.cpp +++ b/test/redfish-core/include/redfish_aggregator_test.cpp @@ -206,6 +206,39 @@ TEST(addPrefixes, ParseJsonObjectNestedArray) "/redfish/v1/Chassis/5B42_TestChassis"); } +TEST(addPrefixes, FixHttpHeadersInResponseBody) +{ + nlohmann::json taskResp = nlohmann::json::parse(R"( + { + "@odata.id": "/redfish/v1/TaskService/Tasks/0", + "Name": "Task 0", + "Payload": { + "HttpHeaders": [ + "User-Agent: curl/7.87.0", + "Accept: */*", + "Host: 127.127.12.7", + "Content-Length: 33", + "Location: /redfish/v1/Managers/bmc/LogServices/Dump/Entries/0" + ] + }, + "PercentComplete": 100, + "TaskMonitor": "/redfish/v1/TaskService/Tasks/0/Monitor", + "TaskState": "Completed", + "TaskStatus": "OK" + } + )", + nullptr, false); + + addPrefixes(taskResp, "5B247A"); + EXPECT_EQ(taskResp["@odata.id"], "/redfish/v1/TaskService/Tasks/5B247A_0"); + EXPECT_EQ(taskResp["TaskMonitor"], + "/redfish/v1/TaskService/Tasks/5B247A_0/Monitor"); + nlohmann::json& httpHeaders = taskResp["Payload"]["HttpHeaders"]; + EXPECT_EQ( + httpHeaders[4], + "Location: /redfish/v1/Managers/5B247A_bmc/LogServices/Dump/Entries/0"); +} + // Attempts to perform prefix fixing on a response with response code "result". // Fixing should always occur void assertProcessResponse(unsigned result) -- cgit v1.2.3