J-Bakuli commented on code in PR #13841:
URL: https://github.com/apache/ignite/pull/13841#discussion_r4679219887
##########
modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/IgniteSqlSchemaIndexingTest.java:
##########
@@ -194,6 +200,206 @@ public void testSchemaEscapeAll() throws Exception {
ignite(0).destroyCache(cfgEsc.getName());
}
+ /**
+ * Tests that a schema name with a quote does not create SCHEMA_INJECTED,
+ * a row is readable through that schema, and destroying the cache drops
the schema.
+ *
+ * @throws Exception If failed.
+ */
+ @Test
+ public void testSchemaNameWithQuote() throws Exception {
+ startGrid(0);
+
+ String schemaName = "A\";CREATE TABLE PUBLIC.SCHEMA_INJECTED(ID
INT);--";
+
+ String quotedSchema = "\"" + schemaName.replace("\"", "\"\"") + "\"";
+
+ IgniteCache<Integer, Fact> cache =
ignite(0).createCache(cacheConfig("stmtSchema", true, Integer.class, Fact.class)
+ .setSqlSchema("\"" + schemaName + "\""));
+
+ assertH2TableAbsent("SCHEMA_INJECTED");
+
+ cache.put(1, new Fact(1, "v"));
+
+ List<List<?>> rows = cache.query(new SqlFieldsQuery(
+ "select f.name from " + quotedSchema + ".Fact f")).getAll();
+
+ assertEquals(1, rows.size());
+ assertEquals("v", rows.get(0).get(0));
+
+ ignite(0).destroyCache(cache.getName());
+
+ assertH2TableAbsent("SCHEMA_INJECTED");
+
+ assertFalse("Schema is not dropped in H2", h2SchemaExists(schemaName));
+ }
+
+ /**
+ * Tests that a table name with a quote does not create TABLE_INJECTED,
+ * a row is readable through that table, and destroying the cache drops
the table.
+ *
+ * @throws Exception If failed.
+ */
+ @Test
+ public void testTableNameWithQuote() throws Exception {
+ startGrid(0);
+
+ String tblName = "A\";CREATE TABLE PUBLIC.TABLE_INJECTED(ID INT);--";
+
+ String quotedTbl = "\"" + tblName.replace("\"", "\"\"") + "\"";
+
+ QueryEntity entity = new QueryEntity()
+ .setTableName(tblName)
+ .setKeyType(Integer.class.getName())
+ .setValueFieldName("name")
+ .setValueType(String.class.getName())
+ .addQueryField("name", String.class.getName(), null);
+
+ IgniteCache<Integer, String> cache = ignite(0).createCache(new
CacheConfiguration<Integer, String>("stmtTable")
+ .setQueryEntities(Collections.singletonList(entity)));
+
+ assertH2TableAbsent("TABLE_INJECTED");
+
+ cache.put(1, "v");
+
+ List<List<?>> rows = cache.query(new SqlFieldsQuery(
+ "select name from " + quotedTbl)).getAll();
+
+ assertEquals(1, rows.size());
+ assertEquals("v", rows.get(0).get(0));
+
+ ignite(0).destroyCache(cache.getName());
+
+ assertH2TableAbsent("TABLE_INJECTED");
+
+ assertFalse("Table is not dropped in H2", h2TableExists(tblName));
+ }
+
+ /**
+ * Tests that creating a cache with this column name does not create
COLUMN_INJECTED,
+ * the index on that column is created, and a row is readable through that
column.
+ *
+ * @throws Exception If failed.
+ */
+ @Test
+ public void testColumnNameWithQuote() throws Exception {
+ startGrid(0);
+
+ String colName = "C\" VARCHAR);CREATE TABLE PUBLIC.COLUMN_INJECTED(ID
INT);--";
+
+ String quotedCol = "\"" + colName.replace("\"", "\"\"") + "\"";
Review Comment:
Ilja, thank you, I have applied those changes
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]