From f8dc7c0329891442486db0c8b436be2e083b1a6d Mon Sep 17 00:00:00 2001 From: Aboullos Date: Tue, 10 Mar 2020 10:38:15 +0100 Subject: [PATCH] KEYCLOAK-13007 Add LDAPAccountTest --- .../org/keycloak/testsuite/util/LDAPRule.java | 7 +- .../ui/account2/LDAPAccountTest.java | 89 +++++++++++++++++++ .../ui/account2/page/SigningInPage.java | 9 ++ .../tests/other/pom.xml | 2 +- .../integration-arquillian/tests/pom.xml | 2 +- 5 files changed, 105 insertions(+), 4 deletions(-) create mode 100644 testsuite/integration-arquillian/tests/other/base-ui/src/test/java/org/keycloak/testsuite/ui/account2/LDAPAccountTest.java diff --git a/testsuite/integration-arquillian/tests/base/src/main/java/org/keycloak/testsuite/util/LDAPRule.java b/testsuite/integration-arquillian/tests/base/src/main/java/org/keycloak/testsuite/util/LDAPRule.java index 1b9a4c6658..6dd534d62b 100644 --- a/testsuite/integration-arquillian/tests/base/src/main/java/org/keycloak/testsuite/util/LDAPRule.java +++ b/testsuite/integration-arquillian/tests/base/src/main/java/org/keycloak/testsuite/util/LDAPRule.java @@ -22,9 +22,12 @@ import org.junit.rules.ExternalResource; import org.keycloak.models.LDAPConstants; import org.keycloak.util.ldap.LDAPEmbeddedServer; +import java.io.File; import java.util.Map; import java.util.Properties; +import static org.keycloak.testsuite.utils.io.IOUtil.PROJECT_BUILD_DIRECTORY; + /** * @author Marek Posolda */ @@ -36,7 +39,7 @@ public class LDAPRule extends ExternalResource { private static final String PROPERTY_KEYSTORE_FILE = "keystoreFile"; - private static final String PRIVATE_KEY = "keystore/keycloak.jks"; + private static final String PRIVATE_KEY = "dependency/keystore/keycloak.jks"; private static final String PROPERTY_CERTIFICATE_PASSWORD = "certificatePassword"; @@ -87,7 +90,7 @@ public class LDAPRule extends ExternalResource { defaultProperties.setProperty(LDAPEmbeddedServer.PROPERTY_LDIF_FILE, "classpath:ldap/users.ldif"); defaultProperties.setProperty(PROPERTY_ENABLE_SSL, "true"); defaultProperties.setProperty(PROPERTY_CERTIFICATE_PASSWORD, "secret"); - defaultProperties.setProperty(PROPERTY_KEYSTORE_FILE, this.getClass().getClassLoader().getResource(LDAPRule.PRIVATE_KEY).getFile()); + defaultProperties.setProperty(PROPERTY_KEYSTORE_FILE, new File(PROJECT_BUILD_DIRECTORY, PRIVATE_KEY).getAbsolutePath()); return new LDAPEmbeddedServer(defaultProperties); } diff --git a/testsuite/integration-arquillian/tests/other/base-ui/src/test/java/org/keycloak/testsuite/ui/account2/LDAPAccountTest.java b/testsuite/integration-arquillian/tests/other/base-ui/src/test/java/org/keycloak/testsuite/ui/account2/LDAPAccountTest.java new file mode 100644 index 0000000000..014d69aebf --- /dev/null +++ b/testsuite/integration-arquillian/tests/other/base-ui/src/test/java/org/keycloak/testsuite/ui/account2/LDAPAccountTest.java @@ -0,0 +1,89 @@ +/* + * Copyright 2020 Red Hat, Inc. and/or its affiliates + * and other contributors as indicated by the @author tags. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.keycloak.testsuite.ui.account2; + +import org.jboss.arquillian.graphene.page.Page; +import org.junit.*; +import org.keycloak.models.RealmModel; +import org.keycloak.models.credential.PasswordCredentialModel; +import org.keycloak.representations.idm.*; +import org.keycloak.storage.ldap.idm.model.LDAPObject; +import org.keycloak.testsuite.federation.ldap.LDAPTestContext; +import org.keycloak.testsuite.ui.account2.page.SigningInPage; +import org.keycloak.testsuite.util.LDAPRule; +import org.keycloak.testsuite.util.LDAPTestUtils; + +import static org.keycloak.representations.idm.CredentialRepresentation.PASSWORD; +import static org.keycloak.testsuite.admin.Users.setPasswordFor; +import static org.keycloak.testsuite.auth.page.AuthRealm.TEST; + +/** + * @author Alfredo Moises Boullosa + */ +public class LDAPAccountTest extends AbstractAccountTest { + + @Page + private SigningInPage signingInPage; + + private SigningInPage.CredentialType passwordCredentialType; + @ClassRule + public static LDAPRule ldapRule = new LDAPRule(); + + @Before + public void beforeSigningInTest() { + passwordCredentialType = signingInPage.getCredentialType(PasswordCredentialModel.TYPE); + + testingClient.testing().ldap(TEST).createLDAPProvider(ldapRule.getConfig(), true); + log.infof("LDAP Provider created"); + + String userName = "johnkeycloak"; + String firstName = "Jonh"; + String lastName = "Doe"; + String email = "john@email.org"; + + testingClient.server().run(session -> { + LDAPTestContext ctx = LDAPTestContext.init(session); + RealmModel appRealm = ctx.getRealm(); + + // Delete all LDAP users and add some new for testing + LDAPTestUtils.removeAllLDAPUsers(ctx.getLdapProvider(), appRealm); + + LDAPObject john = LDAPTestUtils.addLDAPUser(ctx.getLdapProvider(), appRealm, userName, firstName, lastName, email, null, "1234"); + LDAPTestUtils.updateLDAPPassword(ctx.getLdapProvider(), john, PASSWORD); + }); + + testRealmLoginPage.setAuthRealm(testRealmPage); + testRealmAccountPage.setAuthRealm(testRealmPage); + + testUser = createUserRepresentation(userName, email, firstName, lastName, true); + setPasswordFor(testUser, PASSWORD); + + resetTestRealmSession(); + } + + @Test + public void createdNotVisibleTest() { + signingInPage.navigateTo(); + loginPage.form().login(testUser); + + SigningInPage.UserCredential userCredential = passwordCredentialType.getUserCredential("password"); + + Assert.assertTrue("ROW is not present", userCredential.isPresent()); + Assert.assertFalse("Created at is present", userCredential.hasCreatedAt()); + } +} diff --git a/testsuite/integration-arquillian/tests/other/base-ui/src/test/java/org/keycloak/testsuite/ui/account2/page/SigningInPage.java b/testsuite/integration-arquillian/tests/other/base-ui/src/test/java/org/keycloak/testsuite/ui/account2/page/SigningInPage.java index 727e91fdf3..95175ac242 100644 --- a/testsuite/integration-arquillian/tests/other/base-ui/src/test/java/org/keycloak/testsuite/ui/account2/page/SigningInPage.java +++ b/testsuite/integration-arquillian/tests/other/base-ui/src/test/java/org/keycloak/testsuite/ui/account2/page/SigningInPage.java @@ -180,6 +180,15 @@ public class SigningInPage extends AbstractLoggedInPage { return getTextFromItem(LABEL); } + public boolean hasCreatedAt() { + boolean result = false; + try { + result = getItemElement(CREATED_AT).isDisplayed(); + } catch (NoSuchElementException e) {} + + return result; + } + public String getCreatedAtStr() { return getTextFromItem(CREATED_AT).split("Created: ")[1]; } diff --git a/testsuite/integration-arquillian/tests/other/pom.xml b/testsuite/integration-arquillian/tests/other/pom.xml index 04cdec93f3..2ae753336c 100644 --- a/testsuite/integration-arquillian/tests/other/pom.xml +++ b/testsuite/integration-arquillian/tests/other/pom.xml @@ -60,7 +60,7 @@ integration-arquillian-tests-base ${project.version} tests - arquillian.xml,keycloak-add-user.json,test-constants.properties,kerberos/*,keystore/keycloak.truststore,password-blacklists/*,log4j.properties,vault/* + arquillian.xml,keycloak-add-user.json,test-constants.properties,kerberos/*,keystore/*,password-blacklists/*,log4j.properties,vault/* diff --git a/testsuite/integration-arquillian/tests/pom.xml b/testsuite/integration-arquillian/tests/pom.xml index eb98637b72..5b98370cbc 100755 --- a/testsuite/integration-arquillian/tests/pom.xml +++ b/testsuite/integration-arquillian/tests/pom.xml @@ -379,7 +379,7 @@ src/test/resources - keystore/keycloak.truststore + keystore/**