From c7a97cfd21cbc208d9f40289edc146f9c061c4bb Mon Sep 17 00:00:00 2001 From: Vaclav Muzikar Date: Wed, 19 Apr 2017 13:51:24 +0200 Subject: [PATCH] KEYCLOAK-4761 Prepare the testsuite for Java adapter backward compatibility testing --- .../org/keycloak/admin/client/Keycloak.java | 16 ++++++++++---- .../testsuite/arquillian/SuiteContext.java | 13 ++++++++++++ .../testsuite/util/AdminClientUtil.java | 21 +++++++++++++++++-- .../testsuite/AbstractKeycloakTest.java | 2 +- .../AbstractDemoServletsAdapterTest.java | 6 ++++-- 5 files changed, 49 insertions(+), 9 deletions(-) diff --git a/integration/admin-client/src/main/java/org/keycloak/admin/client/Keycloak.java b/integration/admin-client/src/main/java/org/keycloak/admin/client/Keycloak.java index fa7ed0586f..a37e085862 100755 --- a/integration/admin-client/src/main/java/org/keycloak/admin/client/Keycloak.java +++ b/integration/admin-client/src/main/java/org/keycloak/admin/client/Keycloak.java @@ -20,6 +20,7 @@ package org.keycloak.admin.client; import org.jboss.resteasy.client.jaxrs.ResteasyClient; import org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder; import org.jboss.resteasy.client.jaxrs.ResteasyWebTarget; +import org.jboss.resteasy.plugins.providers.jackson.ResteasyJackson2Provider; import org.keycloak.admin.client.resource.BearerAuthFilter; import org.keycloak.admin.client.resource.RealmResource; import org.keycloak.admin.client.resource.RealmsResource; @@ -31,7 +32,6 @@ import javax.net.ssl.HostnameVerifier; import javax.net.ssl.SSLSession; import java.net.URI; -import java.security.KeyStore; import static org.keycloak.OAuth2Constants.PASSWORD; @@ -66,12 +66,20 @@ public class Keycloak { } public static Keycloak getInstance(String serverUrl, String realm, String username, String password, String clientId, String clientSecret, SSLContext sslContext) { - ResteasyClient client = new ResteasyClientBuilder() + return getInstance(serverUrl, realm, username, password, clientId, clientSecret, sslContext, null); + } + + public static Keycloak getInstance(String serverUrl, String realm, String username, String password, String clientId, String clientSecret, SSLContext sslContext, ResteasyJackson2Provider customJacksonProvider) { + ResteasyClientBuilder clientBuilder = new ResteasyClientBuilder() .sslContext(sslContext) .hostnameVerification(ResteasyClientBuilder.HostnameVerificationPolicy.WILDCARD) - .connectionPoolSize(10).build(); + .connectionPoolSize(10); - return new Keycloak(serverUrl, realm, username, password, clientId, clientSecret, PASSWORD, client, null); + if (customJacksonProvider != null) { + clientBuilder.register(customJacksonProvider); + } + + return new Keycloak(serverUrl, realm, username, password, clientId, clientSecret, PASSWORD, clientBuilder.build(), null); } private static ResteasyClientBuilder newResteasyClientBuilder() { diff --git a/testsuite/integration-arquillian/tests/base/src/main/java/org/keycloak/testsuite/arquillian/SuiteContext.java b/testsuite/integration-arquillian/tests/base/src/main/java/org/keycloak/testsuite/arquillian/SuiteContext.java index dfad4f5d51..fab303a46d 100644 --- a/testsuite/integration-arquillian/tests/base/src/main/java/org/keycloak/testsuite/arquillian/SuiteContext.java +++ b/testsuite/integration-arquillian/tests/base/src/main/java/org/keycloak/testsuite/arquillian/SuiteContext.java @@ -45,6 +45,12 @@ public final class SuiteContext { private boolean adminPasswordUpdated; private final Map smtpServer = new HashMap<>(); + /** + * True if the testsuite is running in the adapter backward compatibility testing mode, + * i.e. if the tests are running against newer auth server + */ + private static final boolean adapterCompatTesting = Boolean.parseBoolean(System.getProperty("testsuite.adapter.compat.testing")); + public SuiteContext(Set arquillianContainers) { this.container = arquillianContainers; this.adminPasswordUpdated = false; @@ -101,6 +107,10 @@ public final class SuiteContext { return container; } + public boolean isAdapterCompatTesting() { + return adapterCompatTesting; + } + @Override public String toString() { String containers = "Auth server: " + (isAuthServerCluster() ? "\nFrontend: " : "") @@ -111,6 +121,9 @@ public final class SuiteContext { if (isAuthServerMigrationEnabled()) { containers += "Migrated from: " + System.getProperty("migrated.auth.server.version") + "\n"; } + if (isAdapterCompatTesting()) { + containers += "Adapter backward compatibility testing mode!\n"; + } return "SUITE CONTEXT:\n" + containers; } diff --git a/testsuite/integration-arquillian/tests/base/src/main/java/org/keycloak/testsuite/util/AdminClientUtil.java b/testsuite/integration-arquillian/tests/base/src/main/java/org/keycloak/testsuite/util/AdminClientUtil.java index 9543373960..c1869d78aa 100644 --- a/testsuite/integration-arquillian/tests/base/src/main/java/org/keycloak/testsuite/util/AdminClientUtil.java +++ b/testsuite/integration-arquillian/tests/base/src/main/java/org/keycloak/testsuite/util/AdminClientUtil.java @@ -26,7 +26,10 @@ import java.security.cert.CertificateException; import javax.net.ssl.SSLContext; +import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.ObjectMapper; import org.apache.http.ssl.SSLContexts; +import org.jboss.resteasy.plugins.providers.jackson.ResteasyJackson2Provider; import org.keycloak.admin.client.Keycloak; import org.keycloak.models.Constants; import org.keycloak.testsuite.arquillian.AuthServerTestEnricher; @@ -38,7 +41,7 @@ import static org.keycloak.testsuite.util.IOUtil.PROJECT_BUILD_DIRECTORY; public class AdminClientUtil { - public static Keycloak createAdminClient() throws Exception { + public static Keycloak createAdminClient(boolean ignoreUnknownProperties) throws Exception { SSLContext ssl = null; if ("true".equals(System.getProperty("auth.server.ssl.required"))) { File trustore = new File(PROJECT_BUILD_DIRECTORY, "dependency/keystore/keycloak.truststore"); @@ -47,10 +50,24 @@ public class AdminClientUtil { System.setProperty("javax.net.ssl.trustStore", trustore.getAbsolutePath()); } + ResteasyJackson2Provider jacksonProvider = null; + + // We need to ignore unknown JSON properties e.g. in the adapter configuration representation + // during adapter backward compatibility testing + if (ignoreUnknownProperties) { + jacksonProvider = new ResteasyJackson2Provider(); + ObjectMapper objectMapper = new ObjectMapper(); + objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + jacksonProvider.setMapper(objectMapper); + } + return Keycloak.getInstance(AuthServerTestEnricher.getAuthServerContextRoot() + "/auth", - MASTER, ADMIN, ADMIN, Constants.ADMIN_CLI_CLIENT_ID, null, ssl); + MASTER, ADMIN, ADMIN, Constants.ADMIN_CLI_CLIENT_ID, null, ssl, jacksonProvider); } + public static Keycloak createAdminClient() throws Exception { + return createAdminClient(false); + } private static SSLContext getSSLContextWithTrustore(File file, String password) throws CertificateException, NoSuchAlgorithmException, KeyStoreException, IOException, KeyManagementException { if (!file.isFile()) { diff --git a/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/AbstractKeycloakTest.java b/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/AbstractKeycloakTest.java index 136a1454e7..ae1db357dd 100644 --- a/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/AbstractKeycloakTest.java +++ b/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/AbstractKeycloakTest.java @@ -135,7 +135,7 @@ public abstract class AbstractKeycloakTest { public void beforeAbstractKeycloakTest() throws Exception { adminClient = testContext.getAdminClient(); if (adminClient == null) { - adminClient = AdminClientUtil.createAdminClient(); + adminClient = AdminClientUtil.createAdminClient(suiteContext.isAdapterCompatTesting()); testContext.setAdminClient(adminClient); } diff --git a/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/adapter/servlet/AbstractDemoServletsAdapterTest.java b/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/adapter/servlet/AbstractDemoServletsAdapterTest.java index 275a078a30..f7a9335336 100644 --- a/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/adapter/servlet/AbstractDemoServletsAdapterTest.java +++ b/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/adapter/servlet/AbstractDemoServletsAdapterTest.java @@ -469,8 +469,10 @@ public abstract class AbstractDemoServletsAdapterTest extends AbstractServletsAd assertNotNull(version2); assertNotNull(version2.getVersion()); assertNotNull(version2.getBuildTime()); - assertEquals(version.getVersion(), version2.getVersion()); - assertEquals(version.getBuildTime(), version2.getBuildTime()); + if (!suiteContext.isAdapterCompatTesting()) { + assertEquals(version.getVersion(), version2.getVersion()); + assertEquals(version.getBuildTime(), version2.getBuildTime()); + } client.close(); }