use of org.keycloak.testsuite.updaters.UserAttributeUpdater in project keycloak by keycloak.
the class RequiredActionEmailVerificationTest method verifyEmailClickLinkRequiredActionsCleared.
@Test
public void verifyEmailClickLinkRequiredActionsCleared() throws IOException, MessagingException {
try (Closeable u = new UserAttributeUpdater(testRealm().users().get(testUserId)).setEmailVerified(true).setRequiredActions().update()) {
testRealm().users().get(testUserId).executeActionsEmail(Arrays.asList(RequiredAction.VERIFY_EMAIL.name()));
Assert.assertEquals(1, greenMail.getReceivedMessages().length);
MimeMessage message = greenMail.getLastReceivedMessage();
String verificationUrl = getPasswordResetEmailLink(message);
driver.manage().deleteAllCookies();
driver.navigate().to(verificationUrl);
accountPage.setAuthRealm(testRealm().toRepresentation().getRealm());
accountPage.navigateTo();
loginPage.assertCurrent();
loginPage.login("test-user@localhost", "password");
accountPage.assertCurrent();
}
}
use of org.keycloak.testsuite.updaters.UserAttributeUpdater in project keycloak by keycloak.
the class RequiredActionEmailVerificationTest method verifyEmailDuringAuthFlowFirstClickLink.
@Test
public void verifyEmailDuringAuthFlowFirstClickLink() throws IOException, MessagingException {
try (Closeable u = new UserAttributeUpdater(testRealm().users().get(testUserId)).setEmailVerified(false).setRequiredActions(RequiredAction.VERIFY_EMAIL).update()) {
testRealm().users().get(testUserId).executeActionsEmail(Arrays.asList(RequiredAction.VERIFY_EMAIL.name()));
Assert.assertEquals(1, greenMail.getReceivedMessages().length);
MimeMessage message = greenMail.getLastReceivedMessage();
String verificationUrl = getPasswordResetEmailLink(message);
driver.manage().deleteAllCookies();
driver.navigate().to(verificationUrl);
accountPage.setAuthRealm(testRealm().toRepresentation().getRealm());
accountPage.navigateTo();
loginPage.assertCurrent();
loginPage.login("test-user@localhost", "password");
verifyEmailPage.assertCurrent();
}
}
use of org.keycloak.testsuite.updaters.UserAttributeUpdater in project keycloak by keycloak.
the class RequiredActionEmailVerificationTest method verifyEmailNewBrowserSessionWithClientRedirect.
// https://issues.jboss.org/browse/KEYCLOAK-5861
@Test
public void verifyEmailNewBrowserSessionWithClientRedirect() throws IOException, MessagingException {
try (Closeable u = new UserAttributeUpdater(testRealm().users().get(testUserId)).setEmailVerified(false).update()) {
testRealm().users().get(testUserId).executeActionsEmail(Arrays.asList(RequiredAction.VERIFY_EMAIL.name()));
Assert.assertEquals(1, greenMail.getReceivedMessages().length);
MimeMessage message = greenMail.getLastReceivedMessage();
String verificationUrl = getPasswordResetEmailLink(message);
driver.manage().deleteAllCookies();
driver.navigate().to(verificationUrl.trim());
proceedPage.assertCurrent();
proceedPage.clickProceedLink();
infoPage.assertCurrent();
assertEquals("Your account has been updated.", infoPage.getInfo());
// Now log into account page
accountPage.setAuthRealm(testRealm().toRepresentation().getRealm());
accountPage.navigateTo();
loginPage.assertCurrent();
loginPage.login("test-user@localhost", "password");
accountPage.assertCurrent();
}
}
use of org.keycloak.testsuite.updaters.UserAttributeUpdater in project keycloak by keycloak.
the class RequiredActionEmailVerificationTest method verifyEmailDuringAuthFlowAfterRefresh.
@Test
public void verifyEmailDuringAuthFlowAfterRefresh() throws IOException, MessagingException {
try (Closeable u = new UserAttributeUpdater(testRealm().users().get(testUserId)).setEmailVerified(true).update()) {
final String testRealmName = testRealm().toRepresentation().getRealm();
accountPage.setAuthRealm(testRealmName);
// Browser 1: Log in
accountPage.navigateTo();
loginPage.assertCurrent();
loginPage.login("test-user@localhost", "password");
accountPage.assertCurrent();
// Browser 2: Log in
driver2.navigate().to(accountPage.buildUri().toString());
assertThat(driver2.getTitle(), is("Sign in to " + testRealmName));
driver2.findElement(By.id("username")).sendKeys("test-user@localhost");
driver2.findElement(By.id("password")).sendKeys("password");
driver2.findElement(By.id("password")).submit();
assertThat(driver2.getCurrentUrl(), Matchers.startsWith(accountPage.buildUri().toString()));
// Admin: set required action to VERIFY_EMAIL
try (Closeable u1 = new UserAttributeUpdater(testRealm().users().get(testUserId)).setEmailVerified(false).setRequiredActions(RequiredAction.VERIFY_EMAIL).update()) {
// Browser 2: Refresh window
driver2.navigate().refresh();
assertThat(driver2.getCurrentUrl(), Matchers.startsWith(accountPage.buildUri().toString()));
// Browser 1: Logout
driver.navigate().to(oauth.getLogoutUrl().redirectUri(accountPage.buildUri().toString()).build());
// Browser 1: Go to account page
accountPage.navigateTo();
// Browser 1: Log in
loginPage.assertCurrent();
loginPage.login("test-user@localhost", "password");
verifyEmailPage.assertCurrent();
// Browser 2 [still logged in]: Click the email verification link
Assert.assertEquals(1, greenMail.getReceivedMessages().length);
MimeMessage message = greenMail.getLastReceivedMessage();
String verificationUrl = getPasswordResetEmailLink(message);
driver2.navigate().to(verificationUrl.trim());
// Browser 2: Confirm email belongs to the user
final WebElement proceedLink = driver2.findElement(By.linkText("ยป Click here to proceed"));
assertThat(proceedLink, Matchers.notNullValue());
proceedLink.click();
// Browser 2: Expect confirmation
assertThat(driver2.getPageSource(), Matchers.containsString("kc-info-message"));
assertThat(driver2.getPageSource(), Matchers.containsString("Your email address has been verified."));
// Browser 1: Expect land back to account after refresh
driver.navigate().refresh();
accountPage.assertCurrent();
}
}
}
use of org.keycloak.testsuite.updaters.UserAttributeUpdater in project keycloak by keycloak.
the class RoleMapperTest method singleRealmRoleWithDots.
@Test
public void singleRealmRoleWithDots() throws Exception {
pmu.add(createSamlProtocolMapper(RoleListMapper.PROVIDER_ID, AttributeStatementHelper.SAML_ATTRIBUTE_NAME, ROLE_ATTRIBUTE_NAME, AttributeStatementHelper.SAML_ATTRIBUTE_NAMEFORMAT, AttributeStatementHelper.BASIC, RoleListMapper.SINGLE_ROLE_ATTRIBUTE, "true")).update();
RoleRepresentation roleWithDots = realmsResouce().realm(REALM_NAME).roles().get("role.with.dots").toRepresentation();
try (UserAttributeUpdater uau = UserAttributeUpdater.forUserByUsername(adminClient, REALM_NAME, bburkeUser.getUsername()).update();
RoleScopeUpdater rsu = uau.realmRoleScope().removeByName("user").add(roleWithDots).update()) {
testExpectedRoles(SAML_CLIENT_ID_EMPLOYEE_2, "manager", "role.with.dots", "empl.oyee", "employee");
}
}
Aggregations