Search in sources :

Example 21 with RealmAttributeUpdater

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

the class RegisterTest method registerUpperCaseEmailWithChangedEmailAsUsername.

@Test
public void registerUpperCaseEmailWithChangedEmailAsUsername() throws IOException {
    String userId = registerUpperCaseAndGetUserId(false);
    assertThat(userId, notNullValue());
    oauth.openLogout();
    events.clear();
    try (RealmAttributeUpdater rau = configureRealmRegistrationEmailAsUsername(true).update()) {
        loginPage.open();
        loginPage.assertCurrent();
        final String EMAIL = "TEST@localhost";
        loginPage.login(EMAIL, "password");
        assertThat(RequestType.AUTH_RESPONSE, is(appPage.getRequestType()));
        events.expectLogin().detail("username", EMAIL).user(userId).assertEvent();
    } finally {
        assertThat(userId, notNullValue());
        testRealm().users().get(userId).remove();
    }
}
Also used : RealmAttributeUpdater(org.keycloak.testsuite.updaters.RealmAttributeUpdater) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.Test) AbstractTestRealmKeycloakTest(org.keycloak.testsuite.AbstractTestRealmKeycloakTest)

Example 22 with RealmAttributeUpdater

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

the class RegisterTest method registerUserMissingOrInvalidEmail_emailAsUsername.

@Test
public void registerUserMissingOrInvalidEmail_emailAsUsername() throws IOException {
    try (RealmAttributeUpdater rau = configureRealmRegistrationEmailAsUsername(true).update()) {
        loginPage.open();
        loginPage.clickRegister();
        registerPage.assertCurrent();
        registerPage.registerWithEmailAsUsername("firstName", "lastName", null, "password", "password");
        registerPage.assertCurrent();
        assertEquals("Please specify email.", registerPage.getInputAccountErrors().getEmailError());
        events.expectRegister(null, null).removeDetail("username").removeDetail("email").error("invalid_registration").assertEvent();
        registerPage.registerWithEmailAsUsername("firstName", "lastName", "registerUserInvalidEmailemail", "password", "password");
        registerPage.assertCurrent();
        assertEquals("Invalid email address.", registerPage.getInputAccountErrors().getEmailError());
        events.expectRegister("registerUserInvalidEmailemail", "registerUserInvalidEmailemail").error("invalid_registration").assertEvent();
    }
}
Also used : RealmAttributeUpdater(org.keycloak.testsuite.updaters.RealmAttributeUpdater) Test(org.junit.Test) AbstractTestRealmKeycloakTest(org.keycloak.testsuite.AbstractTestRealmKeycloakTest)

Example 23 with RealmAttributeUpdater

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

the class RegisterTest method registerUpperCaseEmailAsUsername.

@Test
public void registerUpperCaseEmailAsUsername() throws IOException {
    try (RealmAttributeUpdater rau = configureRealmRegistrationEmailAsUsername(true).update()) {
        String userId = registerUpperCaseAndGetUserId(true);
        assertThat(userId, notNullValue());
        testRealm().users().get(userId).remove();
    }
}
Also used : RealmAttributeUpdater(org.keycloak.testsuite.updaters.RealmAttributeUpdater) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.Test) AbstractTestRealmKeycloakTest(org.keycloak.testsuite.AbstractTestRealmKeycloakTest)

Example 24 with RealmAttributeUpdater

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

the class RegisterTest method registerUserSuccess_emailAsUsername.

@Test
public void registerUserSuccess_emailAsUsername() throws IOException {
    try (RealmAttributeUpdater rau = configureRealmRegistrationEmailAsUsername(true).update()) {
        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();
        UserRepresentation 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);
    }
}
Also used : RealmAttributeUpdater(org.keycloak.testsuite.updaters.RealmAttributeUpdater) Matchers.containsString(org.hamcrest.Matchers.containsString) UserRepresentation(org.keycloak.representations.idm.UserRepresentation) Test(org.junit.Test) AbstractTestRealmKeycloakTest(org.keycloak.testsuite.AbstractTestRealmKeycloakTest)

Example 25 with RealmAttributeUpdater

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

the class RegisterTest method registerUserNotEmailPasswordPolicy.

// KEYCLOAK-12729
@Test
public void registerUserNotEmailPasswordPolicy() throws IOException {
    try (RealmAttributeUpdater rau = configureRealmRegistrationEmailAsUsername(true).setPasswordPolicy("notEmail").update()) {
        loginPage.open();
        assertTrue(loginPage.isCurrent());
        loginPage.clickRegister();
        registerPage.assertCurrent();
        registerPage.registerWithEmailAsUsername("firstName", "lastName", "registerUserNotEmail@email", "registerUserNotEmail@email", "registerUserNotEmail@email");
        assertTrue(registerPage.isCurrent());
        assertEquals("Invalid password: must not be equal to the email.", registerPage.getInputPasswordErrors().getPasswordError());
    }
}
Also used : RealmAttributeUpdater(org.keycloak.testsuite.updaters.RealmAttributeUpdater) 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