kikocis/java-driver public
Changesets · Branches · Tags · Compare
| Changeset | bf4830f0f22974e4515a4457644e4730520f1cbecd9de2683da4b59cf7db8330 |
|---|---|
| Author | Andrew Tolbert <andrew.tolbert@datastax.com> · 2015-11-03 06:55 -06:00 |
| Committer | olim7t <omichallat+github@gmail.com> · 2015-11-05 18:55 +01:00 |
| Parents | c9eb91bc7496 |
4 files changed
modified driver-core/src/test/java/com/datastax/driver/core/CCMBridge.java +4 −0
| @@ -60,9 +60,13 @@ | ||
| 60 | 60 | public static final String DEFAULT_CLIENT_TRUSTSTORE_PASSWORD = "cassandra1sfun"; |
| 61 | 61 | public static final String DEFAULT_CLIENT_TRUSTSTORE_PATH = "/client.truststore"; |
| 62 | 62 | |
| 63 | + public static final File DEFAULT_CLIENT_TRUSTSTORE_FILE = createTempStore(DEFAULT_CLIENT_TRUSTSTORE_PATH); | |
| 64 | + | |
| 63 | 65 | public static final String DEFAULT_CLIENT_KEYSTORE_PASSWORD = "cassandra1sfun"; |
| 64 | 66 | public static final String DEFAULT_CLIENT_KEYSTORE_PATH = "/client.keystore"; |
| 65 | 67 | |
| 68 | + public static final File DEFAULT_CLIENT_KEYSTORE_FILE = createTempStore(DEFAULT_CLIENT_KEYSTORE_PATH); | |
| 69 | + | |
| 66 | 70 | public static final String DEFAULT_SERVER_TRUSTSTORE_PASSWORD = "cassandra1sfun"; |
| 67 | 71 | public static final String DEFAULT_SERVER_TRUSTSTORE_PATH = "/server.truststore"; |
| 68 | 72 |
modified driver-core/src/test/java/com/datastax/driver/core/SSLAuthenticatedEncryptionTest.java +23 −2
| @@ -20,8 +20,7 @@ | ||
| 20 | 20 | |
| 21 | 21 | import com.datastax.driver.core.exceptions.NoHostAvailableException; |
| 22 | 22 | |
| 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.*; | |
| 25 | 24 | |
| 26 | 25 | public class SSLAuthenticatedEncryptionTest extends SSLTestBase { |
| 27 | 26 | |
| @@ -59,4 +58,26 @@ | ||
| 59 | 58 | public void should_not_connect_without_client_auth_but_node_requires_auth() throws Exception { |
| 60 | 59 | connectWithSSLOptions(getSSLOptions(Optional.<String>absent(), Optional.of(DEFAULT_CLIENT_TRUSTSTORE_PATH))); |
| 61 | 60 | } |
| 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 | + } | |
| 62 | 83 | } |
modified driver-core/src/test/java/com/datastax/driver/core/SSLEncryptionTest.java +21 −2
| @@ -23,8 +23,7 @@ | ||
| 23 | 23 | import com.datastax.driver.core.exceptions.NoHostAvailableException; |
| 24 | 24 | |
| 25 | 25 | 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.*; | |
| 28 | 27 | |
| 29 | 28 | public class SSLEncryptionTest extends SSLTestBase { |
| 30 | 29 | |
| @@ -118,4 +117,24 @@ | ||
| 118 | 117 | cluster.close(); |
| 119 | 118 | } |
| 120 | 119 | } |
| 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 | + } | |
| 121 | 140 | } |
modified driver-core/src/test/java/com/datastax/driver/core/SSLTestBase.java +36 −0
| @@ -25,7 +25,9 @@ | ||
| 25 | 25 | import org.testng.annotations.AfterClass; |
| 26 | 26 | import org.testng.annotations.BeforeClass; |
| 27 | 27 | |
| 28 | +import static com.datastax.driver.core.CCMBridge.DEFAULT_CLIENT_KEYSTORE_FILE; | |
| 28 | 29 | import static com.datastax.driver.core.CCMBridge.DEFAULT_CLIENT_KEYSTORE_PASSWORD; |
| 30 | +import static com.datastax.driver.core.CCMBridge.DEFAULT_CLIENT_TRUSTSTORE_FILE; | |
| 29 | 31 | import static com.datastax.driver.core.CCMBridge.DEFAULT_CLIENT_TRUSTSTORE_PASSWORD; |
| 30 | 32 | public abstract class SSLTestBase { |
| 31 | 33 | |
| @@ -74,6 +76,40 @@ | ||
| 74 | 76 | } |
| 75 | 77 | } |
| 76 | 78 | |
| 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 | + | |
| 77 | 113 | /** |
| 78 | 114 | * @param keyStorePath Path to keystore, if absent is not used. |
| 79 | 115 | * @param trustStorePath Path to truststore, if absent is not used. |