geode-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From u..@apache.org
Subject [1/8] incubator-geode git commit: GEODE-420: Clean up of SocketCreator code in tests. SocketCreatorFactory currently singleton, to amend at later stage
Date Tue, 12 Jul 2016 20:01:00 GMT
Repository: incubator-geode
Updated Branches:
  refs/heads/feature/GEODE-420 8e8337dde -> 399a63878


http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/399a6387/geode-core/src/test/java/com/gemstone/gemfire/internal/net/SocketCreatorFactoryJUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/internal/net/SocketCreatorFactoryJUnitTest.java
b/geode-core/src/test/java/com/gemstone/gemfire/internal/net/SocketCreatorFactoryJUnitTest.java
new file mode 100644
index 0000000..c4d6846
--- /dev/null
+++ b/geode-core/src/test/java/com/gemstone/gemfire/internal/net/SocketCreatorFactoryJUnitTest.java
@@ -0,0 +1,211 @@
+/*
+ * 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 com.gemstone.gemfire.internal.net;
+
+import static com.gemstone.gemfire.distributed.ConfigurationProperties.*;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.Properties;
+
+import org.junit.After;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+import com.gemstone.gemfire.distributed.SSLEnabledComponents;
+import com.gemstone.gemfire.distributed.internal.DistributionConfigImpl;
+import com.gemstone.gemfire.test.dunit.Assert;
+import com.gemstone.gemfire.test.junit.categories.UnitTest;
+
+@Category(UnitTest.class)
+public class SocketCreatorFactoryJUnitTest extends JSSESocketJUnitTest {
+
+  @After
+  public void tearDown() {
+    SocketCreatorFactory.close();
+  }
+
+  @Test
+  public void testClusterSSLConfig() {
+
+  }
+
+  @Test
+  public void testNewSSLConfigSSLComponentALL() {
+    Properties properties = configureSSLProperties(SSLEnabledComponents.ALL);
+
+    DistributionConfigImpl distributionConfig = new DistributionConfigImpl(properties);
+    SocketCreatorFactory.setDistributionConfig(distributionConfig);
+
+    Assert.assertTrue(SocketCreatorFactory.getClusterSSLSocketCreator().useSSL());
+    Assert.assertTrue(SocketCreatorFactory.getGatewaySSLSocketCreator().useSSL());
+    Assert.assertTrue(SocketCreatorFactory.getJMXManagerSSLSocketCreator().useSSL());
+    Assert.assertTrue(SocketCreatorFactory.getServerSSLSocketCreator().useSSL());
+    Assert.assertTrue(SocketCreatorFactory.getHTTPServiceSSLSocketCreator().useSSL());
+
+  }
+
+  @Test
+  public void testNewSSLConfigSSLComponentCLUSTER() {
+    Properties properties = configureSSLProperties(SSLEnabledComponents.CLUSTER);
+
+    DistributionConfigImpl distributionConfig = new DistributionConfigImpl(properties);
+    SocketCreatorFactory.setDistributionConfig(distributionConfig);
+
+    Assert.assertTrue(SocketCreatorFactory.getClusterSSLSocketCreator().useSSL());
+    Assert.assertFalse(SocketCreatorFactory.getGatewaySSLSocketCreator().useSSL());
+    Assert.assertFalse(SocketCreatorFactory.getJMXManagerSSLSocketCreator().useSSL());
+    Assert.assertFalse(SocketCreatorFactory.getServerSSLSocketCreator().useSSL());
+    Assert.assertFalse(SocketCreatorFactory.getHTTPServiceSSLSocketCreator().useSSL());
+  }
+
+  @Test
+  public void testNewSSLConfigSSLComponentGATEWAY() {
+    Properties properties = configureSSLProperties(SSLEnabledComponents.GATEWAY);
+
+    DistributionConfigImpl distributionConfig = new DistributionConfigImpl(properties);
+    SocketCreatorFactory.setDistributionConfig(distributionConfig);
+
+    Assert.assertFalse(SocketCreatorFactory.getClusterSSLSocketCreator().useSSL());
+    Assert.assertTrue(SocketCreatorFactory.getGatewaySSLSocketCreator().useSSL());
+    Assert.assertFalse(SocketCreatorFactory.getJMXManagerSSLSocketCreator().useSSL());
+    Assert.assertFalse(SocketCreatorFactory.getServerSSLSocketCreator().useSSL());
+    Assert.assertFalse(SocketCreatorFactory.getHTTPServiceSSLSocketCreator().useSSL());
+
+  }
+
+  @Test
+  public void testNewSSLConfigSSLComponentHTTP_SERVICE() {
+    Properties properties = configureSSLProperties(SSLEnabledComponents.HTTP_SERVICE);
+
+    DistributionConfigImpl distributionConfig = new DistributionConfigImpl(properties);
+    SocketCreatorFactory.setDistributionConfig(distributionConfig);
+
+    Assert.assertFalse(SocketCreatorFactory.getClusterSSLSocketCreator().useSSL());
+    Assert.assertFalse(SocketCreatorFactory.getGatewaySSLSocketCreator().useSSL());
+    Assert.assertFalse(SocketCreatorFactory.getJMXManagerSSLSocketCreator().useSSL());
+    Assert.assertFalse(SocketCreatorFactory.getServerSSLSocketCreator().useSSL());
+    Assert.assertTrue(SocketCreatorFactory.getHTTPServiceSSLSocketCreator().useSSL());
+
+  }
+
+  @Test
+  public void testNewSSLConfigSSLComponentJMX() {
+    Properties properties = configureSSLProperties(SSLEnabledComponents.JMX);
+
+    DistributionConfigImpl distributionConfig = new DistributionConfigImpl(properties);
+    SocketCreatorFactory.setDistributionConfig(distributionConfig);
+
+    Assert.assertFalse(SocketCreatorFactory.getClusterSSLSocketCreator().useSSL());
+    Assert.assertFalse(SocketCreatorFactory.getGatewaySSLSocketCreator().useSSL());
+    Assert.assertTrue(SocketCreatorFactory.getJMXManagerSSLSocketCreator().useSSL());
+    Assert.assertFalse(SocketCreatorFactory.getServerSSLSocketCreator().useSSL());
+    Assert.assertFalse(SocketCreatorFactory.getHTTPServiceSSLSocketCreator().useSSL());
+
+  }
+
+  @Test
+  public void testNewSSLConfigSSLComponentSERVER() {
+    Properties properties = configureSSLProperties(SSLEnabledComponents.SERVER);
+
+    DistributionConfigImpl distributionConfig = new DistributionConfigImpl(properties);
+    SocketCreatorFactory.setDistributionConfig(distributionConfig);
+
+    Assert.assertFalse(SocketCreatorFactory.getClusterSSLSocketCreator().useSSL());
+    Assert.assertFalse(SocketCreatorFactory.getGatewaySSLSocketCreator().useSSL());
+    Assert.assertFalse(SocketCreatorFactory.getJMXManagerSSLSocketCreator().useSSL());
+    Assert.assertTrue(SocketCreatorFactory.getServerSSLSocketCreator().useSSL());
+    Assert.assertFalse(SocketCreatorFactory.getHTTPServiceSSLSocketCreator().useSSL());
+  }
+
+  @Test
+  public void testNewSSLConfigSSLComponentCombinations1() {
+    Properties properties = configureSSLProperties(commaDelimetedString(SSLEnabledComponents.CLUSTER,
SSLEnabledComponents.SERVER));
+
+    DistributionConfigImpl distributionConfig = new DistributionConfigImpl(properties);
+    SocketCreatorFactory.setDistributionConfig(distributionConfig);
+
+    Assert.assertTrue(SocketCreatorFactory.getClusterSSLSocketCreator().useSSL());
+    Assert.assertFalse(SocketCreatorFactory.getGatewaySSLSocketCreator().useSSL());
+    Assert.assertFalse(SocketCreatorFactory.getJMXManagerSSLSocketCreator().useSSL());
+    Assert.assertTrue(SocketCreatorFactory.getServerSSLSocketCreator().useSSL());
+    Assert.assertFalse(SocketCreatorFactory.getHTTPServiceSSLSocketCreator().useSSL());
+  }
+
+  @Test
+  public void testNewSSLConfigSSLComponentCombinations2() {
+    Properties properties = configureSSLProperties(commaDelimetedString(SSLEnabledComponents.CLUSTER,
SSLEnabledComponents.SERVER, SSLEnabledComponents.HTTP_SERVICE, SSLEnabledComponents.JMX));
+
+    DistributionConfigImpl distributionConfig = new DistributionConfigImpl(properties);
+    SocketCreatorFactory.setDistributionConfig(distributionConfig);
+
+    Assert.assertTrue(SocketCreatorFactory.getClusterSSLSocketCreator().useSSL());
+    Assert.assertFalse(SocketCreatorFactory.getGatewaySSLSocketCreator().useSSL());
+    Assert.assertTrue(SocketCreatorFactory.getJMXManagerSSLSocketCreator().useSSL());
+    Assert.assertTrue(SocketCreatorFactory.getServerSSLSocketCreator().useSSL());
+    Assert.assertTrue(SocketCreatorFactory.getHTTPServiceSSLSocketCreator().useSSL());
+  }
+
+  private Properties configureSSLProperties(String sslComponents) {
+    Properties properties = new Properties();
+    try {
+      File jks = findTestJKS();
+
+      properties.setProperty(MCAST_PORT, "0");
+      properties.setProperty(CLUSTER_SSL_ENABLED, "true");
+      properties.setProperty(CLUSTER_SSL_REQUIRE_AUTHENTICATION, "true");
+      properties.setProperty(CLUSTER_SSL_CIPHERS, "any");
+      properties.setProperty(CLUSTER_SSL_PROTOCOLS, "TLSv1.2");
+      properties.setProperty(CLUSTER_SSL_KEYSTORE, jks.getCanonicalPath());
+      properties.setProperty(CLUSTER_SSL_KEYSTORE_PASSWORD, "password");
+      properties.setProperty(CLUSTER_SSL_KEYSTORE_TYPE, "JKS");
+      properties.setProperty(CLUSTER_SSL_TRUSTSTORE, jks.getCanonicalPath());
+      properties.setProperty(CLUSTER_SSL_TRUSTSTORE_PASSWORD, "password");
+      properties.setProperty(SSL_ENABLED_COMPONENTS, sslComponents);
+    } catch (IOException e) {
+      Assert.fail("Failed to configure the cluster");
+    }
+    return properties;
+  }
+
+
+  private String commaDelimetedString(final String... sslComponents) {
+    StringBuilder stringBuilder = new StringBuilder();
+    for (String sslComponent : sslComponents) {
+      stringBuilder.append(sslComponent);
+      stringBuilder.append(",");
+    }
+    return stringBuilder.substring(0, stringBuilder.length() - 1);
+  }
+
+  @Test
+  public void testLegacyServerSSLConfig() {
+  }
+
+  @Test
+  public void testLegacyJMXSSLConfig() {
+  }
+
+  @Test
+  public void testLegacyGatewaySSLConfig() {
+  }
+
+  @Test
+  public void testLegacyHttpServiceSSLConfig() {
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/399a6387/geode-core/src/test/java/com/gemstone/gemfire/internal/tcp/ConnectionJUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/internal/tcp/ConnectionJUnitTest.java
b/geode-core/src/test/java/com/gemstone/gemfire/internal/tcp/ConnectionJUnitTest.java
index 3a88707..2b0fa0e 100755
--- a/geode-core/src/test/java/com/gemstone/gemfire/internal/tcp/ConnectionJUnitTest.java
+++ b/geode-core/src/test/java/com/gemstone/gemfire/internal/tcp/ConnectionJUnitTest.java
@@ -29,8 +29,8 @@ import com.gemstone.gemfire.CancelCriterion;
 import com.gemstone.gemfire.distributed.internal.DM;
 import com.gemstone.gemfire.distributed.internal.membership.InternalDistributedMember;
 import com.gemstone.gemfire.distributed.internal.membership.MembershipManager;
-import com.gemstone.gemfire.internal.SocketCloser;
-import com.gemstone.gemfire.internal.SocketCreator;
+import com.gemstone.gemfire.internal.net.SocketCloser;
+import com.gemstone.gemfire.internal.net.SocketCreator;
 import com.gemstone.gemfire.test.junit.categories.UnitTest;
 
 @Category(UnitTest.class)

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/399a6387/geode-core/src/test/java/com/gemstone/gemfire/redis/RedisDistDUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/redis/RedisDistDUnitTest.java b/geode-core/src/test/java/com/gemstone/gemfire/redis/RedisDistDUnitTest.java
index c10e521..02766ee 100644
--- a/geode-core/src/test/java/com/gemstone/gemfire/redis/RedisDistDUnitTest.java
+++ b/geode-core/src/test/java/com/gemstone/gemfire/redis/RedisDistDUnitTest.java
@@ -28,7 +28,7 @@ import redis.clients.jedis.Jedis;
 import com.gemstone.gemfire.cache.CacheFactory;
 import com.gemstone.gemfire.distributed.ConfigurationProperties;
 import com.gemstone.gemfire.internal.AvailablePortHelper;
-import com.gemstone.gemfire.internal.SocketCreator;
+import com.gemstone.gemfire.internal.net.SocketCreator;
 import com.gemstone.gemfire.test.dunit.AsyncInvocation;
 import com.gemstone.gemfire.test.dunit.DistributedTestUtils;
 import com.gemstone.gemfire.test.dunit.Host;

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/399a6387/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/NetworkUtils.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/NetworkUtils.java b/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/NetworkUtils.java
index dec882e..feb64a4 100755
--- a/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/NetworkUtils.java
+++ b/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/NetworkUtils.java
@@ -17,7 +17,7 @@
 package com.gemstone.gemfire.test.dunit;
 
 import com.gemstone.gemfire.distributed.internal.DistributionConfig;
-import com.gemstone.gemfire.internal.SocketCreator;
+import com.gemstone.gemfire.internal.net.SocketCreator;
 
 import java.net.UnknownHostException;
 

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/399a6387/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/internal/JUnit4DistributedTestCase.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/internal/JUnit4DistributedTestCase.java
b/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/internal/JUnit4DistributedTestCase.java
index 9f962db..bed3cad 100755
--- a/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/internal/JUnit4DistributedTestCase.java
+++ b/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/internal/JUnit4DistributedTestCase.java
@@ -31,7 +31,7 @@ import com.gemstone.gemfire.distributed.DistributedSystem;
 import com.gemstone.gemfire.distributed.internal.DistributionConfig;
 import com.gemstone.gemfire.distributed.internal.DistributionMessageObserver;
 import com.gemstone.gemfire.distributed.internal.InternalDistributedSystem;
-import com.gemstone.gemfire.internal.SocketCreator;
+import com.gemstone.gemfire.internal.net.SocketCreator;
 import com.gemstone.gemfire.internal.admin.ClientStatsManager;
 import com.gemstone.gemfire.internal.cache.*;
 import com.gemstone.gemfire.internal.cache.tier.InternalClientMembership;
@@ -40,6 +40,7 @@ import com.gemstone.gemfire.internal.cache.tier.sockets.ClientProxyMembershipID;
 import com.gemstone.gemfire.internal.cache.tier.sockets.Message;
 import com.gemstone.gemfire.internal.cache.xmlcache.CacheCreation;
 import com.gemstone.gemfire.internal.logging.LogService;
+import com.gemstone.gemfire.internal.net.SocketCreatorFactory;
 import com.gemstone.gemfire.management.internal.cli.LogWrapper;
 import com.gemstone.gemfire.test.dunit.*;
 import com.gemstone.gemfire.test.dunit.standalone.DUnitLauncher;
@@ -153,6 +154,7 @@ public abstract class JUnit4DistributedTestCase implements DistributedTestFixtur
     }
     if (system == null || !system.isConnected()) {
       // Figure out our distributed system properties
+      SocketCreatorFactory.close();
       Properties p = DistributedTestUtils.getAllDistributedSystemProperties(props);
       lastSystemCreatedInTest = getTestClass(); // used to be getDeclaringClass()
       if (logPerTest) {

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/399a6387/geode-wan/src/main/java/com/gemstone/gemfire/internal/cache/wan/GatewayReceiverImpl.java
----------------------------------------------------------------------
diff --git a/geode-wan/src/main/java/com/gemstone/gemfire/internal/cache/wan/GatewayReceiverImpl.java
b/geode-wan/src/main/java/com/gemstone/gemfire/internal/cache/wan/GatewayReceiverImpl.java
index 3779749..e57916c 100644
--- a/geode-wan/src/main/java/com/gemstone/gemfire/internal/cache/wan/GatewayReceiverImpl.java
+++ b/geode-wan/src/main/java/com/gemstone/gemfire/internal/cache/wan/GatewayReceiverImpl.java
@@ -32,7 +32,7 @@ import com.gemstone.gemfire.cache.wan.GatewayTransportFilter;
 import com.gemstone.gemfire.distributed.internal.InternalDistributedSystem;
 import com.gemstone.gemfire.distributed.internal.ResourceEvent;
 import com.gemstone.gemfire.internal.AvailablePort;
-import com.gemstone.gemfire.internal.SocketCreator;
+import com.gemstone.gemfire.internal.net.SocketCreator;
 import com.gemstone.gemfire.internal.cache.CacheServerImpl;
 import com.gemstone.gemfire.internal.cache.GemFireCacheImpl;
 import com.gemstone.gemfire.internal.i18n.LocalizedStrings;

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/399a6387/geode-web-api/src/main/java/com/gemstone/gemfire/rest/internal/web/swagger/config/RestApiPathProvider.java
----------------------------------------------------------------------
diff --git a/geode-web-api/src/main/java/com/gemstone/gemfire/rest/internal/web/swagger/config/RestApiPathProvider.java
b/geode-web-api/src/main/java/com/gemstone/gemfire/rest/internal/web/swagger/config/RestApiPathProvider.java
index b35dce9..36ad90f 100644
--- a/geode-web-api/src/main/java/com/gemstone/gemfire/rest/internal/web/swagger/config/RestApiPathProvider.java
+++ b/geode-web-api/src/main/java/com/gemstone/gemfire/rest/internal/web/swagger/config/RestApiPathProvider.java
@@ -18,7 +18,7 @@ package com.gemstone.gemfire.rest.internal.web.swagger.config;
 
 import com.gemstone.gemfire.distributed.internal.DistributionConfig;
 import com.gemstone.gemfire.distributed.internal.InternalDistributedSystem;
-import com.gemstone.gemfire.internal.SocketCreator;
+import com.gemstone.gemfire.internal.net.SocketCreator;
 import com.gemstone.gemfire.internal.lang.StringUtils;
 import com.mangofactory.swagger.core.SwaggerPathProvider;
 import org.springframework.beans.factory.annotation.Autowired;


Mime
View raw message