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