1 #include "bmcweb_config.h"
2 
3 #include "http_response.hpp"
4 #include "include/async_resp.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_11_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(), 1);
49     EXPECT_EQ(json["Links"]["Sessions"].size(), 1);
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.9.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(
75         json["UUID"],
76         testing::MatchesRegex("[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               bmcwebInsecureEnableQueryParams);
85     EXPECT_EQ(json["ProtocolFeaturesSupported"]["ExpandQuery"]["Levels"],
86               bmcwebInsecureEnableQueryParams);
87     EXPECT_EQ(json["ProtocolFeaturesSupported"]["ExpandQuery"]["Links"],
88               bmcwebInsecureEnableQueryParams);
89     EXPECT_EQ(json["ProtocolFeaturesSupported"]["ExpandQuery"]["NoLinks"],
90               bmcwebInsecureEnableQueryParams);
91     if (bmcwebInsecureEnableQueryParams)
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_FALSE(json["ProtocolFeaturesSupported"]["FilterQuery"]);
102     EXPECT_TRUE(json["ProtocolFeaturesSupported"]["OnlyMemberQuery"]);
103     EXPECT_TRUE(json["ProtocolFeaturesSupported"]["SelectQuery"]);
104     EXPECT_FALSE(
105         json["ProtocolFeaturesSupported"]["DeepOperations"]["DeepPOST"]);
106     EXPECT_FALSE(
107         json["ProtocolFeaturesSupported"]["DeepOperations"]["DeepPATCH"]);
108     EXPECT_EQ(json["ProtocolFeaturesSupported"]["DeepOperations"].size(), 2);
109     EXPECT_EQ(json.size(), 21);
110 }
111 
112 TEST(HandleServiceRootGet, ServiceRootStaticAttributesAreExpected)
113 {
114     auto shareAsyncResp = std::make_shared<bmcweb::AsyncResp>();
115 
116     shareAsyncResp->res.setCompleteRequestHandler(assertServiceRootGet);
117 
118     redfish::handleServiceRootGetImpl(shareAsyncResp);
119 }
120 
121 } // namespace
122 } // namespace redfish
123