1 // SPDX-License-Identifier: Apache-2.0
2 // SPDX-FileCopyrightText: Copyright OpenBMC Authors
3 #include "async_resp.hpp"
4 #include "dbus_privileges.hpp"
5 #include "dbus_utility.hpp"
6
7 #include <memory>
8
9 #include <gtest/gtest.h>
10
11 namespace crow
12 {
13 namespace
14 {
15
TEST(HandleRequestUserInfo,NoError)16 TEST(HandleRequestUserInfo, NoError)
17 {
18 const std::shared_ptr<bmcweb::AsyncResp> asyncResp =
19 std::make_shared<bmcweb::AsyncResp>();
20 const boost::system::error_code ec = {};
21 bool called = false;
22
23 handleRequestUserInfo(
24 asyncResp, ec,
25 [&called](const dbus::utility::DBusPropertiesMap& /* userInfoMap */) {
26 called = true;
27 },
28 {});
29 EXPECT_TRUE(called);
30 }
31
TEST(HandleRequestUserInfo,GenericError)32 TEST(HandleRequestUserInfo, GenericError)
33 {
34 const std::shared_ptr<bmcweb::AsyncResp> asyncResp =
35 std::make_shared<bmcweb::AsyncResp>();
36 const boost::system::error_code ec = {1, boost::system::system_category()};
37 bool called = false;
38 handleRequestUserInfo(
39 asyncResp, ec,
40 [&called](const dbus::utility::DBusPropertiesMap& /* userInfoMap */) {
41 called = true;
42 },
43 {});
44 EXPECT_FALSE(called);
45 EXPECT_EQ(asyncResp->res.resultInt(), 500);
46 }
47
TEST(HandleRequestUserInfo,UserManagerUnreachableError)48 TEST(HandleRequestUserInfo, UserManagerUnreachableError)
49 {
50 const std::shared_ptr<bmcweb::AsyncResp> asyncResp =
51 std::make_shared<bmcweb::AsyncResp>();
52 const boost::system::error_code ec = {boost::system::errc::host_unreachable,
53 boost::system::system_category()};
54
55 bool called = false;
56 handleRequestUserInfo(
57 asyncResp, ec,
58 [&called](const dbus::utility::DBusPropertiesMap& /* userInfoMap */) {
59 called = true;
60 },
61 {});
62 EXPECT_FALSE(called);
63 EXPECT_EQ(asyncResp->res.resultInt(), 500);
64 }
65
TEST(HandleRequestUserInfo,UnauthorizedError)66 TEST(HandleRequestUserInfo, UnauthorizedError)
67 {
68 const std::shared_ptr<bmcweb::AsyncResp> asyncResp =
69 std::make_shared<bmcweb::AsyncResp>();
70 const boost::system::error_code ec = {boost::system::errc::io_error,
71 boost::system::system_category()};
72
73 bool called = false;
74 handleRequestUserInfo(
75 asyncResp, ec,
76 [&called](const dbus::utility::DBusPropertiesMap& /* userInfoMap */) {
77 called = true;
78 },
79 {});
80 EXPECT_FALSE(called);
81 EXPECT_EQ(asyncResp->res.resultInt(), 401);
82 }
83 } // namespace
84 } // namespace crow
85