Fix Message arg error in JSON Patch
When array/vector object is expected in JSON patch the error info does
not contain the actual wrong property instead shows "null". Fix is to
correct the value in the error info.
Tested
- add new test case to verify this
- unit tests are passing.
Change-Id: Ica26ac9e501b5a34a5b118769cc1917eeab30524
Signed-off-by: rohitpai <rohitpai77@gmail.com>
diff --git a/redfish-core/include/utils/json_utils.hpp b/redfish-core/include/utils/json_utils.hpp
index 14160b7..dbefefd 100644
--- a/redfish-core/include/utils/json_utils.hpp
+++ b/redfish-core/include/utils/json_utils.hpp
@@ -275,12 +275,12 @@
jsonValue.get_ptr<nlohmann::json::array_t*>();
if (arr == nullptr)
{
- messages::propertyValueTypeError(res, res.jsonValue, key);
+ messages::propertyValueTypeError(res, jsonValue, key);
return false;
}
if (jsonValue.size() != value.size())
{
- messages::propertyValueTypeError(res, res.jsonValue, key);
+ messages::propertyValueTypeError(res, jsonValue, key);
return false;
}
size_t index = 0;
@@ -297,7 +297,7 @@
jsonValue.get_ptr<nlohmann::json::array_t*>();
if (arr == nullptr)
{
- messages::propertyValueTypeError(res, res.jsonValue, key);
+ messages::propertyValueTypeError(res, jsonValue, key);
return false;
}
diff --git a/test/redfish-core/include/utils/json_utils_test.cpp b/test/redfish-core/include/utils/json_utils_test.cpp
index 8092d01..c7f85f1 100644
--- a/test/redfish-core/include/utils/json_utils_test.cpp
+++ b/test/redfish-core/include/utils/json_utils_test.cpp
@@ -394,6 +394,22 @@
EXPECT_THAT(resExtInfo[0]["MessageSeverity"], "Warning");
}
+TEST(ReadJsonPatch, VerifyReadJsonPatchBadVectorObject)
+{
+ crow::Response res;
+ std::error_code ec;
+ nlohmann::json jsonRequest = {{"NotVector", 1}};
+
+ std::vector<int> indices;
+ ASSERT_FALSE(readJson(jsonRequest, res, "NotVector", indices));
+ EXPECT_EQ(res.result(), boost::beast::http::status::bad_request);
+
+ const nlohmann::json& argsExtInfo =
+ res.jsonValue["NotVector@Message.ExtendedInfo"][0];
+ EXPECT_THAT(argsExtInfo["MessageArgs"][0], "1");
+ EXPECT_THAT(argsExtInfo["MessageArgs"][1], "NotVector");
+}
+
TEST(ReadJsonAction, ValidElementsReturnsTrueResponseOkValuesUnpackedCorrectly)
{
crow::Response res;