blob: 9b5f72bf780857080f2299db6c4edf38f034cc38 [file] [log] [blame]
Ed Tanous6cbd6c42025-07-10 09:30:15 -07001// 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
11namespace crow
12{
13namespace
14{
15
16TEST(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
32TEST(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
48TEST(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
66TEST(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