jdeppe-pivotal commented on a change in pull request #6826:
URL: https://github.com/apache/geode/pull/6826#discussion_r704895729



##########
File path: 
geode-apis-compatible-with-redis/src/distributedTest/java/org/apache/geode/redis/SSLDUnitTest.java
##########
@@ -0,0 +1,301 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more 
contributor license
+ * agreements. See the NOTICE file distributed with this work for additional 
information regarding
+ * copyright ownership. The ASF licenses this file to You under the Apache 
License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the 
License. You may obtain a
+ * copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software 
distributed under the License
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 
KIND, either express
+ * or implied. See the License for the specific language governing permissions 
and limitations under
+ * the License.
+ */
+
+package org.apache.geode.redis;
+
+import static 
org.apache.geode.test.dunit.rules.RedisClusterStartupRule.BIND_ADDRESS;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+import java.io.FileInputStream;
+import java.security.KeyStore;
+import java.security.cert.Certificate;
+import java.security.cert.X509Certificate;
+import java.time.Duration;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import java.util.Properties;
+
+import javax.net.ssl.HostnameVerifier;
+import javax.net.ssl.KeyManager;
+import javax.net.ssl.KeyManagerFactory;
+import javax.net.ssl.SSLContext;
+import javax.net.ssl.SSLHandshakeException;
+import javax.net.ssl.SSLSession;
+import javax.net.ssl.TrustManagerFactory;
+
+import io.netty.handler.ssl.NotSslRecordException;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import redis.clients.jedis.Jedis;
+import redis.clients.jedis.exceptions.JedisConnectionException;
+
+import org.apache.geode.cache.ssl.CertStores;
+import org.apache.geode.cache.ssl.CertificateBuilder;
+import org.apache.geode.cache.ssl.CertificateMaterial;
+import org.apache.geode.internal.net.filewatch.PollingFileWatcher;
+import org.apache.geode.test.awaitility.GeodeAwaitility;
+import org.apache.geode.test.dunit.IgnoredException;
+import org.apache.geode.test.dunit.rules.MemberVM;
+import org.apache.geode.test.dunit.rules.RedisClusterStartupRule;
+
+public class SSLDUnitTest {
+
+  @Rule
+  public RedisClusterStartupRule cluster = new RedisClusterStartupRule();
+
+  private static String commonPassword = "password";
+  private static SANCapturingHostnameVerifier hostnameVerifier = new 
SANCapturingHostnameVerifier();
+
+  private int redisPort;
+  private CertificateMaterial ca;
+  private String serverKeyStoreFilename;
+  private String serverTrustStoreFilename;
+
+  @Before
+  public void setup() throws Exception {
+    ca = new CertificateBuilder()
+        .commonName("Test CA")
+        .isCA()
+        .generate();
+
+    CertificateMaterial serverCertificate = new CertificateBuilder()
+        .commonName("server")
+        .issuedBy(ca)
+        .generate();
+
+    CertStores serverStore = CertStores.serverStore();
+    serverStore.withCertificate("server", serverCertificate);
+    serverStore.trust("ca", ca);
+    Properties serverProperties = serverStore.propertiesWith("all", true, 
false);
+
+    MemberVM server = cluster.startRedisVM(0, x -> 
x.withProperties(serverProperties));
+
+    redisPort = cluster.getRedisPort(server);
+    serverKeyStoreFilename = serverProperties.getProperty("ssl-keystore");
+    serverTrustStoreFilename = serverProperties.getProperty("ssl-truststore");
+  }
+
+  @Test
+  public void givenMutualAuthentication_clientCanConnect() throws Exception {
+    try (Jedis jedis = createClient(true, false)) {
+      assertThat(jedis.ping()).isEqualTo("PONG");
+    }
+  }
+
+  @Test
+  public void givenMutualAuthentication_clientErrorsWithoutKeystore() throws 
Exception {
+    IgnoredException.addIgnoredException(SSLHandshakeException.class);
+    IgnoredException.addIgnoredException("SunCertPathBuilderException");
+
+    Jedis jedis;
+    try {
+      // Create the client without a keystore
+      jedis = createClient(false, false);
+    } catch (JedisConnectionException ignored) {
+      return;
+    }
+
+    // Sometimes the client is created successfully - perhaps this is 
platform/JDK specific
+    assertThatThrownBy(jedis::ping).satisfiesAnyOf(
+        e -> assertThat(e.getMessage()).contains("SocketException"),
+        e -> assertThat(e.getMessage()).contains("SSLException"),
+        e -> assertThat(e.getMessage()).contains("SSLHandshakeException"));
+
+    IgnoredException.removeAllExpectedExceptions();
+  }
+
+  @Test
+  public void givenMutualAuthentication_clientErrorsWithSelfSignedCert() 
throws Exception {
+    IgnoredException.addIgnoredException(SSLHandshakeException.class);
+    IgnoredException.addIgnoredException("SunCertPathBuilderException");
+
+    Jedis jedis;
+    try {
+      // Create the client with a self-signed certificate
+      jedis = createClient(true, true);
+    } catch (JedisConnectionException ignored) {
+      return;
+    }
+
+    // Sometimes the client is created successfully - perhaps this is 
platform/JDK specific

Review comment:
       Done.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to