ThrowForInvalidPrivilege: add unit test
This commit adds unit test for the |throwForInvalidPrivilege| function.
Tested: unit test passed
Signed-off-by: Nan Zhou <nanzhoumails@gmail.com>
Change-Id: I0722ce2483adeffd493528c9c952aea9af181de6
diff --git a/test/user_mgr_test.cpp b/test/user_mgr_test.cpp
index 16d6617..f44282e 100644
--- a/test/user_mgr_test.cpp
+++ b/test/user_mgr_test.cpp
@@ -422,5 +422,20 @@
EXPECT_NO_THROW(UserMgr::deleteUser(username));
}
+TEST_F(UserMgrInTest, ThrowForInvalidPrivilegeThrowsWhenPrivilegeIsInvalid)
+{
+ EXPECT_THROW(
+ throwForInvalidPrivilege("whatever"),
+ sdbusplus::xyz::openbmc_project::Common::Error::InvalidArgument);
+}
+
+TEST_F(UserMgrInTest, ThrowForInvalidPrivilegeNoThrowWhenPrivilegeIsValid)
+{
+ EXPECT_NO_THROW(throwForInvalidPrivilege("priv-admin"));
+ EXPECT_NO_THROW(throwForInvalidPrivilege("priv-operator"));
+ EXPECT_NO_THROW(throwForInvalidPrivilege("priv-user"));
+ EXPECT_NO_THROW(throwForInvalidPrivilege("priv-noaccess"));
+}
+
} // namespace user
} // namespace phosphor
diff --git a/user_mgr.hpp b/user_mgr.hpp
index c0ebe0b..9f2770d 100644
--- a/user_mgr.hpp
+++ b/user_mgr.hpp
@@ -313,6 +313,13 @@
virtual void executeUserDelete(const char* userName);
+ /** @brief check for valid privielge
+ * method to check valid privilege, and throw if invalid
+ *
+ * @param[in] priv - privilege of the user
+ */
+ void throwForInvalidPrivilege(const std::string& priv);
+
private:
/** @brief sdbusplus handler */
sdbusplus::bus_t& bus;
@@ -348,13 +355,6 @@
*/
UserSSHLists getUserAndSshGrpList(void);
- /** @brief check for valid privielge
- * method to check valid privilege, and throw if invalid
- *
- * @param[in] priv - privilege of the user
- */
- void throwForInvalidPrivilege(const std::string& priv);
-
/** @brief check for valid groups
* method to check valid groups, and throw if invalid
*