Skip to content
Permalink
Browse files

[CONJ-642] travis correction to permit testing option "rewriteBatched…

…Statements"

(cherry picked from commit ed79b54)
  • Loading branch information...
rusher committed Sep 4, 2018
1 parent ebf3080 commit f25cebbe6c1de2bbb178d79e68b5f3bdb3aef826
Showing with 79 additions and 35 deletions.
  1. +12 −4 src/test/java/org/mariadb/jdbc/ErrorMessageTest.java
  2. +67 −31 src/test/java/org/mariadb/jdbc/SslTest.java
@@ -100,7 +100,9 @@ public void testSmallMultiBatchErrorMessage() throws SQLException {
executeBatchWithException(connection);
fail("Must Have thrown error");
} catch (SQLException sqle) {
if (isMariadbServer() && minVersion(10,2) && sharedOptions().useBulkStmts) {
if ((isMariadbServer() && minVersion(10,2) && sharedOptions().useBulkStmts)
|| sharedOptions().useServerPrepStmts
|| sharedOptions().rewriteBatchedStatements) {
assertTrue("message : " + sqle.getCause().getCause().getMessage(),
sqle.getCause().getCause().getMessage().contains(
"INSERT INTO testErrorMessage(test, test2) values (?, ?)"));
@@ -145,7 +147,9 @@ public void testSmallBulkErrorMessage() throws SQLException {
executeBatchWithException(connection);
fail("Must Have thrown error");
} catch (SQLException sqle) {
if (isMariadbServer() && minVersion(10,2) && sharedOptions().useBulkStmts) {
if ((isMariadbServer() && minVersion(10,2) && sharedOptions().useBulkStmts)
|| sharedOptions().useServerPrepStmts
|| sharedOptions().rewriteBatchedStatements) {
assertTrue("message : " + sqle.getCause().getCause().getMessage(),
sqle.getCause().getCause().getMessage().contains(
"INSERT INTO testErrorMessage(test, test2) values (?, ?)"));
@@ -199,7 +203,9 @@ public void testBigMultiErrorMessage() throws SQLException {
executeBigBatchWithException(connection);
fail("Must Have thrown error");
} catch (SQLException sqle) {
if (isMariadbServer() && minVersion(10,2) && sharedOptions().useBulkStmts) {
if ((isMariadbServer() && minVersion(10,2) && sharedOptions().useBulkStmts)
|| sharedOptions().useServerPrepStmts
|| sharedOptions().rewriteBatchedStatements) {
assertTrue("message : " + sqle.getCause().getCause().getMessage(),
sqle.getCause().getCause().getMessage().contains(
"INSERT INTO testErrorMessage(test, test2) values (?, ?)"));
@@ -254,7 +260,9 @@ public void testBigBulkErrorMessage() throws SQLException {
executeBigBatchWithException(connection);
fail("Must Have thrown error");
} catch (SQLException sqle) {
if (isMariadbServer() && minVersion(10,2) && sharedOptions().useBulkStmts) {
if ((isMariadbServer() && minVersion(10,2) && sharedOptions().useBulkStmts
|| sharedOptions().useServerPrepStmts
|| sharedOptions().rewriteBatchedStatements)) {
assertTrue("message : " + sqle.getCause().getCause().getMessage(),
sqle.getCause().getCause().getMessage().contains(
"INSERT INTO testErrorMessage(test, test2) values (?, ?)"));
@@ -52,13 +52,20 @@

package org.mariadb.jdbc;

import com.sun.jna.Platform;
import org.junit.Assume;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

import java.io.*;
import com.sun.jna.Platform;
import java.io.BufferedReader;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.lang.reflect.Field;
import java.net.InetAddress;
import java.net.UnknownHostException;
@@ -68,12 +75,18 @@
import java.security.cert.Certificate;
import java.security.cert.CertificateException;
import java.security.cert.CertificateFactory;
import java.sql.*;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.SQLNonTransientConnectionException;
import java.sql.Statement;
import java.util.Collection;
import java.util.Properties;
import java.util.UUID;

import static org.junit.Assert.*;
import org.junit.Assume;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;

@SuppressWarnings("ResultOfMethodCallIgnored")
public class SslTest extends BaseTest {
@@ -146,7 +159,7 @@ public void checkSsl() throws SQLException {

@Test
public void useSsl() throws Exception {
Assume.assumeTrue(haveSsl(sharedConnection));
Assume.assumeTrue(haveSsl(sharedConnection) && isMariadbServer());
//Skip SSL test on java 7 since SSL stream size JDK-6521495).
Assume.assumeFalse(System.getProperty("java.version").contains("1.7.")
|| System.getProperty("java.version").contains("1.6."));
@@ -167,7 +180,7 @@ protected void useSslForceTls(String tls) throws Exception {
* Helper method when checking/enabling secure connections for a specific TLS protocol suite.
**/
protected void useSslForceTls(String tls, String ciphers) throws Exception {
Assume.assumeTrue(haveSsl(sharedConnection));
Assume.assumeTrue(haveSsl(sharedConnection) && isMariadbServer());
//Skip SSL test on java 7 since SSL stream size JDK-6521495).
Assume.assumeFalse(System.getProperty("java.version").contains("1.7.")
|| System.getProperty("java.version").contains("1.6."));
@@ -386,6 +399,7 @@ private Connection createConnection(Properties info, String user, String pwd) th
* @throws SQLException exception
*/
public void testConnect(Properties info, boolean sslExpected) throws SQLException {
Assume.assumeTrue(haveSsl(sharedConnection) && isMariadbServer());
testConnect(info, sslExpected, "ssltestUser", "");
}

@@ -399,29 +413,31 @@ public void testConnect(Properties info, boolean sslExpected) throws SQLExceptio
* @throws SQLException if exception occur
*/
public void testConnect(Properties info, boolean sslExpected, String user, String pwd) throws SQLException {
Connection conn = null;
try {
conn = createConnection(info, user, pwd);
// First do a basic select test:
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("SELECT 1");
assertTrue(rs.next());
assertTrue(rs.getInt(1) == 1);

// Then check if SSL matches what is expected
rs = stmt.executeQuery("SHOW STATUS LIKE 'Ssl_cipher'");
assertTrue(rs.next());
String sslCipher = rs.getString(2);
boolean sslActual = sslCipher != null && sslCipher.length() > 0;
assertEquals("sslExpected does not match", sslExpected, sslActual);
} finally {
if (conn != null) conn.close();
}
Assume.assumeTrue(haveSsl(sharedConnection) && isMariadbServer());
Connection conn = null;
try {
conn = createConnection(info, user, pwd);
// First do a basic select test:
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("SELECT 1");
assertTrue(rs.next());
assertTrue(rs.getInt(1) == 1);

// Then check if SSL matches what is expected
rs = stmt.executeQuery("SHOW STATUS LIKE 'Ssl_cipher'");
assertTrue(rs.next());
String sslCipher = rs.getString(2);
boolean sslActual = sslCipher != null && sslCipher.length() > 0;
assertEquals("sslExpected does not match", sslExpected, sslActual);
} finally {
if (conn != null) conn.close();
}

}

@Test
public void testConnectNonSsl() throws SQLException {
Assume.assumeTrue(haveSsl(sharedConnection) && isMariadbServer());
Properties info = new Properties();
try {
testConnect(info, false);
@@ -433,6 +449,7 @@ public void testConnectNonSsl() throws SQLException {

@Test
public void testTrustedServer() throws SQLException {
Assume.assumeTrue(haveSsl(sharedConnection) && isMariadbServer());
Properties info = new Properties();
info.setProperty("useSSL", "true");
info.setProperty("trustServerCertificate", "true");
@@ -441,6 +458,7 @@ public void testTrustedServer() throws SQLException {

@Test
public void testServerCertString() throws SQLException {
Assume.assumeTrue(haveSsl(sharedConnection) && isMariadbServer());
Assume.assumeTrue(hasSameHost());
Properties info = new Properties();
info.setProperty("useSSL", "true");
@@ -450,6 +468,7 @@ public void testServerCertString() throws SQLException {

@Test(expected = SQLException.class)
public void testBadServerCertString() throws SQLException {
Assume.assumeTrue(haveSsl(sharedConnection) && isMariadbServer());
Properties info = new Properties();
info.setProperty("useSSL", "true");
info.setProperty("serverSslCert", "foobar");
@@ -458,6 +477,7 @@ public void testBadServerCertString() throws SQLException {

@Test
public void testServerCertFile() throws SQLException {
Assume.assumeTrue(haveSsl(sharedConnection) && isMariadbServer());
Assume.assumeTrue(hasSameHost());
Properties info = new Properties();
info.setProperty("useSSL", "true");
@@ -467,6 +487,7 @@ public void testServerCertFile() throws SQLException {

@Test
public void testServerCertClasspathFile() throws SQLException {
Assume.assumeTrue(haveSsl(sharedConnection) && isMariadbServer());
Assume.assumeTrue(hasSameHost());
Assume.assumeTrue(new File("target/classes").isDirectory());
Properties info = new Properties();
@@ -487,7 +508,8 @@ public void testWrongServerCert() throws Throwable {
}

@Test
public void conc71() {
public void conc71() throws SQLException {
Assume.assumeTrue(haveSsl(sharedConnection) && isMariadbServer());
Assume.assumeTrue(hasSameHost());
try {
Properties info = new Properties();
@@ -508,6 +530,7 @@ public void conc71() {
@Test
public void testTruststore() throws SQLException, IOException, KeyStoreException, CertificateException, NoSuchAlgorithmException {
Assume.assumeTrue(hasSameHost());
Assume.assumeTrue(haveSsl(sharedConnection) && isMariadbServer());
// generate a truststore from the canned serverCertificate
File tempKeystore = File.createTempFile("keystore", ".tmp");
String keystorePath = tempKeystore.getAbsolutePath();
@@ -528,6 +551,7 @@ public void testTruststore() throws SQLException, IOException, KeyStoreException
@Test
public void testTrustStoreWithPassword() throws IOException, KeyStoreException, CertificateException, NoSuchAlgorithmException, SQLException {
Assume.assumeTrue(hasSameHost());
Assume.assumeTrue(haveSsl(sharedConnection) && isMariadbServer());
// generate a truststore from the canned serverCertificate
File tempKeystore = File.createTempFile("keystore", ".tmp");
String keystorePath = tempKeystore.getAbsolutePath();
@@ -547,6 +571,7 @@ public void testTrustStoreWithPassword() throws IOException, KeyStoreException,
@Test
public void testTrustStoreWithPasswordProperties() throws Exception {
Assume.assumeTrue(hasSameHost());
Assume.assumeTrue(haveSsl(sharedConnection) && isMariadbServer());
// generate a truststore from the canned serverCertificate
File tempKeystore = File.createTempFile("keystore", ".tmp");
String keystorePath = tempKeystore.getAbsolutePath();
@@ -583,6 +608,7 @@ public void testTrustStoreWithPasswordProperties() throws Exception {
public void testTruststoreWithWrongPassword() throws IOException, KeyStoreException, CertificateException, NoSuchAlgorithmException,
SQLException {
Assume.assumeTrue(hasSameHost());
Assume.assumeTrue(haveSsl(sharedConnection) && isMariadbServer());
// generate a truststore from the canned serverCertificate
File tempKeystore = File.createTempFile("keystore", ".tmp");
String keystorePath = tempKeystore.getAbsolutePath();
@@ -601,6 +627,7 @@ public void testTruststoreWithWrongPassword() throws IOException, KeyStoreExcept

@Test(expected = SQLException.class)
public void testTruststoreWithWrongCert() throws IOException, KeyStoreException, CertificateException, NoSuchAlgorithmException, SQLException {
Assume.assumeTrue(haveSsl(sharedConnection) && isMariadbServer());
// generate a truststore from the canned serverCertificate
File tempKeystore = File.createTempFile("keystore", ".tmp");
String keystorePath = tempKeystore.getAbsolutePath();
@@ -620,6 +647,7 @@ public void testTruststoreWithWrongCert() throws IOException, KeyStoreException,
@Test
public void testTruststoreAndClientKeystore() throws SQLException, IOException, KeyStoreException, CertificateException,
NoSuchAlgorithmException {
Assume.assumeTrue(haveSsl(sharedConnection) && isMariadbServer());
// This test only runs if a client keystore and password have been passed in as properties (-DkeystorePath and -DkeystorePassword)
// You can create a keystore as follows:
// echo "kspass" | openssl pkcs12 -export -in "${clientCertFile}" -inkey "${clientKeyFile}" -out "${clientKeystoreFile}"
@@ -654,6 +682,7 @@ public void testTruststoreAndClientKeystore() throws SQLException, IOException,
@Test
public void testAliases() throws SQLException, IOException, KeyStoreException, CertificateException,
NoSuchAlgorithmException {
Assume.assumeTrue(haveSsl(sharedConnection) && isMariadbServer());
// This test only runs if a client keystore and password have been passed in as properties (-DkeystorePath and -DkeystorePassword)
// You can create a keystore as follows:
// echo "kspass" | openssl pkcs12 -export -in "${clientCertFile}" -inkey "${clientKeyFile}" -out "${clientKeystoreFile}"
@@ -685,7 +714,8 @@ public void testAliases() throws SQLException, IOException, KeyStoreException, C


@Test
public void testClientKeystore() throws SQLException, IOException, KeyStoreException, CertificateException, NoSuchAlgorithmException {
public void testClientKeystore() throws SQLException {
Assume.assumeTrue(haveSsl(sharedConnection) && isMariadbServer());
// This test only runs if a client keystore and password have been passed in as properties (-DkeystorePath and -DkeystorePassword)
// You can create a keystore as follows:
// echo "kspass" | openssl pkcs12 -export -in "${clientCertFile}" -inkey "${clientKeyFile}" -out "${clientKeystoreFile}"
@@ -715,6 +745,7 @@ public void testClientKeystore() throws SQLException, IOException, KeyStoreExcep
*/
@Test
public void testClientKeyStoreWithPrivateKeyPwd() throws Exception {
Assume.assumeTrue(haveSsl(sharedConnection) && isMariadbServer());
String clientKeyStore2Path = System.getProperty("keystore2Path");
String clientKeyStore2Password = System.getProperty("keystore2Password");
String clientKeyPassword = System.getProperty("keyPassword");
@@ -760,6 +791,7 @@ public void testClientKeyStoreWithPrivateKeyPwd() throws Exception {
*/
@Test
public void testClientKeyStorePkcs12() throws Exception {
Assume.assumeTrue(haveSsl(sharedConnection) && isMariadbServer());
String clientKeyStore2Path = System.getProperty("keystore2PathP12");
String clientKeyStore2Password = System.getProperty("keystore2Password");
Assume.assumeTrue(clientKeyStore2Password != null && clientKeyStore2Path != null);
@@ -782,6 +814,7 @@ public void testClientKeyStorePkcs12() throws Exception {

@Test
public void testKeyStoreWithProperties() throws Exception {
Assume.assumeTrue(haveSsl(sharedConnection) && isMariadbServer());
Assume.assumeNotNull(clientKeystorePath);
// generate a trustStore from the canned serverCertificate
File tempKeystore = File.createTempFile("keystore", ".tmp");
@@ -834,6 +867,7 @@ public void testKeyStoreWithProperties() throws Exception {

@Test
public void testKeyStoreWhenServerTrustedWithProperties() throws Exception {
Assume.assumeTrue(haveSsl(sharedConnection) && isMariadbServer());
Assume.assumeNotNull(clientKeystorePath);
// generate a trustStore from the canned serverCertificate
File tempKeystore = File.createTempFile("keystore", ".tmp");
@@ -885,6 +919,7 @@ public void testKeyStoreWhenServerTrustedWithProperties() throws Exception {

@Test
public void testClientKeyStoreProperties() throws SQLException, IOException, KeyStoreException, CertificateException, NoSuchAlgorithmException {
Assume.assumeTrue(haveSsl(sharedConnection) && isMariadbServer());
// This test only runs if a client keystore and password have been passed in as properties (-DkeystorePath and -DkeystorePassword)
// You can create a keystore as follows:
// echo "kspass" | openssl pkcs12 -export -in "${clientCertFile}" -inkey "${clientKeyFile}" -out "${clientKeystoreFile}"
@@ -930,6 +965,7 @@ public void testClientKeyStoreProperties() throws SQLException, IOException, Key
@Test(expected = SQLException.class)
public void testTruststoreAndClientKeystoreWrongPassword() throws SQLException, IOException, KeyStoreException, CertificateException,
NoSuchAlgorithmException {
Assume.assumeTrue(haveSsl(sharedConnection) && isMariadbServer());
// This test only runs if a client keystore and password have been passed in as properties (-DkeystorePath and -DkeystorePassword)
// You can create a keystore as follows:
// echo "kspass" | openssl pkcs12 -export -in "${clientCertFile}" -inkey "${clientKeyFile}"

0 comments on commit f25cebb

Please sign in to comment.
You can’t perform that action at this time.