Search in sources :

Example 6 with UserAttributeUpdater

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();
    }
}
Also used : UserAttributeUpdater(org.keycloak.testsuite.updaters.UserAttributeUpdater) MimeMessage(javax.mail.internet.MimeMessage) Closeable(java.io.Closeable) Test(org.junit.Test) AbstractTestRealmKeycloakTest(org.keycloak.testsuite.AbstractTestRealmKeycloakTest) AuthenticationSessionFailoverClusterTest(org.keycloak.testsuite.cluster.AuthenticationSessionFailoverClusterTest)

Example 7 with UserAttributeUpdater

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();
    }
}
Also used : UserAttributeUpdater(org.keycloak.testsuite.updaters.UserAttributeUpdater) MimeMessage(javax.mail.internet.MimeMessage) Closeable(java.io.Closeable) Test(org.junit.Test) AbstractTestRealmKeycloakTest(org.keycloak.testsuite.AbstractTestRealmKeycloakTest) AuthenticationSessionFailoverClusterTest(org.keycloak.testsuite.cluster.AuthenticationSessionFailoverClusterTest)

Example 8 with UserAttributeUpdater

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();
    }
}
Also used : UserAttributeUpdater(org.keycloak.testsuite.updaters.UserAttributeUpdater) MimeMessage(javax.mail.internet.MimeMessage) Closeable(java.io.Closeable) Test(org.junit.Test) AbstractTestRealmKeycloakTest(org.keycloak.testsuite.AbstractTestRealmKeycloakTest) AuthenticationSessionFailoverClusterTest(org.keycloak.testsuite.cluster.AuthenticationSessionFailoverClusterTest)

Example 9 with UserAttributeUpdater

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();
        }
    }
}
Also used : UserAttributeUpdater(org.keycloak.testsuite.updaters.UserAttributeUpdater) MimeMessage(javax.mail.internet.MimeMessage) Closeable(java.io.Closeable) WebElement(org.openqa.selenium.WebElement) Test(org.junit.Test) AbstractTestRealmKeycloakTest(org.keycloak.testsuite.AbstractTestRealmKeycloakTest) AuthenticationSessionFailoverClusterTest(org.keycloak.testsuite.cluster.AuthenticationSessionFailoverClusterTest)

Example 10 with UserAttributeUpdater

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");
    }
}
Also used : RoleRepresentation(org.keycloak.representations.idm.RoleRepresentation) UserAttributeUpdater(org.keycloak.testsuite.updaters.UserAttributeUpdater) RoleScopeUpdater(org.keycloak.testsuite.updaters.RoleScopeUpdater) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)11 UserAttributeUpdater (org.keycloak.testsuite.updaters.UserAttributeUpdater)11 AbstractTestRealmKeycloakTest (org.keycloak.testsuite.AbstractTestRealmKeycloakTest)9 AuthenticationSessionFailoverClusterTest (org.keycloak.testsuite.cluster.AuthenticationSessionFailoverClusterTest)9 MimeMessage (javax.mail.internet.MimeMessage)8 Closeable (java.io.Closeable)6 UserRepresentation (org.keycloak.representations.idm.UserRepresentation)3 RoleRepresentation (org.keycloak.representations.idm.RoleRepresentation)2 RoleScopeUpdater (org.keycloak.testsuite.updaters.RoleScopeUpdater)2 WebElement (org.openqa.selenium.WebElement)2 RealmModel (org.keycloak.models.RealmModel)1 RootAuthenticationSessionModel (org.keycloak.sessions.RootAuthenticationSessionModel)1