Elffuss BraidHub

kikocis/java-driver public

Merge branch '2.1' into 3.0
Changesetcd86ebbd4272b2e273ae967b6700af5646d8c9ed06c421ea4b00b9c10532ac74
Authorolim7t <omichallat+github@gmail.com> · 2015-11-13 20:50 +01:00
Committerolim7t <omichallat+github@gmail.com> · 2015-11-13 20:50 +01:00
Parentsc8806d6ce912, 56ea1f21527e

Browse the files at this changeset

9 files changed

modified build.yaml +13 −1
@@ -13,12 +13,24 @@
1313 build:
1414 - type: maven
1515 version: 3.2.5
16- goals: clean compile test --fail-never -Plong
16+ goals: verify --fail-never -Plong
1717 properties: |
1818 com.datastax.driver.TEST_BASE_NODE_WAIT=120
1919 com.datastax.driver.NEW_NODE_DELAY_SECONDS=100
2020 cassandra.version=$CCM_CASSANDRA_VERSION
2121 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
2234 - xunit:
2335 - "**/target/surefire-reports/TEST-*.xml"
2436 - "**/target/failsafe-reports/TEST-*.xml"
modified changelog/README.md +7 −0
@@ -29,6 +29,8 @@
2929 - [improvement] JAVA-917: Document SSL configuration.
3030 - [improvement] JAVA-652: Add DCAwareRoundRobinPolicy builder.
3131 - [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+
3234
3335
3436 ### 3.0.0-alpha4
@@ -215,6 +217,11 @@
215217 - [improvement] JAVA-782: Unify "Target" enum for schema elements.
216218
217219
220+### 2.1.10 (in progress)
221+
222+- [bug] JAVA-988: Metadata.handleId should handle escaped double quotes.
223+
224+
218225 ### 2.1.9
219226
220227 - [bug] JAVA-942: Fix implementation of UserType.hashCode().
modified driver-core/pom.xml +35 −0
@@ -369,6 +369,41 @@
369369 </build>
370370 </profile>
371371
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+
372407 <profile>
373408 <id>long</id>
374409 <properties>
modified driver-core/src/main/java/com/datastax/driver/core/Metadata.java +21 −9
@@ -46,8 +46,8 @@
4646
4747 final ReentrantLock lock = new ReentrantLock();
4848
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_]*");
5151
5252 Metadata(Cluster.Manager cluster) {
5353 this.cluster = cluster;
@@ -97,20 +97,32 @@
9797 return hosts.values();
9898 }
9999
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+ */
101110 static String handleId(String id) {
102111 // Shouldn't really happen for this method, but no reason to fail here
103112 if (id == null)
104113 return null;
105114
106- if (cqlId.matcher(id).matches())
115+ if (alphanumeric.matcher(id).matches())
107116 return id.toLowerCase();
108117
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
110119 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.
114126 return id;
115127 }
116128
@@ -119,7 +131,7 @@
119131 // but to get a nicer output we don't do it if it's not necessary.
120132 static String escapeId(String ident) {
121133 // 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);
123135 }
124136
125137 // 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 @@
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 // Contain the same keypair as the client keystore, but in format usable by OpenSSL
6771 public static final File DEFAULT_CLIENT_PRIVATE_KEY_FILE = createTempStore("/client.key");
6872 public static final File DEFAULT_CLIENT_CERT_CHAIN_FILE = createTempStore("/client.crt");
@@ -433,13 +437,13 @@
433437 erroredOut = true;
434438 }
435439
436- @BeforeClass(groups = { "short", "long" })
440+ @BeforeClass(groups = { "isolated", "short", "long" })
437441 public void beforeClass() {
438442 maybeInitCluster();
439443 initKeyspace();
440444 }
441445
442- @AfterClass(groups = { "short", "long" })
446+ @AfterClass(groups = { "isolated", "short", "long" })
443447 public void afterClass() {
444448 try {
445449 clearSimpleKeyspace();
modified driver-core/src/test/java/com/datastax/driver/core/MetadataTest.java +23 −0
@@ -127,4 +127,27 @@
127127 }
128128 return tokensByHost;
129129 }
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+ }
130153 }
modified driver-core/src/test/java/com/datastax/driver/core/SSLAuthenticatedEncryptionTest.java +19 −2
@@ -48,8 +48,7 @@
4848 public void should_connect_with_ssl_with_client_auth_and_node_requires_auth(SslImplementation sslImplementation) throws Exception {
4949 connectWithSSLOptions(getSSLOptions(sslImplementation, true, true));
5050 }
51-
52-
51+
5352 /**
5453 * <p>
5554 * Validates that an SSL connection can not be established with if the target
@@ -64,4 +63,22 @@
6463 public void should_not_connect_without_client_auth_but_node_requires_auth(SslImplementation sslImplementation) throws Exception {
6564 connectWithSSLOptions(getSSLOptions(sslImplementation, false, true));
6665 }
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+ }
6784 }
modified driver-core/src/test/java/com/datastax/driver/core/SSLEncryptionTest.java +16 −0
@@ -123,4 +123,20 @@
123123 cluster.close();
124124 }
125125 }
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+ }
126142 }
modified driver-core/src/test/java/com/datastax/driver/core/SSLTestBase.java +26 −2
@@ -39,14 +39,14 @@
3939 this.requireClientAuth = requireClientAuth;
4040 }
4141
42- @BeforeClass(groups={"short", "long"})
42+ @BeforeClass(groups={"isolated", "short", "long"})
4343 public void beforeClass() {
4444 ccm = CCMBridge.builder("test")
4545 .withSSL(requireClientAuth)
4646 .build();
4747 }
4848
49- @AfterClass(groups={"short", "long"})
49+ @AfterClass(groups={"isolated", "short", "long"})
5050 public void afterClass() {
5151 ccm.remove();
5252 }
@@ -76,6 +76,30 @@
7676 }
7777 }
7878
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+
79103 enum SslImplementation { JDK, NETTY_OPENSSL}
80104
81105 /**