KEYCLOAK-4761 Prepare the testsuite for Java adapter backward compatibility testing
This commit is contained in:
parent
906739f8f3
commit
c7a97cfd21
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.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() {
|
||||
|
|
|
@ -45,6 +45,12 @@ public final class SuiteContext {
|
|||
private boolean adminPasswordUpdated;
|
||||
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) {
|
||||
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;
|
||||
}
|
||||
|
|
|
@ -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()) {
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue