From 37acb2fd09c10219848c421d12581282748089bb Mon Sep 17 00:00:00 2001 From: Steven Hawkins Date: Wed, 31 Jan 2024 13:23:07 -0500 Subject: [PATCH] task: upgrading to quarkus 3.7.0.CR1 (#26203) there are several downgrades from the quarkus versions, and some additional logic needed to handle changes with re-creating the configuration Signed-off-by: Steve Hawkins --- .../keycloak/crypto/def/BCOCSPProvider.java | 7 +- .../def/BCUserIdentityExtractorProvider.java | 8 +- operator/pom.xml | 12 -- .../java/org/keycloak/operator/Config.java | 14 +++ .../KeycloakDeploymentDependentResource.java | 19 +-- .../KeycloakRealmImportController.java | 1 - .../integration/BaseOperatorTest.java | 12 +- pom.xml | 30 ++--- .../quarkus/deployment/KeycloakProcessor.java | 14 ++- .../configuration/ConfigArgsConfigSource.java | 2 +- .../configuration/test/ConfigurationTest.java | 109 +++++++++--------- .../it/cli/ShowConfigCommandTest.java | 3 + .../keycloak/it/junit5/extension/CLITest.java | 3 + .../it/junit5/extension/CLITestExtension.java | 8 +- .../extension/ConfigurationTestResource.java | 57 +++++++++ .../services/testsuite-providers/pom.xml | 5 + 16 files changed, 182 insertions(+), 122 deletions(-) create mode 100644 quarkus/tests/junit5/src/main/java/org/keycloak/it/junit5/extension/ConfigurationTestResource.java diff --git a/crypto/default/src/main/java/org/keycloak/crypto/def/BCOCSPProvider.java b/crypto/default/src/main/java/org/keycloak/crypto/def/BCOCSPProvider.java index 114d220546..9ce2d0affb 100644 --- a/crypto/default/src/main/java/org/keycloak/crypto/def/BCOCSPProvider.java +++ b/crypto/default/src/main/java/org/keycloak/crypto/def/BCOCSPProvider.java @@ -18,6 +18,7 @@ package org.keycloak.crypto.def; +import org.bouncycastle.asn1.ASN1IA5String; import org.bouncycastle.asn1.ASN1InputStream; import org.bouncycastle.asn1.ASN1Sequence; import org.bouncycastle.asn1.DERIA5String; @@ -338,8 +339,8 @@ public class BCOCSPProvider extends OCSPProvider { // https://www.ietf.org/rfc/rfc2560.txt, if nextUpdate is not set, // the responder is indicating that newer update is avilable all the time long current = date == null ? System.currentTimeMillis() : date.getTime(); - Date stop = new Date(current + (long) TIME_SKEW); - Date start = new Date(current - (long) TIME_SKEW); + Date stop = new Date(current + TIME_SKEW); + Date start = new Date(current - TIME_SKEW); Iterator iter = Arrays.asList(basicOcspResponse.getResponses()).iterator(); SingleResp singleRes = null; @@ -436,7 +437,7 @@ public class BCOCSPProvider extends OCSPProvider { if (ad.getAccessMethod().equals(AccessDescription.id_ad_ocsp)) { // See https://www.ietf.org/rfc/rfc2560.txt, 3.1 Certificate Content if (ad.getAccessLocation().getTagNo() == GeneralName.uniformResourceIdentifier) { - DERIA5String value = DERIA5String.getInstance(ad.getAccessLocation().getName()); + ASN1IA5String value = DERIA5String.getInstance(ad.getAccessLocation().getName()); responderURIs.add(value.getString()); } } diff --git a/crypto/default/src/main/java/org/keycloak/crypto/def/BCUserIdentityExtractorProvider.java b/crypto/default/src/main/java/org/keycloak/crypto/def/BCUserIdentityExtractorProvider.java index 13581eae64..13302ef4d9 100644 --- a/crypto/default/src/main/java/org/keycloak/crypto/def/BCUserIdentityExtractorProvider.java +++ b/crypto/default/src/main/java/org/keycloak/crypto/def/BCUserIdentityExtractorProvider.java @@ -23,6 +23,8 @@ import org.bouncycastle.asn1.ASN1InputStream; import org.bouncycastle.asn1.ASN1ObjectIdentifier; import org.bouncycastle.asn1.ASN1Sequence; import org.bouncycastle.asn1.ASN1TaggedObject; +import org.bouncycastle.asn1.ASN1UTF8String; +import org.bouncycastle.asn1.BERTags; import org.bouncycastle.asn1.DERUTF8String; import org.bouncycastle.asn1.x500.AttributeTypeAndValue; import org.bouncycastle.asn1.x500.RDN; @@ -162,7 +164,7 @@ public class BCUserIdentityExtractorProvider extends UserIdentityExtractorProvi tempOid = oid.getId(); ASN1Encodable principalNameEncoded = asn1Sequence.getObjectAt(1); - DERUTF8String principalName = DERUTF8String.getInstance(unwrap(principalNameEncoded)); + ASN1UTF8String principalName = DERUTF8String.getInstance(unwrap(principalNameEncoded)); tempOtherName = principalName.getString(); @@ -195,8 +197,8 @@ public class BCUserIdentityExtractorProvider extends UserIdentityExtractorProvi private ASN1Encodable unwrap(ASN1Encodable encodable) { while (encodable instanceof ASN1TaggedObject) { - ASN1TaggedObject taggedObj = (ASN1TaggedObject) encodable; - encodable = taggedObj.getObject(); + ASN1TaggedObject taggedObj = ASN1TaggedObject.getInstance(encodable, BERTags.CONTEXT_SPECIFIC); + encodable = taggedObj.getBaseObject().toASN1Primitive(); } return encodable; diff --git a/operator/pom.xml b/operator/pom.xml index af3bde3b67..3acf3dad25 100644 --- a/operator/pom.xml +++ b/operator/pom.xml @@ -67,18 +67,6 @@ quarkus-operator-sdk-bundle-generator true - - io.quarkus - quarkus-resteasy-jackson - - - io.quarkus - quarkus-rest-client - - - io.quarkus - quarkus-rest-client-jackson - io.quarkus quarkus-kubernetes-client diff --git a/operator/src/main/java/org/keycloak/operator/Config.java b/operator/src/main/java/org/keycloak/operator/Config.java index 0eb1140046..c673fba235 100644 --- a/operator/src/main/java/org/keycloak/operator/Config.java +++ b/operator/src/main/java/org/keycloak/operator/Config.java @@ -18,6 +18,7 @@ package org.keycloak.operator; import io.smallrye.config.ConfigMapping; +import io.smallrye.config.WithDefault; import java.util.Map; @@ -36,4 +37,17 @@ public interface Config { Map podLabels(); } + + // workarounds for OLM env values + // to be removed after https://github.com/keycloak/keycloak/issues/12352 + + @WithDefault("keycloak-operator") + String name(); + + interface Condition { + @WithDefault("keycloak-operator.v999-SNAPSHOT") + String name(); + } + + Condition condition(); } diff --git a/operator/src/main/java/org/keycloak/operator/controllers/KeycloakDeploymentDependentResource.java b/operator/src/main/java/org/keycloak/operator/controllers/KeycloakDeploymentDependentResource.java index ea974ddd13..30c5baf7cc 100644 --- a/operator/src/main/java/org/keycloak/operator/controllers/KeycloakDeploymentDependentResource.java +++ b/operator/src/main/java/org/keycloak/operator/controllers/KeycloakDeploymentDependentResource.java @@ -23,9 +23,7 @@ import io.fabric8.kubernetes.api.model.EnvVarBuilder; import io.fabric8.kubernetes.api.model.EnvVarSource; import io.fabric8.kubernetes.api.model.EnvVarSourceBuilder; import io.fabric8.kubernetes.api.model.PodSpec; -import io.fabric8.kubernetes.api.model.PodSpecFluent.ContainersNested; import io.fabric8.kubernetes.api.model.PodTemplateSpec; -import io.fabric8.kubernetes.api.model.PodTemplateSpecFluent.SpecNested; import io.fabric8.kubernetes.api.model.Secret; import io.fabric8.kubernetes.api.model.SecretKeySelector; import io.fabric8.kubernetes.api.model.VolumeBuilder; @@ -33,7 +31,7 @@ import io.fabric8.kubernetes.api.model.VolumeMountBuilder; import io.fabric8.kubernetes.api.model.apps.StatefulSet; import io.fabric8.kubernetes.api.model.apps.StatefulSetBuilder; import io.fabric8.kubernetes.api.model.apps.StatefulSetSpec; -import io.fabric8.kubernetes.api.model.apps.StatefulSetSpecFluent.TemplateNested; +import io.fabric8.kubernetes.client.KubernetesClient; import io.javaoperatorsdk.operator.api.reconciler.Context; import io.javaoperatorsdk.operator.processing.dependent.kubernetes.CRUDKubernetesDependentResource; import io.javaoperatorsdk.operator.processing.dependent.kubernetes.KubernetesDependent; @@ -103,10 +101,10 @@ public class KeycloakDeploymentDependentResource extends CRUDKubernetesDependent addTruststores(primary, baseDeployment, kcContainer, allSecrets); addEnvVars(baseDeployment, primary, allSecrets); Optional.ofNullable(primary.getSpec().getCacheSpec()) - .ifPresent(c -> configureCache(primary, baseDeployment, kcContainer, c)); + .ifPresent(c -> configureCache(primary, baseDeployment, kcContainer, c, context.getClient())); if (!allSecrets.isEmpty()) { - watchedResources.annotateDeployment(new ArrayList<>(allSecrets), Secret.class, baseDeployment, this.client); + watchedResources.annotateDeployment(new ArrayList<>(allSecrets), Secret.class, baseDeployment, context.getClient()); } StatefulSet existingDeployment = context.getSecondaryResource(StatefulSet.class).orElse(null); @@ -128,7 +126,7 @@ public class KeycloakDeploymentDependentResource extends CRUDKubernetesDependent return baseDeployment; } - private void configureCache(Keycloak keycloakCR, StatefulSet deployment, Container kcContainer, CacheSpec spec) { + private void configureCache(Keycloak keycloakCR, StatefulSet deployment, Container kcContainer, CacheSpec spec, KubernetesClient client) { Optional.ofNullable(spec.getConfigMapFile()).ifPresent(configFile -> { if (configFile.getName() == null || configFile.getKey() == null) { throw new IllegalStateException("Cache file ConfigMap requires both a name and a key"); @@ -151,7 +149,7 @@ public class KeycloakDeploymentDependentResource extends CRUDKubernetesDependent kcContainer.getVolumeMounts().add(0, volumeMount); // currently the only configmap we're watching - watchedResources.annotateDeployment(List.of(configFile.getName()), ConfigMap.class, deployment, this.client); + watchedResources.annotateDeployment(List.of(configFile.getName()), ConfigMap.class, deployment, client); }); } @@ -249,12 +247,7 @@ public class KeycloakDeploymentDependentResource extends CRUDKubernetesDependent } // there isn't currently an editOrNewFirstContainer, so we need to do this manually - ContainersNested>>> containerBuilder = null; - if (specBuilder.buildContainers().isEmpty()) { - containerBuilder = specBuilder.addNewContainer(); - } else { - containerBuilder = specBuilder.editFirstContainer(); - } + var containerBuilder = specBuilder.buildContainers().isEmpty() ? specBuilder.addNewContainer() : specBuilder.editFirstContainer(); containerBuilder.withName("keycloak"); diff --git a/operator/src/main/java/org/keycloak/operator/controllers/KeycloakRealmImportController.java b/operator/src/main/java/org/keycloak/operator/controllers/KeycloakRealmImportController.java index 60fe705eb2..addef4a35f 100644 --- a/operator/src/main/java/org/keycloak/operator/controllers/KeycloakRealmImportController.java +++ b/operator/src/main/java/org/keycloak/operator/controllers/KeycloakRealmImportController.java @@ -57,7 +57,6 @@ public class KeycloakRealmImportController implements Reconciler prepareEventSources(EventSourceContext context) { this.jobDependentResource = new KeycloakRealmImportJobDependentResource(); - this.jobDependentResource.setKubernetesClient(context.getClient()); return EventSourceInitializer.nameEventSourcesFromDependentResource(context, jobDependentResource); } diff --git a/operator/src/test/java/org/keycloak/operator/testsuite/integration/BaseOperatorTest.java b/operator/src/test/java/org/keycloak/operator/testsuite/integration/BaseOperatorTest.java index a3a298080f..33b3f774aa 100644 --- a/operator/src/test/java/org/keycloak/operator/testsuite/integration/BaseOperatorTest.java +++ b/operator/src/test/java/org/keycloak/operator/testsuite/integration/BaseOperatorTest.java @@ -20,8 +20,6 @@ package org.keycloak.operator.testsuite.integration; import io.fabric8.kubernetes.api.model.HasMetadata; import io.fabric8.kubernetes.api.model.NamespaceBuilder; import io.fabric8.kubernetes.api.model.Pod; -import io.fabric8.kubernetes.api.model.PodSpecFluent.ContainersNested; -import io.fabric8.kubernetes.api.model.PodTemplateSpecFluent.SpecNested; import io.fabric8.kubernetes.api.model.Secret; import io.fabric8.kubernetes.api.model.apps.Deployment; import io.fabric8.kubernetes.api.model.apps.StatefulSet; @@ -59,9 +57,7 @@ import org.keycloak.operator.Constants; import org.keycloak.operator.controllers.KeycloakDeploymentDependentResource; import org.keycloak.operator.crds.v2alpha1.deployment.Keycloak; import org.keycloak.operator.crds.v2alpha1.deployment.KeycloakSpecBuilder; -import org.keycloak.operator.crds.v2alpha1.deployment.KeycloakSpecFluent.UnsupportedNested; import org.keycloak.operator.crds.v2alpha1.deployment.KeycloakStatus; -import org.keycloak.operator.crds.v2alpha1.deployment.spec.UnsupportedSpecFluent.PodTemplateNested; import org.keycloak.operator.crds.v2alpha1.realmimport.KeycloakRealmImport; import org.keycloak.operator.testsuite.utils.K8sUtils; import org.opentest4j.TestAbortedException; @@ -405,12 +401,8 @@ public class BaseOperatorTest implements QuarkusTestAfterEachCallback { public static Keycloak disableProbes(Keycloak keycloak) { KeycloakSpecBuilder specBuilder = new KeycloakSpecBuilder(keycloak.getSpec()); var podTemplateSpecBuilder = specBuilder.editOrNewUnsupported().editOrNewPodTemplate().editOrNewSpec(); - ContainersNested>>> containerBuilder = null; - if (podTemplateSpecBuilder.hasContainers()) { - containerBuilder = podTemplateSpecBuilder.editContainer(0); - } else { - containerBuilder = podTemplateSpecBuilder.addNewContainer(); - } + var containerBuilder = podTemplateSpecBuilder.hasContainers() ? podTemplateSpecBuilder.editContainer(0) + : podTemplateSpecBuilder.addNewContainer(); keycloak.setSpec(containerBuilder.withNewLivenessProbe().withNewExec().addToCommand("true").endExec() .endLivenessProbe().withNewReadinessProbe().withNewExec().addToCommand("true").endExec() .endReadinessProbe().withNewStartupProbe().withNewExec().addToCommand("true").endExec() diff --git a/pom.xml b/pom.xml index 6fe45caa81..dd55484fad 100644 --- a/pom.xml +++ b/pom.xml @@ -45,8 +45,8 @@ jboss-snapshots-repository https://s01.oss.sonatype.org/content/repositories/snapshots/ - 3.2.9.Final - 3.2.9.Final + 3.7.0.CR1 + 3.7.0.CR1 ${timestamp} @@ -86,6 +86,8 @@ 1.0.7 + + 1.0.2.3 3.3.10 3.3.10 @@ -106,8 +108,6 @@ 1.0.2.Final 2.0.2.Final 2.0.0.Final - 2.1.19.Final - 2.0.11.Final 2.0.1.Final 2.0.0.Final 1.2.17 @@ -427,6 +427,13 @@ bcpkix-fips ${bouncycastle.pkixfips.version} + + + org.bouncycastle + bc-fips + ${bouncycastle.bcfips.version} + + com.github.ua-parser uap-java @@ -557,11 +564,6 @@ log4j ${log4j.version} - - org.jboss.logmanager - jboss-logmanager - ${jboss.logmanager} - com.googlecode.owasp-java-html-sanitizer owasp-java-html-sanitizer @@ -894,16 +896,6 @@ undertow-server ${elytron.undertow-server.version} - - org.jboss.marshalling - jboss-marshalling - ${jboss.marshalling.version} - - - org.jboss.marshalling - jboss-marshalling-river - ${jboss.marshalling.version} - org.liquibase liquibase-core 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 6a0b98d2ee..1c468711d1 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 @@ -29,7 +29,6 @@ import io.quarkus.deployment.annotations.Consume; import io.quarkus.deployment.annotations.ExecutionTime; import io.quarkus.deployment.annotations.Produce; import io.quarkus.deployment.annotations.Record; -import io.quarkus.deployment.builditem.BootstrapConfigSetupCompleteBuildItem; import io.quarkus.deployment.builditem.CombinedIndexBuildItem; import io.quarkus.deployment.builditem.FeatureBuildItem; import io.quarkus.deployment.builditem.GeneratedResourceBuildItem; @@ -44,6 +43,7 @@ import io.quarkus.resteasy.reactive.server.spi.MethodScannerBuildItem; import io.quarkus.runtime.configuration.ConfigurationException; import io.quarkus.runtime.configuration.ProfileManager; import io.quarkus.vertx.http.deployment.RouteBuildItem; +import io.quarkus.resteasy.reactive.spi.IgnoreStackMixingBuildItem; import io.smallrye.config.ConfigValue; import org.hibernate.cfg.AvailableSettings; import org.hibernate.jpa.boot.internal.ParsedPersistenceXmlDescriptor; @@ -207,6 +207,11 @@ class KeycloakProcessor { return new DeployedScriptSAMLProtocolMapper(metadata); } + @BuildStep + IgnoreStackMixingBuildItem getIgnoreStackMixing() { + return new IgnoreStackMixingBuildItem(); + } + @BuildStep FeatureBuildItem getFeature() { return new FeatureBuildItem("keycloak"); @@ -286,7 +291,7 @@ class KeycloakProcessor { * *

The {@code hibernate-orm} extension expects that the dialect is statically * set to the persistence unit if there is any from the classpath and we use this method to obtain the dialect from the configuration - * file so that we can build the application with whatever dialect we want. In addition to the dialect, we should also be + * file so that we can build the application with whatever dialect we want. In addition to the dialect, we should also be * allowed to set any additional defaults that we think that makes sense. * * @param config @@ -459,9 +464,9 @@ class KeycloakProcessor { .map(ParsedPersistenceXmlDescriptor::getName) .filter(Predicate.not("keycloak-default"::equals)).forEach((String unitName) -> { NamedJpaConnectionProviderFactory factory = new NamedJpaConnectionProviderFactory(); - + factory.setUnitName(unitName); - + factories.get(spi).get(JpaConnectionProvider.class).put(unitName, NamedJpaConnectionProviderFactory.class); preConfiguredProviders.put(unitName, factory); }); @@ -662,7 +667,6 @@ class KeycloakProcessor { })); } - @Consume(BootstrapConfigSetupCompleteBuildItem.class) @Consume(ProfileBuildItem.class) @Produce(CryptoProviderInitBuildItem.class) @BuildStep diff --git a/quarkus/runtime/src/main/java/org/keycloak/quarkus/runtime/configuration/ConfigArgsConfigSource.java b/quarkus/runtime/src/main/java/org/keycloak/quarkus/runtime/configuration/ConfigArgsConfigSource.java index 87042b5f57..b37ff0f4a4 100644 --- a/quarkus/runtime/src/main/java/org/keycloak/quarkus/runtime/configuration/ConfigArgsConfigSource.java +++ b/quarkus/runtime/src/main/java/org/keycloak/quarkus/runtime/configuration/ConfigArgsConfigSource.java @@ -58,7 +58,7 @@ public class ConfigArgsConfigSource extends PropertiesConfigSource { super(parseArguments(), NAME, 600); } - public static void setCliArgs(String[] args) { + public static void setCliArgs(String... args) { System.setProperty(CLI_ARGS, String.join(ARG_SEPARATOR, args)); } diff --git a/quarkus/runtime/src/test/java/org/keycloak/quarkus/runtime/configuration/test/ConfigurationTest.java b/quarkus/runtime/src/test/java/org/keycloak/quarkus/runtime/configuration/test/ConfigurationTest.java index de45b2c9d3..236b6fe0d7 100644 --- a/quarkus/runtime/src/test/java/org/keycloak/quarkus/runtime/configuration/test/ConfigurationTest.java +++ b/quarkus/runtime/src/test/java/org/keycloak/quarkus/runtime/configuration/test/ConfigurationTest.java @@ -43,6 +43,7 @@ import org.junit.After; import org.junit.Assert; import org.junit.Test; import org.keycloak.Config; +import org.keycloak.quarkus.runtime.configuration.ConfigArgsConfigSource; import org.keycloak.quarkus.runtime.configuration.KeycloakConfigSourceProvider; import org.keycloak.quarkus.runtime.configuration.MicroProfileConfigProvider; @@ -57,7 +58,6 @@ public class ConfigurationTest { private static final Properties SYSTEM_PROPERTIES = (Properties) System.getProperties().clone(); private static final Map ENVIRONMENT_VARIABLES = new HashMap<>(System.getenv()); - private static final String ARG_SEPARATOR = ";;"; @SuppressWarnings("unchecked") public static void putEnvVar(String name, String value) { @@ -158,7 +158,7 @@ public class ConfigurationTest { @Test public void testCLIPriorityOverSysProp() { System.setProperty("kc.spi.hostname.default.frontend-url", "http://propvar.unittest"); - System.setProperty(CLI_ARGS, "--spi-hostname-default-frontend-url=http://cli.unittest"); + ConfigArgsConfigSource.setCliArgs("--spi-hostname-default-frontend-url=http://cli.unittest"); assertEquals("http://cli.unittest", initConfig("hostname", "default").get("frontendUrl")); } @@ -187,53 +187,53 @@ public class ConfigurationTest { @Test public void testCommandLineArguments() { - System.setProperty(CLI_ARGS, "--spi-hostname-default-frontend-url=http://fromargs.unittest" + ARG_SEPARATOR + "--no-ssl"); + ConfigArgsConfigSource.setCliArgs("--spi-hostname-default-frontend-url=http://fromargs.unittest", "--no-ssl"); assertEquals("http://fromargs.unittest", initConfig("hostname", "default").get("frontendUrl")); } @Test public void testSpiConfigurationUsingCommandLineArguments() { - System.setProperty(CLI_ARGS, "--spi-hostname-default-frontend-url=http://spifull.unittest"); + ConfigArgsConfigSource.setCliArgs("--spi-hostname-default-frontend-url=http://spifull.unittest"); assertEquals("http://spifull.unittest", initConfig("hostname", "default").get("frontendUrl")); // test multi-word SPI names using camel cases - System.setProperty(CLI_ARGS, "--spi-action-token-handler-verify-email-some-property=test"); + ConfigArgsConfigSource.setCliArgs("--spi-action-token-handler-verify-email-some-property=test"); assertEquals("test", initConfig("action-token-handler", "verify-email").get("some-property")); - System.setProperty(CLI_ARGS, "--spi-action-token-handler-verify-email-some-property=test"); + ConfigArgsConfigSource.setCliArgs("--spi-action-token-handler-verify-email-some-property=test"); assertEquals("test", initConfig("actionTokenHandler", "verifyEmail").get("someProperty")); // test multi-word SPI names using slashes - System.setProperty(CLI_ARGS, "--spi-client-registration-openid-connect-static-jwk-url=http://c.jwk.url"); + ConfigArgsConfigSource.setCliArgs("--spi-client-registration-openid-connect-static-jwk-url=http://c.jwk.url"); assertEquals("http://c.jwk.url", initConfig("client-registration", "openid-connect").get("static-jwk-url")); } @Test public void testResolveTransformedValue() { - System.setProperty(CLI_ARGS, ""); + ConfigArgsConfigSource.setCliArgs(""); assertEquals("none", createConfig().getConfigValue("kc.proxy").getValue()); - System.setProperty(CLI_ARGS, "--proxy=none"); + ConfigArgsConfigSource.setCliArgs("--proxy=none"); assertEquals("none", createConfig().getConfigValue("kc.proxy").getValue()); - System.setProperty(CLI_ARGS, ""); + ConfigArgsConfigSource.setCliArgs(""); assertEquals("none", createConfig().getConfigValue("kc.proxy").getValue()); - System.setProperty(CLI_ARGS, "--proxy=none" + ARG_SEPARATOR + "--http-enabled=false"); + ConfigArgsConfigSource.setCliArgs("--proxy=none", "--http-enabled=false"); assertEquals("false", createConfig().getConfigValue("kc.http-enabled").getValue()); - System.setProperty(CLI_ARGS, "--proxy=none" + ARG_SEPARATOR + "--http-enabled=true"); + ConfigArgsConfigSource.setCliArgs("--proxy=none", "--http-enabled=true"); assertEquals("true", createConfig().getConfigValue("kc.http-enabled").getValue()); } @Test public void testPropertyNamesFromConfig() { - System.setProperty(CLI_ARGS, "--spi-client-registration-openid-connect-static-jwk-url=http://c.jwk.url"); + ConfigArgsConfigSource.setCliArgs("--spi-client-registration-openid-connect-static-jwk-url=http://c.jwk.url"); Config.Scope config = initConfig("client-registration", "openid-connect"); assertEquals(1, config.getPropertyNames().size()); assertEquals("http://c.jwk.url", config.get("static-jwk-url")); - System.setProperty(CLI_ARGS, "--vault-dir=secrets"); + ConfigArgsConfigSource.setCliArgs("--vault-dir=secrets"); config = initConfig("vault", FilesPlainTextVaultProviderFactory.ID); assertEquals(1, config.getPropertyNames().size()); assertEquals("secrets", config.get("dir")); - System.setProperty(CLI_ARGS, "--vault-type=JKS"); + ConfigArgsConfigSource.setCliArgs("--vault-type=JKS"); config = initConfig("vault", FilesKeystoreVaultProviderFactory.ID); assertEquals(1, config.getPropertyNames().size()); assertEquals("JKS", config.get("type")); @@ -255,7 +255,7 @@ public class ConfigurationTest { @Test public void testPropertyMapping() { - System.setProperty(CLI_ARGS, "--db=mariadb" + ARG_SEPARATOR + "--db-url=jdbc:mariadb://localhost/keycloak"); + ConfigArgsConfigSource.setCliArgs("--db=mariadb", "--db-url=jdbc:mariadb://localhost/keycloak"); SmallRyeConfig config = createConfig(); assertEquals(MariaDBDialect.class.getName(), config.getConfigValue("kc.db-dialect").getValue()); assertEquals("jdbc:mariadb://localhost/keycloak", config.getConfigValue("quarkus.datasource.jdbc.url").getValue()); @@ -263,7 +263,7 @@ public class ConfigurationTest { @Test public void testDatabaseUrlProperties() { - System.setProperty(CLI_ARGS, "--db=mariadb" + ARG_SEPARATOR + "--db-url=jdbc:mariadb:aurora://foo/bar?a=1&b=2"); + ConfigArgsConfigSource.setCliArgs("--db=mariadb", "--db-url=jdbc:mariadb:aurora://foo/bar?a=1&b=2"); SmallRyeConfig config = createConfig(); assertEquals(MariaDBDialect.class.getName(), config.getConfigValue("kc.db-dialect").getValue()); assertEquals("jdbc:mariadb:aurora://foo/bar?a=1&b=2", config.getConfigValue("quarkus.datasource.jdbc.url").getValue()); @@ -271,7 +271,7 @@ public class ConfigurationTest { @Test public void testDatabaseDefaults() { - System.setProperty(CLI_ARGS, "--db=dev-file"); + ConfigArgsConfigSource.setCliArgs("--db=dev-file"); SmallRyeConfig config = createConfig(); assertEquals(H2Dialect.class.getName(), config.getConfigValue("kc.db-dialect").getValue()); @@ -283,23 +283,23 @@ public class ConfigurationTest { assertEquals("jdbc:h2:file:" + userHomeUri + "data/h2/keycloakdb;;AUTO_SERVER=TRUE;NON_KEYWORDS=VALUE", config.getConfigValue("quarkus.datasource.jdbc.url").getValue()); - System.setProperty(CLI_ARGS, "--db=dev-mem"); + ConfigArgsConfigSource.setCliArgs("--db=dev-mem"); config = createConfig(); assertEquals(H2Dialect.class.getName(), config.getConfigValue("kc.db-dialect").getValue()); assertEquals("jdbc:h2:mem:keycloakdb;NON_KEYWORDS=VALUE", config.getConfigValue("quarkus.datasource.jdbc.url").getValue()); assertEquals("h2", config.getConfigValue("quarkus.datasource.db-kind").getValue()); - System.setProperty(CLI_ARGS, "--db=dev-mem" + ARG_SEPARATOR + "--db-username=other"); + ConfigArgsConfigSource.setCliArgs("--db=dev-mem", "--db-username=other"); config = createConfig(); assertEquals("sa", config.getConfigValue("quarkus.datasource.username").getValue()); // should be untransformed assertEquals("other", config.getConfigValue("kc.db-username").getValue()); - System.setProperty(CLI_ARGS, "--db=postgres" + ARG_SEPARATOR + "--db-username=other"); + ConfigArgsConfigSource.setCliArgs("--db=postgres", "--db-username=other"); config = createConfig(); assertEquals("other", config.getConfigValue("quarkus.datasource.username").getValue()); - System.setProperty(CLI_ARGS, "--db=postgres"); + ConfigArgsConfigSource.setCliArgs("--db=postgres"); config = createConfig(); // username should not be set, either as the quarkus or kc property assertEquals(null, config.getConfigValue("quarkus.datasource.username").getValue()); @@ -308,7 +308,7 @@ public class ConfigurationTest { @Test public void testDatabaseKindProperties() { - System.setProperty(CLI_ARGS, "--db=postgres" + ARG_SEPARATOR + "--db-url=jdbc:postgresql://localhost/keycloak" + ARG_SEPARATOR + "--db-username=postgres"); + ConfigArgsConfigSource.setCliArgs("--db=postgres", "--db-url=jdbc:postgresql://localhost/keycloak", "--db-username=postgres"); SmallRyeConfig config = createConfig(); assertEquals("org.hibernate.dialect.PostgreSQLDialect", config.getConfigValue("kc.db-dialect").getValue()); @@ -319,7 +319,7 @@ public class ConfigurationTest { @Test public void testDefaultDbPropertiesGetApplied() { - System.setProperty(CLI_ARGS, "--db=postgres" + ARG_SEPARATOR + "--db-url-host=myhost" + ARG_SEPARATOR + "--db-url-database=kcdb" + ARG_SEPARATOR + "--db-url-properties=?foo=bar"); + ConfigArgsConfigSource.setCliArgs("--db=postgres", "--db-url-host=myhost", "--db-url-database=kcdb", "--db-url-properties=?foo=bar"); SmallRyeConfig config = createConfig(); assertEquals("org.hibernate.dialect.PostgreSQLDialect", config.getConfigValue("kc.db-dialect").getValue()); @@ -329,7 +329,7 @@ public class ConfigurationTest { @Test public void testRemoveSpaceFromValue() { - System.setProperty(CLI_ARGS, "--db=postgres "); + ConfigArgsConfigSource.setCliArgs("--db=postgres "); SmallRyeConfig config = createConfig(); assertEquals("org.hibernate.dialect.PostgreSQLDialect", config.getConfigValue("kc.db-dialect").getValue()); @@ -338,7 +338,7 @@ public class ConfigurationTest { @Test public void testDefaultDbPortGetApplied() { - System.setProperty(CLI_ARGS, "--db=mssql" + ARG_SEPARATOR + "--db-url-host=myhost" + ARG_SEPARATOR + "--db-url-database=kcdb" + ARG_SEPARATOR + "--db-url-port=1234" + ARG_SEPARATOR + "--db-url-properties=?foo=bar"); + ConfigArgsConfigSource.setCliArgs("--db=mssql", "--db-url-host=myhost", "--db-url-database=kcdb", "--db-url-port=1234", "--db-url-properties=?foo=bar"); SmallRyeConfig config = createConfig(); assertEquals("org.hibernate.dialect.SQLServerDialect", config.getConfigValue("kc.db-dialect").getValue()); @@ -348,7 +348,7 @@ public class ConfigurationTest { @Test public void testSetDbUrlOverridesDefaultDataSource() { - System.setProperty(CLI_ARGS, "--db=mariadb" + ARG_SEPARATOR + "--db-url-host=myhost" + ARG_SEPARATOR + "--db-url=jdbc:mariadb://localhost/keycloak"); + ConfigArgsConfigSource.setCliArgs("--db=mariadb", "--db-url-host=myhost", "--db-url=jdbc:mariadb://localhost/keycloak"); SmallRyeConfig config = createConfig(); assertEquals("org.hibernate.dialect.MariaDBDialect", config.getConfigValue("kc.db-dialect").getValue()); @@ -360,31 +360,31 @@ public class ConfigurationTest { public void testDatabaseProperties() { System.setProperty("kc.db-url-properties", ";;test=test;test1=test1"); System.setProperty("kc.db-url-path", "test-dir"); - System.setProperty(CLI_ARGS, "--db=dev-file"); + ConfigArgsConfigSource.setCliArgs("--db=dev-file"); SmallRyeConfig config = createConfig(); assertEquals(H2Dialect.class.getName(), config.getConfigValue("kc.db-dialect").getValue()); assertEquals("jdbc:h2:file:test-dir/data/h2/keycloakdb;;test=test;test1=test1;NON_KEYWORDS=VALUE", config.getConfigValue("quarkus.datasource.jdbc.url").getValue()); assertEquals("xa", config.getConfigValue("quarkus.datasource.jdbc.transactions").getValue()); - System.setProperty(CLI_ARGS, ""); + ConfigArgsConfigSource.setCliArgs(""); config = createConfig(); assertEquals(H2Dialect.class.getName(), config.getConfigValue("kc.db-dialect").getValue()); assertEquals("jdbc:h2:file:test-dir/data/h2/keycloakdb;;test=test;test1=test1;NON_KEYWORDS=VALUE", config.getConfigValue("quarkus.datasource.jdbc.url").getValue()); System.setProperty("kc.db-url-properties", "?test=test&test1=test1"); - System.setProperty(CLI_ARGS, "--db=mariadb"); + ConfigArgsConfigSource.setCliArgs("--db=mariadb"); config = createConfig(); assertEquals("jdbc:mariadb://localhost:3306/keycloak?test=test&test1=test1", config.getConfigValue("quarkus.datasource.jdbc.url").getValue()); assertEquals(MariaDBDialect.class.getName(), config.getConfigValue("kc.db-dialect").getValue()); assertEquals(MariaDbDataSource.class.getName(), config.getConfigValue("quarkus.datasource.jdbc.driver").getValue()); - System.setProperty(CLI_ARGS, "--db=postgres"); + ConfigArgsConfigSource.setCliArgs("--db=postgres"); config = createConfig(); assertEquals("jdbc:postgresql://localhost:5432/keycloak?test=test&test1=test1", config.getConfigValue("quarkus.datasource.jdbc.url").getValue()); assertEquals(PostgreSQLDialect.class.getName(), config.getConfigValue("kc.db-dialect").getValue()); assertEquals(PGXADataSource.class.getName(), config.getConfigValue("quarkus.datasource.jdbc.driver").getValue()); - System.setProperty(CLI_ARGS, "--db-schema=test-schema"); + ConfigArgsConfigSource.setCliArgs("--db-schema=test-schema"); config = createConfig(); assertEquals("test-schema", config.getConfigValue("kc.db-schema").getValue()); assertEquals("test-schema", config.getConfigValue("kc.db-schema").getValue()); @@ -419,34 +419,34 @@ public class ConfigurationTest { // If explicitly set, then it is always used regardless of the profile System.clearProperty(Environment.PROFILE); - System.setProperty(CLI_ARGS, "--cache=cluster-foo.xml"); + ConfigArgsConfigSource.setCliArgs("--cache=cluster-foo.xml"); Assert.assertEquals("cluster-foo.xml", initConfig("connectionsInfinispan", "quarkus").get("configFile")); System.setProperty(Environment.PROFILE, "dev"); Assert.assertEquals("cluster-foo.xml", initConfig("connectionsInfinispan", "quarkus").get("configFile")); - System.setProperty(CLI_ARGS, "--cache-stack=foo"); + ConfigArgsConfigSource.setCliArgs("--cache-stack=foo"); Assert.assertEquals("foo", initConfig("connectionsInfinispan", "quarkus").get("stack")); } @Test public void testCommaSeparatedArgValues() { - System.setProperty(CLI_ARGS, "--spi-client-jpa-searchable-attributes=bar,foo"); + ConfigArgsConfigSource.setCliArgs("--spi-client-jpa-searchable-attributes=bar,foo"); assertEquals("bar,foo", initConfig("client-jpa").get("searchable-attributes")); - System.setProperty(CLI_ARGS, "--spi-client-jpa-searchable-attributes=bar,foo,foo bar"); + ConfigArgsConfigSource.setCliArgs("--spi-client-jpa-searchable-attributes=bar,foo,foo bar"); assertEquals("bar,foo,foo bar", initConfig("client-jpa").get("searchable-attributes")); - System.setProperty(CLI_ARGS, "--spi-client-jpa-searchable-attributes=bar,foo, \"foo bar\""); + ConfigArgsConfigSource.setCliArgs("--spi-client-jpa-searchable-attributes=bar,foo, \"foo bar\""); assertEquals("bar,foo, \"foo bar\"", initConfig("client-jpa").get("searchable-attributes")); - System.setProperty(CLI_ARGS, "--spi-client-jpa-searchable-attributes=bar,foo, \"foo bar\"" + ARG_SEPARATOR + "--spi-hostname-default-frontend-url=http://foo.unittest"); + ConfigArgsConfigSource.setCliArgs("--spi-client-jpa-searchable-attributes=bar,foo, \"foo bar\"", "--spi-hostname-default-frontend-url=http://foo.unittest"); assertEquals("http://foo.unittest", initConfig("hostname-default").get("frontend-url")); } @Test public void testDatabaseDriverSetExplicitly() { - System.setProperty(CLI_ARGS, "--db=mssql" + ARG_SEPARATOR + "--db-url=jdbc:sqlserver://localhost/keycloak"); + ConfigArgsConfigSource.setCliArgs("--db=mssql", "--db-url=jdbc:sqlserver://localhost/keycloak"); System.setProperty("kc.db-driver", "com.microsoft.sqlserver.jdbc.SQLServerDriver"); System.setProperty("kc.transaction-xa-enabled", "false"); assertTrue(System.getProperty(CLI_ARGS, "").contains("mssql")); @@ -459,20 +459,20 @@ public class ConfigurationTest { @Test public void testDatabaseDialectSetExplicitly() { - System.setProperty(CLI_ARGS, "--db-dialect=user-defined"); + ConfigArgsConfigSource.setCliArgs("--db-dialect=user-defined"); assertEquals("user-defined", createConfig().getRawValue("kc.db-dialect")); } @Test public void testTransactionTypeChangesDriver() { - System.setProperty(CLI_ARGS, "--db=mssql" + ARG_SEPARATOR + "--transaction-xa-enabled=false"); + ConfigArgsConfigSource.setCliArgs("--db=mssql", "--transaction-xa-enabled=false"); assertTrue(System.getProperty(CLI_ARGS, "").contains("mssql")); SmallRyeConfig jtaEnabledConfig = createConfig(); assertEquals("com.microsoft.sqlserver.jdbc.SQLServerDriver", jtaEnabledConfig.getConfigValue("quarkus.datasource.jdbc.driver").getValue()); assertEquals("enabled", jtaEnabledConfig.getConfigValue("quarkus.datasource.jdbc.transactions").getValue()); - System.setProperty(CLI_ARGS, "--db=mssql" + ARG_SEPARATOR + "--transaction-xa-enabled=true"); + ConfigArgsConfigSource.setCliArgs("--db=mssql", "--transaction-xa-enabled=true"); assertTrue(System.getProperty(CLI_ARGS, "").contains("mssql")); SmallRyeConfig xaConfig = createConfig(); @@ -482,42 +482,42 @@ public class ConfigurationTest { @Test public void testResolveHealthOption() { - System.setProperty(CLI_ARGS, "--health-enabled=true"); + ConfigArgsConfigSource.setCliArgs("--health-enabled=true"); SmallRyeConfig config = createConfig(); assertEquals("true", config.getConfigValue("quarkus.health.extensions.enabled").getValue()); - System.setProperty(CLI_ARGS, ""); + ConfigArgsConfigSource.setCliArgs(""); config = createConfig(); assertEquals("false", config.getConfigValue("quarkus.health.extensions.enabled").getValue()); } @Test public void testResolveMetricsOption() { - System.setProperty(CLI_ARGS, "--metrics-enabled=true"); + ConfigArgsConfigSource.setCliArgs("--metrics-enabled=true"); SmallRyeConfig config = createConfig(); assertEquals("true", config.getConfigValue("quarkus.datasource.metrics.enabled").getValue()); } @Test public void testLogHandlerConfig() { - System.setProperty(CLI_ARGS, "--log=console,file"); + ConfigArgsConfigSource.setCliArgs("--log=console,file"); SmallRyeConfig config = createConfig(); assertEquals("true", config.getConfigValue("quarkus.log.console.enable").getValue()); assertEquals("true", config.getConfigValue("quarkus.log.file.enable").getValue()); assertEquals("false", config.getConfigValue("quarkus.log.handler.gelf.enabled").getValue()); - System.setProperty(CLI_ARGS, "--log=file"); + ConfigArgsConfigSource.setCliArgs("--log=file"); SmallRyeConfig config2 = createConfig(); assertEquals("false", config2.getConfigValue("quarkus.log.console.enable").getValue()); assertEquals("true", config2.getConfigValue("quarkus.log.file.enable").getValue()); assertEquals("false", config2.getConfigValue("quarkus.log.handler.gelf.enabled").getValue()); - System.setProperty(CLI_ARGS, "--log=console"); + ConfigArgsConfigSource.setCliArgs("--log=console"); SmallRyeConfig config3 = createConfig(); assertEquals("true", config3.getConfigValue("quarkus.log.console.enable").getValue()); assertEquals("false", config3.getConfigValue("quarkus.log.file.enable").getValue()); assertEquals("false", config3.getConfigValue("quarkus.log.handler.gelf.enabled").getValue()); - System.setProperty(CLI_ARGS, "--log=console,gelf"); + ConfigArgsConfigSource.setCliArgs("--log=console,gelf"); SmallRyeConfig config4 = createConfig(); assertEquals("true", config4.getConfigValue("quarkus.log.console.enable").getValue()); assertEquals("false", config4.getConfigValue("quarkus.log.file.enable").getValue()); @@ -526,7 +526,7 @@ public class ConfigurationTest { @Test public void testOptionValueWithEqualSign() { - System.setProperty(CLI_ARGS, "--db=postgres" + ARG_SEPARATOR + "--db-password=my_secret="); + ConfigArgsConfigSource.setCliArgs("--db=postgres", "--db-password=my_secret="); SmallRyeConfig config = createConfig(); assertEquals("my_secret=", config.getConfigValue("kc.db-password").getValue()); } @@ -577,7 +577,12 @@ public class ConfigurationTest { private SmallRyeConfig createConfig() { KeycloakConfigSourceProvider.reload(); - ConfigProviderResolver.setInstance(null); - return ConfigUtils.configBuilder(true, LaunchMode.NORMAL).build(); + // older versions of quarkus implicitly picked up this config, now we + // must set it manually + SmallRyeConfig config = ConfigUtils.configBuilder(true, LaunchMode.NORMAL).build(); + SmallRyeConfigProviderResolver resolver = new SmallRyeConfigProviderResolver(); + resolver.registerConfig(config, Thread.currentThread().getContextClassLoader()); + ConfigProviderResolver.setInstance(resolver); + return config; } } diff --git a/quarkus/tests/integration/src/test/java/org/keycloak/it/cli/ShowConfigCommandTest.java b/quarkus/tests/integration/src/test/java/org/keycloak/it/cli/ShowConfigCommandTest.java index ebe2e5db73..5558122769 100644 --- a/quarkus/tests/integration/src/test/java/org/keycloak/it/cli/ShowConfigCommandTest.java +++ b/quarkus/tests/integration/src/test/java/org/keycloak/it/cli/ShowConfigCommandTest.java @@ -20,7 +20,9 @@ package org.keycloak.it.cli; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.keycloak.it.junit5.extension.CLITest; +import org.keycloak.it.junit5.extension.ConfigurationTestResource; +import io.quarkus.test.common.QuarkusTestResource; import io.quarkus.test.junit.main.Launch; import io.quarkus.test.junit.main.LaunchResult; import org.keycloak.quarkus.runtime.cli.command.ShowConfig; @@ -28,6 +30,7 @@ import org.keycloak.quarkus.runtime.configuration.mappers.PropertyMappers; import static org.keycloak.quarkus.runtime.cli.command.Main.CONFIG_FILE_LONG_NAME; +@QuarkusTestResource(value = ConfigurationTestResource.class, restrictToAnnotatedClass = true) @CLITest public class ShowConfigCommandTest { diff --git a/quarkus/tests/junit5/src/main/java/org/keycloak/it/junit5/extension/CLITest.java b/quarkus/tests/junit5/src/main/java/org/keycloak/it/junit5/extension/CLITest.java index cfb5d59ad8..92f37603ce 100644 --- a/quarkus/tests/junit5/src/main/java/org/keycloak/it/junit5/extension/CLITest.java +++ b/quarkus/tests/junit5/src/main/java/org/keycloak/it/junit5/extension/CLITest.java @@ -23,6 +23,9 @@ import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; import org.junit.jupiter.api.extension.ExtendWith; +/** + * When used for in-vm tests, use {@link ConfigurationTestResource} to reset the configuration + */ @Target(ElementType.TYPE) @ExtendWith({ CLITestExtension.class }) @Retention(RetentionPolicy.RUNTIME) diff --git a/quarkus/tests/junit5/src/main/java/org/keycloak/it/junit5/extension/CLITestExtension.java b/quarkus/tests/junit5/src/main/java/org/keycloak/it/junit5/extension/CLITestExtension.java index 49a3bd6699..e26dc70a3b 100644 --- a/quarkus/tests/junit5/src/main/java/org/keycloak/it/junit5/extension/CLITestExtension.java +++ b/quarkus/tests/junit5/src/main/java/org/keycloak/it/junit5/extension/CLITestExtension.java @@ -59,11 +59,12 @@ import static org.keycloak.quarkus.runtime.cli.command.Main.CONFIG_FILE_SHORT_NA public class CLITestExtension extends QuarkusMainTestExtension { private static final String SYS_PROPS = "sys-props"; - private static final String KEY_VALUE_SEPARATOR = "[= ]"; + private static final String KEY_VALUE_SEPARATOR = "[=]"; private KeycloakDistribution dist; private DatabaseContainer databaseContainer; private InfinispanContainer infinispanContainer; private CLIResult result; + static String[] CLI_ARGS = new String[0]; @Override public void beforeEach(ExtensionContext context) throws Exception { @@ -71,13 +72,13 @@ public class CLITestExtension extends QuarkusMainTestExtension { Launch launch = context.getRequiredTestMethod().getAnnotation(Launch.class); getStore(context).put(SYS_PROPS, new HashMap<>(System.getProperties())); - if (launch != null) { + if (launch != null && distConfig == null) { for (String arg : launch.value()) { if (arg.contains(CONFIG_FILE_SHORT_NAME) || arg.contains(CONFIG_FILE_LONG_NAME)) { Pattern kvSeparator = Pattern.compile(KEY_VALUE_SEPARATOR); String[] cfKeyValue = kvSeparator.split(arg); setProperty(KeycloakPropertiesConfigSource.KEYCLOAK_CONFIG_FILE_PROP, cfKeyValue[1]); - } else if (distConfig == null && arg.startsWith("-D")) { + } else if (arg.startsWith("-D")) { // allow setting system properties from JVM tests int keyValueSeparator = arg.indexOf('='); @@ -114,6 +115,7 @@ public class CLITestExtension extends QuarkusMainTestExtension { result = dist.run(Stream.concat(List.of(launch.value()).stream(), List.of(distConfig.defaultOptions()).stream()).collect(Collectors.toList())); } } else { + CLI_ARGS = launch == null ? new String[] {} : launch.value(); configureProfile(context); super.beforeEach(context); } diff --git a/quarkus/tests/junit5/src/main/java/org/keycloak/it/junit5/extension/ConfigurationTestResource.java b/quarkus/tests/junit5/src/main/java/org/keycloak/it/junit5/extension/ConfigurationTestResource.java new file mode 100644 index 0000000000..19cb678a6d --- /dev/null +++ b/quarkus/tests/junit5/src/main/java/org/keycloak/it/junit5/extension/ConfigurationTestResource.java @@ -0,0 +1,57 @@ +/* + * Copyright 2024 Red Hat, Inc. and/or its affiliates + * and other contributors as indicated by the @author tags. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.keycloak.it.junit5.extension; + +import io.quarkus.runtime.LaunchMode; +import io.quarkus.runtime.configuration.ConfigUtils; +import io.quarkus.test.common.QuarkusTestResourceLifecycleManager; +import io.smallrye.config.SmallRyeConfig; +import io.smallrye.config.SmallRyeConfigProviderResolver; + +import org.eclipse.microprofile.config.spi.ConfigProviderResolver; +import org.keycloak.quarkus.runtime.configuration.ConfigArgsConfigSource; +import org.keycloak.quarkus.runtime.configuration.KeycloakConfigSourceProvider; + +import java.util.Map; + +/** + * Used to reset the configuration for {@link CLITest}s + */ +public class ConfigurationTestResource implements QuarkusTestResourceLifecycleManager { + + @Override + public Map start() { + return Map.of(); + } + + @Override + public void stop() { + + } + + @Override + public void inject(Object testInstance) { + ConfigArgsConfigSource.setCliArgs(CLITestExtension.CLI_ARGS); + KeycloakConfigSourceProvider.reload(); + SmallRyeConfig config = ConfigUtils.configBuilder(true, LaunchMode.NORMAL).build(); + SmallRyeConfigProviderResolver resolver = new SmallRyeConfigProviderResolver(); + resolver.registerConfig(config, Thread.currentThread().getContextClassLoader()); + ConfigProviderResolver.setInstance(resolver); + } + +} diff --git a/testsuite/integration-arquillian/servers/auth-server/services/testsuite-providers/pom.xml b/testsuite/integration-arquillian/servers/auth-server/services/testsuite-providers/pom.xml index d99959a670..0d0277216c 100644 --- a/testsuite/integration-arquillian/servers/auth-server/services/testsuite-providers/pom.xml +++ b/testsuite/integration-arquillian/servers/auth-server/services/testsuite-providers/pom.xml @@ -65,6 +65,11 @@ org.wildfly.core wildfly-controller + + + org.jboss.logmanager + jboss-logmanager + org.keycloak.testsuite integration-arquillian-testsuite-providers-deployment