Elffuss BraidHub

kikocis/java-driver public

Add tests for configuring SSL via javax.net.ssl.* System Properties.
Changesetbf4830f0f22974e4515a4457644e4730520f1cbecd9de2683da4b59cf7db8330
AuthorAndrew Tolbert <andrew.tolbert@datastax.com> · 2015-11-03 06:55 -06:00
Committerolim7t <omichallat+github@gmail.com> · 2015-11-05 18:55 +01:00
Parentsc9eb91bc7496

Browse the files at this changeset

4 files changed

modified driver-core/src/test/java/com/datastax/driver/core/CCMBridge.java +4 −0
@@ -60,9 +60,13 @@
6060 public static final String DEFAULT_CLIENT_TRUSTSTORE_PASSWORD = "cassandra1sfun";
6161 public static final String DEFAULT_CLIENT_TRUSTSTORE_PATH = "/client.truststore";
6262
63+ public static final File DEFAULT_CLIENT_TRUSTSTORE_FILE = createTempStore(DEFAULT_CLIENT_TRUSTSTORE_PATH);
64+
6365 public static final String DEFAULT_CLIENT_KEYSTORE_PASSWORD = "cassandra1sfun";
6466 public static final String DEFAULT_CLIENT_KEYSTORE_PATH = "/client.keystore";
6567
68+ public static final File DEFAULT_CLIENT_KEYSTORE_FILE = createTempStore(DEFAULT_CLIENT_KEYSTORE_PATH);
69+
6670 public static final String DEFAULT_SERVER_TRUSTSTORE_PASSWORD = "cassandra1sfun";
6771 public static final String DEFAULT_SERVER_TRUSTSTORE_PATH = "/server.truststore";
6872
modified driver-core/src/test/java/com/datastax/driver/core/SSLAuthenticatedEncryptionTest.java +23 −2
@@ -20,8 +20,7 @@
2020
2121 import com.datastax.driver.core.exceptions.NoHostAvailableException;
2222
23-import static com.datastax.driver.core.CCMBridge.DEFAULT_CLIENT_KEYSTORE_PATH;
24-import static com.datastax.driver.core.CCMBridge.DEFAULT_CLIENT_TRUSTSTORE_PATH;
23+import static com.datastax.driver.core.CCMBridge.*;
2524
2625 public class SSLAuthenticatedEncryptionTest extends SSLTestBase {
2726
@@ -59,4 +58,26 @@
5958 public void should_not_connect_without_client_auth_but_node_requires_auth() throws Exception {
6059 connectWithSSLOptions(getSSLOptions(Optional.<String>absent(), Optional.of(DEFAULT_CLIENT_TRUSTSTORE_PATH)));
6160 }
61+
62+ /**
63+ * <p>
64+ * Validates that SSL connectivity can be configured via the standard javax.net.ssl System properties.
65+ * </p>
66+ *
67+ * @test_category connection:ssl, authentication
68+ * @expected_result Connection can be established.
69+ */
70+ @Test(groups="short")
71+ public void should_use_system_properties_with_default_ssl_options() throws Exception {
72+ try {
73+ System.setProperty("javax.net.ssl.keyStore", DEFAULT_CLIENT_KEYSTORE_FILE.getAbsolutePath());
74+ System.setProperty("javax.net.ssl.keyStorePassword", DEFAULT_CLIENT_KEYSTORE_PASSWORD);
75+ System.setProperty("javax.net.ssl.trustStore", DEFAULT_CLIENT_TRUSTSTORE_FILE.getAbsolutePath());
76+ System.setProperty("javax.net.ssl.trustStorePassword", DEFAULT_CLIENT_TRUSTSTORE_PASSWORD);
77+
78+ connectWithSSL();
79+ } finally {
80+ clearSystemProperties();
81+ }
82+ }
6283 }
modified driver-core/src/test/java/com/datastax/driver/core/SSLEncryptionTest.java +21 −2
@@ -23,8 +23,7 @@
2323 import com.datastax.driver.core.exceptions.NoHostAvailableException;
2424
2525 import static com.datastax.driver.core.Assertions.assertThat;
26-import static com.datastax.driver.core.CCMBridge.DEFAULT_CLIENT_KEYSTORE_PATH;
27-import static com.datastax.driver.core.CCMBridge.DEFAULT_CLIENT_TRUSTSTORE_PATH;
26+import static com.datastax.driver.core.CCMBridge.*;
2827
2928 public class SSLEncryptionTest extends SSLTestBase {
3029
@@ -118,4 +117,24 @@
118117 cluster.close();
119118 }
120119 }
120+
121+ /**
122+ * <p>
123+ * Validates that SSL connectivity can be configured via the standard javax.net.ssl System properties.
124+ * </p>
125+ *
126+ * @test_category connection:ssl
127+ * @expected_result Connection can be established.
128+ */
129+ @Test(groups="short")
130+ public void should_use_system_properties_with_default_ssl_options() throws Exception {
131+ try {
132+ System.setProperty("javax.net.ssl.trustStore", DEFAULT_CLIENT_TRUSTSTORE_FILE.getAbsolutePath());
133+ System.setProperty("javax.net.ssl.trustStorePassword", DEFAULT_CLIENT_TRUSTSTORE_PASSWORD);
134+
135+ connectWithSSL();
136+ } finally {
137+ clearSystemProperties();
138+ }
139+ }
121140 }
modified driver-core/src/test/java/com/datastax/driver/core/SSLTestBase.java +36 −0
@@ -25,7 +25,9 @@
2525 import org.testng.annotations.AfterClass;
2626 import org.testng.annotations.BeforeClass;
2727
28+import static com.datastax.driver.core.CCMBridge.DEFAULT_CLIENT_KEYSTORE_FILE;
2829 import static com.datastax.driver.core.CCMBridge.DEFAULT_CLIENT_KEYSTORE_PASSWORD;
30+import static com.datastax.driver.core.CCMBridge.DEFAULT_CLIENT_TRUSTSTORE_FILE;
2931 import static com.datastax.driver.core.CCMBridge.DEFAULT_CLIENT_TRUSTSTORE_PASSWORD;
3032 public abstract class SSLTestBase {
3133
@@ -74,6 +76,40 @@
7476 }
7577 }
7678
79+ /**
80+ * <p>
81+ * Attempts to connect to a cassandra cluster with using {@link Cluster.Builder#withSSL} with no
82+ * provided {@link SSLOptions} and then closes the created {@link Cluster} instance.
83+ * </p>
84+ *
85+ * @throws Exception A {@link com.datastax.driver.core.exceptions.NoHostAvailableException} will be
86+ * raised here if connection cannot be established.
87+ */
88+ protected void connectWithSSL() throws Exception {
89+ Cluster cluster = null;
90+ try {
91+ cluster = Cluster.builder()
92+ .addContactPoint(CCMBridge.IP_PREFIX + '1')
93+ .withSSL()
94+ .build();
95+
96+ cluster.connect();
97+ } finally {
98+ if (cluster != null)
99+ cluster.close();
100+ }
101+ }
102+
103+ /**
104+ * Clears all System properties associated with SSL key and trust stores.
105+ */
106+ protected void clearSystemProperties() {
107+ System.clearProperty("javax.net.ssl.keyStore");
108+ System.clearProperty("javax.net.ssl.keyStorePassword");
109+ System.clearProperty("javax.net.ssl.trustStore");
110+ System.clearProperty("javax.net.ssl.trustStorePassword");
111+ }
112+
77113 /**
78114 * @param keyStorePath Path to keystore, if absent is not used.
79115 * @param trustStorePath Path to truststore, if absent is not used.