KEYCLOAK-19496 Unignore ArtifactBindingCustomResolverTest and make SetDefaultProvider Annotation usable for Quarkus-based distribution

This commit is contained in:
Dominik 2021-10-07 11:13:31 +02:00 committed by Pedro Igor
parent 6e591305f9
commit 00feef4dbe
5 changed files with 53 additions and 19 deletions

View file

@ -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

View file

@ -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();

View file

@ -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());

View file

@ -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();
}
}

View file

@ -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 {