From 059a132476bf3d6ef160d5173fcc13e4ca961075 Mon Sep 17 00:00:00 2001 From: Dominik Guhr Date: Thu, 28 Jul 2022 13:00:11 +0200 Subject: [PATCH] Fixes the regression in 19 for MariaDB, MySQL and other DBs databases that are not using an official liquibase type in Database.java could not be seeded anymore because the liquibase types we use in model-jpa were not indexed and loaded during the build anymore. Introduces highly needed tests for other databases than postgres, because postgres has an official liquibase databasetype in its list in database.java and as such differs from nearly all other vendors. Closes #13389 --- .github/workflows/ci.yml | 2 +- .../quarkus/deployment/IsJpaStoreEnabled.java | 5 +++++ .../quarkus/deployment/IsLegacyStoreEnabled.java | 3 +++ .../quarkus/deployment/KeycloakProcessor.java | 8 ++++++-- quarkus/tests/integration/pom.xml | 4 ++++ .../it/junit5/extension/DatabaseContainer.java | 5 +++++ .../resources/database/scripts/init-mariadb.sql | 16 ++++++++++++++++ .../resources/database/scripts/init-mysql.sql | 16 ++++++++++++++++ .../storage/database/dist/MariaDBDistTest.java | 3 ++- .../it/storage/database/dist/MySQLDistTest.java | 10 ++++++++++ 10 files changed, 68 insertions(+), 4 deletions(-) create mode 100644 quarkus/tests/integration/src/main/resources/database/scripts/init-mariadb.sql create mode 100644 quarkus/tests/integration/src/main/resources/database/scripts/init-mysql.sql create mode 100644 quarkus/tests/integration/src/test/java/org/keycloak/it/storage/database/dist/MySQLDistTest.java diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 13a6f569bf..c57cc5e524 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -490,7 +490,7 @@ jobs: - name: Run Quarkus Storage Tests run: | - ./mvnw clean install -nsu -B -f quarkus/tests/pom.xml -Ptest-database -Dtest=PostgreSQLDistTest,DatabaseOptionsDistTest,JPAStoreDistTest,HotRodStoreDistTest,MixedStoreDistTest | misc/log/trimmer.sh + ./mvnw clean install -nsu -B -f quarkus/tests/pom.xml -Ptest-database -Dtest=PostgreSQLDistTest,MariaDBDistTest#testSuccessful,MySQLDistTest#testSuccessful,DatabaseOptionsDistTest,JPAStoreDistTest,HotRodStoreDistTest,MixedStoreDistTest | misc/log/trimmer.sh TEST_RESULT=${PIPESTATUS[0]} find . -path '*/target/surefire-reports/*.xml' | zip -q reports-quarkus-tests.zip -@ exit $TEST_RESULT diff --git a/quarkus/deployment/src/main/java/org/keycloak/quarkus/deployment/IsJpaStoreEnabled.java b/quarkus/deployment/src/main/java/org/keycloak/quarkus/deployment/IsJpaStoreEnabled.java index 8bcf8928c6..aed4ee55b7 100644 --- a/quarkus/deployment/src/main/java/org/keycloak/quarkus/deployment/IsJpaStoreEnabled.java +++ b/quarkus/deployment/src/main/java/org/keycloak/quarkus/deployment/IsJpaStoreEnabled.java @@ -25,6 +25,11 @@ import java.util.Optional; import java.util.function.BooleanSupplier; import org.keycloak.config.StorageOptions; +/*** + * Checks if JPA is enabled either for the legacy or the new store. + * + * Returns true if the legacy store is used or the new store is used with storage==jpa + */ public class IsJpaStoreEnabled implements BooleanSupplier { @Override diff --git a/quarkus/deployment/src/main/java/org/keycloak/quarkus/deployment/IsLegacyStoreEnabled.java b/quarkus/deployment/src/main/java/org/keycloak/quarkus/deployment/IsLegacyStoreEnabled.java index bfed5a2e6e..9a6365b5a0 100644 --- a/quarkus/deployment/src/main/java/org/keycloak/quarkus/deployment/IsLegacyStoreEnabled.java +++ b/quarkus/deployment/src/main/java/org/keycloak/quarkus/deployment/IsLegacyStoreEnabled.java @@ -23,6 +23,9 @@ import static org.keycloak.quarkus.runtime.configuration.MicroProfileConfigProvi import java.util.function.BooleanSupplier; +/** + * Checks if the legacy store is enabled. returns true if no storage=... is set. Returns false otherwise. + */ public class IsLegacyStoreEnabled implements BooleanSupplier { @Override diff --git a/quarkus/deployment/src/main/java/org/keycloak/quarkus/deployment/KeycloakProcessor.java b/quarkus/deployment/src/main/java/org/keycloak/quarkus/deployment/KeycloakProcessor.java index 4f430bc98f..7511150cc8 100644 --- a/quarkus/deployment/src/main/java/org/keycloak/quarkus/deployment/KeycloakProcessor.java +++ b/quarkus/deployment/src/main/java/org/keycloak/quarkus/deployment/KeycloakProcessor.java @@ -127,7 +127,6 @@ import io.quarkus.vertx.http.deployment.FilterBuildItem; import org.keycloak.quarkus.runtime.services.health.KeycloakReadyHealthCheck; import org.keycloak.quarkus.runtime.storage.database.jpa.NamedJpaConnectionProviderFactory; -import org.keycloak.quarkus.runtime.storage.database.jpa.QuarkusJpaMapStorageProviderFactory; import org.keycloak.quarkus.runtime.themes.FlatClasspathThemeResourceProviderFactory; import org.keycloak.representations.provider.ScriptProviderDescriptor; import org.keycloak.representations.provider.ScriptProviderMetadata; @@ -471,10 +470,15 @@ class KeycloakProcessor { } @BuildStep(onlyIf = IsJpaStoreEnabled.class, onlyIfNot = IsLegacyStoreEnabled.class) - void indexJpaStore(BuildProducer indexDependencyBuildItemBuildProducer) { + void indexNewJpaStore(BuildProducer indexDependencyBuildItemBuildProducer) { indexDependencyBuildItemBuildProducer.produce(new IndexDependencyBuildItem("org.keycloak", "keycloak-model-map-jpa")); } + @BuildStep(onlyIf = IsLegacyStoreEnabled.class) + void indexLegacyJpaStore(BuildProducer indexDependencyBuildItemBuildProducer) { + indexDependencyBuildItemBuildProducer.produce(new IndexDependencyBuildItem("org.keycloak", "keycloak-model-jpa")); + } + @Record(ExecutionTime.STATIC_INIT) @BuildStep void initializeFilter(BuildProducer filters, KeycloakRecorder recorder) { diff --git a/quarkus/tests/integration/pom.xml b/quarkus/tests/integration/pom.xml index 4143d6f195..4eb1962980 100644 --- a/quarkus/tests/integration/pom.xml +++ b/quarkus/tests/integration/pom.xml @@ -87,6 +87,10 @@ org.testcontainers mariadb + + org.testcontainers + mysql + diff --git a/quarkus/tests/integration/src/main/java/org/keycloak/it/junit5/extension/DatabaseContainer.java b/quarkus/tests/integration/src/main/java/org/keycloak/it/junit5/extension/DatabaseContainer.java index a3d1e25919..e7dc9edea7 100644 --- a/quarkus/tests/integration/src/main/java/org/keycloak/it/junit5/extension/DatabaseContainer.java +++ b/quarkus/tests/integration/src/main/java/org/keycloak/it/junit5/extension/DatabaseContainer.java @@ -23,6 +23,7 @@ import org.keycloak.it.utils.KeycloakDistribution; import org.testcontainers.containers.GenericContainer; import org.testcontainers.containers.JdbcDatabaseContainer; import org.testcontainers.containers.MariaDBContainer; +import org.testcontainers.containers.MySQLContainer; import org.testcontainers.containers.PostgreSQLContainer; import org.testcontainers.utility.DockerImageName; import org.testcontainers.utility.DockerImageName; @@ -95,15 +96,19 @@ public class DatabaseContainer { private GenericContainer createContainer() { String POSTGRES_IMAGE = System.getProperty("kc.db.postgresql.container.image", "postgres:alpine"); String MARIADB_IMAGE = System.getProperty("kc.db.mariadb.container.image", "mariadb:10.5.9"); + String MYSQL_IMAGE = System.getProperty("kc.db.mysql.container.image", "mysql:latest"); DockerImageName POSTGRES = DockerImageName.parse(POSTGRES_IMAGE).asCompatibleSubstituteFor("postgres"); DockerImageName MARIADB = DockerImageName.parse(MARIADB_IMAGE).asCompatibleSubstituteFor("mariadb"); + DockerImageName MYSQL = DockerImageName.parse(MYSQL_IMAGE).asCompatibleSubstituteFor("mysql"); switch (alias) { case "postgres": return configureJdbcContainer(new PostgreSQLContainer(POSTGRES)); case "mariadb": return configureJdbcContainer(new MariaDBContainer(MARIADB)); + case "mysql": + return configureJdbcContainer(new MySQLContainer(MYSQL)); case "infinispan": return configureInfinispanUser(new GenericContainer("quay.io/infinispan/server:12.1.7.Final")) .withExposedPorts(11222); diff --git a/quarkus/tests/integration/src/main/resources/database/scripts/init-mariadb.sql b/quarkus/tests/integration/src/main/resources/database/scripts/init-mariadb.sql new file mode 100644 index 0000000000..365273c213 --- /dev/null +++ b/quarkus/tests/integration/src/main/resources/database/scripts/init-mariadb.sql @@ -0,0 +1,16 @@ +/* + * Copyright 2021 Red Hat, Inc. and/or its affiliates + * and other contributors as indicated by the @author tags. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ diff --git a/quarkus/tests/integration/src/main/resources/database/scripts/init-mysql.sql b/quarkus/tests/integration/src/main/resources/database/scripts/init-mysql.sql new file mode 100644 index 0000000000..8320fd4976 --- /dev/null +++ b/quarkus/tests/integration/src/main/resources/database/scripts/init-mysql.sql @@ -0,0 +1,16 @@ +/* + * Copyright 2021 Red Hat, Inc. and/or its affiliates + * and other contributors as indicated by the @author tags. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ \ No newline at end of file diff --git a/quarkus/tests/integration/src/test/java/org/keycloak/it/storage/database/dist/MariaDBDistTest.java b/quarkus/tests/integration/src/test/java/org/keycloak/it/storage/database/dist/MariaDBDistTest.java index 8acc3f3810..cf1934059d 100644 --- a/quarkus/tests/integration/src/test/java/org/keycloak/it/storage/database/dist/MariaDBDistTest.java +++ b/quarkus/tests/integration/src/test/java/org/keycloak/it/storage/database/dist/MariaDBDistTest.java @@ -18,10 +18,11 @@ package org.keycloak.it.storage.database.dist; import org.keycloak.it.junit5.extension.CLITest; +import org.keycloak.it.junit5.extension.DistributionTest; import org.keycloak.it.junit5.extension.WithDatabase; import org.keycloak.it.storage.database.MariaDBTest; -@CLITest +@DistributionTest(removeBuildOptionsAfterBuild = true) @WithDatabase(alias = "mariadb") public class MariaDBDistTest extends MariaDBTest { diff --git a/quarkus/tests/integration/src/test/java/org/keycloak/it/storage/database/dist/MySQLDistTest.java b/quarkus/tests/integration/src/test/java/org/keycloak/it/storage/database/dist/MySQLDistTest.java new file mode 100644 index 0000000000..9ec65ba2db --- /dev/null +++ b/quarkus/tests/integration/src/test/java/org/keycloak/it/storage/database/dist/MySQLDistTest.java @@ -0,0 +1,10 @@ +package org.keycloak.it.storage.database.dist; + +import org.keycloak.it.junit5.extension.DistributionTest; +import org.keycloak.it.junit5.extension.WithDatabase; +import org.keycloak.it.storage.database.MySQLTest; + +@DistributionTest(removeBuildOptionsAfterBuild = true) +@WithDatabase(alias = "mysql") +public class MySQLDistTest extends MySQLTest { +}