public void AllowLoginAttemptTest() { // arrange var user = new User { FailedLoginCount = 4, FailedLoginTimerStart = DateTime.Now.AddMinutes(-5) }; user.SetPassword("password"); // act user.AttemptLogin("wrongpassword"); // should reset FailedLoginStart var canLogin = user.CheckCanLogin(); // assert Assert.IsTrue(canLogin, "User should be able to attempt a login."); }
public void SetLoginBanTest() { // arrange var user = new User(); user.SetPassword("password"); // act user.AttemptLogin("wrongpassword"); user.AttemptLogin("wrongpassword"); user.AttemptLogin("wrongpassword"); user.AttemptLogin("wrongpassword"); user.AttemptLogin("wrongpassword"); var canLogin = user.CheckCanLogin(); // assert Assert.IsFalse(canLogin, "User should not be able to login."); }
public void ResetLoginBanTest() { // arrange var password = "******"; var user = new User(); user.BanLoginEnd = DateTime.Now.AddMilliseconds(-1); user.FailedLoginCount = 5; user.FailedLoginTimerStart = DateTime.Now.AddMinutes(-20); user.SetPassword(password); // act var canLogin = user.CheckCanLogin(); user.AttemptLogin(password); // assert Assert.IsTrue(canLogin, "User should be able to login."); Assert.IsNull(user.BanLoginEnd, "Ban clock should be reset."); Assert.IsNull(user.FailedLoginTimerStart, "Failed login timer should be reset."); Assert.AreEqual(0, user.FailedLoginCount, "Failed login count should be reset."); }
public void SetAndVerifyPasswordTest() { // arrange var user = new User(); // act user.SetPassword("thisIsMyNiftyPassword"); // assert Assert.IsFalse(user.AttemptLogin("thisismyniftypassword")); Assert.IsTrue(user.AttemptLogin("thisIsMyNiftyPassword")); }
public void ResetFailedLoginCountAndTimerTest() { // arrange var originalTimer = DateTime.Now.AddMinutes(-5); var user = new User { FailedLoginCount = 4, FailedLoginTimerStart = originalTimer }; user.SetPassword("password"); // act user.AttemptLogin("wrongpassword"); // assert Assert.AreEqual(user.FailedLoginCount, 1, "Counter wasn't reset"); Assert.AreNotEqual(user.FailedLoginTimerStart, originalTimer, "Timer didn't change."); Assert.IsTrue(user.FailedLoginTimerStart > originalTimer, "Timer wasn't reset"); }