SOLR-8184: Negative tests for JDBC Connection String

This commit is contained in:
Kevin Risden 2016-05-06 08:39:00 -05:00
parent 66fc6aaf8d
commit 732e7e80c6
3 changed files with 27 additions and 2 deletions

View File

@ -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 release

View File

@ -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());
}
@Test
public void testProcessUrl() throws Exception {
DriverImpl driver = new DriverImpl();

View File

@ -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 {
@Test
public void testErrorPropagation() throws Exception {
//Test error propagation
Properties 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