Search in sources :

Example 1 with BasicCredentials

use of io.dropwizard.auth.basic.BasicCredentials in project keywhiz by square.

the class BcryptAuthenticatorTest method bcryptAuthenticatorCreatesUserOnSuccess.

@Test
public void bcryptAuthenticatorCreatesUserOnSuccess() throws Exception {
    when(userDAO.getHashedPassword("sysadmin")).thenReturn(Optional.of(hashedPass));
    User user = bcryptAuthenticator.authenticate(new BasicCredentials("sysadmin", "validpass")).orElseThrow(RuntimeException::new);
    assertThat(user).isEqualTo(User.named("sysadmin"));
}
Also used : User(keywhiz.auth.User) BasicCredentials(io.dropwizard.auth.basic.BasicCredentials) Test(org.junit.Test)

Example 2 with BasicCredentials

use of io.dropwizard.auth.basic.BasicCredentials in project keywhiz by square.

the class LdapAuthenticatorTest method ldapAuthenticatorRejectsInvalidUsername.

@Test
public void ldapAuthenticatorRejectsInvalidUsername() throws Exception {
    String crazyUsername = "sysadmin)`~!@#$%^&*()+=[]{}\\|;:'\",<>?/\r\n\t";
    Optional<User> missingUser = ldapAuthenticator.authenticate(new BasicCredentials(crazyUsername, "badpass"));
    assertThat(missingUser.isPresent()).isFalse();
}
Also used : User(keywhiz.auth.User) BasicCredentials(io.dropwizard.auth.basic.BasicCredentials) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 3 with BasicCredentials

use of io.dropwizard.auth.basic.BasicCredentials in project keywhiz by square.

the class LdapAuthenticatorTest method ldapAuthenticatorCreatesUserOnSuccess.

@Test
public void ldapAuthenticatorCreatesUserOnSuccess() throws Exception {
    when(ldapConnectionFactory.getLDAPConnection(PEOPLE_DN, "validpass")).thenReturn(ldapUserAuthConnection);
    User user = ldapAuthenticator.authenticate(new BasicCredentials("sysadmin", "validpass")).orElseThrow(RuntimeException::new);
    assertThat(user).isEqualTo(User.named("sysadmin"));
}
Also used : User(keywhiz.auth.User) BasicCredentials(io.dropwizard.auth.basic.BasicCredentials) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 4 with BasicCredentials

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

Example 5 with BasicCredentials

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

Aggregations

BasicCredentials (io.dropwizard.auth.basic.BasicCredentials)8 User (keywhiz.auth.User)8 Test (org.junit.Test)8 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)4