Validate ExtendedInfo entry and MessageId types in GenericRedfishParser Verify the @Message.ExtendedInfo entry is a JSON object and MessageId is a string before extracting it, returning InvalidArgumentError otherwise. Enable the unit tests for non-object ExtendedInfo entries and missing or non-string MessageId values. PiperOrigin-RevId: 1024819311 Change-Id: Ifd0664d68b537fd4cabd637384c01c9862f945e2
diff --git a/bmc/register_actions_bmc.cc b/bmc/register_actions_bmc.cc index 7fedb05..e019b54 100644 --- a/bmc/register_actions_bmc.cc +++ b/bmc/register_actions_bmc.cc
@@ -70,12 +70,19 @@ << *js; } const nlohmann::json& info = (*extended_info)[0]; - auto message_id = info.find("MessageId"); - if (message_id == info.end()) { - LOG(ERROR) << "Failed to parse bmc's response to JSON: " << *js; - return absl::InvalidArgumentError("Failed to parse bmc's response to JSON"); + if (!info.is_object()) { + LOG(ERROR) << "Redfish ExtendedInfo entry is not a JSON object: " << *js; + return absl::InvalidArgumentError( + "Redfish ExtendedInfo entry is not a JSON object"); } - std::string status = *message_id; + auto message_id = info.find("MessageId"); + if (message_id == info.end() || !message_id->is_string()) { + LOG(ERROR) << "Redfish ExtendedInfo entry missing string MessageId: " + << *js; + return absl::InvalidArgumentError( + "Redfish ExtendedInfo entry missing string MessageId"); + } + const std::string& status = message_id->get_ref<const std::string&>(); std::vector<std::string> v = absl::StrSplit(status, '.'); if (v.size() > 4 && v[4] == "Success") { return absl::OkStatus();
diff --git a/bmc/register_actions_bmc_test.cc b/bmc/register_actions_bmc_test.cc index 76e3a3e..f95c8d6 100644 --- a/bmc/register_actions_bmc_test.cc +++ b/bmc/register_actions_bmc_test.cc
@@ -981,9 +981,6 @@ HasSubstr("must not set target_component.name")); } -// TODO(b/586984685): Remove once all follow-up fixes land. -bool SkipUntilFollowupCl() { return true; } - TEST(GenericRedfishParserTest, ValidSuccessResponseReturnsOk) { nlohmann::json payload = { {"@Message.ExtendedInfo", {{{"MessageId", "Base.1.13.0.Success"}}}}, @@ -1060,9 +1057,6 @@ } TEST(GenericRedfishParserTest, NonObjectExtendedInfoEntryReturnsError) { - if (SkipUntilFollowupCl()) { - GTEST_SKIP() << "Fixed in follow-up CL"; - } nlohmann::json payload = { {"@Message.ExtendedInfo", {"not an object"}}, }; @@ -1070,9 +1064,6 @@ } TEST(GenericRedfishParserTest, MissingOrNonStringMessageIdReturnsError) { - if (SkipUntilFollowupCl()) { - GTEST_SKIP() << "Fixed in follow-up CL"; - } nlohmann::json missing_id = { {"@Message.ExtendedInfo", {nlohmann::json::object()}}, };
diff --git a/piper_cl.txt b/piper_cl.txt index 1746335..05d4359 100644 --- a/piper_cl.txt +++ b/piper_cl.txt
@@ -1 +1 @@ -1024809079 +1024819311