Пример #1
0
  @Test
  public void changePassword() {
    changePasswordPage.open();
    loginPage.login("test-user@localhost", "password");

    Event event =
        events
            .expectLogin()
            .client("account")
            .detail(Details.REDIRECT_URI, ACCOUNT_REDIRECT + "?path=password")
            .assertEvent();
    String sessionId = event.getSessionId();
    String userId = event.getUserId();
    changePasswordPage.changePassword("", "new-password", "new-password");

    Assert.assertEquals("Please specify password.", profilePage.getError());

    changePasswordPage.changePassword("password", "new-password", "new-password2");

    Assert.assertEquals("Password confirmation doesn't match.", profilePage.getError());

    changePasswordPage.changePassword("password", "new-password", "new-password");

    Assert.assertEquals("Your password has been updated.", profilePage.getSuccess());

    events.expectAccount(EventType.UPDATE_PASSWORD).assertEvent();

    changePasswordPage.logout();

    events
        .expectLogout(sessionId)
        .detail(Details.REDIRECT_URI, changePasswordPage.getPath())
        .assertEvent();

    loginPage.open();
    loginPage.login("test-user@localhost", "password");

    Assert.assertEquals("Invalid username or password.", loginPage.getError());

    events
        .expectLogin()
        .session((String) null)
        .error("invalid_user_credentials")
        .removeDetail(Details.CONSENT)
        .assertEvent();

    loginPage.open();
    loginPage.login("test-user@localhost", "new-password");

    Assert.assertEquals(RequestType.AUTH_RESPONSE, appPage.getRequestType());

    events.expectLogin().assertEvent();
  }
  @Test
  public void grantAccessTokenUserNotFound() throws Exception {
    oauth.clientId("resource-owner");

    OAuthClient.AccessTokenResponse response =
        oauth.doGrantAccessTokenRequest("secret", "invalid", "invalid");

    assertEquals(401, response.getStatusCode());

    assertEquals("invalid_grant", response.getError());

    events
        .expectLogin()
        .client("resource-owner")
        .user((String) null)
        .session((String) null)
        .detail(Details.AUTH_METHOD, "oauth_credentials")
        .detail(Details.RESPONSE_TYPE, "token")
        .detail(Details.USERNAME, "invalid")
        .removeDetail(Details.CODE_ID)
        .removeDetail(Details.REDIRECT_URI)
        .removeDetail(Details.CONSENT)
        .error(Errors.INVALID_USER_CREDENTIALS)
        .assertEvent();
  }
Пример #3
0
  @Test
  public void registerUserSuccess_emailAsUsername() {
    configureRelamRegistrationEmailAsUsername(true);

    try {
      loginPage.open();
      loginPage.clickRegister();
      registerPage.assertCurrent();

      registerPage.registerWithEmailAsUsername(
          "firstName", "lastName", "registerUserSuccessE@email", "password", "password");

      assertEquals(RequestType.AUTH_RESPONSE, appPage.getRequestType());

      String userId =
          events
              .expectRegister("registerUserSuccessE@email", "registerUserSuccessE@email")
              .assertEvent()
              .getUserId();
      events
          .expectLogin()
          .detail("username", "registerusersuccesse@email")
          .user(userId)
          .assertEvent();

      UserModel user = getUser(userId);
      Assert.assertNotNull(user);
      Assert.assertNotNull(user.getCreatedTimestamp());
      // test that timestamp is current with 10s tollerance
      Assert.assertTrue((System.currentTimeMillis() - user.getCreatedTimestamp()) < 10000);

    } finally {
      configureRelamRegistrationEmailAsUsername(false);
    }
  }
Пример #4
0
  @Test
  public void setupTotp() {
    totpPage.open();
    loginPage.login("test-user@localhost", "password");

    events
        .expectLogin()
        .client("account")
        .detail(Details.REDIRECT_URI, ACCOUNT_REDIRECT + "?path=totp")
        .assertEvent();

    Assert.assertTrue(totpPage.isCurrent());

    Assert.assertFalse(driver.getPageSource().contains("Remove Google"));

    // Error with false code
    totpPage.configure(totp.generate(totpPage.getTotpSecret() + "123"));

    Assert.assertEquals("Invalid authenticator code.", profilePage.getError());

    totpPage.configure(totp.generate(totpPage.getTotpSecret()));

    Assert.assertEquals("Mobile authenticator configured.", profilePage.getSuccess());

    events.expectAccount(EventType.UPDATE_TOTP).assertEvent();

    Assert.assertTrue(driver.getPageSource().contains("pficon-delete"));

    totpPage.removeTotp();

    events.expectAccount(EventType.REMOVE_TOTP).assertEvent();
  }
Пример #5
0
  // KEYCLOAK-2102
  @Test
  public void spnegoCaseInsensitiveTest() throws Exception {
    KeycloakRule keycloakRule = getKeycloakRule();
    AssertEvents events = getAssertEvents();

    Response spnegoResponse = spnegoLogin("MyDuke", "theduke");
    Assert.assertEquals(302, spnegoResponse.getStatus());

    events
        .expectLogin()
        .client("kerberos-app")
        .user(keycloakRule.getUser("test", "myduke").getId())
        .detail(Details.REDIRECT_URI, KERBEROS_APP_URL)
        // .detail(Details.AUTH_METHOD, "spnego")
        .detail(Details.USERNAME, "myduke")
        .assertEvent();

    String location = spnegoResponse.getLocation().toString();
    driver.navigate().to(location);

    String pageSource = driver.getPageSource();
    Assert.assertTrue(
        pageSource.contains("Kerberos Test")
            && pageSource.contains("Kerberos servlet secured content"));

    spnegoResponse.close();
    events.clear();
  }
Пример #6
0
  @Test
  public void registerUserSuccess() {
    loginPage.open();
    loginPage.clickRegister();
    registerPage.assertCurrent();

    registerPage.register(
        "firstName",
        "lastName",
        "registerUserSuccess@email",
        "registerUserSuccess",
        "password",
        "password");

    assertEquals(RequestType.AUTH_RESPONSE, appPage.getRequestType());

    String userId =
        events
            .expectRegister("registerUserSuccess", "registerUserSuccess@email")
            .assertEvent()
            .getUserId();
    events.expectLogin().detail("username", "registerusersuccess").user(userId).assertEvent();

    UserModel user = getUser(userId);
    Assert.assertNotNull(user);
    Assert.assertNotNull(user.getCreatedTimestamp());
    // test that timestamp is current with 10s tollerance
    Assert.assertTrue((System.currentTimeMillis() - user.getCreatedTimestamp()) < 10000);
    // test user info is set from form
    assertEquals("registerusersuccess", user.getUsername());
    assertEquals("registerusersuccess@email", user.getEmail());
    assertEquals("firstName", user.getFirstName());
    assertEquals("lastName", user.getLastName());
  }
Пример #7
0
  @Test
  public void sessions() {
    loginPage.open();
    loginPage.clickRegister();

    registerPage.register(
        "view", "sessions", "view-sessions@localhost", "view-sessions", "password", "password");

    Event registerEvent =
        events.expectRegister("view-sessions", "view-sessions@localhost").assertEvent();
    String userId = registerEvent.getUserId();

    events.expectLogin().user(userId).detail(Details.USERNAME, "view-sessions").assertEvent();

    sessionsPage.open();

    Assert.assertTrue(sessionsPage.isCurrent());

    List<List<String>> sessions = sessionsPage.getSessions();
    Assert.assertEquals(1, sessions.size());
    Assert.assertEquals("127.0.0.1", sessions.get(0).get(0));

    // Create second session
    WebDriver driver2 = WebRule.createWebDriver();
    try {
      OAuthClient oauth2 = new OAuthClient(driver2);
      oauth2.state("mystate");
      oauth2.doLogin("view-sessions", "password");

      Event login2Event =
          events.expectLogin().user(userId).detail(Details.USERNAME, "view-sessions").assertEvent();

      sessionsPage.open();
      sessions = sessionsPage.getSessions();
      Assert.assertEquals(2, sessions.size());

      sessionsPage.logoutAll();

      events.expectLogout(registerEvent.getSessionId());
      events.expectLogout(login2Event.getSessionId());
    } finally {
      driver2.close();
    }
  }
Пример #8
0
  @Test
  public void loginWithHotpSuccess() throws Exception {
    loginPage.open();
    loginPage.login("test-user@localhost", "password");

    Assert.assertTrue(loginTotpPage.isCurrent());

    loginTotpPage.login(otp.generateHOTP("hotpSecret", counter++));

    Assert.assertEquals(RequestType.AUTH_RESPONSE, appPage.getRequestType());

    events.expectLogin().assertEvent();
  }
Пример #9
0
  @Test
  public void resetPasswordCancel() throws IOException, MessagingException {
    loginPage.open();
    loginPage.resetPassword();

    resetPasswordPage.assertCurrent();

    resetPasswordPage.changePassword("login-test");

    resetPasswordPage.assertCurrent();

    events
        .expectRequiredAction(EventType.SEND_RESET_PASSWORD)
        .user(userId)
        .detail(Details.USERNAME, "login-test")
        .detail(Details.EMAIL, "*****@*****.**")
        .assertEvent()
        .getSessionId();

    resetPasswordPage.backToLogin();

    Assert.assertTrue(loginPage.isCurrent());

    loginPage.login("login-test", "password");

    events.expectLogin().user(userId).detail(Details.USERNAME, "login-test").assertEvent();

    Assert.assertEquals(1, greenMail.getReceivedMessages().length);

    MimeMessage message = greenMail.getReceivedMessages()[0];

    String body = (String) message.getContent();
    String changePasswordUrl = MailUtil.getLink(body);

    driver.navigate().to(changePasswordUrl.trim());

    events
        .expect(EventType.RESET_PASSWORD_ERROR)
        .client((String) null)
        .user((String) null)
        .error("invalid_code")
        .clearDetails()
        .assertEvent();

    Assert.assertTrue(errorPage.isCurrent());
    Assert.assertEquals(
        "Unknown code, please login again through your application.", errorPage.getError());
  }
Пример #10
0
  @Test
  public void changeProfileNoAccess() throws Exception {
    profilePage.open();
    loginPage.login("test-user-no-access@localhost", "password");

    events
        .expectLogin()
        .client("account")
        .user(keycloakRule.getUser("test", "test-user-no-access@localhost").getId())
        .detail(Details.USERNAME, "test-user-no-access@localhost")
        .detail(Details.REDIRECT_URI, ACCOUNT_REDIRECT)
        .assertEvent();

    Assert.assertTrue(errorPage.isCurrent());
    Assert.assertEquals("No access", errorPage.getError());
  }
Пример #11
0
  @Test
  public void loginWithHotpInvalidPassword() throws Exception {
    loginPage.open();
    loginPage.login("test-user@localhost", "invalid");

    Assert.assertTrue(loginPage.isCurrent());

    Assert.assertEquals("Invalid username or password.", loginPage.getError());

    events
        .expectLogin()
        .error("invalid_user_credentials")
        .session((String) null)
        .removeDetail(Details.CONSENT)
        .assertEvent();
  }
  @Test
  public void grantAccessTokenLogout() throws Exception {
    oauth.clientId("resource-owner");

    OAuthClient.AccessTokenResponse response =
        oauth.doGrantAccessTokenRequest("secret", "test-user@localhost", "password");

    assertEquals(200, response.getStatusCode());

    AccessToken accessToken = oauth.verifyToken(response.getAccessToken());
    RefreshToken refreshToken = oauth.verifyRefreshToken(response.getRefreshToken());

    events
        .expectLogin()
        .client("resource-owner")
        .session(accessToken.getSessionState())
        .detail(Details.AUTH_METHOD, "oauth_credentials")
        .detail(Details.RESPONSE_TYPE, "token")
        .detail(Details.TOKEN_ID, accessToken.getId())
        .detail(Details.REFRESH_TOKEN_ID, refreshToken.getId())
        .removeDetail(Details.CODE_ID)
        .removeDetail(Details.REDIRECT_URI)
        .removeDetail(Details.CONSENT)
        .assertEvent();

    HttpResponse logoutResponse = oauth.doLogout(response.getRefreshToken(), "secret");
    assertEquals(204, logoutResponse.getStatusLine().getStatusCode());
    events
        .expectLogout(accessToken.getSessionState())
        .client("resource-owner")
        .removeDetail(Details.REDIRECT_URI)
        .assertEvent();

    response = oauth.doRefreshTokenRequest(response.getRefreshToken(), "secret");
    assertEquals(400, response.getStatusCode());
    assertEquals("invalid_grant", response.getError());

    events
        .expectRefresh(refreshToken.getId(), refreshToken.getSessionState())
        .client("resource-owner")
        .removeDetail(Details.TOKEN_ID)
        .removeDetail(Details.UPDATED_REFRESH_TOKEN_ID)
        .error(Errors.INVALID_TOKEN)
        .assertEvent();
  }
  private void grantAccessToken(String login) throws Exception {
    oauth.clientId("resource-owner");

    OAuthClient.AccessTokenResponse response =
        oauth.doGrantAccessTokenRequest("secret", login, "password");

    assertEquals(200, response.getStatusCode());

    AccessToken accessToken = oauth.verifyToken(response.getAccessToken());
    RefreshToken refreshToken = oauth.verifyRefreshToken(response.getRefreshToken());

    events
        .expectLogin()
        .client("resource-owner")
        .user(userId)
        .session(accessToken.getSessionState())
        .detail(Details.AUTH_METHOD, "oauth_credentials")
        .detail(Details.RESPONSE_TYPE, "token")
        .detail(Details.TOKEN_ID, accessToken.getId())
        .detail(Details.REFRESH_TOKEN_ID, refreshToken.getId())
        .detail(Details.USERNAME, login)
        .removeDetail(Details.CODE_ID)
        .removeDetail(Details.REDIRECT_URI)
        .removeDetail(Details.CONSENT)
        .assertEvent();

    assertEquals(accessToken.getSessionState(), refreshToken.getSessionState());

    OAuthClient.AccessTokenResponse refreshedResponse =
        oauth.doRefreshTokenRequest(response.getRefreshToken(), "secret");

    AccessToken refreshedAccessToken = oauth.verifyToken(refreshedResponse.getAccessToken());
    RefreshToken refreshedRefreshToken =
        oauth.verifyRefreshToken(refreshedResponse.getRefreshToken());

    assertEquals(accessToken.getSessionState(), refreshedAccessToken.getSessionState());
    assertEquals(accessToken.getSessionState(), refreshedRefreshToken.getSessionState());

    events
        .expectRefresh(refreshToken.getId(), refreshToken.getSessionState())
        .user(userId)
        .client("resource-owner")
        .assertEvent();
  }
  @Test
  public void grantAccessTokenInvalidClientCredentials() throws Exception {
    oauth.clientId("resource-owner");

    OAuthClient.AccessTokenResponse response =
        oauth.doGrantAccessTokenRequest("invalid", "test-user@localhost", "password");

    assertEquals(400, response.getStatusCode());

    assertEquals("unauthorized_client", response.getError());

    events
        .expectLogin()
        .client("resource-owner")
        .session((String) null)
        .clearDetails()
        .error(Errors.INVALID_CLIENT_CREDENTIALS)
        .user((String) null)
        .assertEvent();
  }
Пример #15
0
  @Test
  public void changePasswordWithLengthPasswordPolicy() {
    keycloakRule.update(
        new KeycloakRule.KeycloakSetup() {
          @Override
          public void config(
              RealmManager manager, RealmModel adminstrationRealm, RealmModel appRealm) {
            appRealm.setPasswordPolicy(new PasswordPolicy("length"));
          }
        });

    try {
      changePasswordPage.open();
      loginPage.login("test-user@localhost", "password");

      events
          .expectLogin()
          .client("account")
          .detail(Details.REDIRECT_URI, ACCOUNT_REDIRECT + "?path=password")
          .assertEvent();

      changePasswordPage.changePassword("", "new", "new");

      Assert.assertEquals("Please specify password.", profilePage.getError());

      changePasswordPage.changePassword("password", "new-password", "new-password");

      Assert.assertEquals("Your password has been updated.", profilePage.getSuccess());

      events.expectAccount(EventType.UPDATE_PASSWORD).assertEvent();
    } finally {
      keycloakRule.update(
          new KeycloakRule.KeycloakSetup() {
            @Override
            public void config(
                RealmManager manager, RealmModel adminstrationRealm, RealmModel appRealm) {
              appRealm.setPasswordPolicy(new PasswordPolicy(null));
            }
          });
    }
  }
Пример #16
0
  @Test
  public void loginWithHotpFailure() throws Exception {
    loginPage.open();
    loginPage.login("test-user@localhost", "password");

    Assert.assertTrue(loginTotpPage.isCurrent());

    loginTotpPage.login("123456");
    loginTotpPage.assertCurrent();
    Assert.assertEquals("Invalid authenticator code.", loginPage.getError());

    // loginPage.assertCurrent();  // Invalid authenticator code.
    // Assert.assertEquals("Invalid username or password.", loginPage.getError());

    events
        .expectLogin()
        .error("invalid_user_credentials")
        .session((String) null)
        .removeDetail(Details.CONSENT)
        .assertEvent();
  }
Пример #17
0
  // KEYCLOAK-1534
  @Test
  public void changeEmailToExisting() {
    profilePage.open();
    loginPage.login("test-user@localhost", "password");

    events
        .expectLogin()
        .client("account")
        .detail(Details.REDIRECT_URI, ACCOUNT_REDIRECT)
        .assertEvent();

    Assert.assertEquals("test-user@localhost", profilePage.getUsername());
    Assert.assertEquals("test-user@localhost", profilePage.getEmail());

    // Change to the email, which some other user has
    profilePage.updateProfile("New first", "New last", "test-user-no-access@localhost");

    profilePage.assertCurrent();
    Assert.assertEquals("Email already exists.", profilePage.getError());
    Assert.assertEquals("New first", profilePage.getFirstName());
    Assert.assertEquals("New last", profilePage.getLastName());
    Assert.assertEquals("test-user-no-access@localhost", profilePage.getEmail());

    events.assertEmpty();

    // Change some other things, but not email
    profilePage.updateProfile("New first", "New last", "test-user@localhost");

    Assert.assertEquals("Your account has been updated.", profilePage.getSuccess());
    Assert.assertEquals("New first", profilePage.getFirstName());
    Assert.assertEquals("New last", profilePage.getLastName());
    Assert.assertEquals("test-user@localhost", profilePage.getEmail());

    events.expectAccount(EventType.UPDATE_PROFILE).assertEvent();

    // Change email and other things to original values
    profilePage.updateProfile("Tom", "Brady", "test-user@localhost");
    events.expectAccount(EventType.UPDATE_PROFILE).assertEvent();
  }
Пример #18
0
  // More tests (including revoke) are in OAuthGrantTest
  @Test
  public void applications() {
    applicationsPage.open();
    loginPage.login("test-user@localhost", "password");

    events
        .expectLogin()
        .client("account")
        .detail(Details.REDIRECT_URI, ACCOUNT_REDIRECT + "?path=applications")
        .assertEvent();
    Assert.assertTrue(applicationsPage.isCurrent());

    Map<String, AccountApplicationsPage.AppEntry> apps = applicationsPage.getApplications();
    Assert.assertEquals(3, apps.size());

    AccountApplicationsPage.AppEntry accountEntry = apps.get("Account");
    Assert.assertEquals(2, accountEntry.getRolesAvailable().size());
    Assert.assertTrue(accountEntry.getRolesAvailable().contains("Manage account in Account"));
    Assert.assertTrue(accountEntry.getRolesAvailable().contains("View profile in Account"));
    Assert.assertEquals(1, accountEntry.getRolesGranted().size());
    Assert.assertTrue(accountEntry.getRolesGranted().contains("Full Access"));
    Assert.assertEquals(1, accountEntry.getProtocolMappersGranted().size());
    Assert.assertTrue(accountEntry.getProtocolMappersGranted().contains("Full Access"));

    AccountApplicationsPage.AppEntry testAppEntry = apps.get("test-app");
    Assert.assertEquals(4, testAppEntry.getRolesAvailable().size());
    Assert.assertTrue(testAppEntry.getRolesGranted().contains("Full Access"));
    Assert.assertTrue(testAppEntry.getProtocolMappersGranted().contains("Full Access"));

    AccountApplicationsPage.AppEntry thirdPartyEntry = apps.get("third-party");
    Assert.assertEquals(2, thirdPartyEntry.getRolesAvailable().size());
    Assert.assertTrue(thirdPartyEntry.getRolesAvailable().contains("Have User privileges"));
    Assert.assertTrue(
        thirdPartyEntry.getRolesAvailable().contains("Have Customer User privileges in test-app"));
    Assert.assertEquals(0, thirdPartyEntry.getRolesGranted().size());
    Assert.assertEquals(0, thirdPartyEntry.getProtocolMappersGranted().size());
  }
Пример #19
0
  @Test
  public void resetPasswordWithPasswordPolicy() throws IOException, MessagingException {
    keycloakRule.update(
        new KeycloakRule.KeycloakSetup() {
          @Override
          public void config(
              RealmManager manager, RealmModel adminstrationRealm, RealmModel appRealm) {
            appRealm.setPasswordPolicy(new PasswordPolicy("length"));
          }
        });

    loginPage.open();
    loginPage.resetPassword();

    resetPasswordPage.assertCurrent();

    resetPasswordPage.changePassword("login-test");

    resetPasswordPage.assertCurrent();

    Assert.assertEquals(
        "You should receive an email shortly with further instructions.",
        resetPasswordPage.getSuccessMessage());

    Assert.assertEquals(1, greenMail.getReceivedMessages().length);

    MimeMessage message = greenMail.getReceivedMessages()[0];

    String body = (String) message.getContent();
    String changePasswordUrl = MailUtil.getLink(body);

    String sessionId =
        events
            .expectRequiredAction(EventType.SEND_RESET_PASSWORD)
            .user(userId)
            .detail(Details.USERNAME, "login-test")
            .detail(Details.EMAIL, "*****@*****.**")
            .assertEvent()
            .getSessionId();

    driver.navigate().to(changePasswordUrl.trim());

    updatePasswordPage.assertCurrent();

    updatePasswordPage.changePassword("invalid", "invalid");

    Assert.assertEquals("Invalid password: minimum length 8", resetPasswordPage.getErrorMessage());

    updatePasswordPage.changePassword(
        "resetPasswordWithPasswordPolicy", "resetPasswordWithPasswordPolicy");

    events
        .expectRequiredAction(EventType.UPDATE_PASSWORD)
        .user(userId)
        .session(sessionId)
        .detail(Details.USERNAME, "login-test")
        .assertEvent();

    Assert.assertEquals(RequestType.AUTH_RESPONSE, appPage.getRequestType());

    events
        .expectLogin()
        .user(userId)
        .detail(Details.USERNAME, "login-test")
        .session(sessionId)
        .assertEvent();

    oauth.openLogout();

    events.expectLogout(sessionId).user(userId).session(sessionId).assertEvent();

    loginPage.open();

    loginPage.login("login-test", "resetPasswordWithPasswordPolicy");

    Assert.assertEquals(RequestType.AUTH_RESPONSE, appPage.getRequestType());

    events.expectLogin().user(userId).detail(Details.USERNAME, "login-test").assertEvent();
  }
Пример #20
0
  private void resetPassword(String username) throws IOException, MessagingException {
    loginPage.open();
    loginPage.resetPassword();

    resetPasswordPage.assertCurrent();

    resetPasswordPage.changePassword(username);

    resetPasswordPage.assertCurrent();

    String sessionId =
        events
            .expectRequiredAction(EventType.SEND_RESET_PASSWORD)
            .user(userId)
            .detail(Details.USERNAME, username)
            .detail(Details.EMAIL, "*****@*****.**")
            .assertEvent()
            .getSessionId();

    Assert.assertEquals(
        "You should receive an email shortly with further instructions.",
        resetPasswordPage.getSuccessMessage());

    Assert.assertEquals(1, greenMail.getReceivedMessages().length);

    MimeMessage message = greenMail.getReceivedMessages()[0];

    String body = (String) message.getContent();
    String changePasswordUrl = MailUtil.getLink(body);

    driver.navigate().to(changePasswordUrl.trim());

    updatePasswordPage.assertCurrent();

    updatePasswordPage.changePassword("resetPassword", "resetPassword");

    events
        .expectRequiredAction(EventType.UPDATE_PASSWORD)
        .user(userId)
        .session(sessionId)
        .detail(Details.USERNAME, username)
        .assertEvent();

    Assert.assertEquals(RequestType.AUTH_RESPONSE, appPage.getRequestType());

    events
        .expectLogin()
        .user(userId)
        .detail(Details.USERNAME, username)
        .session(sessionId)
        .assertEvent();

    oauth.openLogout();

    events.expectLogout(sessionId).user(userId).session(sessionId).assertEvent();

    loginPage.open();

    loginPage.login("login-test", "resetPassword");

    events.expectLogin().user(userId).detail(Details.USERNAME, "login-test").assertEvent();

    Assert.assertEquals(RequestType.AUTH_RESPONSE, appPage.getRequestType());
  }
Пример #21
0
  @Test
  public void changeProfile() {
    profilePage.open();
    loginPage.login("test-user@localhost", "password");

    events
        .expectLogin()
        .client("account")
        .detail(Details.REDIRECT_URI, ACCOUNT_REDIRECT)
        .assertEvent();

    Assert.assertEquals("Tom", profilePage.getFirstName());
    Assert.assertEquals("Brady", profilePage.getLastName());
    Assert.assertEquals("test-user@localhost", profilePage.getEmail());

    // All fields are required, so there should be an error when something is missing.
    profilePage.updateProfile("", "New last", "*****@*****.**");

    Assert.assertEquals("Please specify first name.", profilePage.getError());
    Assert.assertEquals("", profilePage.getFirstName());
    Assert.assertEquals("New last", profilePage.getLastName());
    Assert.assertEquals("*****@*****.**", profilePage.getEmail());

    events.assertEmpty();

    profilePage.updateProfile("New first", "", "*****@*****.**");

    Assert.assertEquals("Please specify last name.", profilePage.getError());
    Assert.assertEquals("New first", profilePage.getFirstName());
    Assert.assertEquals("", profilePage.getLastName());
    Assert.assertEquals("*****@*****.**", profilePage.getEmail());

    events.assertEmpty();

    profilePage.updateProfile("New first", "New last", "");

    Assert.assertEquals("Please specify email.", profilePage.getError());
    Assert.assertEquals("New first", profilePage.getFirstName());
    Assert.assertEquals("New last", profilePage.getLastName());
    Assert.assertEquals("", profilePage.getEmail());

    events.assertEmpty();

    profilePage.clickCancel();

    Assert.assertEquals("Tom", profilePage.getFirstName());
    Assert.assertEquals("Brady", profilePage.getLastName());
    Assert.assertEquals("test-user@localhost", profilePage.getEmail());

    events.assertEmpty();

    profilePage.updateProfile("New first", "New last", "*****@*****.**");

    Assert.assertEquals("Your account has been updated.", profilePage.getSuccess());
    Assert.assertEquals("New first", profilePage.getFirstName());
    Assert.assertEquals("New last", profilePage.getLastName());
    Assert.assertEquals("*****@*****.**", profilePage.getEmail());

    events.expectAccount(EventType.UPDATE_PROFILE).assertEvent();
    events
        .expectAccount(EventType.UPDATE_EMAIL)
        .detail(Details.PREVIOUS_EMAIL, "test-user@localhost")
        .detail(Details.UPDATED_EMAIL, "*****@*****.**")
        .assertEvent();

    // reset user for other tests
    profilePage.updateProfile("Tom", "Brady", "test-user@localhost");
    events.clear();
  }
Пример #22
0
  @Test
  public void usernamePasswordLoginTest() throws Exception {
    KeycloakRule keycloakRule = getKeycloakRule();
    AssertEvents events = getAssertEvents();

    // Change editMode to READ_ONLY
    updateProviderEditMode(UserFederationProvider.EditMode.READ_ONLY);

    // Login with username/password from kerberos
    changePasswordPage.open();
    // Only needed if you are providing a click thru to bypass kerberos.  Currently there is a
    // javascript
    // to forward the user if kerberos isn't enabled.
    // bypassPage.isCurrent();
    // bypassPage.clickContinue();
    loginPage.assertCurrent();
    loginPage.login("jduke", "theduke");
    changePasswordPage.assertCurrent();

    // Change password is not possible as editMode is READ_ONLY
    changePasswordPage.changePassword("theduke", "newPass", "newPass");
    Assert.assertTrue(
        driver
            .getPageSource()
            .contains("You can't update your password as your account is read only"));

    // Change editMode to UNSYNCED
    updateProviderEditMode(UserFederationProvider.EditMode.UNSYNCED);

    // Successfully change password now
    changePasswordPage.changePassword("theduke", "newPass", "newPass");
    Assert.assertTrue(driver.getPageSource().contains("Your password has been updated."));
    changePasswordPage.logout();

    // Only needed if you are providing a click thru to bypass kerberos.  Currently there is a
    // javascript
    // to forward the user if kerberos isn't enabled.
    // bypassPage.isCurrent();
    // bypassPage.clickContinue();
    // Login with old password doesn't work, but with new password works
    loginPage.login("jduke", "theduke");
    loginPage.assertCurrent();
    loginPage.login("jduke", "newPass");
    changePasswordPage.assertCurrent();
    changePasswordPage.logout();

    // Assert SPNEGO login still with the old password as mode is unsynced
    events.clear();
    Response spnegoResponse = spnegoLogin("jduke", "theduke");
    Assert.assertEquals(302, spnegoResponse.getStatus());
    String redirect = spnegoResponse.getLocation().toString();
    events
        .expectLogin()
        .client("kerberos-app")
        .user(keycloakRule.getUser("test", "jduke").getId())
        .detail(Details.REDIRECT_URI, KERBEROS_APP_URL)
        // .detail(Details.AUTH_METHOD, "spnego")
        .detail(Details.USERNAME, "jduke")
        .assertEvent();
    spnegoResponse.close();
  }
Пример #23
0
  @Test
  public void changeUsername() {
    // allow to edit the username in realm
    keycloakRule.update(
        new KeycloakRule.KeycloakSetup() {
          @Override
          public void config(
              RealmManager manager, RealmModel adminstrationRealm, RealmModel appRealm) {
            appRealm.setEditUsernameAllowed(true);
          }
        });

    try {
      profilePage.open();
      loginPage.login("test-user@localhost", "password");

      events
          .expectLogin()
          .client("account")
          .detail(Details.REDIRECT_URI, ACCOUNT_REDIRECT)
          .assertEvent();

      Assert.assertEquals("test-user@localhost", profilePage.getUsername());
      Assert.assertEquals("Tom", profilePage.getFirstName());
      Assert.assertEquals("Brady", profilePage.getLastName());
      Assert.assertEquals("test-user@localhost", profilePage.getEmail());

      // All fields are required, so there should be an error when something is missing.
      profilePage.updateProfile("", "New first", "New last", "*****@*****.**");

      Assert.assertEquals("Please specify username.", profilePage.getError());
      Assert.assertEquals("", profilePage.getUsername());
      Assert.assertEquals("New first", profilePage.getFirstName());
      Assert.assertEquals("New last", profilePage.getLastName());
      Assert.assertEquals("*****@*****.**", profilePage.getEmail());

      events.assertEmpty();

      // Change to the username already occupied by other user
      profilePage.updateProfile(
          "test-user-no-access@localhost", "New first", "New last", "*****@*****.**");

      Assert.assertEquals("Username already exists.", profilePage.getError());
      Assert.assertEquals("test-user-no-access@localhost", profilePage.getUsername());
      Assert.assertEquals("New first", profilePage.getFirstName());
      Assert.assertEquals("New last", profilePage.getLastName());
      Assert.assertEquals("*****@*****.**", profilePage.getEmail());

      events.assertEmpty();

      profilePage.updateProfile(
          "test-user-new@localhost", "New first", "New last", "*****@*****.**");

      Assert.assertEquals("Your account has been updated.", profilePage.getSuccess());
      Assert.assertEquals("test-user-new@localhost", profilePage.getUsername());
      Assert.assertEquals("New first", profilePage.getFirstName());
      Assert.assertEquals("New last", profilePage.getLastName());
      Assert.assertEquals("*****@*****.**", profilePage.getEmail());

    } finally {
      // reset user for other tests
      profilePage.updateProfile("test-user@localhost", "Tom", "Brady", "test-user@localhost");
      events.clear();

      // reset realm
      keycloakRule.update(
          new KeycloakRule.KeycloakSetup() {
            @Override
            public void config(
                RealmManager manager, RealmModel adminstrationRealm, RealmModel appRealm) {
              appRealm.setEditUsernameAllowed(false);
            }
          });
    }
  }
Пример #24
0
  @Test
  public void registerPasswordPolicy() {
    keycloakRule.configure(
        new KeycloakRule.KeycloakSetup() {
          @Override
          public void config(
              RealmManager manager, RealmModel adminstrationRealm, RealmModel appRealm) {
            appRealm.setPasswordPolicy(new PasswordPolicy("length"));
          }
        });

    try {
      loginPage.open();
      loginPage.clickRegister();
      registerPage.assertCurrent();

      registerPage.register(
          "firstName",
          "lastName",
          "registerPasswordPolicy@email",
          "registerPasswordPolicy",
          "pass",
          "pass");

      registerPage.assertCurrent();
      assertEquals("Invalid password: minimum length 8.", registerPage.getError());

      events
          .expectRegister("registerPasswordPolicy", "registerPasswordPolicy@email")
          .removeDetail(Details.USERNAME)
          .removeDetail(Details.EMAIL)
          .user((String) null)
          .error("invalid_registration")
          .assertEvent();

      registerPage.register(
          "firstName",
          "lastName",
          "registerPasswordPolicy@email",
          "registerPasswordPolicy",
          "password",
          "password");
      assertEquals(RequestType.AUTH_RESPONSE, appPage.getRequestType());

      String userId =
          events
              .expectRegister("registerPasswordPolicy", "registerPasswordPolicy@email")
              .assertEvent()
              .getUserId();

      events
          .expectLogin()
          .user(userId)
          .detail(Details.USERNAME, "registerpasswordpolicy")
          .assertEvent();
    } finally {
      keycloakRule.configure(
          new KeycloakRule.KeycloakSetup() {
            @Override
            public void config(
                RealmManager manager, RealmModel adminstrationRealm, RealmModel appRealm) {
              appRealm.setPasswordPolicy(new PasswordPolicy(null));
            }
          });
    }
  }