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