Skip to content

Commit d3958bf

Browse files
author
Philip Z
committed
Exercise malformed Business ID tables on live SQL providers
1 parent bb3d5b4 commit d3958bf

2 files changed

Lines changed: 58 additions & 2 deletions

File tree

‎.github/workflows/live-dialects.yml‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ jobs:
5050
- name: Verify both live dialects (skips are forbidden)
5151
run: >-
5252
mvn -B -ntp -pl teaql-postgres,teaql-mysql,examples/business-id-runtime -am
53-
-Dtest=PostgresIntegrationTest,MysqlIntegrationTest,JdbcBusinessIdLiveDialectIT#postgresAllocatesAcrossInstancesAndRestart+mysqlAllocatesAcrossInstancesAndRestart
53+
-Dtest=PostgresIntegrationTest,MysqlIntegrationTest,JdbcBusinessIdLiveDialectIT#postgresAllocatesAcrossInstancesAndRestart+mysqlAllocatesAcrossInstancesAndRestart+postgresRejectsUnprotectedBusinessIdTable+mysqlRejectsUnprotectedBusinessIdTable
5454
-Dsurefire.failIfNoSpecifiedTests=false test
5555
5656
business-id-sqlserver:
@@ -87,5 +87,5 @@ jobs:
8787
- name: Verify SQL Server Business ID schema and allocation (skips are forbidden)
8888
run: >-
8989
mvn -B -ntp -pl examples/business-id-runtime -am
90-
'-Dtest=JdbcBusinessIdLiveDialectIT#sqlServerAllocatesAcrossInstancesAndRestart+sqlServerConcurrentSchemaStartupIsIdempotent'
90+
'-Dtest=JdbcBusinessIdLiveDialectIT#sqlServerAllocatesAcrossInstancesAndRestart+sqlServerConcurrentSchemaStartupIsIdempotent+sqlServerRejectsUnprotectedBusinessIdTable'
9191
-Dsurefire.failIfNoSpecifiedTests=false test

‎examples/business-id-runtime/src/test/java/io/teaql/examples/businessid/JdbcBusinessIdLiveDialectIT.java‎

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import io.teaql.core.sql.dialect.OracleDialect;
1111
import java.sql.Connection;
1212
import java.sql.DriverManager;
13+
import java.sql.Statement;
1314
import java.time.LocalDate;
1415
import java.util.ArrayList;
1516
import java.util.HashSet;
@@ -45,6 +46,21 @@ public void sqlServerAllocatesAcrossInstancesAndRestart() throws Exception {
4546
verify("MSSQL");
4647
}
4748

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+
4864
@Test
4965
public void dm8AllocatesAcrossInstancesAndRestart() throws Exception {
5066
verify("DM8");
@@ -176,6 +192,46 @@ private void verify(String dialect) throws Exception {
176192
}
177193
}
178194

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+
179235
private static JdbcBusinessIdAllocator allocator(Connection connection, String dialect) {
180236
if ("ORACLE".equals(dialect)) {
181237
return new JdbcBusinessIdAllocator(

0 commit comments

Comments
 (0)