8000 fix: updating the test extension logic by shawkins · Pull Request #48759 · keycloak/keycloak · GitHub
[go: up one dir, main page]

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8000
Original file line number Diff line number Diff line change
Expand Up @@ -173,15 +173,15 @@ public <T> T runWithDisabled(Supplier<T> execution) {
}

public void saveDryRunProperties() throws FileNotFoundException, IOException {
Path path = Environment.getHomePath().orElseThrow().resolve("lib").resolve("dryRun.properties");
Path path = Environment.getHomePath().orElseThrow().resolve("lib").resolve("quarkus").resolve("dryRun.properties");
var properties = Picocli.getNonPersistedBuildTimeOptions();
try (FileOutputStream fos = new FileOutputStream(path.toFile())) {
properties.store(fos, null);
}
}

public void useDryRunProperties() {
Path path = Environment.getHomePath().orElseThrow().resolve("lib").resolve("dryRun.properties");
Path path = Environment.getHomePath().orElseThrow().resolve("lib").resolve("quarkus").resolve("dryRun.properties");
if (Files.exists(path)) {
Properties properties = new Properties();
try (FileInputStream fis = new FileInputStream(path.toFile())) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.keycloak.it.cli.dist;

import java.io.File;
import java.io.IOException;
import java.nio.file.Path;
import java.util.Map;
import java.util.function.Consumer;

Expand All @@ -12,15 +13,11 @@
import org.keycloak.it.utils.RawKeycloakDistribution;
import org.keycloak.quarkus.runtime.cli.command.StartDev;

import io.quarkus.test.junit.main.Launch;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInstance;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsString;
import static org.junit.jupiter.api.Assertions.assertTrue;

/**
* Runs test with distribution placed in a directory that has special characters in name.
Expand All @@ -30,42 +27,23 @@
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
abstract class AbstractPathDistTest {

/**
* Switches temporary directory used by the {@link RawKeycloakDistribution}.
*/
private static final String JAVA_IO_TMPDIR = "java.io.tmpdir";
private String originalTmpDir = null;

protected abstract String getSubPath();

@BeforeAll
void changeTmpDir() {
originalTmpDir = System.getProperty(JAVA_IO_TMPDIR);
System.setProperty(JAVA_IO_TMPDIR, originalTmpDir + File.separator + getSubPath());
}

@AfterAll
void switchBackToOriginalTmpDir() {
if (originalTmpDir != null) {
System.setProperty(JAVA_IO_TMPDIR, originalTmpDir);
originalTmpDir = null;
}
}

@BeforeStartDistribution(AddCustomScriptsProvider.class)
@RawDistOnly(reason = "Testing installation path handling")
@Test
@Launch(StartDev.NAME)
void testApplicationBuildAndStart(CLIResult result, KeycloakDistribution dist) {
assertDistPath(dist);
result.assertStartedDevMode();
assertThat(result.getOutput(), containsString("Updating the configuration and installing your custom providers, if any. Please wait."));
}

private void assertDistPath(KeycloakDistribution dist) {
void testApplicationBuildAndStart(KeycloakDistribution dist) throws IOException {
RawKeycloakDistribution rawDist = dist.unwrap(RawKeycloakDistribution.class);
String distPath = rawDist.getDistPath().toString();
assertTrue(distPath.contains(getSubPath()), "Test must run with '" + getSubPath() + "' in path. Actual path: " + distPath);
Path distPath = rawDist.getDistPath();
Path newPath = distPath.getParent().resolve(getSubPath()).resolve(distPath.getFileName());
rawDist.setDistPath(newPath);
try {
CLIResult result = dist.run(StartDev.NAME);
result.assertStartedDevMode();
assertThat(result.getOutput(), containsString("Updating the configuration and installing your custom providers, if any. Please wait."));
} finally {
rawDist.setDistPath(distPath);
}
}

public static final class AddCustomScriptsProvider implements Consumer<KeycloakDistribution> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,22 +34,27 @@
import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.MethodOrderer.OrderAnnotation;
import org.junit.jupiter.api.Order;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestMethodOrder;
import org.junit.jupiter.api.condition.EnabledOnOs;
import org.junit.jupiter.api.condition.OS;
import org.junit.jupiter.api.io.TempDir;
import org.testcontainers.shaded.com.google.common.io.Files;

@DistributionTest(reInstall = DistributionTest.ReInstall.BEFORE_TEST)
@DistributionTest(defaultOptions = {"--db=dev-file", "--http-enabled=true", "--hostname-strict=false"})
@RawDistOnly(reason = "Not possible to mount files using docker.")
@Storage(defaultLocalCache = false)
@Tag(DistributionTest.SMOKE)
@Tag(DistributionTest.SLOW)
@TestMethodOrder(OrderAnnotation.class)
public class ClusterConfigDistTest {

private static final String WARN_DEFAULT_CACHE_MUTATIONS = "Modifying the default cache configuration in the config file";

@Order(1) // run the dev specific tests together to prevent later reaugmentations
@Test
@Launch({ "start-dev", "--cache=ispn" })
void changeClusterSetting(CLIResult result) {
Expand All @@ -58,23 +63,23 @@ void changeClusterSetting(CLIResult result) {
}

@Test
@Launch({ "start-dev", "--cache=ispn", "--cache-embedded-network-bind-address=127.0.0.2","--cache-embedded-network-bind-port=7802"})
@Launch({ "start", "--cache-embedded-network-bind-address=127.0.0.2","--cache-embedded-network-bind-port=7802"})
void changeBindAddressAndPort(CLIResult result) {
result.assertClusteredCache();
result.assertMessage("physical addresses are `[127.0.0.2:7802]`");
result.assertMessage("ISPN000078: Starting JGroups channel `ISPN` with stack `jdbc-ping`");
}

@Test
@Launch({ "start-dev", "--cache=ispn", "--cache-embedded-network-bind-address=127.0.0.1","--cache-embedded-network-bind-port=7801", "--cache-embedded-network-external-address=127.0.0.2", "--cache-embedded-network-external-port=7802"})
@Launch({ "start", "--cache-embedded-network-bind-address=127.0.0.1","--cache-embedded-network-bind-port=7801", "--cache-embedded-network-external-address=127.0.0.2", "--cache-embedded-network-external-port=7802"})
void changeBindAndExternalAddress(CLIResult result) {
result.assertClusteredCache();
result.assertMessage("physical addresses are `[127.0.0.2:7802]`");
result.assertMessage("ISPN000078: Starting JGroups channel `ISPN` with stack `jdbc-ping`");
}

@Test
@Launch({ "start-dev", "--cache=ispn", "--cache-embedded-network-bind-address=127.0.0.1", "-Djgroups.bind.address=127.0.0.2", "-Djgroups.bind_addr=127.0.0.3"})
@Launch({ "start", "--cache-embedded-network-bind-address=127.0.0.1", "-Djgroups.bind.address=127.0.0.2", "-Djgroups.bind_addr=127.0.0.3"})
void testJGroupsBindAddressPropertyAlsoExists(CLIResult result) {
result.assertClusteredCache();
result.assertMessage("Conflicting system property 'jgroups.bind.address' and CLI arg 'cache-embedded-network-bind-address' set, utilising CLI value '127.0.0.1'");
Expand All @@ -84,76 +89,76 @@ void testJGroupsBindAddressPropertyAlsoExists(CLIResult result) {
}

@Test
@Launch({ "start-dev", "--cache=ispn", "-Djgroups.bind.address=127.0.0.2", "-Djgroups.bind.port=7801"})
@Launch({ "start", "-Djgroups.bind.address=127.0.0.2", "-Djgroups.bind.port=7801"})
void testJGroupsBindAddressProperty(CLIResult result) {
result.assertClusteredCache();
result.assertMessage("physical addresses are `[127.0.0.2:7801]`");
result.assertMessage("ISPN000078: Starting JGroups channel `ISPN` with stack `jdbc-ping`");
}

@Test
@Launch({ 8BD0 "start-dev", "--cache=ispn", "--cache-embedded-network-bind-address=match-address:127.0.0.*"})
@Launch({ "start", "--cache-embedded-network-bind-address=match-address:127.0.0.*"})
void testBindSiteMatches(CLIResult result) {
result.assertClusteredCache();
result.assertMessage("physical addresses are `[127.0.0.");
result.assertMessage("ISPN000078: Starting JGroups channel `ISPN` with stack `jdbc-ping`");
}

@Test
@Launch({ "start-dev", "--cache=ispn", "--cache-embedded-network-bind-address=SITE_LOCAL"})
@Launch({ "start", "--cache-embedded-network-bind-address=SITE_LOCAL"})
void testBindSiteLocal(CLIResult result) {
result.assertClusteredCache();
result.assertMessage("ISPN000078: Starting JGroups channel `ISPN` with stack `jdbc-ping`");
}

@Test
@Launch({ "start-dev", "--cache=ispn", "--cache-stack=jdbc-ping-udp"})
@Launch({ "start", "--cache-stack=jdbc-ping-udp"})
void testJdbcPingTCP(CLIResult result) {
result.assertClusteredCache();
result.assertMessage("ISPN000078: Starting JGroups channel `ISPN` with stack `jdbc-ping-udp`");
}

@Test
@Launch({ "start-dev", "--cache=ispn", "--cache-stack=azure" })
@Launch({ "start", "--cache-stack=azure" })
void warnDeprecatedCloudStack(CLIResult result) {
result.assertMessage("Stack 'azure' is deprecated. We recommend to use 'jdbc-ping' instead");
}

@Test
@Launch({ "start-dev", "--cache-config-file=invalid" })
@Launch({ "start", "--cache-config-file=invalid" })
void failInvalidClusterConfig(CLIResult result) {
result.assertError("Cache config file 'invalid' does not exist in the conf directory");
}

@Test
@Launch({ "start-dev", "--cache=ispn", "--cache-stack=kubernetes" })
@Launch({ "start", "--cache-stack=kubernetes" })
void failMisConfiguredClusterStack(CLIResult result) {
result.assertMessage("ERROR: dns_query can not be null or empty");
}

@Test
@Launch({ "start-dev", "--cache=ispn", "--cache-stack=invalid" })
@Launch({ "start", "--cache-stack=invalid" })
void failInvalidClusterStack(CLIResult result) {
result.assertMessage("No such JGroups stack 'invalid'");
}

@Test
@Launch({ "start-dev", "--cache-config-file=cache-ispn.xml" })
@Launch({ "start", "--cache-config-file=cache-ispn.xml" })
void testExplicitCacheConfigFile(CLIResult result) {
result.assertStartedDevMode();
result.assertStarted();
result.assertClusteredCache();
}

@Test
@Launch({ "start", "--cache=ispn", "--log-level=info,org.keycloak.connections.infinispan:debug", "--http-enabled=true", "--hostname-strict=false"})
@Launch({ "start", "--log-level=info,org.keycloak.connections.infinispan:debug"})
void testPrintCacheConfigurationsDebug(CLIResult result) {
result.assertStarted();
result.assertMessage("Infinispan configuration");
}

@Test
@EnabledOnOs(value = { OS.LINUX, OS.MAC }, disabledReason = "different shell escaping behaviour on Windows.")
@Launch({ "start", "--db=dev-file", "--log-level=info,org.infinispan.remoting.transport.jgroups.JGroupsTransport:debug","--http-enabled=true", "--hostname-strict=false" })
@Launch({ "start", "--log-level=info,org.infinispan.remoting.transport.jgroups.JGroupsTransport:debug"})
void testStartDefaultsToClustering(CLIResult result) {
result.assertStarted();
result.assertClusteredCache();
Expand All @@ -162,13 +167,14 @@ void testStartDefaultsToClustering(CLIResult result) {

@Test
@EnabledOnOs(value = { OS.WINDOWS }, disabledReason = "different shell behaviour on Windows.")
@Launch({ "start", "--db=dev-file", "--log-level=\"info,org.infinispan.remoting.transport.jgroups.JGroupsTransport:debug\"","--http-enabled=true", "--hostname-strict=false" })
@Launch({ "start", "--log-level=\"info,org.infinispan.remoting.transport.jgroups.JGroupsTransport:debug\"" })
void testWinStartDefaultsToClustering(CLIResult result) {
result.assertStarted();
result.assertClusteredCache();
result.assertMessage("JGroups protocol stack: TCP");
}

@Order(2)
@Test
@Launch({ "start-dev" })
void testStartDevDefaultsToLocalCaches(CLIResult result) {
Expand All @@ -179,6 +185,7 @@ void testStartDevDefaultsToLocalCaches(CLIResult result) {
result.assertNoMessage("Starting JGroups certificate reload manager");
}

@Order(3)
@Test
@BeforeStartDistribution(ConfigureCacheUsingAsyncEncryption.class)
@Launch({ "start-dev", "--cache-config-file=cache-ispn-asym-enc.xml" })
Expand All @@ -188,14 +195,14 @@ void testCustomCacheStackInConfigFile(CLIResult result) {

@Test
@BeforeStartDistribution(ConfigureCacheUsingAsyncEncryption.class)
@Launch({"start", "--cache-config-file=cache-ispn-asym-enc.xml", "--http-enabled=true", "--hostname-strict=false", "--cache-embedded-mtls-enabled=false"})
@Launch({"start", "--cache-config-file=cache-ispn-asym-enc.xml", "--cache-embedded-mtls-enabled=false"})
void testCustomCacheStackInConfigFileNotDev(CLIResult result) {
result.assertMessage("ISPN000078: Starting JGroups channel `ISPN` with stack `encrypt-udp`");
}

@Test
@BeforeStartDistribution(ConfigureCustomCache.class)
@Launch({ "start-dev", "--cache-config-file=cache-ispn-custom-cache.xml" })
@Launch({ "start", "--cache-config-file=cache-ispn-custom-cache.xml" })
void testCustomCacheConfigurationWarning(CLIResult result) {
result.assertMessage(WARN_DEFAULT_CACHE_MUTATIONS);
}
Expand All @@ -208,32 +215,32 @@ void testAbsoluteCacheFile(KeycloakDistribution dist, @TempDir Path tempDir) thr
Files.write(is.readAllBytes(), customCacheFile);
}

LaunchResult result = dist.run("start-dev", "--cache-config-file=" + customCacheFile.getAbsolutePath());
LaunchResult result = dist.run("start", "--cache-config-file=" + customCacheFile.getAbsolutePath());
Assertions.assertEquals(0, result.exitCode());
MatcherAssert.assertThat(result.getOutput(), Matchers.containsString(WARN_DEFAULT_CACHE_MUTATIONS));

String absolutePath = missingCacheFile.getAbsolutePath();
result = dist.run("start-dev", "--cache-config-file=" + absolutePath);
result = dist.run("start", "--cache-config-file=" + absolutePath);
Assertions.assertEquals(2, result.exitCode());
MatcherAssert.assertThat(result.getErrorOutput(), Matchers.matchesRegex("Cache config file '" + absolutePath + "' does not exist"));
}

@Test
@BeforeStartDistribution(ConfigureCustomCache.class)
@Launch({ "start-dev", "--cache-config-file=cache-ispn-custom-cache.xml", "--cache-config-mutate=true" })
@Launch({ "start", "--cache-config-file=cache-ispn-custom-cache.xml", "--cache-config-mutate=true" })
void testCustomCacheConfigurationNoWarning(CLIResult result) {
result.assertNoMessage(WARN_DEFAULT_CACHE_MUTATIONS);
}

@Test
@BeforeStartDistribution(ConfigureCustomCache.class)
@Launch({ "start-dev", "--cache-config-file=cache-ispn-custom-user-cache.xml"})
@Launch({ "start", "--cache-config-file=cache-ispn-custom-user-cache.xml"})
void testCustomUserCacheConfigurationNoWarning(CLIResult result) {
result.assertNoMessage(WARN_DEFAULT_CACHE_MUTATIONS);
}

@Test
@Launch({ "start", "--cache=local", "--http-enabled=true", "--hostname-strict=false"})
@Launch({ "start", "--cache=local"})
void testNotClustered(CLIResult result) {
result.assertStarted();
result.assertLocalCache();
Expand All @@ -244,13 +251,13 @@ void testNotClustered(CLIResult result) {
}

@Test
@Launch({ "start-dev", "--cache-embedded-users-max-count=-1" })
@Launch({ "start", "--cache-embedded-users-max-count=-1" })
void testNegativeMaxCountIgnoredForBoundedCache(CLIResult result) {
result.assertMessage("Ignoring unbounded max-count for cache 'users'");
}

@Test
@Launch({ "start-dev", "--cache-embedded-sessions-max-count=-1", "--features-disabled=persistent-user-sessions" })
@Launch({ "start", "--cache-embedded-sessions-max-count=-1", "--features-disabled=persistent-user-sessions" })
void testNegativeMaxCountAllowedForVolatileCache(CLIResult result) {
result.assertNoMessage("Ignoring unbounded max-count for cache 'sessions'");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,7 @@ void testImportFromFileCreatedByExportAllRealms(KeycloakDistribution dist) throw
dist.run("start-dev", "--import-realm");
dist.run("--profile=dev", "export", "--file=../data/import/realm.json", "--verbose");

RawKeycloakDistribution rawDist = dist.unwrap(RawKeycloakDistribution.class);
FileUtil.deleteDirectory(rawDist.getDistPath().resolve("data").resolve("h2").toAbsolutePath());
dist.unwrap(RawKeycloakDistribution.class).resetH2Dir();

CLIResult result = dist.run("start-dev", "--import-realm");
result.assertMessage("Realm 'quickstart-realm' imported");
Expand All @@ -99,8 +98,7 @@ void testImportFromFileCreatedByExportSingleRealm(KeycloakDistribution dist) thr
dist.run("start-dev", "--import-realm");
dist.run("--profile=dev", "export", "--realm=quickstart-realm", "--file=../data/import/realm.json");

RawKeycloakDistribution rawDist = dist.unwrap(RawKeycloakDistribution.class);
FileUtil.deleteDirectory(rawDist.getDistPath().resolve("data").resolve("h2").toAbsolutePath());
dist.unwrap(RawKeycloakDistribution.class).resetH2Dir();

CLIResult result = dist.run("start-dev", "--import-realm");
result.assertMessage("Realm 'quickstart-realm' imported");
Expand All @@ -115,7 +113,7 @@ void testImportFromDirCreatedByExport(KeycloakDistribution dist) throws IOExcept
FileUtil.deleteDirectory(rawDist.getDistPath().resolve("data").resolve("import").toAbsolutePath());
dist.run("--profile=dev", "export", "--dir=../data/import");

FileUtil.deleteDirectory(rawDist.getDistPath().resolve("data").resolve("h2").toAbsolutePath());
dist.unwrap(RawKeycloakDistribution.class).resetH2Dir();

CLIResult result = dist.run("start-dev", "--import-realm");
result.assertMessage("Realm 'quickstart-realm' imported");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
package org.keycloak.it.cli.dist;

import java.io.IOException;

import org.keycloak.it.junit5.extension.DistributionTest;
import org.keycloak.it.junit5.extension.RawDistOnly;
import org.keycloak.it.utils.KeycloakDistribution;
import org.keycloak.it.utils.RawKeycloakDistribution;

import io.quarkus.deployment.util.FileUtil;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;

Expand All @@ -13,7 +17,10 @@
public class LiquibaseDistTest {

@Test
public void dbLockMultipleExecution(KeycloakDistribution distribution) {
public void dbLockMultipleExecution(KeycloakDistribution distribution) throws IOException {
// force a full db initialization
RawKeycloakDistribution rawDist = distribution.unwrap(RawKeycloakDistribution.class);
FileUtil.deleteDirectory(rawDist.getDistPath().resolve("data").resolve("h2").toAbsolutePath());
var result = distribution.run("start-dev", "--log-level=org.keycloak.connections.jpa.updater.liquibase.lock.CustomLockService:trace");
result.assertMessage("Initialize Database Lock Table, current locks []");
result.assertMessage("Initialized record in the database lock table");
Expand Down
Loading
Loading
0