|
10 | 10 | import io.teaql.core.sql.dialect.OracleDialect; |
11 | 11 | import java.sql.Connection; |
12 | 12 | import java.sql.DriverManager; |
| 13 | +import java.sql.Statement; |
13 | 14 | import java.time.LocalDate; |
14 | 15 | import java.util.ArrayList; |
15 | 16 | import java.util.HashSet; |
@@ -45,6 +46,21 @@ public void sqlServerAllocatesAcrossInstancesAndRestart() throws Exception { |
45 | 46 | verify("MSSQL"); |
46 | 47 | } |
47 | 48 |
|
| 49 | + @Test |
| 50 | + public void postgresRejectsUnprotectedBusinessIdTable() throws Exception { |
| 51 | + rejectUnprotectedTable("POSTGRES"); |
| 52 | + } |
| 53 | + |
| 54 | + @Test |
| 55 | + public void mysqlRejectsUnprotectedBusinessIdTable() throws Exception { |
| 56 | + rejectUnprotectedTable("MYSQL"); |
| 57 | + } |
| 58 | + |
| 59 | + @Test |
| 60 | + public void sqlServerRejectsUnprotectedBusinessIdTable() throws Exception { |
| 61 | + rejectUnprotectedTable("MSSQL"); |
| 62 | + } |
| 63 | + |
48 | 64 | @Test |
49 | 65 | public void dm8AllocatesAcrossInstancesAndRestart() throws Exception { |
50 | 66 | verify("DM8"); |
@@ -176,6 +192,46 @@ private void verify(String dialect) throws Exception { |
176 | 192 | } |
177 | 193 | } |
178 | 194 |
|
| 195 | + private void rejectUnprotectedTable(String dialect) throws Exception { |
| 196 | + String prefix = "TEAQL_TEST_" + dialect + "_"; |
| 197 | + String url = System.getenv(prefix + "URL"); |
| 198 | + String user = System.getenv(prefix + "USER"); |
| 199 | + String password = System.getenv(prefix + "PASSWORD"); |
| 200 | + if (url == null || user == null || password == null) { |
| 201 | + if (Boolean.parseBoolean(System.getenv("TEAQL_REQUIRE_LIVE_DB"))) { |
| 202 | + Assert.fail(dialect + " Business ID live gate requires URL, USER, and PASSWORD"); |
| 203 | + } |
| 204 | + Assume.assumeTrue(dialect + " live database is not configured", false); |
| 205 | + } |
| 206 | + Assert.assertTrue("Use a dedicated teaql_live_* database for " + dialect, |
| 207 | + url.contains("teaql_live_")); |
| 208 | + |
| 209 | + String table = "bid_shape_" + UUID.randomUUID().toString().substring(0, 8); |
| 210 | + try (Connection connection = DriverManager.getConnection(url, user, password)) { |
| 211 | + try (Statement statement = connection.createStatement()) { |
| 212 | + statement.execute("CREATE TABLE " + table + " (" |
| 213 | + + "scope_key VARCHAR(512), current_value BIGINT NOT NULL, " |
| 214 | + + "version BIGINT NOT NULL, updated_at BIGINT NOT NULL)"); |
| 215 | + } |
| 216 | + try { |
| 217 | + JdbcBusinessIdAllocator allocator = new JdbcBusinessIdAllocator( |
| 218 | + BusinessIdRuntimeExampleTest.database(connection), table); |
| 219 | + UserContext context = BusinessIdRuntimeExampleTest.context( |
| 220 | + BUSINESS_DATE, allocator); |
| 221 | + context.putAttribute(SchemaExecutor.class.getName(), |
| 222 | + BusinessIdRuntimeExampleTest.noOpSchemaExecutor()); |
| 223 | + IllegalStateException failure = Assert.assertThrows( |
| 224 | + IllegalStateException.class, context::ensureSchema); |
| 225 | + Assert.assertTrue(failure.getMessage(), |
| 226 | + failure.getMessage().contains("scope_key")); |
| 227 | + } finally { |
| 228 | + try (Statement statement = connection.createStatement()) { |
| 229 | + statement.execute("DROP TABLE " + table); |
| 230 | + } |
| 231 | + } |
| 232 | + } |
| 233 | + } |
| 234 | + |
179 | 235 | private static JdbcBusinessIdAllocator allocator(Connection connection, String dialect) { |
180 | 236 | if ("ORACLE".equals(dialect)) { |
181 | 237 | return new JdbcBusinessIdAllocator( |
|
0 commit comments