예제 #1
0
  @Test(expected = BadCredentialsException.class)
  public void shouldThrowExceptionIfUserIsNotFound() {
    String username = "******";
    String password = "******";

    when(allAdminUsers.findByName(username)).thenReturn(null);

    authenticationService.checkFor(username, password);
  }
예제 #2
0
  @Test(expected = BadCredentialsException.class)
  public void shouldThrowExceptionIfUserPasswordIsNotCorrect() {
    String username = "******";
    String password = "******";
    AdminUser adminUser = new AdminUser(username, password);

    when(allAdminUsers.findByName(username)).thenReturn(adminUser);

    authenticationService.checkFor(username, "notAku");
  }
예제 #3
0
  @Test
  public void shouldUseAllAdminUsersToValidateUser() {
    String username = "******";
    String password = "******";
    AdminUser adminUser = new AdminUser(username, password);

    when(allAdminUsers.findByName(username)).thenReturn(adminUser);

    AuthenticationResponse authenticationResponse =
        authenticationService.checkFor(username, password);
    assertTrue(authenticationResponse.roles().contains("admin"));
  }