[KEYCLOAK-10066] Merge Preview Features Test: OpenshiftClientStorage
This commit is contained in:
parent
215331e947
commit
b18d88a37b
4 changed files with 124 additions and 21 deletions
|
@ -835,27 +835,19 @@ public class TestingResourceProvider implements RealmResourceProvider {
|
|||
@Path("/enable-feature/{feature}")
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
public Response enableFeature(@PathParam("feature") String feature) {
|
||||
Profile.Feature featureProfile;
|
||||
|
||||
Profile.Feature featureProfile = Profile.Feature.valueOf(feature);
|
||||
|
||||
if (featureProfile == null)
|
||||
try {
|
||||
featureProfile = Profile.Feature.valueOf(feature);
|
||||
} catch (IllegalArgumentException e) {
|
||||
System.err.printf("Feature '%s' doesn't exist!!\n", feature);
|
||||
return Response.status(Response.Status.NOT_FOUND).build();
|
||||
}
|
||||
|
||||
if (Profile.isFeatureEnabled(featureProfile))
|
||||
return Response.ok().build();
|
||||
|
||||
System.setProperty("keycloak.profile.feature." + feature.toLowerCase(), "enabled");
|
||||
|
||||
switch (featureProfile.getType()) {
|
||||
case PREVIEW:
|
||||
Profile.getPreviewFeatures().add(featureProfile);
|
||||
break;
|
||||
case EXPERIMENTAL:
|
||||
Profile.getExperimentalFeatures().add(featureProfile);
|
||||
break;
|
||||
}
|
||||
|
||||
Profile.getDisabledFeatures().remove(featureProfile);
|
||||
System.setProperty("keycloak.profile.feature." + featureProfile.toString().toLowerCase(), "enabled");
|
||||
Profile.init();
|
||||
|
||||
if (Profile.isFeatureEnabled(featureProfile))
|
||||
|
@ -868,17 +860,19 @@ public class TestingResourceProvider implements RealmResourceProvider {
|
|||
@Path("/disable-feature/{feature}")
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
public Response disableFeature(@PathParam("feature") String feature) {
|
||||
Profile.Feature featureProfile;
|
||||
|
||||
Profile.Feature featureProfile = Profile.Feature.valueOf(feature);
|
||||
|
||||
if (featureProfile == null)
|
||||
try {
|
||||
featureProfile = Profile.Feature.valueOf(feature);
|
||||
} catch (IllegalArgumentException e) {
|
||||
System.err.printf("Feature '%s' doesn't exist!!\n", feature);
|
||||
return Response.status(Response.Status.NOT_FOUND).build();
|
||||
}
|
||||
|
||||
if (!Profile.isFeatureEnabled(featureProfile))
|
||||
return Response.ok().build();
|
||||
|
||||
System.getProperties().remove("keycloak.profile.feature." + feature.toLowerCase());
|
||||
Profile.getDisabledFeatures().add(featureProfile);
|
||||
System.getProperties().remove("keycloak.profile.feature." + featureProfile.toString().toLowerCase());
|
||||
Profile.init();
|
||||
|
||||
if (!Profile.isFeatureEnabled(featureProfile))
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
*/
|
||||
package org.keycloak.testsuite.arquillian.annotation;
|
||||
|
||||
import org.keycloak.common.Profile;
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
|
@ -51,4 +52,9 @@ public @interface RestartContainer {
|
|||
* @return Wait time in milliseconds after database initialization.
|
||||
*/
|
||||
long intializeDatabaseWait() default 0;
|
||||
|
||||
/**
|
||||
* @return Array of features, which should be enabled.
|
||||
*/
|
||||
Profile.Feature[] enableFeatures() default {};
|
||||
}
|
||||
|
|
|
@ -47,7 +47,10 @@ import org.jboss.shrinkwrap.api.ShrinkWrap;
|
|||
import org.jboss.shrinkwrap.api.asset.StringAsset;
|
||||
import org.jboss.shrinkwrap.api.exporter.ZipExporter;
|
||||
import org.jboss.shrinkwrap.api.spec.WebArchive;
|
||||
import org.keycloak.common.Profile;
|
||||
import org.keycloak.helpers.DropAllServlet;
|
||||
import org.keycloak.testsuite.arquillian.AuthServerTestEnricher;
|
||||
import org.keycloak.testsuite.arquillian.ContainerInfo;
|
||||
import org.keycloak.testsuite.arquillian.annotation.RestartContainer;
|
||||
import org.wildfly.extras.creaper.commands.deployments.Deploy;
|
||||
import org.wildfly.extras.creaper.commands.deployments.Undeploy;
|
||||
|
@ -58,7 +61,15 @@ import org.wildfly.extras.creaper.core.online.OnlineOptions;
|
|||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.nio.file.FileAlreadyExistsException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.Properties;
|
||||
|
||||
/**
|
||||
* Changes behaviour of original ContainerEventController to stop manual containers
|
||||
|
@ -68,6 +79,7 @@ import java.util.List;
|
|||
*
|
||||
* @author vramik
|
||||
* @author pskopek
|
||||
* @author mabartos
|
||||
*/
|
||||
public class KeycloakContainerEventsController extends ContainerEventController {
|
||||
|
||||
|
@ -83,7 +95,7 @@ public class KeycloakContainerEventsController extends ContainerEventController
|
|||
}
|
||||
|
||||
@Override
|
||||
public void execute(@Observes(precedence = 3) AfterClass event) {
|
||||
public void execute(@Observes(precedence = 0) AfterClass event) {
|
||||
try {
|
||||
container.fire(new UnDeployManagedDeployments());
|
||||
} finally {
|
||||
|
@ -130,6 +142,14 @@ public class KeycloakContainerEventsController extends ContainerEventController
|
|||
if (restartContainer.withoutKeycloakAddUserFile()) {
|
||||
copyKeycloakAddUserFile();
|
||||
}
|
||||
|
||||
if (restartContainer.enableFeatures().length != 0) {
|
||||
changeStateOfFeatures(restartContainer, false);
|
||||
// Auth-server has to be restarted again. If not, the features will not to be disabled.
|
||||
container.fire(new StopManualContainers());
|
||||
container.fire(new StopSuiteContainers());
|
||||
container.fire(new StartSuiteContainers());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -140,6 +160,10 @@ public class KeycloakContainerEventsController extends ContainerEventController
|
|||
if (restartContainer.withoutKeycloakAddUserFile()) {
|
||||
removeKeycloakAddUserFile();
|
||||
}
|
||||
|
||||
if (restartContainer.enableFeatures().length != 0) {
|
||||
changeStateOfFeatures(restartContainer, true);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -242,6 +266,83 @@ public class KeycloakContainerEventsController extends ContainerEventController
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Change state of features, which are contained in {@code enableFeatures} param.
|
||||
* This method either enable or disable features.
|
||||
* If auth-server is JBossBased, then the features are either enabled or disabled via {@code profile.properties}.
|
||||
*
|
||||
* @param restartContainer to pass more information from test annotation.
|
||||
* @param enableFeatures if the features will be enabled or disabled.
|
||||
*/
|
||||
private void changeStateOfFeatures(RestartContainer restartContainer, boolean enableFeatures) {
|
||||
Optional<Container> authServerOptional = containerRegistry.get().getContainers().stream()
|
||||
.filter(f -> f.getName().startsWith("auth-server-")).findFirst();
|
||||
|
||||
if (authServerOptional.isPresent()) {
|
||||
Container authServer = authServerOptional.get();
|
||||
boolean isJbossBased = new ContainerInfo(authServer).isJBossBased();
|
||||
|
||||
if (isJbossBased) {
|
||||
ContainerDef conf = authServer.getContainerConfiguration();
|
||||
String jbossHome = conf.getContainerProperty("jbossHome");
|
||||
Path fileProps = null;
|
||||
if (jbossHome != null) {
|
||||
try {
|
||||
Path dir = Paths.get(jbossHome + "/standalone/configuration");
|
||||
fileProps = dir.resolve("profile.properties");
|
||||
|
||||
if (enableFeatures) {
|
||||
Path file = Files.createFile(fileProps);
|
||||
Properties props = new Properties();
|
||||
Arrays.stream(restartContainer.enableFeatures()).forEach(f -> props.setProperty("feature." + f.toString().toLowerCase(), "enabled"));
|
||||
PrintWriter pw = new PrintWriter(file.toFile());
|
||||
props.list(pw);
|
||||
pw.close();
|
||||
} else {
|
||||
Files.deleteIfExists(fileProps);
|
||||
}
|
||||
} catch (FileAlreadyExistsException ex) {
|
||||
changeFeaturesInExistingProps(restartContainer, fileProps, true);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (enableFeatures) {
|
||||
Arrays.stream(restartContainer.enableFeatures())
|
||||
.forEach(f -> System.setProperty("keycloak.profile.feature." + f.toString().toLowerCase(), "enabled"));
|
||||
} else {
|
||||
Arrays.stream(restartContainer.enableFeatures())
|
||||
.forEach(f -> System.getProperties().remove("keycloak.profile.feature." + f.toString().toLowerCase()));
|
||||
}
|
||||
}
|
||||
Profile.init();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* If exists {@code profile.properties} file, then another properties are only appended to the file.
|
||||
*
|
||||
* @param restartContainer to pass more information from test annotation
|
||||
* @param file path to profile.properties
|
||||
* @param enableFeatures if features will be enabled or disabled
|
||||
*/
|
||||
private void changeFeaturesInExistingProps(RestartContainer restartContainer, Path file, boolean enableFeatures) {
|
||||
Profile.Feature[] features = restartContainer.enableFeatures();
|
||||
String state = enableFeatures ? "enabled" : "disabled";
|
||||
|
||||
if (features.length != 0) {
|
||||
Properties props = new Properties();
|
||||
try {
|
||||
props.load(Files.newBufferedReader(file));
|
||||
Arrays.stream(features).forEach(f -> props.setProperty("feature." + f.toString().toLowerCase(), state));
|
||||
props.store(Files.newBufferedWriter(file), "");
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Coppied from org.jboss.arquillian.container.impl.client.container.ContainerDeployController
|
||||
*
|
||||
|
|
|
@ -56,6 +56,7 @@ import org.keycloak.storage.openshift.OpenshiftClientStorageProviderFactory;
|
|||
import org.keycloak.testsuite.AbstractTestRealmKeycloakTest;
|
||||
import org.keycloak.testsuite.AssertEvents;
|
||||
import org.keycloak.testsuite.admin.ApiUtil;
|
||||
import org.keycloak.testsuite.arquillian.annotation.RestartContainer;
|
||||
import org.keycloak.testsuite.pages.AppPage;
|
||||
import org.keycloak.testsuite.pages.ConsentPage;
|
||||
import org.keycloak.testsuite.pages.ErrorPage;
|
||||
|
@ -68,6 +69,7 @@ import org.keycloak.testsuite.util.OAuthClient;
|
|||
*
|
||||
* @author <a href="mailto:psilva@redhat.com">Pedro Igor</a>
|
||||
*/
|
||||
@RestartContainer(enableFeatures = OPENSHIFT_INTEGRATION)
|
||||
public final class OpenshiftClientStorageTest extends AbstractTestRealmKeycloakTest {
|
||||
|
||||
private static Undertow OPENSHIFT_API_SERVER;
|
||||
|
|
Loading…
Reference in a new issue