summaryrefslogtreecommitdiff
path: root/test/redfish-core
diff options
context:
space:
mode:
authorKhang Kieu <khangk@google.com>2023-01-24 02:42:17 +0300
committerEd Tanous <ed@tanous.net>2023-02-11 05:44:36 +0300
commit0af78d5a61687d999d7ec68b003137db1201b225 (patch)
tree923fa54dfb67c736a43c5a5dcf3cdf070ed4c676 /test/redfish-core
parentb4963077e81b23b3745293e90fbc4840a90b7d0a (diff)
downloadbmcweb-0af78d5a61687d999d7ec68b003137db1201b225.tar.xz
Aggregation: Fix up aggregated response header URIs
The aggregator did not propagate header's fields from aggregated responses. This change will take into account of response code other than 200, which will modify a field called "Location". The Location field in the response's header will point to where the response data can be read from. This "Location" field in response Header will now contain the correct URI with the prefix appended. We will also copy over other Header Values to aggregated response. These header values include "Content-Type", "Allow", "Retry-After", and also the response's body Added some test cases for the above fixes. Tested: Unit Tests pass. Queries reponse that returns other result than 200 that has Location field and the response received is as expected. Signed-off-by: Khang Kieu <khangk@google.com> Change-Id: I77c7dae32a103fbec3015fe14b51a3ed0022143e
Diffstat (limited to 'test/redfish-core')
-rw-r--r--test/redfish-core/include/redfish_aggregator_test.cpp38
1 files changed, 38 insertions, 0 deletions
diff --git a/test/redfish-core/include/redfish_aggregator_test.cpp b/test/redfish-core/include/redfish_aggregator_test.cpp
index 5a7d2d0a9e..345854fdde 100644
--- a/test/redfish-core/include/redfish_aggregator_test.cpp
+++ b/test/redfish-core/include/redfish_aggregator_test.cpp
@@ -217,11 +217,23 @@ void assertProcessResponse(unsigned result)
resp.body() =
jsonResp.dump(2, ' ', true, nlohmann::json::error_handler_t::replace);
resp.addHeader("Content-Type", "application/json");
+ resp.addHeader("Allow", "GET");
+ resp.addHeader("Location", "/redfish/v1/Chassis/TestChassis");
+ resp.addHeader("Link", "</redfish/v1/Test.json>; rel=describedby");
+ resp.addHeader("Retry-After", "120");
resp.result(result);
auto asyncResp = std::make_shared<bmcweb::AsyncResp>();
RedfishAggregator::processResponse("prefix", asyncResp, resp);
+ EXPECT_EQ(asyncResp->res.getHeaderValue("Content-Type"),
+ "application/json");
+ EXPECT_EQ(asyncResp->res.getHeaderValue("Allow"), "GET");
+ EXPECT_EQ(asyncResp->res.getHeaderValue("Location"),
+ "/redfish/v1/Chassis/prefix_TestChassis");
+ EXPECT_EQ(asyncResp->res.getHeaderValue("Link"), "");
+ EXPECT_EQ(asyncResp->res.getHeaderValue("Retry-After"), "120");
+
EXPECT_EQ(asyncResp->res.jsonValue["Name"], "Test");
EXPECT_EQ(asyncResp->res.jsonValue["@odata.id"],
"/redfish/v1/Chassis/prefix_TestChassis");
@@ -445,6 +457,32 @@ TEST(processCollectionResponse, preserveHeaders)
EXPECT_EQ(asyncResp->res.getHeaderValue("OData-Version"), "4.0");
EXPECT_EQ(asyncResp->res.getHeaderValue("Location"), "");
}
+void assertProcessResponseContentType(std::string_view contentType)
+{
+ crow::Response resp;
+ resp.body() = "responseBody";
+ resp.addHeader("Content-Type", contentType);
+ resp.addHeader("Location", "/redfish/v1/Chassis/TestChassis");
+ resp.addHeader("Link", "metadataLink");
+ resp.addHeader("Retry-After", "120");
+
+ auto asyncResp = std::make_shared<bmcweb::AsyncResp>();
+ RedfishAggregator::processResponse("prefix", asyncResp, resp);
+ EXPECT_EQ(asyncResp->res.getHeaderValue("Content-Type"), contentType);
+ EXPECT_EQ(asyncResp->res.getHeaderValue("Location"),
+ "/redfish/v1/Chassis/prefix_TestChassis");
+ EXPECT_EQ(asyncResp->res.getHeaderValue("Link"), "");
+ EXPECT_EQ(asyncResp->res.getHeaderValue("Retry-After"), "120");
+ EXPECT_EQ(asyncResp->res.body(), "responseBody");
+}
+
+TEST(processResponse, DifferentContentType)
+{
+ assertProcessResponseContentType("application/xml");
+ assertProcessResponseContentType("application/yaml");
+ assertProcessResponseContentType("text/event-stream");
+ assertProcessResponseContentType(";charset=utf-8");
+}
} // namespace
} // namespace redfish