// 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(); }
@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()); }
@Test public void viewLog() { keycloakRule.update( new KeycloakSetup() { @Override public void config( RealmManager manager, RealmModel adminstrationRealm, RealmModel appRealm) { appRealm.setEventsEnabled(true); } }); try { List<Event> expectedEvents = new LinkedList<Event>(); loginPage.open(); loginPage.clickRegister(); registerPage.register( "view", "log", "view-log@localhost", "view-log", "password", "password"); expectedEvents.add(events.poll()); expectedEvents.add(events.poll()); profilePage.open(); profilePage.updateProfile("view", "log2", "view-log@localhost"); expectedEvents.add(events.poll()); logPage.open(); Assert.assertTrue(logPage.isCurrent()); List<List<String>> actualEvents = logPage.getEvents(); Assert.assertEquals(expectedEvents.size(), actualEvents.size()); for (Event e : expectedEvents) { boolean match = false; for (List<String> a : logPage.getEvents()) { if (e.getType().toString().replace('_', ' ').toLowerCase().equals(a.get(1)) && e.getIpAddress().equals(a.get(2)) && e.getClientId().equals(a.get(3))) { match = true; break; } } if (!match) { Assert.fail("Event not found " + e.getType()); } } } finally { keycloakRule.update( new KeycloakSetup() { @Override public void config( RealmManager manager, RealmModel adminstrationRealm, RealmModel appRealm) { appRealm.setEventsEnabled(false); } }); } }
@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); } }); } }
@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(); }