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