diff --git a/scripts/docker-compose.yml b/scripts/docker-compose.yml index 187f297fbc9..df3828e9677 100644 --- a/scripts/docker-compose.yml +++ b/scripts/docker-compose.yml @@ -2,7 +2,7 @@ name: uaa services: postgres: - image: "postgres:17.2" + image: "postgres:15" ports: - 5432:5432 volumes: @@ -10,7 +10,7 @@ services: environment: - POSTGRES_PASSWORD=changeme mysql: - image: "mysql:5.7.44-oraclelinux7" + image: "mysql:8" ports: - 3306:3306 volumes: diff --git a/server/src/test/java/org/cloudfoundry/identity/uaa/db/V2_7_3__StoreSubDomainAsLowerCase_Tests.java b/server/src/test/java/org/cloudfoundry/identity/uaa/db/V2_7_3__StoreSubDomainAsLowerCase_Tests.java index 2677019b529..b65bf39609a 100644 --- a/server/src/test/java/org/cloudfoundry/identity/uaa/db/V2_7_3__StoreSubDomainAsLowerCase_Tests.java +++ b/server/src/test/java/org/cloudfoundry/identity/uaa/db/V2_7_3__StoreSubDomainAsLowerCase_Tests.java @@ -6,6 +6,7 @@ import org.cloudfoundry.identity.uaa.zone.JdbcIdentityZoneProvisioning; import org.cloudfoundry.identity.uaa.zone.MultitenancyFixture; import org.flywaydb.core.api.migration.Context; +import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; @@ -13,6 +14,7 @@ import org.springframework.jdbc.core.JdbcTemplate; import org.cloudfoundry.identity.uaa.oauth.common.util.RandomValueStringGenerator; +import java.sql.Connection; import java.sql.SQLException; import java.sql.Timestamp; import java.util.Arrays; @@ -36,15 +38,23 @@ class V2_7_3__StoreSubDomainAsLowerCase_Tests { @Autowired private JdbcTemplate jdbcTemplate; + private Connection connection; + + @AfterEach + void closeConnection() { + try { + connection.close(); + } catch (Exception ignore) { + } + } @BeforeEach void setUpDuplicateZones() throws SQLException { provisioning = new JdbcIdentityZoneProvisioning(jdbcTemplate); migration = new V2_7_3__StoreSubDomainAsLowerCase(); generator = new RandomValueStringGenerator(6); - + connection = jdbcTemplate.getDataSource().getConnection(); context = mock(Context.class); - when(context.getConnection()).thenReturn( - jdbcTemplate.getDataSource().getConnection()); + when(context.getConnection()).thenReturn(connection); } @Test diff --git a/server/src/test/java/org/cloudfoundry/identity/uaa/scim/test/TestUtils.java b/server/src/test/java/org/cloudfoundry/identity/uaa/scim/test/TestUtils.java index 2b21acb82ba..6dc56e9a57f 100644 --- a/server/src/test/java/org/cloudfoundry/identity/uaa/scim/test/TestUtils.java +++ b/server/src/test/java/org/cloudfoundry/identity/uaa/scim/test/TestUtils.java @@ -1,8 +1,10 @@ package org.cloudfoundry.identity.uaa.scim.test; import org.cloudfoundry.identity.uaa.scim.ScimUser; +import org.cloudfoundry.identity.uaa.util.beans.DbUtils; import org.springframework.jdbc.core.JdbcTemplate; +import java.sql.SQLException; import java.util.Collections; import java.util.stream.Stream; @@ -14,8 +16,15 @@ public class TestUtils { public static void deleteFrom( final JdbcTemplate jdbcTemplate, final String... tables) { + DbUtils dbUtils = new DbUtils(); Stream.of(tables) - .map(table -> "delete from " + table) + .map(table -> { + try { + return "delete from " + dbUtils.getQuotedIdentifier(table, jdbcTemplate); + } catch (SQLException e) { + throw new RuntimeException(e); + } + }) .forEach(jdbcTemplate::update); } diff --git a/uaa/src/test/java/org/cloudfoundry/identity/uaa/db/TestZonifyGroupSchema_V2_4_1.java b/uaa/src/test/java/org/cloudfoundry/identity/uaa/db/TestZonifyGroupSchema_V2_4_1.java index cc45d0e5a63..ac0d0951ade 100644 --- a/uaa/src/test/java/org/cloudfoundry/identity/uaa/db/TestZonifyGroupSchema_V2_4_1.java +++ b/uaa/src/test/java/org/cloudfoundry/identity/uaa/db/TestZonifyGroupSchema_V2_4_1.java @@ -6,6 +6,7 @@ import org.cloudfoundry.identity.uaa.scim.ScimUser; import org.cloudfoundry.identity.uaa.scim.endpoints.ScimGroupEndpoints; import org.cloudfoundry.identity.uaa.scim.endpoints.ScimUserEndpoints; +import org.cloudfoundry.identity.uaa.util.beans.DbUtils; import org.cloudfoundry.identity.uaa.zone.IdentityZone; import org.cloudfoundry.identity.uaa.zone.IdentityZoneEndpoints; import org.cloudfoundry.identity.uaa.zone.IdentityZoneHolder; @@ -91,9 +92,11 @@ protected Object getActualFieldValue(String field) { } @Test - void test_Ensure_That_New_Fields_NotNull() { - assertThat(webApplicationContext.getBean(JdbcTemplate.class).queryForObject("SELECT count(*) FROM external_group_mapping WHERE origin IS NULL", Integer.class), is(0)); - assertThat(webApplicationContext.getBean(JdbcTemplate.class).queryForObject("SELECT count(*) FROM groups WHERE identity_zone_id IS NULL", Integer.class), is(0)); + void test_Ensure_That_New_Fields_NotNull() throws Exception { + JdbcTemplate jdbcTemplate = webApplicationContext.getBean(JdbcTemplate.class); + DbUtils dbUtils = webApplicationContext.getBean(DbUtils.class); + assertThat(jdbcTemplate.queryForObject("SELECT count(*) FROM external_group_mapping WHERE origin IS NULL", Integer.class), is(0)); + assertThat(jdbcTemplate.queryForObject("SELECT count(*) FROM "+ dbUtils.getQuotedIdentifier("groups", jdbcTemplate) +" WHERE identity_zone_id IS NULL", Integer.class), is(0)); } } diff --git a/uaa/src/test/java/org/cloudfoundry/identity/uaa/mock/zones/IdentityZoneEndpointsMockMvcTests.java b/uaa/src/test/java/org/cloudfoundry/identity/uaa/mock/zones/IdentityZoneEndpointsMockMvcTests.java index ed6b7087243..21f4e2cc2b0 100644 --- a/uaa/src/test/java/org/cloudfoundry/identity/uaa/mock/zones/IdentityZoneEndpointsMockMvcTests.java +++ b/uaa/src/test/java/org/cloudfoundry/identity/uaa/mock/zones/IdentityZoneEndpointsMockMvcTests.java @@ -38,6 +38,7 @@ import org.cloudfoundry.identity.uaa.util.JsonUtils; import org.cloudfoundry.identity.uaa.util.KeyWithCertTest; import org.cloudfoundry.identity.uaa.util.SetServerNameRequestPostProcessor; +import org.cloudfoundry.identity.uaa.util.beans.DbUtils; import org.cloudfoundry.identity.uaa.zone.BrandingInformation; import org.cloudfoundry.identity.uaa.zone.BrandingInformation.Banner; import org.cloudfoundry.identity.uaa.zone.Consent; @@ -172,6 +173,8 @@ class IdentityZoneEndpointsMockMvcTests { private MockMvc mockMvc; private TestClient testClient; + private DbUtils dbUtils; + @BeforeEach void setUp( @Autowired WebApplicationContext webApplicationContext, @@ -186,6 +189,8 @@ void setUp( this.mockMvc = mockMvc; this.testClient = testClient; + dbUtils = webApplicationContext.getBean(DbUtils.class); + UaaClientDetails uaaAdminClient = new UaaClientDetails("uaa-admin-" + generator.generate().toLowerCase(), null, "uaa.admin", @@ -1737,7 +1742,7 @@ void test_delete_zone_cleans_db() throws Exception { assertThat(template.queryForObject("select count(*) from identity_zone where id=?", new Object[]{zone.getId()}, Integer.class)).isZero(); assertThat(template.queryForObject("select count(*) from oauth_client_details where identity_zone_id=?", new Object[]{zone.getId()}, Integer.class)).isZero(); - assertThat(template.queryForObject("select count(*) from groups where identity_zone_id=?", new Object[]{zone.getId()}, Integer.class)).isZero(); + assertThat(template.queryForObject("select count(*) from "+dbUtils.getQuotedIdentifier("groups", template)+" where identity_zone_id=?", new Object[]{zone.getId()}, Integer.class)).isZero(); assertThat(template.queryForObject("select count(*) from sec_audit where identity_zone_id=?", new Object[]{zone.getId()}, Integer.class)).isZero(); assertThat(template.queryForObject("select count(*) from users where identity_zone_id=?", new Object[]{zone.getId()}, Integer.class)).isZero(); assertThat(template.queryForObject("select count(*) from external_group_mapping where origin=?", new Object[]{LOGIN_SERVER}, Integer.class)).isZero();