kikocis/java-driver public
Changesets · Branches · Tags · Compare
| Changeset | cd86ebbd4272b2e273ae967b6700af5646d8c9ed06c421ea4b00b9c10532ac74 |
|---|---|
| Author | olim7t <omichallat+github@gmail.com> · 2015-11-13 20:50 +01:00 |
| Committer | olim7t <omichallat+github@gmail.com> · 2015-11-13 20:50 +01:00 |
| Parents | c8806d6ce912, 56ea1f21527e |
9 files changed
modified build.yaml +13 −1
| @@ -13,12 +13,24 @@ | ||
| 13 | 13 | build: |
| 14 | 14 | - type: maven |
| 15 | 15 | version: 3.2.5 |
| 16 | - goals: clean compile test --fail-never -Plong | |
| 16 | + goals: verify --fail-never -Plong | |
| 17 | 17 | properties: | |
| 18 | 18 | com.datastax.driver.TEST_BASE_NODE_WAIT=120 |
| 19 | 19 | com.datastax.driver.NEW_NODE_DELAY_SECONDS=100 |
| 20 | 20 | cassandra.version=$CCM_CASSANDRA_VERSION |
| 21 | 21 | ccm.java.home=$CCM_JAVA_HOME |
| 22 | + failIfNoTests=false | |
| 23 | + maven.test.failure.ignore=true | |
| 24 | + - type: maven | |
| 25 | + version: 3.2.5 | |
| 26 | + goals: verify --fail-never -Pisolated | |
| 27 | + properties: | | |
| 28 | + com.datastax.driver.TEST_BASE_NODE_WAIT=120 | |
| 29 | + com.datastax.driver.NEW_NODE_DELAY_SECONDS=100 | |
| 30 | + cassandra.version=$CCM_CASSANDRA_VERSION | |
| 31 | + ccm.java.home=$CCM_JAVA_HOME | |
| 32 | + failIfNoTests=false | |
| 33 | + maven.test.failure.ignore=true | |
| 22 | 34 | - xunit: |
| 23 | 35 | - "**/target/surefire-reports/TEST-*.xml" |
| 24 | 36 | - "**/target/failsafe-reports/TEST-*.xml" |
modified changelog/README.md +7 −0
| @@ -29,6 +29,8 @@ | ||
| 29 | 29 | - [improvement] JAVA-917: Document SSL configuration. |
| 30 | 30 | - [improvement] JAVA-652: Add DCAwareRoundRobinPolicy builder. |
| 31 | 31 | - [improvement] JAVA-808: Add generic filtering policy that can be used to exclude specific DCs. |
| 32 | +- [bug] JAVA-988: Metadata.handleId should handle escaped double quotes. | |
| 33 | + | |
| 32 | 34 | |
| 33 | 35 | |
| 34 | 36 | ### 3.0.0-alpha4 |
| @@ -215,6 +217,11 @@ | ||
| 215 | 217 | - [improvement] JAVA-782: Unify "Target" enum for schema elements. |
| 216 | 218 | |
| 217 | 219 | |
| 220 | +### 2.1.10 (in progress) | |
| 221 | + | |
| 222 | +- [bug] JAVA-988: Metadata.handleId should handle escaped double quotes. | |
| 223 | + | |
| 224 | + | |
| 218 | 225 | ### 2.1.9 |
| 219 | 226 | |
| 220 | 227 | - [bug] JAVA-942: Fix implementation of UserType.hashCode(). |
modified driver-core/pom.xml +35 −0
| @@ -369,6 +369,41 @@ | ||
| 369 | 369 | </build> |
| 370 | 370 | </profile> |
| 371 | 371 | |
| 372 | + <profile> | |
| 373 | + <id>isolated</id> | |
| 374 | + <properties> | |
| 375 | + <env>default</env> | |
| 376 | + </properties> | |
| 377 | + <build> | |
| 378 | + <plugins> | |
| 379 | + <plugin> | |
| 380 | + <groupId>org.apache.maven.plugins</groupId> | |
| 381 | + <artifactId>maven-surefire-plugin</artifactId> | |
| 382 | + <version>2.16</version> | |
| 383 | + <configuration> | |
| 384 | + <forkCount>1</forkCount> | |
| 385 | + <reuseForks>false</reuseForks> | |
| 386 | + <groups>isolated</groups> | |
| 387 | + <!-- Files containing tests to be included must be added here. | |
| 388 | + this prevents a fork being created for each test class. --> | |
| 389 | + <includes> | |
| 390 | + <include>**/SSL*Test.java</include> | |
| 391 | + </includes> | |
| 392 | + <reportNameSuffix>isolated</reportNameSuffix> | |
| 393 | + <useFile>false</useFile> | |
| 394 | + <systemPropertyVariables> | |
| 395 | + <cassandra.version>${cassandra.version}</cassandra.version> | |
| 396 | + <ipprefix>${ipprefix}</ipprefix> | |
| 397 | + </systemPropertyVariables> | |
| 398 | + <classpathDependencyExcludes> | |
| 399 | + <classpathDependencyExcludes>io.netty:netty-transport-native-epoll</classpathDependencyExcludes> | |
| 400 | + </classpathDependencyExcludes> | |
| 401 | + </configuration> | |
| 402 | + </plugin> | |
| 403 | + </plugins> | |
| 404 | + </build> | |
| 405 | + </profile> | |
| 406 | + | |
| 372 | 407 | <profile> |
| 373 | 408 | <id>long</id> |
| 374 | 409 | <properties> |
modified driver-core/src/main/java/com/datastax/driver/core/Metadata.java +21 −9
| @@ -46,8 +46,8 @@ | ||
| 46 | 46 | |
| 47 | 47 | final ReentrantLock lock = new ReentrantLock(); |
| 48 | 48 | |
| 49 | - private static final Pattern cqlId = Pattern.compile("\\w+"); | |
| 50 | - private static final Pattern lowercaseId = Pattern.compile("[a-z][a-z0-9_]*"); | |
| 49 | + private static final Pattern alphanumeric = Pattern.compile("\\w+"); // this includes _ | |
| 50 | + private static final Pattern lowercaseAlphanumeric = Pattern.compile("[a-z][a-z0-9_]*"); | |
| 51 | 51 | |
| 52 | 52 | Metadata(Cluster.Manager cluster) { |
| 53 | 53 | this.cluster = cluster; |
| @@ -97,20 +97,32 @@ | ||
| 97 | 97 | return hosts.values(); |
| 98 | 98 | } |
| 99 | 99 | |
| 100 | - // Deal with case sensitivity for a given keyspace or table id | |
| 100 | + /* | |
| 101 | + * Deal with case sensitivity for a given element id (keyspace, table, column, etc.) | |
| 102 | + * | |
| 103 | + * This method is used to convert identifiers provided by the client (through methods such as getKeyspace(String)), | |
| 104 | + * to the format used internally by the driver. | |
| 105 | + * | |
| 106 | + * We expect client-facing APIs to behave like cqlsh, that is: | |
| 107 | + * - identifiers that are mixed-case or contain special characters should be quoted. | |
| 108 | + * - unquoted identifiers will be lowercased: getKeyspace("Foo") will look for a keyspace named "foo" | |
| 109 | + */ | |
| 101 | 110 | static String handleId(String id) { |
| 102 | 111 | // Shouldn't really happen for this method, but no reason to fail here |
| 103 | 112 | if (id == null) |
| 104 | 113 | return null; |
| 105 | 114 | |
| 106 | - if (cqlId.matcher(id).matches()) | |
| 115 | + if (alphanumeric.matcher(id).matches()) | |
| 107 | 116 | return id.toLowerCase(); |
| 108 | 117 | |
| 109 | - // Check if it's enclosed in quotes. If it is, remove them | |
| 118 | + // Check if it's enclosed in quotes. If it is, remove them and unescape internal double quotes | |
| 110 | 119 | if (id.charAt(0) == '"' && id.charAt(id.length() - 1) == '"') |
| 111 | - return id.substring(1, id.length() - 1); | |
| 112 | - | |
| 113 | - // otherwise, just return the id. | |
| 120 | + return id.substring(1, id.length() - 1).replaceAll("\"\"", "\""); | |
| 121 | + | |
| 122 | + // Otherwise, just return the id. | |
| 123 | + // Note that this is a bit at odds with the rules explained above, because the client can pass an | |
| 124 | + // identifier that contains special characters, without the need to quote it. | |
| 125 | + // Still it's better to be lenient here rather than throwing an exception. | |
| 114 | 126 | return id; |
| 115 | 127 | } |
| 116 | 128 | |
| @@ -119,7 +131,7 @@ | ||
| 119 | 131 | // but to get a nicer output we don't do it if it's not necessary. |
| 120 | 132 | static String escapeId(String ident) { |
| 121 | 133 | // we don't need to escape if it's lowercase and match non-quoted CQL3 ids. |
| 122 | - return lowercaseId.matcher(ident).matches() ? ident : quote(ident); | |
| 134 | + return lowercaseAlphanumeric.matcher(ident).matches() ? ident : quote(ident); | |
| 123 | 135 | } |
| 124 | 136 | |
| 125 | 137 | // Builds the internal name of a function/aggregate |
modified driver-core/src/test/java/com/datastax/driver/core/CCMBridge.java +6 −2
| @@ -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 | // Contain the same keypair as the client keystore, but in format usable by OpenSSL |
| 67 | 71 | public static final File DEFAULT_CLIENT_PRIVATE_KEY_FILE = createTempStore("/client.key"); |
| 68 | 72 | public static final File DEFAULT_CLIENT_CERT_CHAIN_FILE = createTempStore("/client.crt"); |
| @@ -433,13 +437,13 @@ | ||
| 433 | 437 | erroredOut = true; |
| 434 | 438 | } |
| 435 | 439 | |
| 436 | - @BeforeClass(groups = { "short", "long" }) | |
| 440 | + @BeforeClass(groups = { "isolated", "short", "long" }) | |
| 437 | 441 | public void beforeClass() { |
| 438 | 442 | maybeInitCluster(); |
| 439 | 443 | initKeyspace(); |
| 440 | 444 | } |
| 441 | 445 | |
| 442 | - @AfterClass(groups = { "short", "long" }) | |
| 446 | + @AfterClass(groups = { "isolated", "short", "long" }) | |
| 443 | 447 | public void afterClass() { |
| 444 | 448 | try { |
| 445 | 449 | clearSimpleKeyspace(); |
modified driver-core/src/test/java/com/datastax/driver/core/MetadataTest.java +23 −0
| @@ -127,4 +127,27 @@ | ||
| 127 | 127 | } |
| 128 | 128 | return tokensByHost; |
| 129 | 129 | } |
| 130 | + | |
| 131 | + @Test(groups = "unit") | |
| 132 | + public void handleId_should_lowercase_unquoted_alphanumeric_identifiers() { | |
| 133 | + assertThat(Metadata.handleId("FooBar1")).isEqualTo("foobar1"); | |
| 134 | + assertThat(Metadata.handleId("Foo_Bar_1")).isEqualTo("foo_bar_1"); | |
| 135 | + } | |
| 136 | + | |
| 137 | + @Test(groups = "unit") | |
| 138 | + public void handleId_should_unquote_and_preserve_case_of_quoted_identifiers() { | |
| 139 | + assertThat(Metadata.handleId("\"FooBar1\"")).isEqualTo("FooBar1"); | |
| 140 | + assertThat(Metadata.handleId("\"Foo_Bar_1\"")).isEqualTo("Foo_Bar_1"); | |
| 141 | + assertThat(Metadata.handleId("\"Foo Bar 1\"")).isEqualTo("Foo Bar 1"); | |
| 142 | + } | |
| 143 | + | |
| 144 | + @Test(groups = "unit") | |
| 145 | + public void handleId_should_unescape_duplicate_double_quotes_in_quoted_identifiers() { | |
| 146 | + assertThat(Metadata.handleId("\"Foo\"\"Bar\"")).isEqualTo("Foo\"Bar"); | |
| 147 | + } | |
| 148 | + | |
| 149 | + @Test(groups = "unit") | |
| 150 | + public void handleId_should_preserve_unquoted_non_alphanumeric_identifiers() { | |
| 151 | + assertThat(Metadata.handleId("Foo Bar")).isEqualTo("Foo Bar"); | |
| 152 | + } | |
| 130 | 153 | } |
modified driver-core/src/test/java/com/datastax/driver/core/SSLAuthenticatedEncryptionTest.java +19 −2
| @@ -48,8 +48,7 @@ | ||
| 48 | 48 | public void should_connect_with_ssl_with_client_auth_and_node_requires_auth(SslImplementation sslImplementation) throws Exception { |
| 49 | 49 | connectWithSSLOptions(getSSLOptions(sslImplementation, true, true)); |
| 50 | 50 | } |
| 51 | - | |
| 52 | - | |
| 51 | + | |
| 53 | 52 | /** |
| 54 | 53 | * <p> |
| 55 | 54 | * Validates that an SSL connection can not be established with if the target |
| @@ -64,4 +63,22 @@ | ||
| 64 | 63 | public void should_not_connect_without_client_auth_but_node_requires_auth(SslImplementation sslImplementation) throws Exception { |
| 65 | 64 | connectWithSSLOptions(getSSLOptions(sslImplementation, false, true)); |
| 66 | 65 | } |
| 66 | + | |
| 67 | + /** | |
| 68 | + * <p> | |
| 69 | + * Validates that SSL connectivity can be configured via the standard javax.net.ssl System properties. | |
| 70 | + * </p> | |
| 71 | + * | |
| 72 | + * @test_category connection:ssl, authentication | |
| 73 | + * @expected_result Connection can be established. | |
| 74 | + */ | |
| 75 | + @Test(groups="isolated") | |
| 76 | + public void should_use_system_properties_with_default_ssl_options() throws Exception { | |
| 77 | + System.setProperty("javax.net.ssl.keyStore", CCMBridge.DEFAULT_CLIENT_KEYSTORE_FILE.getAbsolutePath()); | |
| 78 | + System.setProperty("javax.net.ssl.keyStorePassword", CCMBridge.DEFAULT_CLIENT_KEYSTORE_PASSWORD); | |
| 79 | + System.setProperty("javax.net.ssl.trustStore", CCMBridge.DEFAULT_CLIENT_TRUSTSTORE_FILE.getAbsolutePath()); | |
| 80 | + System.setProperty("javax.net.ssl.trustStorePassword", CCMBridge.DEFAULT_CLIENT_TRUSTSTORE_PASSWORD); | |
| 81 | + | |
| 82 | + connectWithSSL(); | |
| 83 | + } | |
| 67 | 84 | } |
modified driver-core/src/test/java/com/datastax/driver/core/SSLEncryptionTest.java +16 −0
| @@ -123,4 +123,20 @@ | ||
| 123 | 123 | cluster.close(); |
| 124 | 124 | } |
| 125 | 125 | } |
| 126 | + | |
| 127 | + /** | |
| 128 | + * <p> | |
| 129 | + * Validates that SSL connectivity can be configured via the standard javax.net.ssl System properties. | |
| 130 | + * </p> | |
| 131 | + * | |
| 132 | + * @test_category connection:ssl | |
| 133 | + * @expected_result Connection can be established. | |
| 134 | + */ | |
| 135 | + @Test(groups="isolated") | |
| 136 | + public void should_use_system_properties_with_default_ssl_options() throws Exception { | |
| 137 | + System.setProperty("javax.net.ssl.trustStore", CCMBridge.DEFAULT_CLIENT_TRUSTSTORE_FILE.getAbsolutePath()); | |
| 138 | + System.setProperty("javax.net.ssl.trustStorePassword", CCMBridge.DEFAULT_CLIENT_TRUSTSTORE_PASSWORD); | |
| 139 | + | |
| 140 | + connectWithSSL(); | |
| 141 | + } | |
| 126 | 142 | } |
modified driver-core/src/test/java/com/datastax/driver/core/SSLTestBase.java +26 −2
| @@ -39,14 +39,14 @@ | ||
| 39 | 39 | this.requireClientAuth = requireClientAuth; |
| 40 | 40 | } |
| 41 | 41 | |
| 42 | - @BeforeClass(groups={"short", "long"}) | |
| 42 | + @BeforeClass(groups={"isolated", "short", "long"}) | |
| 43 | 43 | public void beforeClass() { |
| 44 | 44 | ccm = CCMBridge.builder("test") |
| 45 | 45 | .withSSL(requireClientAuth) |
| 46 | 46 | .build(); |
| 47 | 47 | } |
| 48 | 48 | |
| 49 | - @AfterClass(groups={"short", "long"}) | |
| 49 | + @AfterClass(groups={"isolated", "short", "long"}) | |
| 50 | 50 | public void afterClass() { |
| 51 | 51 | ccm.remove(); |
| 52 | 52 | } |
| @@ -76,6 +76,30 @@ | ||
| 76 | 76 | } |
| 77 | 77 | } |
| 78 | 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 | + | |
| 79 | 103 | enum SslImplementation { JDK, NETTY_OPENSSL} |
| 80 | 104 | |
| 81 | 105 | /** |