MaxLoginAttemptBeforeLockout: add unit test

This commit adds the unit test for |maxLoginAttemptBeforeLockout|.

Tested: unit test passed.

Coverage:
  lines......: 80.0% (1843 of 2304 lines)
  functions..: 93.3% (374 of 401 functions)
  branches...: 32.3% (2893 of 8961 branches)

Signed-off-by: Nan Zhou <nanzhoumails@gmail.com>
Change-Id: I840dc472d6ac9d58273aaf754195e33276ea139f
diff --git a/test/user_mgr_test.cpp b/test/user_mgr_test.cpp
index b8d61e3..239dbeb 100644
--- a/test/user_mgr_test.cpp
+++ b/test/user_mgr_test.cpp
@@ -209,7 +209,7 @@
 # See the pam_unix manpage for other options.
 
 # here are the per-package modules (the "Primary" block)
-password	[success=ok default=die]	pam_tally2.so debug enforce_for_root reject_username minlen=8 difok=0 lcredit=0 ocredit=0 dcredit=0 ucredit=0 #some comments
+password	[success=ok default=die]	pam_tally2.so debug enforce_for_root reject_username minlen=8 difok=0 lcredit=0 ocredit=0 dcredit=0 ucredit=0 deny=2 #some comments
 password	[success=ok default=die]	pam_cracklib.so debug enforce_for_root reject_username minlen=8 difok=0 lcredit=0 ocredit=0 dcredit=0 ucredit=0 #some comments
 password	[success=ok default=die]	pam_ipmicheck.so spec_grp_name=ipmi use_authtok
 password	[success=ok ignore=ignore default=die]	pam_pwhistory.so debug enforce_for_root remember=0 use_authtok
@@ -619,5 +619,31 @@
     EXPECT_EQ(AccountPolicyIface::rememberOldPasswordTimes(), 0);
 }
 
+TEST_F(UserMgrInTest, MaxLoginAttemptBeforeLockoutReturnsIfValueIsTheSame)
+{
+    initializeAccountPolicy();
+    EXPECT_EQ(AccountPolicyIface::maxLoginAttemptBeforeLockout(), 2);
+    UserMgr::maxLoginAttemptBeforeLockout(2);
+    EXPECT_EQ(AccountPolicyIface::maxLoginAttemptBeforeLockout(), 2);
+}
+
+TEST_F(UserMgrInTest, MaxLoginAttemptBeforeLockoutOnSuccess)
+{
+    initializeAccountPolicy();
+    EXPECT_EQ(AccountPolicyIface::maxLoginAttemptBeforeLockout(), 2);
+    UserMgr::maxLoginAttemptBeforeLockout(16);
+    EXPECT_EQ(AccountPolicyIface::maxLoginAttemptBeforeLockout(), 16);
+}
+
+TEST_F(UserMgrInTest, MaxLoginAttemptBeforeLockoutOnFailure)
+{
+    EXPECT_NO_THROW(dumpStringToFile("whatever", tempPamConfigFile));
+    initializeAccountPolicy();
+    EXPECT_THROW(
+        UserMgr::maxLoginAttemptBeforeLockout(16),
+        sdbusplus::xyz::openbmc_project::Common::Error::InternalFailure);
+    EXPECT_EQ(AccountPolicyIface::rememberOldPasswordTimes(), 0);
+}
+
 } // namespace user
 } // namespace phosphor