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