Example #1
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();
  }
Example #2
0
  @Test
  public void changeProfile() {
    profilePage.open();
    loginPage.login("test-user@localhost", "password");

    Assert.assertEquals("", profilePage.getFirstName());
    Assert.assertEquals("", 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.assertTrue(profilePage.isError());
    Assert.assertEquals("", profilePage.getFirstName());
    Assert.assertEquals("", profilePage.getLastName());
    Assert.assertEquals("test-user@localhost", profilePage.getEmail());

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

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

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

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

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

    Assert.assertTrue(profilePage.isSuccess());
    Assert.assertEquals("New first", profilePage.getFirstName());
    Assert.assertEquals("New last", profilePage.getLastName());
    Assert.assertEquals("*****@*****.**", profilePage.getEmail());
  }
Example #3
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);
            }
          });
    }
  }
Example #4
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();
  }