diff options
author | Carson Labrado <clabrado@google.com> | 2023-01-10 20:23:16 +0300 |
---|---|---|
committer | Ed Tanous <ed@tanous.net> | 2023-01-19 20:27:17 +0300 |
commit | 32d7d8ebeaa642950b4ea58af5580f8ad0822c41 (patch) | |
tree | 7df708dfcbcfd01bc185fec31287e50e7bebc0fd /test/redfish-core | |
parent | ade2fe78b9907e5fa9d96d615f7682dade19e8c8 (diff) | |
download | bmcweb-32d7d8ebeaa642950b4ea58af5580f8ad0822c41.tar.xz |
Aggregation: Fix and forward all responses
We only attempt prefix matching when we receive a 200 response. For
the retry policy we consider 2XX and 404 to be valid codes. Instead we
should forward all responses to the client and let them decide what
action they want to take. As part of that we should always attempt to
do prefix fixing on the response.
Also fixes an oversight where we attempt to do prefix fixing on
"OriginOfCondition" properties. That property is only a URI when it is
an Action parameter in a SubmitTestEvent request. It is an object when
it appears as a response property.
Adds test cases for the above fixes.
Tested:
Tests pass. Queries to top level collections and aggregated URIs still
return expected results with added prefixes.
Signed-off-by: Carson Labrado <clabrado@google.com>
Change-Id: Ic76324ceab618160061be5f3c687af20a857fa25
Diffstat (limited to 'test/redfish-core')
-rw-r--r-- | test/redfish-core/include/redfish_aggregator_test.cpp | 107 |
1 files changed, 106 insertions, 1 deletions
diff --git a/test/redfish-core/include/redfish_aggregator_test.cpp b/test/redfish-core/include/redfish_aggregator_test.cpp index 1b3f9244be..665446c137 100644 --- a/test/redfish-core/include/redfish_aggregator_test.cpp +++ b/test/redfish-core/include/redfish_aggregator_test.cpp @@ -1,9 +1,13 @@ #include "redfish_aggregator.hpp" +#include <nlohmann/json.hpp> + #include <gtest/gtest.h> // IWYU pragma: keep namespace redfish { +namespace +{ TEST(IsPropertyUri, SupportedPropertyReturnsTrue) { @@ -11,7 +15,6 @@ TEST(IsPropertyUri, SupportedPropertyReturnsTrue) EXPECT_TRUE(isPropertyUri("@odata.id")); EXPECT_TRUE(isPropertyUri("Image")); EXPECT_TRUE(isPropertyUri("MetricProperty")); - EXPECT_TRUE(isPropertyUri("OriginOfCondition")); EXPECT_TRUE(isPropertyUri("TaskMonitor")); EXPECT_TRUE(isPropertyUri("target")); } @@ -29,6 +32,7 @@ TEST(IsPropertyUri, SpeificallyIgnoredPropertyReturnsFalse) EXPECT_FALSE(isPropertyUri("@odata.context")); EXPECT_FALSE(isPropertyUri("Destination")); EXPECT_FALSE(isPropertyUri("HostName")); + EXPECT_FALSE(isPropertyUri("OriginOfCondition")); } TEST(IsPropertyUri, UnsupportedPropertyReturnsFalse) @@ -136,4 +140,105 @@ TEST(addPrefixToItem, TopLevelCollections) EXPECT_EQ(jsonRequest["@odata.id"], initial); } } + +TEST(addPrefixes, ParseJsonObject) +{ + nlohmann::json parameter; + parameter["Name"] = "/redfish/v1/Chassis/fakeName"; + parameter["@odata.id"] = "/redfish/v1/Chassis/fakeChassis"; + + addPrefixes(parameter, "abcd"); + EXPECT_EQ(parameter["Name"], "/redfish/v1/Chassis/fakeName"); + EXPECT_EQ(parameter["@odata.id"], "/redfish/v1/Chassis/abcd_fakeChassis"); +} + +TEST(addPrefixes, ParseJsonArray) +{ + nlohmann::json array = nlohmann::json::parse(R"( + { + "Conditions": [ + { + "Message": "This is a test", + "@odata.id": "/redfish/v1/Chassis/TestChassis" + }, + { + "Message": "This is also a test", + "@odata.id": "/redfish/v1/Chassis/TestChassis2" + } + ] + } + )", + nullptr, false); + + addPrefixes(array, "5B42"); + EXPECT_EQ(array["Conditions"][0]["@odata.id"], + "/redfish/v1/Chassis/5B42_TestChassis"); + EXPECT_EQ(array["Conditions"][1]["@odata.id"], + "/redfish/v1/Chassis/5B42_TestChassis2"); +} + +TEST(addPrefixes, ParseJsonObjectNestedArray) +{ + nlohmann::json objWithArray = nlohmann::json::parse(R"( + { + "Status": { + "Conditions": [ + { + "Message": "This is a test", + "MessageId": "Test", + "OriginOfCondition": { + "@odata.id": "/redfish/v1/Chassis/TestChassis" + }, + "Severity": "Critical" + } + ], + "Health": "Critical", + "State": "Enabled" + } + } + )", + nullptr, false); + + addPrefixes(objWithArray, "5B42"); + nlohmann::json& array = objWithArray["Status"]["Conditions"]; + EXPECT_EQ(array[0]["OriginOfCondition"]["@odata.id"], + "/redfish/v1/Chassis/5B42_TestChassis"); +} + +// Attempts to perform prefix fixing on a response with response code "result". +// Fixing should always occur +void assertProcessResponse(unsigned result) +{ + nlohmann::json jsonResp; + jsonResp["@odata.id"] = "/redfish/v1/Chassis/TestChassis"; + jsonResp["Name"] = "Test"; + + crow::Response resp; + resp.body() = + jsonResp.dump(2, ' ', true, nlohmann::json::error_handler_t::replace); + resp.addHeader("Content-Type", "application/json"); + resp.result(result); + + auto asyncResp = std::make_shared<bmcweb::AsyncResp>(); + RedfishAggregator::processResponse("prefix", asyncResp, resp); + + EXPECT_EQ(asyncResp->res.jsonValue["Name"], "Test"); + EXPECT_EQ(asyncResp->res.jsonValue["@odata.id"], + "/redfish/v1/Chassis/prefix_TestChassis"); + EXPECT_EQ(asyncResp->res.resultInt(), result); +} + +TEST(processResponse, validResponseCodes) +{ + assertProcessResponse(100); + assertProcessResponse(200); + assertProcessResponse(204); + assertProcessResponse(300); + assertProcessResponse(404); + assertProcessResponse(405); + assertProcessResponse(500); + assertProcessResponse(507); +} + +} // namespace } // namespace redfish |