Skip to content
Permalink
Browse files

[misc] correcting ssl test

(cherry picked from commit 0badaec)
  • Loading branch information...
rusher committed Sep 6, 2018
1 parent 7df7884 commit ba9b3c8d4b83fe05f7b8f6b844d5df43e94c3393
Showing with 46 additions and 44 deletions.
  1. +46 −44 src/test/java/org/mariadb/jdbc/SslTest.java
@@ -109,53 +109,55 @@ public static void enableCrypto() {
}
}

/**
* Check requirement.
*
* @throws SQLException exception exception
*/
@Before
public void checkSsl() throws SQLException {
//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."));
cancelForVersion(5, 6, 36); //has SSL issues with client authentication.
Assume.assumeTrue(haveSsl(sharedConnection));
try {
InetAddress.getByName("mariadb.example.com").isReachable(3);
} catch (UnknownHostException hostException) {
throw new SQLException("SSL test canceled, database host must be set has "
+ "\"mariadb.example.com\" to permit SSL certificate Host verification");
} catch (IOException ioe) {
/**
* Check requirement.
*
* @throws SQLException exception exception
*/
@Before
public void checkSsl() throws SQLException {
//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."));
cancelForVersion(5, 6, 36); //has SSL issues with client authentication.
Assume.assumeTrue(haveSsl(sharedConnection));
try {
InetAddress.getByName("mariadb.example.com").isReachable(3);
} catch (UnknownHostException hostException) {
throw new SQLException("SSL test canceled, database host must be set has "
+ "\"mariadb.example.com\" to permit SSL certificate Host verification");
} catch (IOException ioe) {

}
}

if (System.getProperty("serverCertificatePath") == null) {
ResultSet rs = sharedConnection.createStatement().executeQuery("select @@ssl_cert");
assertTrue(rs.next());
serverCertificatePath = rs.getString(1);
} else {
serverCertificatePath = System.getProperty("serverCertificatePath");
}
clientKeystorePath = System.getProperty("keystorePath");
clientKeystorePassword = System.getProperty("keystorePassword");
Statement stmt = sharedConnection.createStatement();
try {
stmt.execute("DROP USER 'ssltestUser'@'%'");
} catch (SQLException e) {
}
boolean useOldNotation = true;
if ((isMariadbServer() && minVersion(10,2,0)) || (!isMariadbServer() && minVersion(8,0,0))) {
useOldNotation = false;
}
if (useOldNotation) {
stmt.execute("CREATE USER 'ssltestUser'@'%'");
stmt.execute("GRANT ALL PRIVILEGES ON *.* TO 'ssltestUser'@'%' REQUIRE SSL");
} else {
stmt.execute("CREATE USER 'ssltestUser'@'%' REQUIRE SSL");
stmt.execute("GRANT ALL PRIVILEGES ON *.* TO 'ssltestUser'@'%'");
}
if (System.getProperty("serverCertificatePath") == null) {
ResultSet rs = sharedConnection.createStatement().executeQuery("select @@ssl_cert");
assertTrue(rs.next());
serverCertificatePath = rs.getString(1);
} else {
serverCertificatePath = System.getProperty("serverCertificatePath");
}
clientKeystorePath = System.getProperty("keystorePath");
clientKeystorePassword = System.getProperty("keystorePassword");
Statement stmt = sharedConnection.createStatement();
try {
stmt.execute("DROP USER 'ssltestUser'@'%'");
} catch (SQLException e) {
//eat
}
boolean useOldNotation = true;
if ((isMariadbServer() && minVersion(10, 2, 0)) || (!isMariadbServer() && minVersion(8, 0,
0))) {
useOldNotation = false;
}
if (useOldNotation) {
stmt.execute("CREATE USER 'ssltestUser'@'%'");
stmt.execute("GRANT ALL PRIVILEGES ON *.* TO 'ssltestUser'@'%' REQUIRE SSL");
} else {
stmt.execute("CREATE USER 'ssltestUser'@'%' REQUIRE SSL");
stmt.execute("GRANT ALL PRIVILEGES ON *.* TO 'ssltestUser'@'%'");
}
}

@Test
public void useSsl() throws Exception {

0 comments on commit ba9b3c8

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