From 357982adf610e7d93ebecbe0de156cfadb4f004b Mon Sep 17 00:00:00 2001 From: Pedro Igor Date: Tue, 2 Jun 2020 16:18:22 -0300 Subject: [PATCH] [KEYCLOAK-11330] - Initial changes to get testsuite working for Quarkus --- .../keycloak/quarkus/deployment/KeycloakProcessor.java | 8 +------- .../jpa/QuarkusJpaConnectionProviderFactory.java | 2 -- .../java/org/keycloak/provider/quarkus/QuarkusFilter.java | 8 ++++++++ quarkus/server/src/main/resources/application.properties | 2 +- .../testsuite/arquillian/AuthServerTestEnricher.java | 4 ++++ .../arquillian/annotation/AuthServerContainerExclude.java | 3 ++- .../KeycloakQuarkusServerDeployableContainer.java | 2 ++ .../decider/AuthServerExcludeExecutionDecider.java | 8 ++++++++ .../testsuite/openshift/OpenshiftClientStorageTest.java | 2 +- 9 files changed, 27 insertions(+), 12 deletions(-) diff --git a/quarkus/deployment/src/main/java/org/keycloak/quarkus/deployment/KeycloakProcessor.java b/quarkus/deployment/src/main/java/org/keycloak/quarkus/deployment/KeycloakProcessor.java index 0bc526d4d8..241b9c11e6 100644 --- a/quarkus/deployment/src/main/java/org/keycloak/quarkus/deployment/KeycloakProcessor.java +++ b/quarkus/deployment/src/main/java/org/keycloak/quarkus/deployment/KeycloakProcessor.java @@ -73,15 +73,9 @@ class KeycloakProcessor { Map>> result = new HashMap<>(); for (Spi spi : pm.loadSpis()) { - List loaded = pm.load(spi); - - if (loaded.isEmpty()) { - continue; - } - Set> factories = new HashSet<>(); - for (ProviderFactory factory : loaded) { + for (ProviderFactory factory : pm.load(spi)) { if (Arrays.asList( JBossJtaTransactionManagerLookup.class, DefaultJpaConnectionProviderFactory.class, diff --git a/quarkus/runtime/src/main/java/org/keycloak/connections/jpa/QuarkusJpaConnectionProviderFactory.java b/quarkus/runtime/src/main/java/org/keycloak/connections/jpa/QuarkusJpaConnectionProviderFactory.java index 6e441d18ee..423977e549 100644 --- a/quarkus/runtime/src/main/java/org/keycloak/connections/jpa/QuarkusJpaConnectionProviderFactory.java +++ b/quarkus/runtime/src/main/java/org/keycloak/connections/jpa/QuarkusJpaConnectionProviderFactory.java @@ -381,8 +381,6 @@ public class QuarkusJpaConnectionProviderFactory implements JpaConnectionProvide if (createMasterRealm) { applianceBootstrap.createMasterRealm(); - //TODO: Remove this to reduce startup time. See https://issues.redhat.com/browse/KEYCLOAK-14308. - DefaultKeyProviders.createProviders(session.getContext().getRealm()); } session.getTransactionManager().commit(); diff --git a/quarkus/runtime/src/main/java/org/keycloak/provider/quarkus/QuarkusFilter.java b/quarkus/runtime/src/main/java/org/keycloak/provider/quarkus/QuarkusFilter.java index 7240670dfb..2c69125942 100644 --- a/quarkus/runtime/src/main/java/org/keycloak/provider/quarkus/QuarkusFilter.java +++ b/quarkus/runtime/src/main/java/org/keycloak/provider/quarkus/QuarkusFilter.java @@ -19,6 +19,8 @@ package org.keycloak.provider.quarkus; import io.vertx.core.http.HttpServerRequest; import io.vertx.ext.web.RoutingContext; +import org.jboss.resteasy.plugins.server.servlet.ResteasyContextParameters; +import org.jboss.resteasy.spi.ResteasyDeployment; import org.keycloak.common.ClientConnection; import org.keycloak.common.util.Resteasy; import org.keycloak.models.KeycloakSession; @@ -47,6 +49,12 @@ public class QuarkusFilter implements javax.ws.rs.container.ContainerRequestFilt @Inject RoutingContext routingContext; + public QuarkusFilter() { + //TODO: a temporary hack for https://github.com/quarkusio/quarkus/issues/9647, we need to disable the sanitizer to avoid + // escaping text/html responses from the server + Resteasy.getContextData(ResteasyDeployment.class).setProperty(ResteasyContextParameters.RESTEASY_DISABLE_HTML_SANITIZER, Boolean.TRUE); + } + @Override public void filter(ContainerRequestContext containerRequestContext) { KeycloakSessionFactory sessionFactory = keycloakApplication.getSessionFactory(); diff --git a/quarkus/server/src/main/resources/application.properties b/quarkus/server/src/main/resources/application.properties index 53b9300631..5d82aea3b6 100644 --- a/quarkus/server/src/main/resources/application.properties +++ b/quarkus/server/src/main/resources/application.properties @@ -1,4 +1,4 @@ #quarkus.log.level = DEBUG quarkus.http.root-path=/auth quarkus.application.name=Keycloak -resteasy.disable.html.sanitizer = true \ No newline at end of file +quarkus.banner.enabled=false \ No newline at end of file diff --git a/testsuite/integration-arquillian/tests/base/src/main/java/org/keycloak/testsuite/arquillian/AuthServerTestEnricher.java b/testsuite/integration-arquillian/tests/base/src/main/java/org/keycloak/testsuite/arquillian/AuthServerTestEnricher.java index 13341e76d3..11b09c933c 100644 --- a/testsuite/integration-arquillian/tests/base/src/main/java/org/keycloak/testsuite/arquillian/AuthServerTestEnricher.java +++ b/testsuite/integration-arquillian/tests/base/src/main/java/org/keycloak/testsuite/arquillian/AuthServerTestEnricher.java @@ -159,6 +159,10 @@ public class AuthServerTestEnricher { return AUTH_SERVER_CONTAINER.equals("auth-server-remote"); } + public static boolean isAuthServerQuarkus() { + return AUTH_SERVER_CONTAINER.equals("auth-server-quarkus"); + } + public static String getAuthServerContextRoot() { return getAuthServerContextRoot(0); } diff --git a/testsuite/integration-arquillian/tests/base/src/main/java/org/keycloak/testsuite/arquillian/annotation/AuthServerContainerExclude.java b/testsuite/integration-arquillian/tests/base/src/main/java/org/keycloak/testsuite/arquillian/annotation/AuthServerContainerExclude.java index 7296c9c468..8d9fdffcc4 100644 --- a/testsuite/integration-arquillian/tests/base/src/main/java/org/keycloak/testsuite/arquillian/annotation/AuthServerContainerExclude.java +++ b/testsuite/integration-arquillian/tests/base/src/main/java/org/keycloak/testsuite/arquillian/annotation/AuthServerContainerExclude.java @@ -41,6 +41,7 @@ public @interface AuthServerContainerExclude { AuthServer[] value(); public enum AuthServer { - REMOTE + REMOTE, + QUARKUS } } diff --git a/testsuite/integration-arquillian/tests/base/src/main/java/org/keycloak/testsuite/arquillian/containers/KeycloakQuarkusServerDeployableContainer.java b/testsuite/integration-arquillian/tests/base/src/main/java/org/keycloak/testsuite/arquillian/containers/KeycloakQuarkusServerDeployableContainer.java index 11b44d85f3..0f979d012d 100644 --- a/testsuite/integration-arquillian/tests/base/src/main/java/org/keycloak/testsuite/arquillian/containers/KeycloakQuarkusServerDeployableContainer.java +++ b/testsuite/integration-arquillian/tests/base/src/main/java/org/keycloak/testsuite/arquillian/containers/KeycloakQuarkusServerDeployableContainer.java @@ -131,6 +131,8 @@ public class KeycloakQuarkusServerDeployableContainer implements DeployableConta } try { + // wait before checking for opening a new connection + Thread.sleep(1000); connection = (HttpURLConnection) contextRoot.openConnection(); connection.setReadTimeout((int) getStartTimeout()); diff --git a/testsuite/integration-arquillian/tests/base/src/main/java/org/keycloak/testsuite/arquillian/decider/AuthServerExcludeExecutionDecider.java b/testsuite/integration-arquillian/tests/base/src/main/java/org/keycloak/testsuite/arquillian/decider/AuthServerExcludeExecutionDecider.java index ba1ec5f148..5b4a8cc6ba 100644 --- a/testsuite/integration-arquillian/tests/base/src/main/java/org/keycloak/testsuite/arquillian/decider/AuthServerExcludeExecutionDecider.java +++ b/testsuite/integration-arquillian/tests/base/src/main/java/org/keycloak/testsuite/arquillian/decider/AuthServerExcludeExecutionDecider.java @@ -51,6 +51,10 @@ public class AuthServerExcludeExecutionDecider implements TestExecutionDecider { if (AuthServerTestEnricher.isAuthServerRemote() && excluded.contains(AuthServer.REMOTE)) { return ExecutionDecision.dontExecute("Excluded by @AuthServerContainerExclude."); } + + if (AuthServerTestEnricher.isAuthServerQuarkus() && excluded.contains(AuthServer.QUARKUS)) { + return ExecutionDecision.dontExecute("Excluded by @AuthServerContainerExclude."); + } } else { //class if (testContext.getTestClass().isAnnotationPresent(AuthServerContainerExclude.class)) { List excluded = Arrays.asList(((AuthServerContainerExclude) testContext.getTestClass().getAnnotation(AuthServerContainerExclude.class)).value()); @@ -58,6 +62,10 @@ public class AuthServerExcludeExecutionDecider implements TestExecutionDecider { if (AuthServerTestEnricher.isAuthServerRemote() && excluded.contains(AuthServer.REMOTE)) { return ExecutionDecision.dontExecute("Excluded by @AuthServerContainerExclude."); } + + if (AuthServerTestEnricher.isAuthServerQuarkus() && excluded.contains(AuthServer.QUARKUS)) { + return ExecutionDecision.dontExecute("Excluded by @AuthServerContainerExclude."); + } } } diff --git a/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/openshift/OpenshiftClientStorageTest.java b/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/openshift/OpenshiftClientStorageTest.java index 08b7cab743..46c1b5fe36 100644 --- a/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/openshift/OpenshiftClientStorageTest.java +++ b/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/openshift/OpenshiftClientStorageTest.java @@ -66,7 +66,7 @@ import static org.keycloak.testsuite.admin.ApiUtil.findUserByUsername; * * @author Pedro Igor */ -@AuthServerContainerExclude(AuthServer.REMOTE) +@AuthServerContainerExclude({AuthServer.REMOTE, AuthServer.QUARKUS}) @EnableFeature(value = OPENSHIFT_INTEGRATION, skipRestart = true) public final class OpenshiftClientStorageTest extends AbstractTestRealmKeycloakTest {