Search in sources :

Example 11 with User

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);
}
Also used : Cookie(javax.ws.rs.core.Cookie) User(keywhiz.auth.User) Test(org.junit.Test)

Example 12 with 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();
}
Also used : User(keywhiz.auth.User) BasicCredentials(io.dropwizard.auth.basic.BasicCredentials) Test(org.junit.Test)

Example 13 with User

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();
}
Also used : User(keywhiz.auth.User) BasicCredentials(io.dropwizard.auth.basic.BasicCredentials) Test(org.junit.Test)

Example 14 with User

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();
}
Also used : User(keywhiz.auth.User) BasicCredentials(io.dropwizard.auth.basic.BasicCredentials) Test(org.junit.Test)

Example 15 with User

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();
}
Also used : User(keywhiz.auth.User) BasicCredentials(io.dropwizard.auth.basic.BasicCredentials) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

User (keywhiz.auth.User)17 Test (org.junit.Test)13 BasicCredentials (io.dropwizard.auth.basic.BasicCredentials)8 Ignore (org.junit.Ignore)4 LDAPConnection (com.unboundid.ldap.sdk.LDAPConnection)2 LDAPException (com.unboundid.ldap.sdk.LDAPException)2 GeneralSecurityException (java.security.GeneralSecurityException)2 ForbiddenException (javax.ws.rs.ForbiddenException)2 Cookie (javax.ws.rs.core.Cookie)2 NewCookie (javax.ws.rs.core.NewCookie)2 Response (javax.ws.rs.core.Response)1 SessionCookie (keywhiz.auth.cookie.SessionCookie)1 Request (okhttp3.Request)1 Response (okhttp3.Response)1