From 3e16af8c0fc8b19d367cd6cb85e7b6cb5cfcefeb Mon Sep 17 00:00:00 2001 From: Stefan Wiedemann Date: Thu, 2 May 2024 12:57:25 +0200 Subject: [PATCH] Fix oid4vc tests (#29209) closes #28982 closes #28983 closes #28984 closes #28985 closes #28986 closes #28987 closes #28988 closes #28989 closes #28990 closes #28991 closes #28992 closes #28993 closes #28994 closes #28995 closes #28996 * only enable/disable features that should Signed-off-by: Stefan Wiedemann * use default profile if nothing is set Signed-off-by: Stefan Wiedemann --------- Signed-off-by: Stefan Wiedemann --- .../KeycloakContainerFeaturesController.java | 34 +++++++++++++++---- 1 file changed, 28 insertions(+), 6 deletions(-) diff --git a/testsuite/integration-arquillian/tests/base/src/main/java/org/keycloak/testsuite/arquillian/containers/KeycloakContainerFeaturesController.java b/testsuite/integration-arquillian/tests/base/src/main/java/org/keycloak/testsuite/arquillian/containers/KeycloakContainerFeaturesController.java index 0d9a3d7d4a..22fd47aa7f 100644 --- a/testsuite/integration-arquillian/tests/base/src/main/java/org/keycloak/testsuite/arquillian/containers/KeycloakContainerFeaturesController.java +++ b/testsuite/integration-arquillian/tests/base/src/main/java/org/keycloak/testsuite/arquillian/containers/KeycloakContainerFeaturesController.java @@ -10,8 +10,10 @@ import org.jboss.arquillian.test.spi.event.suite.After; import org.jboss.arquillian.test.spi.event.suite.AfterClass; import org.jboss.arquillian.test.spi.event.suite.Before; import org.jboss.arquillian.test.spi.event.suite.BeforeClass; +import org.jboss.logging.Logger; import org.keycloak.common.Profile; import org.keycloak.testsuite.ProfileAssume; +import org.keycloak.testsuite.arquillian.DeploymentArchiveProcessor; import org.keycloak.testsuite.arquillian.SuiteContext; import org.keycloak.testsuite.arquillian.TestContext; import org.keycloak.testsuite.arquillian.annotation.DisableFeature; @@ -20,12 +22,14 @@ import org.keycloak.testsuite.arquillian.annotation.EnableFeature; import org.keycloak.testsuite.arquillian.annotation.EnableFeatures; import org.keycloak.testsuite.arquillian.annotation.SetDefaultProvider; import org.keycloak.testsuite.client.KeycloakTestingClient; +import org.keycloak.testsuite.util.FeatureDeployerUtil; import org.keycloak.testsuite.util.SpiProvidersSwitchingUtils; import java.lang.reflect.AnnotatedElement; import java.util.Arrays; import java.util.HashSet; import java.util.Objects; +import java.util.Optional; import java.util.Set; import java.util.function.BiConsumer; import java.util.stream.Collectors; @@ -94,7 +98,7 @@ public class KeycloakContainerFeaturesController { private void assertPerformed() { assertThat("An annotation requested to " + action.name() + " feature " + feature.getKey() + ", however after performing this operation " + - "the feature is not in desired state" , + "the feature is not in desired state", ProfileAssume.isFeatureEnabled(feature), is(action == FeatureAction.ENABLE || action == FeatureAction.ENABLE_AND_RESET)); } @@ -188,14 +192,32 @@ public class KeycloakContainerFeaturesController { private Set getUpdateFeaturesSet(AnnotatedElement annotatedElement, State state) { Set ret = new HashSet<>(); + Profile activeProfile = Optional.ofNullable(Profile.getInstance()).orElse(Profile.defaults()); + ret.addAll(Arrays.stream(annotatedElement.getAnnotationsByType(EnableFeature.class)) - .map(annotation -> new UpdateFeature(annotation.value(), annotation.skipRestart(), - state == State.BEFORE ? FeatureAction.ENABLE : FeatureAction.DISABLE_AND_RESET, annotatedElement)) + .map(annotation -> { + if (state == State.BEFORE) { + return new UpdateFeature(annotation.value(), annotation.skipRestart(), FeatureAction.ENABLE, annotatedElement); + } else if (activeProfile.getDisabledFeatures().contains(annotation.value())) { + // only disable if it should be + return new UpdateFeature(annotation.value(), annotation.skipRestart(), FeatureAction.DISABLE_AND_RESET, annotatedElement); + } else { + return new UpdateFeature(annotation.value(), annotation.skipRestart(), FeatureAction.ENABLE, annotatedElement); + } + }) .collect(Collectors.toSet())); ret.addAll(Arrays.stream(annotatedElement.getAnnotationsByType(DisableFeature.class)) - .map(annotation -> new UpdateFeature(annotation.value(), annotation.skipRestart(), - state == State.BEFORE ? FeatureAction.DISABLE : FeatureAction.ENABLE_AND_RESET, annotatedElement)) + .map(annotation -> { + if (state == State.BEFORE) { + return new UpdateFeature(annotation.value(), annotation.skipRestart(), FeatureAction.DISABLE, annotatedElement); + } else if (activeProfile.getDisabledFeatures().contains(annotation.value())) { + // we do not want to enable features that should be disabled by default + return new UpdateFeature(annotation.value(), annotation.skipRestart(), FeatureAction.DISABLE_AND_RESET, annotatedElement); + } else { + return new UpdateFeature(annotation.value(), annotation.skipRestart(), FeatureAction.ENABLE_AND_RESET, annotatedElement); + } + }) .collect(Collectors.toSet())); return ret; @@ -222,7 +244,7 @@ public class KeycloakContainerFeaturesController { return false; } - + public void handleEnableFeaturesAnnotationBeforeClass(@Observes(precedence = 1) BeforeClass event) throws Exception { checkAnnotatedElementForFeatureAnnotations(event.getTestClass().getJavaClass(), State.BEFORE); }