@Test public void returnToAppFromQueryParam() { driver.navigate().to(AccountUpdateProfilePage.PATH + "?referrer=test-app"); loginPage.login("test-user@localhost", "password"); Assert.assertTrue(profilePage.isCurrent()); profilePage.backToApplication(); Assert.assertTrue(appPage.isCurrent()); driver .navigate() .to( AccountUpdateProfilePage.PATH + "?referrer=test-app&referrer_uri=http://localhost:8081/app?test"); Assert.assertTrue(profilePage.isCurrent()); profilePage.backToApplication(); Assert.assertTrue(appPage.isCurrent()); Assert.assertEquals(appPage.baseUrl + "?test", driver.getCurrentUrl()); driver.navigate().to(AccountUpdateProfilePage.PATH + "?referrer=test-app"); Assert.assertTrue(profilePage.isCurrent()); driver.findElement(By.linkText("Authenticator")).click(); Assert.assertTrue(totpPage.isCurrent()); driver.findElement(By.linkText("Account")).click(); Assert.assertTrue(profilePage.isCurrent()); profilePage.backToApplication(); Assert.assertTrue(appPage.isCurrent()); events.clear(); }
@Test public void returnToAppFromHeader() { appPage.open(); appPage.openAccount(); loginPage.login("test-user@localhost", "password"); Assert.assertTrue(profilePage.isCurrent()); profilePage.backToApplication(); Assert.assertTrue(appPage.isCurrent()); }
@Test public void loginSuccess() { loginPage.open(); loginPage.login("test-user@localhost", "password"); Assert.assertEquals(RequestType.AUTH_RESPONSE, appPage.getRequestType()); }
@Test public void changePassword() { changePasswordPage.open(); loginPage.login("test-user@localhost", "password"); changePasswordPage.changePassword("", "new-password", "new-password"); Assert.assertTrue(profilePage.isError()); changePasswordPage.changePassword("password", "new-password", "new-password2"); Assert.assertTrue(profilePage.isError()); changePasswordPage.changePassword("password", "new-password", "new-password"); Assert.assertTrue(profilePage.isSuccess()); changePasswordPage.logout(); loginPage.open(); loginPage.login("test-user@localhost", "password"); Assert.assertEquals("Invalid username or password.", loginPage.getError()); loginPage.open(); loginPage.login("test-user@localhost", "new-password"); Assert.assertEquals(RequestType.AUTH_RESPONSE, appPage.getRequestType()); }
@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); } }
@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()); }
private void loginSuccessAndLogout(String username, String password) { loginPage.open(); loginPage.login(username, password); Assert.assertEquals(AppPage.RequestType.AUTH_RESPONSE, appPage.getRequestType()); Assert.assertNotNull(oauth.getCurrentQuery().get(OAuth2Constants.CODE)); oauth.openLogout(); }
@Test public void returnToAppFromQueryParam() { driver.navigate().to(AccountUpdateProfilePage.PATH + "?referrer=test-app"); loginPage.login("test-user@localhost", "password"); Assert.assertTrue(profilePage.isCurrent()); profilePage.backToApplication(); Assert.assertTrue(appPage.isCurrent()); }
@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 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(); }
@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(); }
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()); }
@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)); } }); } }