Пример #1
0
        public void When_User_Is_Unlocked_FailedPasswordAnswerAttemptWindowStart_Must_Be_Reset_To_Default()
        {
            // Arrange
            User user = new User("username", password, passwordCoder);

            user.IncrementFailedPasswordAnswerAttemptCount();
            user.IncrementFailedPasswordAnswerAttemptCount();
            user.TryToLockoutUser(2);
            var wasLockedOut = user.IsLockedOut;

            // Act
            user.UnlockUser();

            // Assert
            Assert.IsTrue(wasLockedOut, "User wasn't ever locked out.");
            Assert.AreEqual(DateTime.MinValue.ToLocalTime(), user.FailedPasswordAnswerAttemptWindowStart, "FailedPasswordAnswerAttemptWindowstart isn't set to default.");
            Assert.IsTrue(DateTime.MinValue.ToLocalTime() == user.FailedPasswordAnswerAttemptWindowStart, "FailedPasswordAnswerAttemptWindowstart isn't set to default.");
        }
Пример #2
0
        public void When_User_Is_Unlocked_FailedPasswordAnswerAttemptCount_Must_Be_Reset_To_Zero()
        {
            // Arrange
            User user = new User("username", password, passwordCoder);

            user.IncrementFailedPasswordAnswerAttemptCount();
            user.IncrementFailedPasswordAnswerAttemptCount();

            // Act
            user.UnlockUser();

            // Assert
            Assert.AreEqual(0, user.FailedPasswordAnswerAttemptCount, "FailedPasswordAnswerAttemptCount isn't set to zero.");
        }
Пример #3
0
        public void When_Incrementing_FailedPasswordAnswerAttemptCount_Must_Set_Its_StartWindow()
        {
            // Arrange
            User user = new User("username", password, passwordCoder);

            user.UnlockUser();

            // Act

            user.IncrementFailedPasswordAnswerAttemptCount();
            user.IncrementFailedPasswordAnswerAttemptCount();

            // Assert
            Assert.IsTrue(user.FailedPasswordAnswerAttemptWindowStart > DateTime.MinValue.ToLocalTime(), "FailedPasswordAnswerAttemptWindowStart is not changed.");
            Assert.AreNotEqual(DateTime.MinValue.ToLocalTime(), user.FailedPasswordAnswerAttemptWindowStart, "FailedPasswordAnswerAttemptWindowStart and DateTime.MinValue are equal.");
        }
Пример #4
0
        public void If_Time_Of_Tracking_Bad_Attempts_Is_Passed_Counters_Must_Be_Reset()
        {
            // Arrange
            User user = new User("username", password, passwordCoder);

            user.IncrementFailedPasswordAttemptCount();
            user.IncrementFailedPasswordAttemptCount();
            user.IncrementFailedPasswordAnswerAttemptCount();

            PropertyInfo passwordAnswerProperty = user.GetType().GetProperty("FailedPasswordAnswerAttemptWindowStart",
                BindingFlags.Public | BindingFlags.Instance);

            passwordAnswerProperty.SetValue(user, DateTime.Now.AddMinutes(-30), null);

            PropertyInfo passwordProperty = user.GetType().GetProperty("FailedPasswordAttemptWindowStart",
                BindingFlags.Public | BindingFlags.Instance);
            passwordProperty.SetValue(user, DateTime.Now.AddMinutes(-30), null);

            // Act
            user.CheckTrackingFailedAttempts(1);

            // Assert
            Assert.AreEqual(0, user.FailedPasswordAnswerAttemptCount, "FailedPasswordAnswerAttempt counter isn't reset.");
            Assert.AreEqual(DateTime.MinValue.ToLocalTime(), user.FailedPasswordAnswerAttemptWindowStart, "FailedPasswordAnswerAttemptWindowStart isn't reset to min datetime.");
            Assert.AreEqual(0, user.FailedPasswordAttemptCount, "FailedPasswordAttempt counter isn't reset.");
            Assert.AreEqual(DateTime.MinValue.ToLocalTime(), user.FailedPasswordAttemptWindowStart, "FailedPasswordAttemptWindowStart isn't reset to min datetime.");
        }
Пример #5
0
        public void Can_Reset_FailedPasswordAnswerAttemptCount()
        {
            // Arrange
            User user = new User("username", password, passwordCoder);

            user.IncrementFailedPasswordAnswerAttemptCount();
            user.IncrementFailedPasswordAnswerAttemptCount();

            // Act
            user.ResetFailedPasswordAnswerAttemptCount();

            // Assert
            Assert.AreEqual(0, user.FailedPasswordAnswerAttemptCount, "FailedPasswordAnswerAttemptCount isn't set to zero.");
        }
Пример #6
0
        public void Can_Increment_FailedPasswordAnswerAttemptCount()
        {
            // Arrange
            User user = new User("username", password, passwordCoder);

            // Act
            user.IncrementFailedPasswordAnswerAttemptCount();
            user.IncrementFailedPasswordAnswerAttemptCount();
            user.IncrementFailedPasswordAnswerAttemptCount();

            // Assert
            Assert.AreEqual(3, user.FailedPasswordAnswerAttemptCount, "Can't increment FailedPasswordAnswerAttemptCount.");
        }