summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNan Zhou <nanzhoumails@gmail.com>2022-05-06 01:37:45 +0300
committerNan Zhou <nanzhoumails@gmail.com>2022-05-06 01:37:48 +0300
commite479ad5885a300fe6af862da819b25a0c74c9d9f (patch)
tree97d4078d304c6a76375537b9f45c0dc7ad44990c
parentda8ba403e2ebebdfa952f4d1315262f9f275267b (diff)
downloadbmcweb-e479ad5885a300fe6af862da819b25a0c74c9d9f.tar.xz
query: expand: fix a bug in inLinks
Old codes handle links incorrectly; when links appear before some keys, old codes don't expand these keys. Tested: 1. On real hardware, Expand with links are working correctly. 2. Unit tests. Signed-off-by: Nan Zhou <nanzhoumails@gmail.com> Change-Id: I028b55579d833f23120987a24cef4442fdd5800d
-rw-r--r--redfish-core/include/utils/query_param.hpp11
-rw-r--r--redfish-core/include/utils/query_param_test.cpp8
2 files changed, 14 insertions, 5 deletions
diff --git a/redfish-core/include/utils/query_param.hpp b/redfish-core/include/utils/query_param.hpp
index 042451f489..b4a18a3ec2 100644
--- a/redfish-core/include/utils/query_param.hpp
+++ b/redfish-core/include/utils/query_param.hpp
@@ -389,18 +389,19 @@ inline void findNavigationReferencesRecursive(
// Loop the object and look for links
for (auto& element : *obj)
{
- if (!inLinks)
+ bool localInLinks = inLinks;
+ if (!localInLinks)
{
// Check if this is a links node
- inLinks = element.first == "Links";
+ localInLinks = element.first == "Links";
}
// Only traverse the parts of the tree the user asked for
// Per section 7.3 of the redfish specification
- if (inLinks && eType == ExpandType::NotLinks)
+ if (localInLinks && eType == ExpandType::NotLinks)
{
continue;
}
- if (!inLinks && eType == ExpandType::Links)
+ if (!localInLinks && eType == ExpandType::Links)
{
continue;
}
@@ -408,7 +409,7 @@ inline void findNavigationReferencesRecursive(
BMCWEB_LOG_DEBUG << "Traversing response at " << newPtr;
findNavigationReferencesRecursive(eType, element.second, newPtr,
- inLinks, out);
+ localInLinks, out);
}
}
diff --git a/redfish-core/include/utils/query_param_test.cpp b/redfish-core/include/utils/query_param_test.cpp
index 7897807726..e5d8de753a 100644
--- a/redfish-core/include/utils/query_param_test.cpp
+++ b/redfish-core/include/utils/query_param_test.cpp
@@ -302,4 +302,12 @@ TEST(QueryParams, FindNavigationReferencesLink)
EXPECT_TRUE(findNavigationReferences(ExpandType::NotLinks, singleLinkNode,
json::json_pointer(""))
.empty());
+
+ json multiTreeNodes =
+ R"({"Links": {"@odata.id": "/links"}, "Foo" : {"@odata.id": "/foobar"}})"_json;
+ // Should still find Foo
+ EXPECT_THAT(findNavigationReferences(ExpandType::NotLinks, multiTreeNodes,
+ json::json_pointer("")),
+ UnorderedElementsAre(redfish::query_param::ExpandNode{
+ json::json_pointer("/Foo"), "/foobar"}));
}