Skip to content

Commit

Permalink
[CONJ-544] adding test case for session reuse
Browse files Browse the repository at this point in the history
  • Loading branch information
rusher committed Jan 14, 2019
1 parent af75571 commit 29eb179
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions src/test/java/org/mariadb/jdbc/SslTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,56 @@ public void testTruststore()
}
}

@Test
public void testNoSessionResumption()
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();
try {
generateKeystoreFromFile(serverCertificatePath, keystorePath, null);

Properties info = new Properties();
info.setProperty("useSSL", "true");
info.setProperty("trustStore", "file://" + keystorePath);

Assume.assumeTrue(haveSsl(sharedConnection) && isMariadbServer());

long sessionsReused = 0;
try (Connection conn = createConnection(info, "ssltestUser", "")) {
// First do a basic select test:
Statement stmt = conn.createStatement();

try (ResultSet 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", true, sslActual);
}

try (ResultSet rs = stmt.executeQuery("SHOW STATUS LIKE 'Ssl_sessions_reused'")) {
assertTrue(rs.next());
sessionsReused = rs.getLong(2);
}

try (Connection conn2 = createConnection(info, "ssltestUser", "")) {
Statement stmt2 = conn2.createStatement();

try (ResultSet rs = stmt2.executeQuery("SHOW STATUS LIKE 'Ssl_sessions_reused'")) {
assertTrue(rs.next());
assertEquals(sessionsReused, rs.getLong(2));
}
}
}
} catch (SQLNonTransientConnectionException nonTransient) {
//java 9 doesn't accept empty keystore
} finally {
tempKeystore.delete();
}
}

@Test
public void testTrustStoreWithPassword()
throws IOException, KeyStoreException, CertificateException, NoSuchAlgorithmException, SQLException {
Expand Down

0 comments on commit 29eb179

Please sign in to comment.