MinPasswordLength: add unit test
Add unit test for the |minPasswordLength| function.
It can be shown that the test coverage increased.
Tested: unit test passed.
Coverage data:
lines......: 78.7% (1779 of 2261 lines)
functions..: 92.3% (348 of 377 functions)
branches...: 32.5% (2812 of 8655 branches)
Signed-off-by: Nan Zhou <nanzhoumails@gmail.com>
Change-Id: I85d309ac2cf1467ee1c56c6ecb076d82c5082e28
diff --git a/test/user_mgr_test.cpp b/test/user_mgr_test.cpp
index f2a9dd7..d10921a 100644
--- a/test/user_mgr_test.cpp
+++ b/test/user_mgr_test.cpp
@@ -552,5 +552,43 @@
EXPECT_NO_THROW(UserMgr::deleteUser(username));
}
+TEST_F(UserMgrInTest, MinPasswordLengthReturnsIfValueIsTheSame)
+{
+ initializeAccountPolicy();
+ EXPECT_EQ(AccountPolicyIface::minPasswordLength(), 8);
+ UserMgr::minPasswordLength(8);
+ EXPECT_EQ(AccountPolicyIface::minPasswordLength(), 8);
+}
+
+TEST_F(UserMgrInTest,
+ MinPasswordLengthRejectsTooShortPasswordWithInvalidArgument)
+{
+ initializeAccountPolicy();
+ EXPECT_EQ(AccountPolicyIface::minPasswordLength(), 8);
+ EXPECT_THROW(
+ UserMgr::minPasswordLength(minPasswdLength - 1),
+ sdbusplus::xyz::openbmc_project::Common::Error::InvalidArgument);
+ EXPECT_EQ(AccountPolicyIface::minPasswordLength(), 8);
+}
+
+TEST_F(UserMgrInTest, MinPasswordLengthOnSuccess)
+{
+ initializeAccountPolicy();
+ EXPECT_EQ(AccountPolicyIface::minPasswordLength(), 8);
+ UserMgr::minPasswordLength(16);
+ EXPECT_EQ(AccountPolicyIface::minPasswordLength(), 16);
+}
+
+TEST_F(UserMgrInTest, MinPasswordLengthOnFailure)
+{
+ EXPECT_NO_THROW(dumpStringToFile("whatever", tempPamConfigFile));
+ initializeAccountPolicy();
+ EXPECT_EQ(AccountPolicyIface::minPasswordLength(), 8);
+ EXPECT_THROW(
+ UserMgr::minPasswordLength(16),
+ sdbusplus::xyz::openbmc_project::Common::Error::InternalFailure);
+ EXPECT_EQ(AccountPolicyIface::minPasswordLength(), 8);
+}
+
} // namespace user
} // namespace phosphor