name constraint check: add unit tests
This commit adds unit test for |ThrowForUserNameConstraints|. All lines
are covered by test now.
Tested: unit test passed
Signed-off-by: Nan Zhou <nanzhoumails@gmail.com>
Change-Id: If1a0ff823ca0767f068030f205efdc1eb33e3029
diff --git a/test/user_mgr_test.cpp b/test/user_mgr_test.cpp
index 15a56fc..588c2fa 100644
--- a/test/user_mgr_test.cpp
+++ b/test/user_mgr_test.cpp
@@ -331,5 +331,34 @@
sdbusplus::xyz::openbmc_project::User::Common::Error::UserNameExists);
}
+TEST_F(
+ UserMgrInTest,
+ ThrowForUserNameConstraintsExceedIpmiMaxUserNameLenThrowsUserNameGroupFail)
+{
+ std::string strWith17Chars(17, 'A');
+ EXPECT_THROW(throwForUserNameConstraints(strWith17Chars, {"ipmi"}),
+ sdbusplus::xyz::openbmc_project::User::Common::Error::
+ UserNameGroupFail);
+}
+
+TEST_F(
+ UserMgrInTest,
+ ThrowForUserNameConstraintsExceedSystemMaxUserNameLenThrowsInvalidArgument)
+{
+ std::string strWith31Chars(31, 'A');
+ EXPECT_THROW(
+ throwForUserNameConstraints(strWith31Chars, {}),
+ sdbusplus::xyz::openbmc_project::Common::Error::InvalidArgument);
+}
+
+TEST_F(UserMgrInTest,
+ ThrowForUserNameConstraintsRegexMismatchThrowsInvalidArgument)
+{
+ std::string startWithNumber = "0ABC";
+ EXPECT_THROW(
+ throwForUserNameConstraints(startWithNumber, {"ipmi"}),
+ sdbusplus::xyz::openbmc_project::Common::Error::InvalidArgument);
+}
+
} // namespace user
} // namespace phosphor