KEYCLOAK-19496 Unignore ArtifactBindingCustomResolverTest and make SetDefaultProvider Annotation usable for Quarkus-based distribution
This commit is contained in:
parent
6e591305f9
commit
00feef4dbe
5 changed files with 53 additions and 19 deletions
|
@ -40,4 +40,4 @@ spi.connections-http-client.default.reuse-connections=false
|
||||||
spi.events-store.jpa.max-detail-length=2000
|
spi.events-store.jpa.max-detail-length=2000
|
||||||
|
|
||||||
# set known protocol ports for basicsamltest
|
# 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
|
||||||
|
|
|
@ -556,13 +556,9 @@ public class AuthServerTestEnricher {
|
||||||
TestContext testContext = new TestContext(suiteContext, event.getTestClass().getJavaClass());
|
TestContext testContext = new TestContext(suiteContext, event.getTestClass().getJavaClass());
|
||||||
testContextProducer.set(testContext);
|
testContextProducer.set(testContext);
|
||||||
|
|
||||||
if (!isAuthServerRemote() && !isAuthServerQuarkus()) {
|
if (!isAuthServerRemote()) {
|
||||||
boolean wasUpdated = false;
|
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)) {
|
if (event.getTestClass().isAnnotationPresent(SetDefaultProvider.class)) {
|
||||||
SetDefaultProvider defaultProvider = event.getTestClass().getAnnotation(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) {
|
if (wasUpdated) {
|
||||||
restartAuthServer();
|
restartAuthServer();
|
||||||
testContext.reconnectAdminClient();
|
testContext.reconnectAdminClient();
|
||||||
|
@ -883,19 +884,20 @@ public class AuthServerTestEnricher {
|
||||||
|
|
||||||
removeTestRealms(testContext, adminClient);
|
removeTestRealms(testContext, adminClient);
|
||||||
|
|
||||||
if (!isAuthServerRemote() && !isAuthServerQuarkus()) {
|
if (!isAuthServerRemote()) {
|
||||||
|
|
||||||
boolean wasUpdated = false;
|
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)) {
|
if (event.getTestClass().isAnnotationPresent(SetDefaultProvider.class)) {
|
||||||
SpiProvidersSwitchingUtils.removeProvider(suiteContext, event.getTestClass().getAnnotation(SetDefaultProvider.class));
|
SpiProvidersSwitchingUtils.removeProvider(suiteContext, event.getTestClass().getAnnotation(SetDefaultProvider.class));
|
||||||
wasUpdated = true;
|
wasUpdated = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (event.getTestClass().isAnnotationPresent(EnableVault.class) && !isAuthServerQuarkus()) {
|
||||||
|
VaultUtils.disableVault(suiteContext, event.getTestClass().getAnnotation(EnableVault.class).providerId());
|
||||||
|
wasUpdated = true;
|
||||||
|
}
|
||||||
|
|
||||||
if (wasUpdated) {
|
if (wasUpdated) {
|
||||||
restartAuthServer();
|
restartAuthServer();
|
||||||
testContext.reconnectAdminClient();
|
testContext.reconnectAdminClient();
|
||||||
|
|
|
@ -176,10 +176,11 @@ public class KeycloakQuarkusServerDeployableContainer implements DeployableConta
|
||||||
if (configuration.getDebugPort() > 0) {
|
if (configuration.getDebugPort() > 0) {
|
||||||
commands.add("--debug");
|
commands.add("--debug");
|
||||||
commands.add(Integer.toString(configuration.getDebugPort()));
|
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("--debug");
|
||||||
commands.add(System.getProperty("auth.server.debug.port", "5005"));
|
commands.add(System.getProperty("auth.server.debug.port", "5005"));
|
||||||
}
|
}
|
||||||
|
|
||||||
commands.add("--http-port=" + configuration.getBindHttpPort());
|
commands.add("--http-port=" + configuration.getBindHttpPort());
|
||||||
commands.add("--https-port=" + configuration.getBindHttpsPort());
|
commands.add("--https-port=" + configuration.getBindHttpsPort());
|
||||||
|
|
||||||
|
|
|
@ -11,6 +11,12 @@ import org.wildfly.extras.creaper.core.online.OnlineManagementClient;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
public class SpiProvidersSwitchingUtils {
|
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 {
|
public static void addProviderDefaultValue(SuiteContext suiteContext, SetDefaultProvider annotation) throws IOException, CliException {
|
||||||
ContainerInfo authServerInfo = suiteContext.getAuthServerInfo();
|
ContainerInfo authServerInfo = suiteContext.getAuthServerInfo();
|
||||||
|
|
||||||
|
@ -18,14 +24,14 @@ public class SpiProvidersSwitchingUtils {
|
||||||
System.setProperty("keycloak." + annotation.spi() + ".provider", annotation.providerId());
|
System.setProperty("keycloak." + annotation.spi() + ".provider", annotation.providerId());
|
||||||
} else if (authServerInfo.isQuarkus()) {
|
} else if (authServerInfo.isQuarkus()) {
|
||||||
KeycloakQuarkusServerDeployableContainer container = (KeycloakQuarkusServerDeployableContainer) authServerInfo.getArquillianContainer().getDeployableContainer();
|
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 {
|
} else {
|
||||||
OnlineManagementClient client = AuthServerTestEnricher.getManagementClient();
|
OnlineManagementClient client = AuthServerTestEnricher.getManagementClient();
|
||||||
|
|
||||||
if (annotation.onlyUpdateDefault()) {
|
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 {
|
} 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();
|
client.close();
|
||||||
|
@ -43,11 +49,35 @@ public class SpiProvidersSwitchingUtils {
|
||||||
} else {
|
} else {
|
||||||
OnlineManagementClient client = AuthServerTestEnricher.getManagementClient();
|
OnlineManagementClient client = AuthServerTestEnricher.getManagementClient();
|
||||||
if (annotation.onlyUpdateDefault()) {
|
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 {
|
} else {
|
||||||
client.execute("/subsystem=keycloak-server/spi=" + annotation.spi() + "/:remove");
|
client.execute(SUBSYSTEM_KEYCLOAK_SERVER_SPI + annotation.spi() + "/:remove");
|
||||||
}
|
}
|
||||||
client.close();
|
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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,10 +18,11 @@ import static org.hamcrest.Matchers.containsString;
|
||||||
import static org.hamcrest.Matchers.is;
|
import static org.hamcrest.Matchers.is;
|
||||||
import static org.hamcrest.Matchers.not;
|
import static org.hamcrest.Matchers.not;
|
||||||
import static org.hamcrest.Matchers.notNullValue;
|
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.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")
|
@SetDefaultProvider(spi = "saml-artifact-resolver", providerId = "0005")
|
||||||
public class ArtifactBindingCustomResolverTest extends ArtifactBindingTest {
|
public class ArtifactBindingCustomResolverTest extends ArtifactBindingTest {
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue