Beispiel #1
0
        public void verifyUsernameIsInvalid()
        {
            User                 user            = new User();
            UserRepository       repo            = new UserRepository();
            PasswordHasher       hasherAlgorithm = new HmacSha512Hasher();
            UserManagerViewModel target          = new UserManagerViewModel(user, repo, hasherAlgorithm);

            target.Username = "******";
            target.Password = "******";
            target.Realname = "Mig";
            target.AddUser();
            Assert.AreEqual(1, target.Users.Count, "Should have addded the user");

            //User is clear
            Assert.IsTrue(String.IsNullOrEmpty(target.Username));
            Assert.IsTrue(String.IsNullOrEmpty(target.Password));
            Assert.IsTrue(String.IsNullOrEmpty(target.Realname));

            //Test User
            target.Username = "******";
            target.Password = "******";
            target.IsUserValid();
            Assert.IsFalse(target.IsAuthenticated, "User should be invalid");
            Assert.IsFalse(String.IsNullOrEmpty((target as IDataErrorInfo).Error), "There should be an error message");
        }
Beispiel #2
0
        public void verifyThatAfterCorrectingPropertiesAndUserValidNoErrorMessagesExist()
        {
            User                 user            = new User();
            UserRepository       repo            = new UserRepository();
            PasswordHasher       hasherAlgorithm = new HmacSha512Hasher();
            UserManagerViewModel target          = new UserManagerViewModel(user, repo, hasherAlgorithm);

            target.Username = "******";
            target.Password = "******";
            target.Realname = "Mig";
            target.AddUser();
            Assert.AreEqual(1, target.Users.Count, "Should have addded the user");

            //Test User - Fail
            target.Username = "******";
            target.Password = "******";
            target.IsUserValid();
            Assert.IsFalse(target.IsAuthenticated, "User should be invalid");
            Assert.IsFalse(String.IsNullOrEmpty((target as IDataErrorInfo).Error), "There should be an error message");

            //Test User - Pass
            target.Username = "******";
            target.Password = "******";
            target.IsUserValid();
            Assert.IsTrue(target.IsAuthenticated, "User should be valid");
            Assert.IsTrue(String.IsNullOrEmpty((target as IDataErrorInfo).Error), "There should not be an error message");
        }
Beispiel #3
0
        public void hmacsha512Test()
        {
            string         key            = "key";
            PasswordHasher target         = new HmacSha512Hasher();
            string         hashedPassword = target.GetHash(@"teste", key);
            string         validHash      = @"3ec5572cbd1a609b00bec40e37ba5630b1218c146c339cdd26286ada12aebb77db9e5527c268cc04e1242b8817c26b1abc34077ea6a5702934f62d44417bdf3c";

            Assert.True(target.VerifyHash(@"teste", validHash, key));
        }
Beispiel #4
0
        public void addUserThroughCommandAddUser()
        {
            User                 user            = new User();
            UserRepository       repo            = new UserRepository();
            PasswordHasher       hasherAlgorithm = new HmacSha512Hasher();
            UserManagerViewModel target          = new UserManagerViewModel(user, repo, hasherAlgorithm);

            target.Username = "******";
            target.Password = "******";
            target.Realname = "Mig";
            target.AddUserCommand.Execute(null);
            Assert.AreEqual(1, target.Users.Count, "Should have addded the user");
        }
Beispiel #5
0
        protected override void OnStartup(StartupEventArgs e)
        {
            base.OnStartup(e);
            MainWindow window = new MainWindow();

            User           user      = new User();
            UserRepository repo      = new UserRepository();
            PasswordHasher hasher    = new HmacSha512Hasher();
            var            viewModel = new UserManagerViewModel(user, repo, hasher);

            window.DataContext = viewModel;
            window.Show();
        }
Beispiel #6
0
        public void addingNewUserUserHashingFunction()
        {
            User                 user            = new User();
            UserRepository       repo            = new UserRepository();
            PasswordHasher       hasherAlgorithm = new HmacSha512Hasher();
            UserManagerViewModel target          = new UserManagerViewModel(user, repo, hasherAlgorithm);

            target.Username = "******";
            target.Password = "******";
            target.Realname = "Mig";
            target.AddUser();

            Assert.IsTrue(hasherAlgorithm.VerifyHash("teste", target.Users[0].Password, "mige"));
        }
Beispiel #7
0
        public void verifyThatAfterAddingUserUIisCleared()
        {
            User                 user            = new User();
            UserRepository       repo            = new UserRepository();
            PasswordHasher       hasherAlgorithm = new HmacSha512Hasher();
            UserManagerViewModel target          = new UserManagerViewModel(user, repo, hasherAlgorithm);

            target.Username = "******";
            target.Password = "******";
            target.Realname = "Mig";
            target.AddUser();

            Assert.IsTrue(String.IsNullOrEmpty(target.Username));
            Assert.IsTrue(String.IsNullOrEmpty(target.Password));
            Assert.IsTrue(String.IsNullOrEmpty(target.Realname));
        }
Beispiel #8
0
        public void verifyThatAddingUserWithErrorsFails()
        {
            User                 user            = new User();
            UserRepository       repo            = new UserRepository();
            PasswordHasher       hasherAlgorithm = new HmacSha512Hasher();
            UserManagerViewModel target          = new UserManagerViewModel(user, repo, hasherAlgorithm);

            target.Username = "******";
            target.Password = "******";
            target.Realname = "Mig";
            string error = (target as IDataErrorInfo)["Username"];

            Assert.IsFalse(String.IsNullOrEmpty(error), "Should have received error message");

            target.AddUser();
            Assert.AreEqual(0, target.Users.Count, "Should have not addded the user");
        }