From 00feef4dbe9c465cc9c4ddd0fd999959038f3219 Mon Sep 17 00:00:00 2001 From: Dominik Date: Thu, 7 Oct 2021 11:13:31 +0200 Subject: [PATCH] KEYCLOAK-19496 Unignore ArtifactBindingCustomResolverTest and make SetDefaultProvider Annotation usable for Quarkus-based distribution --- .../src/main/content/conf/keycloak.properties | 2 +- .../arquillian/AuthServerTestEnricher.java | 22 +++++----- ...cloakQuarkusServerDeployableContainer.java | 3 +- .../util/SpiProvidersSwitchingUtils.java | 40 ++++++++++++++++--- .../ArtifactBindingCustomResolverTest.java | 5 ++- 5 files changed, 53 insertions(+), 19 deletions(-) diff --git a/testsuite/integration-arquillian/servers/auth-server/quarkus/src/main/content/conf/keycloak.properties b/testsuite/integration-arquillian/servers/auth-server/quarkus/src/main/content/conf/keycloak.properties index d60d4e34dc..5af594ea21 100644 --- a/testsuite/integration-arquillian/servers/auth-server/quarkus/src/main/content/conf/keycloak.properties +++ b/testsuite/integration-arquillian/servers/auth-server/quarkus/src/main/content/conf/keycloak.properties @@ -40,4 +40,4 @@ spi.connections-http-client.default.reuse-connections=false spi.events-store.jpa.max-detail-length=2000 # set known protocol ports for basicsamltest -spi.login-protocol.saml.known-protocols=http=${auth.server.http.port:},https=${auth.server.https.port:} +spi.login-protocol.saml.known-protocols=http=8180,https=8543 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 661a90e771..905f411b4f 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 @@ -556,13 +556,9 @@ public class AuthServerTestEnricher { TestContext testContext = new TestContext(suiteContext, event.getTestClass().getJavaClass()); testContextProducer.set(testContext); - if (!isAuthServerRemote() && !isAuthServerQuarkus()) { + if (!isAuthServerRemote()) { boolean wasUpdated = false; - if (event.getTestClass().isAnnotationPresent(EnableVault.class)) { - VaultUtils.enableVault(suiteContext, event.getTestClass().getAnnotation(EnableVault.class).providerId()); - wasUpdated = true; - } if (event.getTestClass().isAnnotationPresent(SetDefaultProvider.class)) { SetDefaultProvider defaultProvider = event.getTestClass().getAnnotation(SetDefaultProvider.class); @@ -572,6 +568,11 @@ public class AuthServerTestEnricher { } } + if (!isAuthServerQuarkus() && event.getTestClass().isAnnotationPresent(EnableVault.class)) { + VaultUtils.enableVault(suiteContext, event.getTestClass().getAnnotation(EnableVault.class).providerId()); + wasUpdated = true; + } + if (wasUpdated) { restartAuthServer(); testContext.reconnectAdminClient(); @@ -883,19 +884,20 @@ public class AuthServerTestEnricher { removeTestRealms(testContext, adminClient); - if (!isAuthServerRemote() && !isAuthServerQuarkus()) { + if (!isAuthServerRemote()) { boolean wasUpdated = false; - if (event.getTestClass().isAnnotationPresent(EnableVault.class)) { - VaultUtils.disableVault(suiteContext, event.getTestClass().getAnnotation(EnableVault.class).providerId()); - wasUpdated = true; - } if (event.getTestClass().isAnnotationPresent(SetDefaultProvider.class)) { SpiProvidersSwitchingUtils.removeProvider(suiteContext, event.getTestClass().getAnnotation(SetDefaultProvider.class)); wasUpdated = true; } + if (event.getTestClass().isAnnotationPresent(EnableVault.class) && !isAuthServerQuarkus()) { + VaultUtils.disableVault(suiteContext, event.getTestClass().getAnnotation(EnableVault.class).providerId()); + wasUpdated = true; + } + if (wasUpdated) { restartAuthServer(); testContext.reconnectAdminClient(); 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 76b6236e16..aa71147567 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 @@ -176,10 +176,11 @@ public class KeycloakQuarkusServerDeployableContainer implements DeployableConta if (configuration.getDebugPort() > 0) { commands.add("--debug"); commands.add(Integer.toString(configuration.getDebugPort())); - } else if (Boolean.valueOf(System.getProperty("auth.server.debug", "false"))) { + } else if (Boolean.parseBoolean(System.getProperty("auth.server.debug", "false"))) { commands.add("--debug"); commands.add(System.getProperty("auth.server.debug.port", "5005")); } + commands.add("--http-port=" + configuration.getBindHttpPort()); commands.add("--https-port=" + configuration.getBindHttpsPort()); diff --git a/testsuite/integration-arquillian/tests/base/src/main/java/org/keycloak/testsuite/util/SpiProvidersSwitchingUtils.java b/testsuite/integration-arquillian/tests/base/src/main/java/org/keycloak/testsuite/util/SpiProvidersSwitchingUtils.java index 59abd20fc9..70f7c0aafb 100644 --- a/testsuite/integration-arquillian/tests/base/src/main/java/org/keycloak/testsuite/util/SpiProvidersSwitchingUtils.java +++ b/testsuite/integration-arquillian/tests/base/src/main/java/org/keycloak/testsuite/util/SpiProvidersSwitchingUtils.java @@ -11,6 +11,12 @@ import org.wildfly.extras.creaper.core.online.OnlineManagementClient; import java.io.IOException; public class SpiProvidersSwitchingUtils { + + private static final String SUBSYSTEM_KEYCLOAK_SERVER_SPI = "/subsystem=keycloak-server/spi="; + private static final String KEYCLOAKX_ARG_SPI_PREFIX = "--spi-"; + + private SpiProvidersSwitchingUtils() {} + public static void addProviderDefaultValue(SuiteContext suiteContext, SetDefaultProvider annotation) throws IOException, CliException { ContainerInfo authServerInfo = suiteContext.getAuthServerInfo(); @@ -18,14 +24,14 @@ public class SpiProvidersSwitchingUtils { System.setProperty("keycloak." + annotation.spi() + ".provider", annotation.providerId()); } else if (authServerInfo.isQuarkus()) { KeycloakQuarkusServerDeployableContainer container = (KeycloakQuarkusServerDeployableContainer) authServerInfo.getArquillianContainer().getDeployableContainer(); - container.forceReAugmentation("-Dkeycloak." + annotation.spi() + ".provider=" + annotation.providerId()); + container.forceReAugmentation(KEYCLOAKX_ARG_SPI_PREFIX + toDashCase(annotation.spi()) +"-provider="+annotation.providerId()); } else { OnlineManagementClient client = AuthServerTestEnricher.getManagementClient(); if (annotation.onlyUpdateDefault()) { - client.execute("/subsystem=keycloak-server/spi=" + annotation.spi() + ":write-attribute(name=default-provider, value=" + annotation.providerId() + ")"); + client.execute(SUBSYSTEM_KEYCLOAK_SERVER_SPI + annotation.spi() + ":write-attribute(name=default-provider, value=" + annotation.providerId() + ")"); } else { - client.execute("/subsystem=keycloak-server/spi=" + annotation.spi() + "/:add(default-provider=\"" + annotation.providerId() + "\")"); + client.execute(SUBSYSTEM_KEYCLOAK_SERVER_SPI + annotation.spi() + "/:add(default-provider=\"" + annotation.providerId() + "\")"); } client.close(); @@ -43,11 +49,35 @@ public class SpiProvidersSwitchingUtils { } else { OnlineManagementClient client = AuthServerTestEnricher.getManagementClient(); if (annotation.onlyUpdateDefault()) { - client.execute("/subsystem=keycloak-server/spi=" + annotation.spi() + "/:undefine-attribute(name=default-provider)"); + client.execute(SUBSYSTEM_KEYCLOAK_SERVER_SPI + annotation.spi() + "/:undefine-attribute(name=default-provider)"); } else { - client.execute("/subsystem=keycloak-server/spi=" + annotation.spi() + "/:remove"); + client.execute(SUBSYSTEM_KEYCLOAK_SERVER_SPI + annotation.spi() + "/:remove"); } client.close(); } } + + /** + * Parses the non-standard SPI-Name format to the standardized format + * we use in the Keycloak.X Configuration + * @param s possibly non-standard spi name + * @return standardized spi name in dash-case. e.g. userProfile -> user-profile + */ + private static String toDashCase(String s) { + StringBuilder sb = new StringBuilder(s.length()); + boolean l = false; + + for (int i = 0; i < s.length(); i++) { + char c = s.charAt(i); + if (l && Character.isUpperCase(c)) { + sb.append('-'); + c = Character.toLowerCase(c); + l = false; + } else { + l = Character.isLowerCase(c); + } + sb.append(c); + } + return sb.toString(); + } } diff --git a/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/saml/ArtifactBindingCustomResolverTest.java b/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/saml/ArtifactBindingCustomResolverTest.java index 03a8a30f9e..b902f35df4 100644 --- a/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/saml/ArtifactBindingCustomResolverTest.java +++ b/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/saml/ArtifactBindingCustomResolverTest.java @@ -18,10 +18,11 @@ import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.not; import static org.hamcrest.Matchers.notNullValue; +import static org.keycloak.testsuite.arquillian.annotation.AuthServerContainerExclude.AuthServer.REMOTE; import static org.keycloak.testsuite.util.SamlClient.Binding.POST; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; -@AuthServerContainerExclude({AuthServerContainerExclude.AuthServer.QUARKUS, AuthServerContainerExclude.AuthServer.REMOTE}) // Can't be done on quarkus or remote because currently quarkus or remote doesn't support the SetDefaultProvider annotation +@AuthServerContainerExclude(value = {REMOTE}, details = "currently remote doesn't support the SetDefaultProvider annotation") @SetDefaultProvider(spi = "saml-artifact-resolver", providerId = "0005") public class ArtifactBindingCustomResolverTest extends ArtifactBindingTest {