Search in sources :

Example 6 with RealmAttributeUpdater

use of org.keycloak.testsuite.updaters.RealmAttributeUpdater in project keycloak by keycloak.

the class RegisterTest method registerUserSuccessWithEmailVerificationWithResend.

@Test
// GreenMailRule is not working atm
@AuthServerContainerExclude(AuthServer.REMOTE)
public void registerUserSuccessWithEmailVerificationWithResend() throws Exception {
    try (RealmAttributeUpdater rau = setVerifyEmail(true).update()) {
        loginPage.open();
        loginPage.clickRegister();
        registerPage.assertCurrent();
        registerPage.register("firstName", "lastName", "registerUserSuccessWithEmailVerificationWithResend@email", "registerUserSuccessWithEmailVerificationWithResend", "password", "password");
        verifyEmailPage.assertCurrent();
        String userId = events.expectRegister("registerUserSuccessWithEmailVerificationWithResend", "registerUserSuccessWithEmailVerificationWithResend@email").assertEvent().getUserId();
        {
            assertTrue("Expecting verify email", greenMail.waitForIncomingEmail(1000, 1));
            events.expect(EventType.SEND_VERIFY_EMAIL).detail(Details.EMAIL, "registerUserSuccessWithEmailVerificationWithResend@email".toLowerCase()).user(userId).assertEvent();
            verifyEmailPage.clickResendEmail();
            verifyEmailPage.assertCurrent();
            assertTrue("Expecting second verify email", greenMail.waitForIncomingEmail(1000, 1));
            events.expect(EventType.SEND_VERIFY_EMAIL).detail(Details.EMAIL, "registerUserSuccessWithEmailVerificationWithResend@email".toLowerCase()).user(userId).assertEvent();
            MimeMessage message = greenMail.getLastReceivedMessage();
            String link = MailUtils.getPasswordResetEmailLink(message);
            driver.navigate().to(link);
        }
        events.expectRequiredAction(EventType.VERIFY_EMAIL).detail(Details.EMAIL, "registerUserSuccessWithEmailVerificationWithResend@email".toLowerCase()).user(userId).assertEvent();
        assertUserRegistered(userId, "registerUserSuccessWithEmailVerificationWithResend", "registerUserSuccessWithEmailVerificationWithResend@email");
        appPage.assertCurrent();
        assertEquals(RequestType.AUTH_RESPONSE, appPage.getRequestType());
    // test that timestamp is current with 10s tollerance
    // test user info is set from form
    }
}
Also used : MimeMessage(javax.mail.internet.MimeMessage) RealmAttributeUpdater(org.keycloak.testsuite.updaters.RealmAttributeUpdater) Matchers.containsString(org.hamcrest.Matchers.containsString) AuthServerContainerExclude(org.keycloak.testsuite.arquillian.annotation.AuthServerContainerExclude) Test(org.junit.Test) AbstractTestRealmKeycloakTest(org.keycloak.testsuite.AbstractTestRealmKeycloakTest)

Example 7 with RealmAttributeUpdater

use of org.keycloak.testsuite.updaters.RealmAttributeUpdater in project keycloak by keycloak.

the class RegisterTest method registerUserNotUsernamePasswordPolicy.

// KEYCLOAK-3266
@Test
public void registerUserNotUsernamePasswordPolicy() throws IOException {
    try (RealmAttributeUpdater rau = getRealmAttributeUpdater().setPasswordPolicy("notUsername").update()) {
        loginPage.open();
        assertTrue(loginPage.isCurrent());
        loginPage.clickRegister();
        registerPage.assertCurrent();
        registerPage.register("firstName", "lastName", "registerUserNotUsername@email", "registerUserNotUsername", "registerUserNotUsername", "registerUserNotUsername");
        assertTrue(registerPage.isCurrent());
        assertEquals("Invalid password: must not be equal to the username.", registerPage.getInputPasswordErrors().getPasswordError());
        adminClient.realm("test").users().create(UserBuilder.create().username("registerUserNotUsername").build());
        registerPage.register("firstName", "lastName", "registerUserNotUsername@email", "registerUserNotUsername", "registerUserNotUsername", "registerUserNotUsername");
        assertTrue(registerPage.isCurrent());
        assertEquals("Username already exists.", registerPage.getInputAccountErrors().getUsernameError());
        registerPage.register("firstName", "lastName", "registerUserNotUsername@email", null, "password", "password");
        assertTrue(registerPage.isCurrent());
        assertEquals("Please specify username.", registerPage.getInputAccountErrors().getUsernameError());
    }
}
Also used : RealmAttributeUpdater(org.keycloak.testsuite.updaters.RealmAttributeUpdater) Test(org.junit.Test) AbstractTestRealmKeycloakTest(org.keycloak.testsuite.AbstractTestRealmKeycloakTest)

Example 8 with RealmAttributeUpdater

use of org.keycloak.testsuite.updaters.RealmAttributeUpdater in project keycloak by keycloak.

the class RegisterTest method registerUserSuccessWithEmailVerification.

@Test
// GreenMailRule is not working atm
@AuthServerContainerExclude(AuthServer.REMOTE)
public void registerUserSuccessWithEmailVerification() throws Exception {
    try (RealmAttributeUpdater rau = setVerifyEmail(true).update()) {
        loginPage.open();
        loginPage.clickRegister();
        registerPage.assertCurrent();
        registerPage.register("firstName", "lastName", "registerUserSuccessWithEmailVerification@email", "registerUserSuccessWithEmailVerification", "password", "password");
        verifyEmailPage.assertCurrent();
        String userId = events.expectRegister("registerUserSuccessWithEmailVerification", "registerUserSuccessWithEmailVerification@email").assertEvent().getUserId();
        {
            assertTrue("Expecting verify email", greenMail.waitForIncomingEmail(1000, 1));
            events.expect(EventType.SEND_VERIFY_EMAIL).detail(Details.EMAIL, "registerUserSuccessWithEmailVerification@email".toLowerCase()).user(userId).assertEvent();
            MimeMessage message = greenMail.getLastReceivedMessage();
            String link = MailUtils.getPasswordResetEmailLink(message);
            driver.navigate().to(link);
        }
        events.expectRequiredAction(EventType.VERIFY_EMAIL).detail(Details.EMAIL, "registerUserSuccessWithEmailVerification@email".toLowerCase()).user(userId).assertEvent();
        assertUserRegistered(userId, "registerUserSuccessWithEmailVerification", "registerUserSuccessWithEmailVerification@email");
        appPage.assertCurrent();
        assertEquals(RequestType.AUTH_RESPONSE, appPage.getRequestType());
    // test that timestamp is current with 10s tollerance
    // test user info is set from form
    }
}
Also used : MimeMessage(javax.mail.internet.MimeMessage) RealmAttributeUpdater(org.keycloak.testsuite.updaters.RealmAttributeUpdater) Matchers.containsString(org.hamcrest.Matchers.containsString) AuthServerContainerExclude(org.keycloak.testsuite.arquillian.annotation.AuthServerContainerExclude) Test(org.junit.Test) AbstractTestRealmKeycloakTest(org.keycloak.testsuite.AbstractTestRealmKeycloakTest)

Example 9 with RealmAttributeUpdater

use of org.keycloak.testsuite.updaters.RealmAttributeUpdater in project keycloak by keycloak.

the class RegisterTest method registerWithLoginHint_emailAsUsername.

@Test
public void registerWithLoginHint_emailAsUsername() throws IOException {
    try (RealmAttributeUpdater rau = configureRealmRegistrationEmailAsUsername(true).update()) {
        registerPage.openWithLoginHint("test@test.com");
        assertEquals("test@test.com", registerPage.getEmail());
    }
}
Also used : RealmAttributeUpdater(org.keycloak.testsuite.updaters.RealmAttributeUpdater) Test(org.junit.Test) AbstractTestRealmKeycloakTest(org.keycloak.testsuite.AbstractTestRealmKeycloakTest)

Example 10 with RealmAttributeUpdater

use of org.keycloak.testsuite.updaters.RealmAttributeUpdater in project keycloak by keycloak.

the class LoginTest method loginRememberMeExpiredIdle.

@Test
// TODO remove this (KEYCLOAK-16228)
@DisableFeature(value = Profile.Feature.ACCOUNT2, skipRestart = true)
public void loginRememberMeExpiredIdle() throws Exception {
    try (Closeable c = new RealmAttributeUpdater(adminClient.realm("test")).setSsoSessionIdleTimeoutRememberMe(1).setRememberMe(true).update()) {
        // login form shown after redirect from app
        oauth.clientId("test-app");
        oauth.redirectUri(OAuthClient.APP_ROOT + "/auth");
        oauth.openLoginForm();
        assertTrue(loginPage.isCurrent());
        loginPage.setRememberMe(true);
        loginPage.login("test-user@localhost", "password");
        // sucessful login - app page should be on display.
        events.expectLogin().detail(Details.USERNAME, "test-user@localhost").assertEvent();
        appPage.assertCurrent();
        // expire idle timeout using the timeout window.
        setTimeOffset(2 + SessionTimeoutHelper.IDLE_TIMEOUT_WINDOW_SECONDS);
        // trying to open the account page with an expired idle timeout should redirect back to the login page.
        appPage.openAccount();
        loginPage.assertCurrent();
    }
}
Also used : Closeable(java.io.Closeable) RealmAttributeUpdater(org.keycloak.testsuite.updaters.RealmAttributeUpdater) DisableFeature(org.keycloak.testsuite.arquillian.annotation.DisableFeature) Test(org.junit.Test) AbstractTestRealmKeycloakTest(org.keycloak.testsuite.AbstractTestRealmKeycloakTest)

Aggregations

Test (org.junit.Test)27 RealmAttributeUpdater (org.keycloak.testsuite.updaters.RealmAttributeUpdater)27 AbstractTestRealmKeycloakTest (org.keycloak.testsuite.AbstractTestRealmKeycloakTest)15 Matchers.containsString (org.hamcrest.Matchers.containsString)10 List (java.util.List)5 AuthServerContainerExclude (org.keycloak.testsuite.arquillian.annotation.AuthServerContainerExclude)5 WebAuthnRealmAttributeUpdater (org.keycloak.testsuite.webauthn.updaters.WebAuthnRealmAttributeUpdater)5 Closeable (java.io.Closeable)4 Arrays (java.util.Arrays)4 HashMap (java.util.HashMap)4 Set (java.util.Set)4 Response (javax.ws.rs.core.Response)4 Matchers.equalTo (org.hamcrest.Matchers.equalTo)4 Assert.assertFalse (org.junit.Assert.assertFalse)4 IOException (java.io.IOException)3 URISyntaxException (java.net.URISyntaxException)3 HashSet (java.util.HashSet)3 Map (java.util.Map)3 UUID (java.util.UUID)3 MimeMessage (javax.mail.internet.MimeMessage)3