1 #include "bmcweb_config.h" 2 3 #include "async_resp.hpp" 4 #include "http_response.hpp" 5 #include "nlohmann/json.hpp" 6 #include "service_root.hpp" 7 8 #include <memory> 9 #include <vector> 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 bmcwebInsecureEnableQueryParams); 88 EXPECT_EQ(json["ProtocolFeaturesSupported"]["ExpandQuery"]["Levels"], 89 bmcwebInsecureEnableQueryParams); 90 EXPECT_EQ(json["ProtocolFeaturesSupported"]["ExpandQuery"]["Links"], 91 bmcwebInsecureEnableQueryParams); 92 EXPECT_EQ(json["ProtocolFeaturesSupported"]["ExpandQuery"]["NoLinks"], 93 bmcwebInsecureEnableQueryParams); 94 if (bmcwebInsecureEnableQueryParams) 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_FALSE(json["ProtocolFeaturesSupported"]["FilterQuery"]); 105 EXPECT_TRUE(json["ProtocolFeaturesSupported"]["OnlyMemberQuery"]); 106 EXPECT_TRUE(json["ProtocolFeaturesSupported"]["SelectQuery"]); 107 EXPECT_FALSE( 108 json["ProtocolFeaturesSupported"]["DeepOperations"]["DeepPOST"]); 109 EXPECT_FALSE( 110 json["ProtocolFeaturesSupported"]["DeepOperations"]["DeepPATCH"]); 111 EXPECT_EQ(json["ProtocolFeaturesSupported"]["DeepOperations"].size(), 2); 112 EXPECT_EQ(json.size(), 21); 113 } 114 115 TEST(HandleServiceRootGet, ServiceRootStaticAttributesAreExpected) 116 { 117 auto shareAsyncResp = std::make_shared<bmcweb::AsyncResp>(); 118 119 shareAsyncResp->res.setCompleteRequestHandler(assertServiceRootGet); 120 121 redfish::handleServiceRootGetImpl(shareAsyncResp); 122 } 123 124 } // namespace 125 } // namespace redfish 126