summaryrefslogtreecommitdiff
path: root/test/include/dbus_privileges_test.cpp
blob: 9b5f72bf780857080f2299db6c4edf38f034cc38 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: Copyright OpenBMC Authors
#include "async_resp.hpp"
#include "dbus_privileges.hpp"
#include "dbus_utility.hpp"

#include <memory>

#include <gtest/gtest.h>

namespace crow
{
namespace
{

TEST(HandleRequestUserInfo, NoError)
{
    const std::shared_ptr<bmcweb::AsyncResp> asyncResp =
        std::make_shared<bmcweb::AsyncResp>();
    const boost::system::error_code ec = {};
    bool called = false;

    handleRequestUserInfo(
        asyncResp, ec,
        [&called](const dbus::utility::DBusPropertiesMap& /* userInfoMap */) {
            called = true;
        },
        {});
    EXPECT_TRUE(called);
}

TEST(HandleRequestUserInfo, GenericError)
{
    const std::shared_ptr<bmcweb::AsyncResp> asyncResp =
        std::make_shared<bmcweb::AsyncResp>();
    const boost::system::error_code ec = {1, boost::system::system_category()};
    bool called = false;
    handleRequestUserInfo(
        asyncResp, ec,
        [&called](const dbus::utility::DBusPropertiesMap& /* userInfoMap */) {
            called = true;
        },
        {});
    EXPECT_FALSE(called);
    EXPECT_EQ(asyncResp->res.resultInt(), 500);
}

TEST(HandleRequestUserInfo, UserManagerUnreachableError)
{
    const std::shared_ptr<bmcweb::AsyncResp> asyncResp =
        std::make_shared<bmcweb::AsyncResp>();
    const boost::system::error_code ec = {boost::system::errc::host_unreachable,
                                          boost::system::system_category()};

    bool called = false;
    handleRequestUserInfo(
        asyncResp, ec,
        [&called](const dbus::utility::DBusPropertiesMap& /* userInfoMap */) {
            called = true;
        },
        {});
    EXPECT_FALSE(called);
    EXPECT_EQ(asyncResp->res.resultInt(), 500);
}

TEST(HandleRequestUserInfo, UnauthorizedError)
{
    const std::shared_ptr<bmcweb::AsyncResp> asyncResp =
        std::make_shared<bmcweb::AsyncResp>();
    const boost::system::error_code ec = {boost::system::errc::io_error,
                                          boost::system::system_category()};

    bool called = false;
    handleRequestUserInfo(
        asyncResp, ec,
        [&called](const dbus::utility::DBusPropertiesMap& /* userInfoMap */) {
            called = true;
        },
        {});
    EXPECT_FALSE(called);
    EXPECT_EQ(asyncResp->res.resultInt(), 401);
}
} // namespace
} // namespace crow