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