use of org.keycloak.testsuite.updaters.UserAttributeUpdater in project keycloak by keycloak.
the class RequiredActionEmailVerificationTest method verifyEmailInNewBrowserWhileLoggedInFirstBrowser.
@Test
public void verifyEmailInNewBrowserWhileLoggedInFirstBrowser() throws IOException, MessagingException {
UserAttributeUpdater userAttributeUpdater = new UserAttributeUpdater(testRealm().users().get(testUserId));
userAttributeUpdater.setEmailVerified(true).update();
final String testRealmName = testRealm().toRepresentation().getRealm();
accountPage.setAuthRealm(testRealmName);
oauth.realm(testRealmName).clientId("account").redirectUri(getAuthServerRoot() + "realms/" + testRealmName + "/account");
loginPage.open();
loginPage.login("test-user@localhost", "password");
accountPage.assertCurrent();
userAttributeUpdater.setEmailVerified(false).setRequiredActions(RequiredAction.VERIFY_EMAIL).update();
// this will result in email verification
loginPage.open();
verifyEmailPage.assertCurrent();
Assert.assertEquals(1, greenMail.getReceivedMessages().length);
MimeMessage message = greenMail.getLastReceivedMessage();
String verificationUrl = getPasswordResetEmailLink(message);
// confirm in the second browser
driver2.navigate().to(verificationUrl);
// follow the link
final WebElement proceedLink = driver2.findElement(By.linkText("» Click here to proceed"));
assertThat(proceedLink, Matchers.notNullValue());
proceedLink.click();
// confirmation in the second browser
assertThat(driver2.getPageSource(), Matchers.containsString("kc-info-message"));
assertThat(driver2.getPageSource(), Matchers.containsString("Your email address has been verified."));
final WebElement backToApplicationLink = driver2.findElement(By.linkText("« Back to Application"));
assertThat(backToApplicationLink, Matchers.notNullValue());
backToApplicationLink.click();
// login page should be shown in the second browser
assertThat(driver2.getPageSource(), Matchers.containsString("kc-login"));
assertThat(driver2.getPageSource(), Matchers.containsString("Sign in"));
// email should be verified and required actions empty
UserRepresentation user = testRealm().users().get(testUserId).toRepresentation();
Assert.assertTrue(user.isEmailVerified());
Assert.assertThat(user.getRequiredActions(), Matchers.empty());
// after refresh in the first browser the account console should be shown
driver.navigate().refresh();
accountPage.assertCurrent();
}
use of org.keycloak.testsuite.updaters.UserAttributeUpdater in project keycloak by keycloak.
the class RequiredActionEmailVerificationTest method verifyEmailDuringAuthFlow.
@Test
public void verifyEmailDuringAuthFlow() throws IOException, MessagingException {
try (Closeable u = new UserAttributeUpdater(testRealm().users().get(testUserId)).setEmailVerified(false).setRequiredActions(RequiredAction.VERIFY_EMAIL).update()) {
accountPage.setAuthRealm(testRealm().toRepresentation().getRealm());
accountPage.navigateTo();
loginPage.assertCurrent();
loginPage.login("test-user@localhost", "password");
verifyEmailPage.assertCurrent();
Assert.assertEquals(1, greenMail.getReceivedMessages().length);
MimeMessage message = greenMail.getLastReceivedMessage();
String verificationUrl = getPasswordResetEmailLink(message);
driver.navigate().to(verificationUrl.trim());
accountPage.assertCurrent();
}
}
use of org.keycloak.testsuite.updaters.UserAttributeUpdater in project keycloak by keycloak.
the class RequiredActionEmailVerificationTest method verifyEmailDuringAuthFlowAfterLogout.
@Test
public void verifyEmailDuringAuthFlowAfterLogout() throws IOException, MessagingException {
try (Closeable u = new UserAttributeUpdater(testRealm().users().get(testUserId)).setEmailVerified(true).update()) {
accountPage.setAuthRealm(testRealm().toRepresentation().getRealm());
accountPage.navigateTo();
loginPage.assertCurrent();
loginPage.login("test-user@localhost", "password");
accountPage.assertCurrent();
driver.navigate().to(oauth.getLogoutUrl().redirectUri(accountPage.buildUri().toString()).build());
loginPage.assertCurrent();
verifyEmailDuringAuthFlow();
}
}
use of org.keycloak.testsuite.updaters.UserAttributeUpdater in project keycloak by keycloak.
the class RequiredActionEmailVerificationTest method verifyEmailWhileLoggedIn.
@Test
public void verifyEmailWhileLoggedIn() throws IOException, MessagingException {
UserAttributeUpdater userAttributeUpdater = new UserAttributeUpdater(testRealm().users().get(testUserId));
userAttributeUpdater.setEmailVerified(true).update();
final String testRealmName = testRealm().toRepresentation().getRealm();
accountPage.setAuthRealm(testRealmName);
oauth.realm(testRealmName).clientId("account").redirectUri(getAuthServerRoot() + "realms/" + testRealmName + "/account");
loginPage.open();
loginPage.login("test-user@localhost", "password");
accountPage.assertCurrent();
userAttributeUpdater.setEmailVerified(false).setRequiredActions(RequiredAction.VERIFY_EMAIL).update();
// this will result in email verification
loginPage.open();
verifyEmailPage.assertCurrent();
Assert.assertEquals(1, greenMail.getReceivedMessages().length);
MimeMessage message = greenMail.getLastReceivedMessage();
String verificationUrl = getPasswordResetEmailLink(message);
// confirm
driver.navigate().to(verificationUrl);
// back to account, already logged in
accountPage.assertCurrent();
// email should be verified and required actions empty
UserRepresentation user = testRealm().users().get(testUserId).toRepresentation();
Assert.assertTrue(user.isEmailVerified());
Assert.assertThat(user.getRequiredActions(), Matchers.empty());
}
use of org.keycloak.testsuite.updaters.UserAttributeUpdater in project keycloak by keycloak.
the class RequiredActionEmailVerificationTest method verifyEmailViaAuthSessionWhileLoggedIn.
@Test
public void verifyEmailViaAuthSessionWhileLoggedIn() throws IOException, MessagingException {
Assume.assumeTrue("Works only on auth-server-undertow", AuthServerTestEnricher.AUTH_SERVER_CONTAINER.equals(AuthServerTestEnricher.AUTH_SERVER_CONTAINER_DEFAULT));
UserAttributeUpdater userAttributeUpdater = new UserAttributeUpdater(testRealm().users().get(testUserId));
userAttributeUpdater.setEmailVerified(false).update();
final String testRealmName = testRealm().toRepresentation().getRealm();
accountPage.setAuthRealm(testRealmName);
oauth.realm(testRealmName).clientId("account").redirectUri(getAuthServerRoot() + "realms/" + testRealmName + "/account");
loginPage.open();
String authSessionId = AuthenticationSessionFailoverClusterTest.getAuthSessionCookieValue(driver);
String realmId = testRealm().toRepresentation().getId();
testingClient.server().run(session -> {
RealmModel realm = session.realms().getRealm(realmId);
RootAuthenticationSessionModel ras = session.authenticationSessions().getRootAuthenticationSession(realm, authSessionId);
assertThat("Expecting single auth session", ras.getAuthenticationSessions().keySet(), Matchers.hasSize(1));
ras.getAuthenticationSessions().forEach((id, as) -> as.addRequiredAction(RequiredAction.VERIFY_EMAIL));
});
loginPage.login("test-user@localhost", "password");
verifyEmailPage.assertCurrent();
Assert.assertEquals(1, greenMail.getReceivedMessages().length);
MimeMessage message = greenMail.getLastReceivedMessage();
String verificationUrl = getPasswordResetEmailLink(message);
// confirm
driver.navigate().to(verificationUrl);
// back to account, already logged in
accountPage.assertCurrent();
// email should be verified and required actions empty
UserRepresentation user = testRealm().users().get(testUserId).toRepresentation();
Assert.assertTrue(user.isEmailVerified());
Assert.assertThat(user.getRequiredActions(), Matchers.empty());
}
Aggregations