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"); }
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"); }
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)); }
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"); }
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(); }
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")); }
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)); }
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"); }