Apache Solr open-source search software
SOLR-8184: Negative tests for JDBC Connection String
Kevin Risden732e7e80c6fc
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txtindex 5df62e50374..6fbc11b611f 100644--- a/solr/CHANGES.txt+++ b/solr/CHANGES.txt@@ -256,10 +256,12 @@ Other Changes* SOLR-9053: Upgrade commons-fileupload to 1.3.1, fixing a potential vulnerability (Jeff Field, Mike Drob via janhoy)-* SOLR-9066 Make CountMetric return long instead of double (Kevin Risden)+* SOLR-9066: Make CountMetric return long instead of double (Kevin Risden)* SOLR-9065: Migrate SolrJ distributed tests to SolrCloudTestCase. (Alan Woodward)+* SOLR-8184: Negative tests for JDBC Connection String (Susheel Kumar, Jason Gerlowski, Kevin Risden)+================== 6.0.0 ==================Consult the LUCENE_CHANGES.txt file for additional, low level, changes in this releasediff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/io/sql/JdbcDriverTest.java b/solr/solrj/src/test/org/apache/solr/client/solrj/io/sql/JdbcDriverTest.javaindex 3b2d0895ef5..e9e262c11d2 100644--- a/solr/solrj/src/test/org/apache/solr/client/solrj/io/sql/JdbcDriverTest.java+++ b/solr/solrj/src/test/org/apache/solr/client/solrj/io/sql/JdbcDriverTest.java@@ -54,6 +54,12 @@ public class JdbcDriverTest extends SolrTestCaseJ4 {Connection con = DriverManager.getConnection("jdbc:solr://", new Properties());}+ @Test(expected = SQLException.class)+ public void testConnectionStringJumbled() throws Exception {+ final String sampleZkHost="zoo1:9983/foo";+ DriverManager.getConnection("solr:jdbc://" + sampleZkHost + "?collection=collection1", new Properties());+ }+@Testpublic void testProcessUrl() throws Exception {DriverImpl driver = new DriverImpl();diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/io/sql/JdbcTest.java b/solr/solrj/src/test/org/apache/solr/client/solrj/io/sql/JdbcTest.javaindex 1829c70f54a..728a24bef2c 100644--- a/solr/solrj/src/test/org/apache/solr/client/solrj/io/sql/JdbcTest.java+++ b/solr/solrj/src/test/org/apache/solr/client/solrj/io/sql/JdbcTest.java@@ -22,6 +22,7 @@ import java.sql.DriverManager;import java.sql.PreparedStatement;import java.sql.ResultSet;import java.sql.ResultSetMetaData;+import java.sql.SQLException;import java.sql.Statement;import java.sql.Types;import java.util.ArrayList;@@ -398,7 +399,6 @@ public class JdbcTest extends SolrCloudTestCase {@Testpublic void testErrorPropagation() throws Exception {-//Test error propagationProperties props = new Properties();props.put("aggregationMode", "facet");@@ -412,7 +412,24 @@ public class JdbcTest extends SolrCloudTestCase {}}}+ }+ @Test+ public void testSQLExceptionThrownWhenQueryAndConnUseDiffCollections() throws Exception {+ String badCollection = COLLECTION + "bad";+ String connectionString = "jdbc:solr://" + zkHost + "?collection=" + badCollection;+ String sql = "select id, a_i, a_s, a_f from " + badCollection + " order by a_i desc limit 2";++ //Bad connection string: wrong collection name+ try(Connection connection = DriverManager.getConnection(connectionString)) {+ try (Statement statement = connection.createStatement()) {+ try (ResultSet ignored = statement.executeQuery(sql)) {+ fail("Expected query against wrong collection to throw a SQLException.");+ }+ }+ } catch (SQLException ignore) {+ // Expected exception due to miss matched collection+ }}@Test