Exemple #1
0
        public void ConfirmEmailTest()
        {
            // arrange
            var user1 = new User
            {
                NewEmail = "*****@*****.**",
                NewEmailConfirmationKey = "CorrectKey"
            };
            user1.SetPassword("CorrrectPassword");

            var user2 = new User
            {
                NewEmail = "*****@*****.**",
                NewEmailConfirmationKey = "CorrectKey"
            };
            user2.SetPassword("CorrrectPassword");

            var user3 = new User
            {
                NewEmail = "*****@*****.**",
                NewEmailConfirmationKey = "CorrectKey"
            };
            user3.SetPassword("CorrrectPassword");

            var user4 = new User
            {
                NewEmail = "*****@*****.**",
                NewEmailConfirmationKey = "CorrectKey"
            };
            user4.SetPassword("CorrrectPassword");

            // act
            bool shouldBeFalse = user1.ConfirmEmail("CorrrectPassword", "*****@*****.**", "CorrectKey");
            bool shouldAlsoBeFalse = user2.ConfirmEmail("CorrrectPassword", "*****@*****.**", "WrongKey");
            bool shouldBeTrue = user3.ConfirmEmail("CorrrectPassword", "*****@*****.**", "CorrectKey");
            bool anotherShouldBeFalse = user4.ConfirmEmail("WrongPassword", "*****@*****.**", "CorrectKey");

            // assert
            Assert.IsNull(user1.ConfirmedEmail, "Confirmed sendEmail should be null.");
            Assert.IsNotNull(user1.NewEmail, "New sendEmail should not be null.");
            Assert.IsNotNull(user1.NewEmailConfirmationKey, "New sendEmail confirmation key should not be null.");
            Assert.IsFalse(shouldBeFalse, "The confirm sendEmail method should have returned false.");

            Assert.IsNull(user2.ConfirmedEmail, "Confirmed sendEmail should be null.");
            Assert.IsNotNull(user2.NewEmail, "New sendEmail should not be null.");
            Assert.IsNotNull(user2.NewEmailConfirmationKey, "New sendEmail confirmation key should not be null.");
            Assert.IsFalse(shouldAlsoBeFalse, "The confirm sendEmail method should have returned false.");

            Assert.IsNull(user3.NewEmail, "New sendEmail should be null.");
            Assert.IsNotNull(user3.ConfirmedEmail, "Confirmed sendEmail should not be null.");
            Assert.IsNull(user3.NewEmailConfirmationKey, "New sendEmail confirmation key should be null.");
            Assert.IsTrue(shouldBeTrue, "The confirm sendEmail method should have returned true.");

            Assert.IsNull(user4.ConfirmedEmail, "Confirmed sendEmail should be null.");
            Assert.IsNotNull(user4.NewEmail, "New sendEmail should not be null.");
            Assert.IsNotNull(user4.NewEmailConfirmationKey, "New sendEmail confirmation key should not be null.");
            Assert.IsFalse(anotherShouldBeFalse, "The confirm sendEmail method should have returned false.");
        }
        public void RejectLoginForWrongPasswordTest()
        {
            // arrange
            var user = new User();
            user.SetNewEmail("*****@*****.**");
            user.SetPassword("password");

            uow.GetRepository<User>().Add(user);

            // act
            var isSuccess = webSecurity.Login("*****@*****.**", "wrongpassword");

            // assert
            Assert.IsFalse(isSuccess.Success, "User with incorrect password should not be logged in.");
        }
        public void LoginUserTest()
        {
            // arrange
            var user = new User();
            user.SetNewEmail("*****@*****.**");
            user.SetPassword("password");

            uow.GetRepository<User>().Add(user);

            // act
            var isSuccess = webSecurity.Login("*****@*****.**", "password");

            // assert
            Assert.IsTrue(isSuccess.Success, "User should be logged in.");
        }
Exemple #4
0
        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 static List<User> CreateUsers(List<Role> roles, List<Profile> profiles)
        {
            var users = new List<User>();

            var superUser = new User
            {
                Id = Guid.Parse("a54b4703-f055-4492-8a31-39efe5c5223d"),
                ConfirmedEmail = "*****@*****.**",
                UserProfile = profiles.First(x => x.Id == Guid.Parse("43edfc9a-b019-43ca-9536-e0051a7243c9"))
            };
            superUser.SetPassword("4Password!");
            superUser.Roles.Add(roles.First(r => r.Description == "Super User"));
            users.Add(superUser);

            var mercynaryUser = new User
            {
                Id = Guid.Parse("f0450fab-6095-4284-8785-0888c14a8e05"),
                NewEmail = "*****@*****.**",
                UserProfile = profiles.First(x => x.Id == Guid.Parse("57853c1a-ec2a-4de8-9642-a3494e415fb2"))
            };
            mercynaryUser.SetPassword("password");
            mercynaryUser.Roles.Add(roles.First(x => x.Id == Guid.Parse("0cde999b-4e51-43b5-b716-e1835c78882b")));
            users.Add(mercynaryUser);

            return users;
        }
Exemple #6
0
        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.");
        }
Exemple #7
0
        public void SetAndVerifyPasswordTest()
        {
            // arrange
            var user = new User();

            // act
            user.SetPassword("thisIsMyNiftyPassword");

            // assert
            Assert.IsFalse(user.AttemptLogin("thisismyniftypassword"));
            Assert.IsTrue(user.AttemptLogin("thisIsMyNiftyPassword"));
        }
Exemple #8
0
        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.");
        }
Exemple #9
0
        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");
        }
        public User ToUser(MetroRegionService metroRegionService)
        {
            var user = new User
            {
                UserProfile = new Profile {
                    FirstName = this.FirstName,
                    LastName = this.LastName,
                    CellPhoneNumber = this.CellPhone,
                    MetroRegion = metroRegionService.GetRegion(this.Region)
                }
            };
            user.SetNewEmail(this.Email);
            user.SetPassword(this.Password);

            return user;
        }
        public void RejectLoginTest()
        {
            // arrange
            var user = new User();
            user.SetPassword("password");
            user.SetNewEmail("*****@*****.**");
            user.BanLoginEnd = DateTime.Now.AddMinutes(2);

            uow.GetRepository<User>().Add(user);

            // act
            var isSuccess = webSecurity.Login("*****@*****.**", "password");

            // assert
            Assert.IsFalse(isSuccess.Success, "User should not be logged in");
        }