Merge pull request #4044 from vmuzikar/adapter-compat-upstream
KEYCLOAK-4761 Support for Java adapter backward compatibility testing
This commit is contained in:
commit
f50e08d111
5 changed files with 49 additions and 9 deletions
|
@ -20,6 +20,7 @@ package org.keycloak.admin.client;
|
||||||
import org.jboss.resteasy.client.jaxrs.ResteasyClient;
|
import org.jboss.resteasy.client.jaxrs.ResteasyClient;
|
||||||
import org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder;
|
import org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder;
|
||||||
import org.jboss.resteasy.client.jaxrs.ResteasyWebTarget;
|
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.BearerAuthFilter;
|
||||||
import org.keycloak.admin.client.resource.RealmResource;
|
import org.keycloak.admin.client.resource.RealmResource;
|
||||||
import org.keycloak.admin.client.resource.RealmsResource;
|
import org.keycloak.admin.client.resource.RealmsResource;
|
||||||
|
@ -31,7 +32,6 @@ import javax.net.ssl.HostnameVerifier;
|
||||||
import javax.net.ssl.SSLSession;
|
import javax.net.ssl.SSLSession;
|
||||||
|
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.security.KeyStore;
|
|
||||||
|
|
||||||
import static org.keycloak.OAuth2Constants.PASSWORD;
|
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) {
|
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)
|
.sslContext(sslContext)
|
||||||
.hostnameVerification(ResteasyClientBuilder.HostnameVerificationPolicy.WILDCARD)
|
.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() {
|
private static ResteasyClientBuilder newResteasyClientBuilder() {
|
||||||
|
|
|
@ -45,6 +45,12 @@ public final class SuiteContext {
|
||||||
private boolean adminPasswordUpdated;
|
private boolean adminPasswordUpdated;
|
||||||
private final Map<String, String> smtpServer = new HashMap<>();
|
private final Map<String, String> 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<ContainerInfo> arquillianContainers) {
|
public SuiteContext(Set<ContainerInfo> arquillianContainers) {
|
||||||
this.container = arquillianContainers;
|
this.container = arquillianContainers;
|
||||||
this.adminPasswordUpdated = false;
|
this.adminPasswordUpdated = false;
|
||||||
|
@ -101,6 +107,10 @@ public final class SuiteContext {
|
||||||
return container;
|
return container;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isAdapterCompatTesting() {
|
||||||
|
return adapterCompatTesting;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
String containers = "Auth server: " + (isAuthServerCluster() ? "\nFrontend: " : "")
|
String containers = "Auth server: " + (isAuthServerCluster() ? "\nFrontend: " : "")
|
||||||
|
@ -111,6 +121,9 @@ public final class SuiteContext {
|
||||||
if (isAuthServerMigrationEnabled()) {
|
if (isAuthServerMigrationEnabled()) {
|
||||||
containers += "Migrated from: " + System.getProperty("migrated.auth.server.version") + "\n";
|
containers += "Migrated from: " + System.getProperty("migrated.auth.server.version") + "\n";
|
||||||
}
|
}
|
||||||
|
if (isAdapterCompatTesting()) {
|
||||||
|
containers += "Adapter backward compatibility testing mode!\n";
|
||||||
|
}
|
||||||
return "SUITE CONTEXT:\n"
|
return "SUITE CONTEXT:\n"
|
||||||
+ containers;
|
+ containers;
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,7 +26,10 @@ import java.security.cert.CertificateException;
|
||||||
|
|
||||||
import javax.net.ssl.SSLContext;
|
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.apache.http.ssl.SSLContexts;
|
||||||
|
import org.jboss.resteasy.plugins.providers.jackson.ResteasyJackson2Provider;
|
||||||
import org.keycloak.admin.client.Keycloak;
|
import org.keycloak.admin.client.Keycloak;
|
||||||
import org.keycloak.models.Constants;
|
import org.keycloak.models.Constants;
|
||||||
import org.keycloak.testsuite.arquillian.AuthServerTestEnricher;
|
import org.keycloak.testsuite.arquillian.AuthServerTestEnricher;
|
||||||
|
@ -38,7 +41,7 @@ import static org.keycloak.testsuite.util.IOUtil.PROJECT_BUILD_DIRECTORY;
|
||||||
|
|
||||||
public class AdminClientUtil {
|
public class AdminClientUtil {
|
||||||
|
|
||||||
public static Keycloak createAdminClient() throws Exception {
|
public static Keycloak createAdminClient(boolean ignoreUnknownProperties) throws Exception {
|
||||||
SSLContext ssl = null;
|
SSLContext ssl = null;
|
||||||
if ("true".equals(System.getProperty("auth.server.ssl.required"))) {
|
if ("true".equals(System.getProperty("auth.server.ssl.required"))) {
|
||||||
File trustore = new File(PROJECT_BUILD_DIRECTORY, "dependency/keystore/keycloak.truststore");
|
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());
|
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",
|
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 {
|
private static SSLContext getSSLContextWithTrustore(File file, String password) throws CertificateException, NoSuchAlgorithmException, KeyStoreException, IOException, KeyManagementException {
|
||||||
if (!file.isFile()) {
|
if (!file.isFile()) {
|
||||||
|
|
|
@ -135,7 +135,7 @@ public abstract class AbstractKeycloakTest {
|
||||||
public void beforeAbstractKeycloakTest() throws Exception {
|
public void beforeAbstractKeycloakTest() throws Exception {
|
||||||
adminClient = testContext.getAdminClient();
|
adminClient = testContext.getAdminClient();
|
||||||
if (adminClient == null) {
|
if (adminClient == null) {
|
||||||
adminClient = AdminClientUtil.createAdminClient();
|
adminClient = AdminClientUtil.createAdminClient(suiteContext.isAdapterCompatTesting());
|
||||||
testContext.setAdminClient(adminClient);
|
testContext.setAdminClient(adminClient);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -469,8 +469,10 @@ public abstract class AbstractDemoServletsAdapterTest extends AbstractServletsAd
|
||||||
assertNotNull(version2);
|
assertNotNull(version2);
|
||||||
assertNotNull(version2.getVersion());
|
assertNotNull(version2.getVersion());
|
||||||
assertNotNull(version2.getBuildTime());
|
assertNotNull(version2.getBuildTime());
|
||||||
assertEquals(version.getVersion(), version2.getVersion());
|
if (!suiteContext.isAdapterCompatTesting()) {
|
||||||
assertEquals(version.getBuildTime(), version2.getBuildTime());
|
assertEquals(version.getVersion(), version2.getVersion());
|
||||||
|
assertEquals(version.getBuildTime(), version2.getBuildTime());
|
||||||
|
}
|
||||||
client.close();
|
client.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue