use of keywhiz.auth.User in project keywhiz by square.
the class UserAuthFactoryTest method successfulAuth.
@Test
public void successfulAuth() throws Exception {
User user = User.named("username");
Cookie sessionCookie = new Cookie("session", "valid-session");
cookies.put(sessionCookie.getName(), sessionCookie);
when(cookieAuthenticator.authenticate(sessionCookie)).thenReturn(Optional.of(user));
assertThat(factory.provide(request)).isEqualTo(user);
}
use of keywhiz.auth.User in project keywhiz by square.
the class BcryptAuthenticatorTest method bcryptAuthenticatorRejectsInvalidUsername.
@Test
public void bcryptAuthenticatorRejectsInvalidUsername() throws Exception {
String crazyUsername = "sysadmin)`~!@#$%^&*()+=[]{}\\|;:'\",<>?/\r\n\t";
Optional<User> missingUser = bcryptAuthenticator.authenticate(new BasicCredentials(crazyUsername, "validpass"));
assertThat(missingUser).isEmpty();
}
use of keywhiz.auth.User in project keywhiz by square.
the class BcryptAuthenticatorTest method bcryptAuthenticatorFailsForBadPassword.
@Test
public void bcryptAuthenticatorFailsForBadPassword() throws Exception {
when(userDAO.getHashedPassword("sysadmin")).thenReturn(Optional.of(hashedPass));
Optional<User> missingUser = bcryptAuthenticator.authenticate(new BasicCredentials("sysadmin", "badpass"));
assertThat(missingUser).isEmpty();
}
use of keywhiz.auth.User in project keywhiz by square.
the class BcryptAuthenticatorTest method bcryptAuthenticatorFailsForBadUser.
@Test
public void bcryptAuthenticatorFailsForBadUser() throws Exception {
when(userDAO.getHashedPassword("invaliduser")).thenReturn(Optional.empty());
Optional<User> missingUser = bcryptAuthenticator.authenticate(new BasicCredentials("invaliduser", "validpass"));
assertThat(missingUser).isEmpty();
}
use of keywhiz.auth.User in project keywhiz by square.
the class LdapAuthenticatorTest method ldapAuthenticatorThrowsWhenAuthFails.
@Ignore
@Test
public void ldapAuthenticatorThrowsWhenAuthFails() throws Exception {
// Zero results on a search indicates no valid user.
when(dnSearchResult.getEntryCount()).thenReturn(0);
Optional<User> missingUser = ldapAuthenticator.authenticate(new BasicCredentials("sysadmin", "badpass"));
assertThat(missingUser).isEmpty();
}
Aggregations