Search in sources :

Example 1 with JdbcPropertySet

use of com.mysql.cj.jdbc.JdbcPropertySet in project aws-mysql-jdbc by awslabs.

the class ConnectionTest method testSslConnectionOptions.

/**
 * Tests that given SSL/TLS related connection properties values are processed as expected.
 *
 * @throws Exception
 */
@Test
public void testSslConnectionOptions() throws Exception {
    assumeTrue((((MysqlConnection) this.conn).getSession().getServerSession().getCapabilities().getCapabilityFlags() & NativeServerSession.CLIENT_SSL) != 0, "This test requires server with SSL support.");
    assumeTrue(supportsTLSv1_2(((MysqlConnection) this.conn).getSession().getServerSession().getServerVersion()), "This test requires server with TLSv1.2+ support.");
    assumeTrue(supportsTestCertificates(this.stmt), "This test requires the server configured with SSL certificates from ConnectorJ/src/test/config/ssl-test-certs");
    Connection testConn;
    JdbcPropertySet propSet;
    testConn = getConnectionWithProps(this.sslFreeBaseUrl, "");
    propSet = ((JdbcConnection) testConn).getPropertySet();
    assertEquals(SslMode.PREFERRED, propSet.getProperty(PropertyKey.sslMode).getValue());
    assertNull(propSet.getProperty(PropertyKey.trustCertificateKeyStoreUrl).getValue());
    assertEquals("JKS", propSet.getProperty(PropertyKey.trustCertificateKeyStoreType).getValue());
    assertNull(propSet.getProperty(PropertyKey.trustCertificateKeyStorePassword).getValue());
    assertTrue(propSet.getBooleanProperty(PropertyKey.fallbackToSystemTrustStore).getValue());
    assertNull(propSet.getProperty(PropertyKey.clientCertificateKeyStoreUrl).getValue());
    assertEquals("JKS", propSet.getProperty(PropertyKey.clientCertificateKeyStoreType).getValue());
    assertNull(propSet.getProperty(PropertyKey.clientCertificateKeyStorePassword).getValue());
    assertTrue(propSet.getBooleanProperty(PropertyKey.fallbackToSystemKeyStore).getValue());
    testConn.close();
    Properties props = new Properties();
    props.setProperty(PropertyKey.sslMode.getKeyName(), SslMode.DISABLED.toString());
    props.setProperty(PropertyKey.trustCertificateKeyStoreUrl.getKeyName(), "trust-cert-keystore-url");
    props.setProperty(PropertyKey.trustCertificateKeyStoreType.getKeyName(), "trust-cert-keystore-type");
    props.setProperty(PropertyKey.trustCertificateKeyStorePassword.getKeyName(), "trust-cert-keystore-pwd");
    props.setProperty(PropertyKey.fallbackToSystemTrustStore.getKeyName(), "false");
    props.setProperty(PropertyKey.clientCertificateKeyStoreUrl.getKeyName(), "client-cert-keystore-url");
    props.setProperty(PropertyKey.clientCertificateKeyStoreType.getKeyName(), "client-cert-keystore-type");
    props.setProperty(PropertyKey.clientCertificateKeyStorePassword.getKeyName(), "client-cert-keystore-pwd");
    props.setProperty(PropertyKey.fallbackToSystemKeyStore.getKeyName(), "false");
    testConn = getConnectionWithProps(this.sslFreeBaseUrl, props);
    propSet = ((JdbcConnection) testConn).getPropertySet();
    assertEquals(SslMode.DISABLED, propSet.getProperty(PropertyKey.sslMode).getValue());
    assertEquals("trust-cert-keystore-url", propSet.getProperty(PropertyKey.trustCertificateKeyStoreUrl).getValue());
    assertEquals("trust-cert-keystore-type", propSet.getProperty(PropertyKey.trustCertificateKeyStoreType).getValue());
    assertEquals("trust-cert-keystore-pwd", propSet.getProperty(PropertyKey.trustCertificateKeyStorePassword).getValue());
    assertFalse(propSet.getBooleanProperty(PropertyKey.fallbackToSystemTrustStore).getValue());
    assertEquals("client-cert-keystore-url", propSet.getProperty(PropertyKey.clientCertificateKeyStoreUrl).getValue());
    assertEquals("client-cert-keystore-type", propSet.getProperty(PropertyKey.clientCertificateKeyStoreType).getValue());
    assertEquals("client-cert-keystore-pwd", propSet.getProperty(PropertyKey.clientCertificateKeyStorePassword).getValue());
    assertFalse(propSet.getBooleanProperty(PropertyKey.fallbackToSystemKeyStore).getValue());
    testConn.close();
    props.setProperty(PropertyKey.fallbackToSystemTrustStore.getKeyName(), "true");
    props.setProperty(PropertyKey.fallbackToSystemKeyStore.getKeyName(), "true");
    testConn = getConnectionWithProps(this.sslFreeBaseUrl, props);
    propSet = ((JdbcConnection) testConn).getPropertySet();
    assertEquals(SslMode.DISABLED, propSet.getProperty(PropertyKey.sslMode).getValue());
    assertEquals("trust-cert-keystore-url", propSet.getProperty(PropertyKey.trustCertificateKeyStoreUrl).getValue());
    assertEquals("trust-cert-keystore-type", propSet.getProperty(PropertyKey.trustCertificateKeyStoreType).getValue());
    assertEquals("trust-cert-keystore-pwd", propSet.getProperty(PropertyKey.trustCertificateKeyStorePassword).getValue());
    assertTrue(propSet.getBooleanProperty(PropertyKey.fallbackToSystemTrustStore).getValue());
    assertEquals("client-cert-keystore-url", propSet.getProperty(PropertyKey.clientCertificateKeyStoreUrl).getValue());
    assertEquals("client-cert-keystore-type", propSet.getProperty(PropertyKey.clientCertificateKeyStoreType).getValue());
    assertEquals("client-cert-keystore-pwd", propSet.getProperty(PropertyKey.clientCertificateKeyStorePassword).getValue());
    assertTrue(propSet.getBooleanProperty(PropertyKey.fallbackToSystemKeyStore).getValue());
    testConn.close();
}
Also used : Connection(java.sql.Connection) JdbcConnection(com.mysql.cj.jdbc.JdbcConnection) MysqlConnection(com.mysql.cj.MysqlConnection) MysqlConnection(com.mysql.cj.MysqlConnection) Properties(java.util.Properties) JdbcPropertySet(com.mysql.cj.jdbc.JdbcPropertySet) Test(org.junit.jupiter.api.Test)

Example 2 with JdbcPropertySet

use of com.mysql.cj.jdbc.JdbcPropertySet in project aws-mysql-jdbc by awslabs.

the class FailoverConnectionPluginTest method initFailoverPlugin.

private FailoverConnectionPlugin initFailoverPlugin(Properties properties) throws SQLException {
    final JdbcPropertySet propertySet = new JdbcPropertySetImpl();
    propertySet.initializeProperties(properties);
    when(mockConnection.getPropertySet()).thenReturn(propertySet);
    return new FailoverConnectionPlugin(mockCurrentConnectionProvider, propertySet, mockNextPlugin, mockLogger, mockConnectionProvider, () -> mockTopologyService, () -> mockClusterMetricContainer);
}
Also used : JdbcPropertySet(com.mysql.cj.jdbc.JdbcPropertySet) JdbcPropertySetImpl(com.mysql.cj.jdbc.JdbcPropertySetImpl)

Aggregations

JdbcPropertySet (com.mysql.cj.jdbc.JdbcPropertySet)2 MysqlConnection (com.mysql.cj.MysqlConnection)1 JdbcConnection (com.mysql.cj.jdbc.JdbcConnection)1 JdbcPropertySetImpl (com.mysql.cj.jdbc.JdbcPropertySetImpl)1 Connection (java.sql.Connection)1 Properties (java.util.Properties)1 Test (org.junit.jupiter.api.Test)1