xref: /openbmc/bmcweb/features/google/google_service_root_test.cpp (revision 3b28fa2b201513be89807dfb76b47b3ca7ee3f9b)
1*3b28fa2bSEd Tanous // SPDX-License-Identifier: Apache-2.0
2*3b28fa2bSEd Tanous // SPDX-FileCopyrightText: Copyright OpenBMC Authors
3*3b28fa2bSEd Tanous #include "async_resp.hpp"
4*3b28fa2bSEd Tanous #include "google_service_root.hpp"
5*3b28fa2bSEd Tanous #include "http_request.hpp"
6*3b28fa2bSEd Tanous #include "http_response.hpp"
7*3b28fa2bSEd Tanous 
8*3b28fa2bSEd Tanous #include <boost/beast/http/verb.hpp>
9*3b28fa2bSEd Tanous #include <nlohmann/json.hpp>
10*3b28fa2bSEd Tanous 
11*3b28fa2bSEd Tanous #include <memory>
12*3b28fa2bSEd Tanous #include <system_error>
13*3b28fa2bSEd Tanous 
14*3b28fa2bSEd Tanous #include <gtest/gtest.h>
15*3b28fa2bSEd Tanous 
16*3b28fa2bSEd Tanous namespace crow::google_api
17*3b28fa2bSEd Tanous {
18*3b28fa2bSEd Tanous namespace
19*3b28fa2bSEd Tanous {
20*3b28fa2bSEd Tanous 
validateServiceRootGet(crow::Response & res)21*3b28fa2bSEd Tanous void validateServiceRootGet(crow::Response& res)
22*3b28fa2bSEd Tanous {
23*3b28fa2bSEd Tanous     nlohmann::json& json = res.jsonValue;
24*3b28fa2bSEd Tanous     EXPECT_EQ(json["@odata.id"], "/google/v1");
25*3b28fa2bSEd Tanous     EXPECT_EQ(json["@odata.type"],
26*3b28fa2bSEd Tanous               "#GoogleServiceRoot.v1_0_0.GoogleServiceRoot");
27*3b28fa2bSEd Tanous     EXPECT_EQ(json["@odata.id"], "/google/v1");
28*3b28fa2bSEd Tanous     EXPECT_EQ(json["Id"], "Google Rest RootService");
29*3b28fa2bSEd Tanous     EXPECT_EQ(json["Name"], "Google Service Root");
30*3b28fa2bSEd Tanous     EXPECT_EQ(json["Version"], "1.0.0");
31*3b28fa2bSEd Tanous     EXPECT_EQ(json["RootOfTrustCollection"]["@odata.id"],
32*3b28fa2bSEd Tanous               "/google/v1/RootOfTrustCollection");
33*3b28fa2bSEd Tanous }
34*3b28fa2bSEd Tanous 
TEST(HandleGoogleV1Get,OnSuccess)35*3b28fa2bSEd Tanous TEST(HandleGoogleV1Get, OnSuccess)
36*3b28fa2bSEd Tanous {
37*3b28fa2bSEd Tanous     std::error_code ec;
38*3b28fa2bSEd Tanous     auto asyncResp = std::make_shared<bmcweb::AsyncResp>();
39*3b28fa2bSEd Tanous 
40*3b28fa2bSEd Tanous     asyncResp->res.setCompleteRequestHandler(validateServiceRootGet);
41*3b28fa2bSEd Tanous 
42*3b28fa2bSEd Tanous     crow::Request dummyRequest{{boost::beast::http::verb::get, "", 11}, ec};
43*3b28fa2bSEd Tanous     handleGoogleV1Get(dummyRequest, asyncResp);
44*3b28fa2bSEd Tanous }
45*3b28fa2bSEd Tanous 
46*3b28fa2bSEd Tanous } // namespace
47*3b28fa2bSEd Tanous } // namespace crow::google_api
48