1 #include "bmcweb_config.h" 2 3 #include "async_resp.hpp" 4 #include "http_response.hpp" 5 #include "service_root.hpp" 6 7 #include <nlohmann/json.hpp> 8 9 #include <cstddef> 10 #include <memory> 11 12 #include <gmock/gmock.h> // IWYU pragma: keep 13 #include <gtest/gtest.h> // IWYU pragma: keep 14 15 // IWYU pragma: no_include <gtest/gtest-message.h> 16 // IWYU pragma: no_include <gtest/gtest-test-part.h> 17 // IWYU pragma: no_include "gtest/gtest_pred_impl.h" 18 // IWYU pragma: no_include <gmock/gmock-matchers.h> 19 // IWYU pragma: no_include <gtest/gtest-matchers.h> 20 21 namespace redfish 22 { 23 namespace 24 { 25 26 void assertServiceRootGet(crow::Response& res) 27 { 28 nlohmann::json& json = res.jsonValue; 29 EXPECT_EQ(json["@odata.id"], "/redfish/v1"); 30 EXPECT_EQ(json["@odata.type"], "#ServiceRoot.v1_15_0.ServiceRoot"); 31 32 EXPECT_EQ(json["AccountService"]["@odata.id"], 33 "/redfish/v1/AccountService"); 34 EXPECT_EQ(json["AccountService"].size(), 1); 35 36 EXPECT_EQ(json["CertificateService"]["@odata.id"], 37 "/redfish/v1/CertificateService"); 38 EXPECT_EQ(json["CertificateService"].size(), 1); 39 40 EXPECT_EQ(json["Chassis"]["@odata.id"], "/redfish/v1/Chassis"); 41 EXPECT_EQ(json["Chassis"].size(), 1); 42 43 EXPECT_EQ(json["EventService"]["@odata.id"], "/redfish/v1/EventService"); 44 EXPECT_EQ(json["EventService"].size(), 1); 45 46 EXPECT_EQ(json["Id"], "RootService"); 47 EXPECT_EQ(json["Links"]["Sessions"]["@odata.id"], 48 "/redfish/v1/SessionService/Sessions"); 49 EXPECT_EQ(json["Links"].size(), 2); 50 EXPECT_EQ(json["Links"]["Sessions"].size(), 1); 51 EXPECT_EQ(json["Links"]["ManagerProvidingService"].size(), 1); 52 EXPECT_EQ(json["Links"]["ManagerProvidingService"]["@odata.id"], 53 "/redfish/v1/Managers/bmc"); 54 55 EXPECT_EQ(json["Managers"]["@odata.id"], "/redfish/v1/Managers"); 56 EXPECT_EQ(json["Managers"].size(), 1); 57 58 EXPECT_EQ(json["Name"], "Root Service"); 59 EXPECT_EQ(json["RedfishVersion"], "1.17.0"); 60 61 EXPECT_EQ(json["Registries"]["@odata.id"], "/redfish/v1/Registries"); 62 EXPECT_EQ(json["Registries"].size(), 1); 63 64 EXPECT_EQ(json["SessionService"]["@odata.id"], 65 "/redfish/v1/SessionService"); 66 EXPECT_EQ(json["SessionService"].size(), 1); 67 68 EXPECT_EQ(json["Systems"]["@odata.id"], "/redfish/v1/Systems"); 69 EXPECT_EQ(json["Systems"].size(), 1); 70 71 EXPECT_EQ(json["Tasks"]["@odata.id"], "/redfish/v1/TaskService"); 72 EXPECT_EQ(json["Tasks"].size(), 1); 73 74 EXPECT_EQ(json["TelemetryService"]["@odata.id"], 75 "/redfish/v1/TelemetryService"); 76 EXPECT_EQ(json["TelemetryService"].size(), 1); 77 78 EXPECT_THAT(json["UUID"], 79 testing::MatchesRegex( 80 "[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-" 81 "9a-fA-F]{4}-[0-9a-fA-F]{12}")); 82 83 EXPECT_EQ(json["UpdateService"]["@odata.id"], "/redfish/v1/UpdateService"); 84 85 EXPECT_EQ(json["ProtocolFeaturesSupported"].size(), 6); 86 EXPECT_FALSE(json["ProtocolFeaturesSupported"]["ExcerptQuery"]); 87 EXPECT_EQ(json["ProtocolFeaturesSupported"]["ExpandQuery"]["ExpandAll"], 88 BMCWEB_INSECURE_ENABLE_REDFISH_QUERY); 89 EXPECT_EQ(json["ProtocolFeaturesSupported"]["ExpandQuery"]["Levels"], 90 BMCWEB_INSECURE_ENABLE_REDFISH_QUERY); 91 EXPECT_EQ(json["ProtocolFeaturesSupported"]["ExpandQuery"]["Links"], 92 BMCWEB_INSECURE_ENABLE_REDFISH_QUERY); 93 EXPECT_EQ(json["ProtocolFeaturesSupported"]["ExpandQuery"]["NoLinks"], 94 BMCWEB_INSECURE_ENABLE_REDFISH_QUERY); 95 if constexpr (BMCWEB_INSECURE_ENABLE_REDFISH_QUERY) 96 { 97 EXPECT_EQ(json["ProtocolFeaturesSupported"]["ExpandQuery"].size(), 5); 98 EXPECT_EQ(json["ProtocolFeaturesSupported"]["ExpandQuery"]["MaxLevels"], 99 6); 100 } 101 else 102 { 103 EXPECT_EQ(json["ProtocolFeaturesSupported"]["ExpandQuery"].size(), 4); 104 } 105 EXPECT_EQ(json["ProtocolFeaturesSupported"]["FilterQuery"], 106 BMCWEB_INSECURE_ENABLE_REDFISH_QUERY); 107 EXPECT_TRUE(json["ProtocolFeaturesSupported"]["OnlyMemberQuery"]); 108 EXPECT_TRUE(json["ProtocolFeaturesSupported"]["SelectQuery"]); 109 EXPECT_FALSE( 110 json["ProtocolFeaturesSupported"]["DeepOperations"]["DeepPOST"]); 111 EXPECT_FALSE( 112 json["ProtocolFeaturesSupported"]["DeepOperations"]["DeepPATCH"]); 113 EXPECT_EQ(json["ProtocolFeaturesSupported"]["DeepOperations"].size(), 2); 114 115 size_t expectedSize = 21; 116 117 if (BMCWEB_REDFISH_AGGREGATION) 118 { 119 EXPECT_EQ(json["AggregationService"]["@odata.id"], 120 "/redfish/v1/AggregationService"); 121 expectedSize++; 122 } 123 124 EXPECT_EQ(json.size(), expectedSize); 125 } 126 127 TEST(HandleServiceRootGet, ServiceRootStaticAttributesAreExpected) 128 { 129 auto shareAsyncResp = std::make_shared<bmcweb::AsyncResp>(); 130 131 shareAsyncResp->res.setCompleteRequestHandler(assertServiceRootGet); 132 133 redfish::handleServiceRootGetImpl(shareAsyncResp); 134 } 135 136 } // namespace 137 } // namespace redfish 138