예제 #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.");
        }
예제 #2
0
        public void CheckUserIsBannedTest()
        {
            // arrange
            var user = new User();
            user.BanLoginEnd = DateTime.Now.AddMinutes(1);

            // act
            var canLogin = user.CheckCanLogin();

            // assert
            Assert.IsFalse(canLogin, "User should be banned");
        }
예제 #3
0
        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.");
        }
예제 #4
0
        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.");
        }
예제 #5
0
        public void SignUpUser(User user)
        {
            if (userRepo.Get(u => u.NewEmail == user.NewEmail || u.ConfirmedEmail == user.NewEmail).Any())
            {
                throw new ArgumentException("This email is unavailable.");
            }

            if (user.Roles == null || user.Roles.Count == 0)
            {
                var roleRepo = unitOfWork.GetRepository<Role>();
                user.Roles = new List<Role>();
                user.Roles.Add(roleRepo.Get(x => x.InitialRole).First());
            }

            userRepo.Add(user);
        }
예제 #6
0
        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");
        }
예제 #7
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.");
        }
예제 #8
0
        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;
        }
예제 #9
0
        public void SetLowercaseEmailTest()
        {
            // arrange
            var email = "*****@*****.**";
            var expectedResult = "*****@*****.**";

            // act
            var user = new User { NewEmail = email, ConfirmedEmail = email };

            // assert
            Assert.AreEqual(expectedResult, user.NewEmail, "New email isn't lowercase.");
            Assert.AreEqual(expectedResult, user.ConfirmedEmail, "Confirmed email isn't lowercase.");
        }
예제 #10
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.");
        }
예제 #11
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.");
        }
예제 #12
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");
        }
예제 #13
0
        public void GetUserEmailTest()
        {
            // arrange
            var user1 = new User { NewEmail = "*****@*****.**" };
            var user2 = new User { NewEmail = "*****@*****.**", ConfirmedEmail = "*****@*****.**" };
            var user3 = new User { ConfirmedEmail = "*****@*****.**" };

            // act
            var email1 = user1.GetEmail();
            var email2 = user2.GetEmail();
            var email3 = user3.GetEmail();

            // assert
            Assert.AreEqual("*****@*****.**", email1);
            Assert.AreEqual("*****@*****.**", email2);
            Assert.AreEqual("*****@*****.**", email3);
        }
예제 #14
0
        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;
        }
예제 #15
0
        public void SignUpUserTest()
        {
            // arrange
            var newUser = new User { NewEmail = "*****@*****.**" };

            // act
            userService.SignUpUser(newUser);

            // assert
            Assert.IsNotNull(
                userService.GetAllUsers().FirstOrDefault(x => x.NewEmail == newUser.NewEmail),
                "User wasn't added to mock repo.");
            Assert.AreEqual(
                Guid.Parse("0cde999b-4e51-43b5-b716-e1835c78882b"),
                userService.GetAllUsers().First(x => x.NewEmail == newUser.NewEmail).Roles.First().Id);
        }
예제 #16
0
        public void RejectUserWithDuplicateConfirmedEmailTest()
        {
            // arrange
            var newUser = new User { ConfirmedEmail = "*****@*****.**" }; // this email should already exist

            // act
            userService.SignUpUser(newUser);

            // assert
            Assert.AreEqual(
                1,
                userService.GetAllUsers().Where(x => x.NewEmail == newUser.NewEmail || x.ConfirmedEmail == newUser.NewEmail),
                "Too many users were added with the same email address."
            );
        }
예제 #17
0
        public void SetAndVerifyPasswordTest()
        {
            // arrange
            var user = new User();

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

            // assert
            Assert.IsFalse(user.AttemptLogin("thisismyniftypassword"));
            Assert.IsTrue(user.AttemptLogin("thisIsMyNiftyPassword"));
        }