You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by ds...@apache.org on 2015/10/16 02:29:46 UTC

[1/4] incubator-geode git commit: more cleanup of old ssl unit test

Repository: incubator-geode
Updated Branches:
  refs/heads/feature/GEODE-397 47ad35dc7 -> b023af4c9


more cleanup of old ssl unit test


Project: http://git-wip-us.apache.org/repos/asf/incubator-geode/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-geode/commit/1e13aad9
Tree: http://git-wip-us.apache.org/repos/asf/incubator-geode/tree/1e13aad9
Diff: http://git-wip-us.apache.org/repos/asf/incubator-geode/diff/1e13aad9

Branch: refs/heads/feature/GEODE-397
Commit: 1e13aad93eb6822580a2768c2844621c1f9a6887
Parents: 47ad35d
Author: Darrel Schneider <ds...@pivotal.io>
Authored: Thu Oct 15 15:44:26 2015 -0700
Committer: Darrel Schneider <ds...@pivotal.io>
Committed: Thu Oct 15 15:44:26 2015 -0700

----------------------------------------------------------------------
 .../internal/CacheServerSSLConnectionDUnit.java | 403 +++----------------
 1 file changed, 65 insertions(+), 338 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/1e13aad9/gemfire-core/src/test/java/com/gemstone/gemfire/cache/client/internal/CacheServerSSLConnectionDUnit.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/test/java/com/gemstone/gemfire/cache/client/internal/CacheServerSSLConnectionDUnit.java b/gemfire-core/src/test/java/com/gemstone/gemfire/cache/client/internal/CacheServerSSLConnectionDUnit.java
index 28b5010..0a13c75 100644
--- a/gemfire-core/src/test/java/com/gemstone/gemfire/cache/client/internal/CacheServerSSLConnectionDUnit.java
+++ b/gemfire-core/src/test/java/com/gemstone/gemfire/cache/client/internal/CacheServerSSLConnectionDUnit.java
@@ -7,15 +7,10 @@
  */
 package com.gemstone.gemfire.cache.client.internal;
 
-import java.io.File;
 import java.io.IOException;
 import java.io.PrintWriter;
 import java.io.StringWriter;
-import java.net.InetAddress;
-import java.net.UnknownHostException;
 import java.util.Properties;
-import java.util.Set;
-
 import com.gemstone.gemfire.cache.Cache;
 import com.gemstone.gemfire.cache.CacheFactory;
 import com.gemstone.gemfire.cache.Region;
@@ -25,10 +20,7 @@ import com.gemstone.gemfire.cache.client.ClientCache;
 import com.gemstone.gemfire.cache.client.ClientCacheFactory;
 import com.gemstone.gemfire.cache.client.ClientRegionFactory;
 import com.gemstone.gemfire.cache.client.ClientRegionShortcut;
-import com.gemstone.gemfire.cache.client.ServerOperationException;
 import com.gemstone.gemfire.cache.server.CacheServer;
-import com.gemstone.gemfire.distributed.DistributedSystem;
-import com.gemstone.gemfire.distributed.Locator;
 import com.gemstone.gemfire.distributed.internal.DistributionConfig;
 import com.gemstone.gemfire.internal.AvailablePortHelper;
 import com.gemstone.gemfire.security.AuthenticationRequiredException;
@@ -37,7 +29,6 @@ import com.gemstone.gemfire.util.test.TestUtil;
 import dunit.DistributedTestCase;
 import dunit.Host;
 import dunit.VM;
-import dunit.DistributedTestCase.ExpectedException;
 
 /**
  * Tests cacheserver ssl support added. See https://svn.gemstone.com/trac/gemfire/ticket/48995 for details
@@ -48,13 +39,10 @@ public class CacheServerSSLConnectionDUnit extends DistributedTestCase {
   
   private static final long serialVersionUID = 1L;
   private Cache cache;
-  private DistributedSystem ds;
   private CacheServer cacheServer;
   private ClientCache clientCache;
   private int cacheServerPort;
   private String hostName;
-  private int locatorPort;
-  private Locator locator;
   
   private static final String TRUSTED_STORE = "trusted.keystore";
   private static final String CLIENT_KEY_STORE = "client.keystore";
@@ -76,8 +64,9 @@ public class CacheServerSSLConnectionDUnit extends DistributedTestCase {
 
   public Cache createCache(Properties props) throws Exception
   {
-    ds = getSystem(props);
-    cache = CacheFactory.create(ds);
+    props.setProperty("mcast-port", "0");
+    props.setProperty("locators", "");
+    cache = new CacheFactory(props).create();
     if (cache == null) {
       throw new Exception("CacheFactory.create() returned null ");
     }
@@ -106,51 +95,29 @@ public class CacheServerSSLConnectionDUnit extends DistributedTestCase {
   
   
   @SuppressWarnings("rawtypes")
-  public void setUpServerVM(boolean cacheServerSslenabled, boolean p2pProps, String locators) throws Exception {
+  public void setUpServerVM(boolean cacheServerSslenabled) throws Exception {
     Properties gemFireProps = new Properties();
 
     String cacheServerSslprotocols = "any";
     String cacheServerSslciphers = "any";
     boolean cacheServerSslRequireAuth = true;
-    if (!p2pProps) {
-      gemFireProps.put(DistributionConfig.SERVER_SSL_ENABLED_NAME,
-          String.valueOf(cacheServerSslenabled));
-      gemFireProps.put(DistributionConfig.SERVER_SSL_PROTOCOLS_NAME,
-          cacheServerSslprotocols);
-      gemFireProps.put(DistributionConfig.SERVER_SSL_CIPHERS_NAME,
-          cacheServerSslciphers);
-      gemFireProps.put(
-          DistributionConfig.SERVER_SSL_REQUIRE_AUTHENTICATION_NAME,
-          String.valueOf(cacheServerSslRequireAuth));
-      
-      String keyStore = TestUtil.getResourcePath(CacheServerSSLConnectionDUnit.class, SERVER_KEY_STORE);
-      String trustStore = TestUtil.getResourcePath(CacheServerSSLConnectionDUnit.class, SERVER_TRUST_STORE);
-      gemFireProps.put(DistributionConfig.SERVER_SSL_KEYSTORE_TYPE_NAME, "jks");
-      gemFireProps.put(DistributionConfig.SERVER_SSL_KEYSTORE_NAME, keyStore);
-      gemFireProps.put(DistributionConfig.SERVER_SSL_KEYSTORE_PASSWORD_NAME, "password");
-      gemFireProps.put(DistributionConfig.SERVER_SSL_TRUSTSTORE_NAME, trustStore);
-      gemFireProps.put(DistributionConfig.SERVER_SSL_TRUSTSTORE_PASSWORD_NAME, "password");
-    } else {
-      
-      gemFireProps.put(DistributionConfig.SSL_ENABLED_NAME,
-          String.valueOf(cacheServerSslenabled));
-      gemFireProps.put(DistributionConfig.SSL_PROTOCOLS_NAME,
-          cacheServerSslprotocols);
-      gemFireProps.put(DistributionConfig.SSL_CIPHERS_NAME,
-          cacheServerSslciphers);
-      gemFireProps.put(
-          DistributionConfig.SSL_REQUIRE_AUTHENTICATION_NAME,
-          String.valueOf(cacheServerSslRequireAuth));
+    gemFireProps.put(DistributionConfig.SERVER_SSL_ENABLED_NAME,
+        String.valueOf(cacheServerSslenabled));
+    gemFireProps.put(DistributionConfig.SERVER_SSL_PROTOCOLS_NAME,
+        cacheServerSslprotocols);
+    gemFireProps.put(DistributionConfig.SERVER_SSL_CIPHERS_NAME,
+        cacheServerSslciphers);
+    gemFireProps.put(
+        DistributionConfig.SERVER_SSL_REQUIRE_AUTHENTICATION_NAME,
+        String.valueOf(cacheServerSslRequireAuth));
 
-      String keyStore = TestUtil.getResourcePath(CacheServerSSLConnectionDUnit.class, TRUSTED_STORE);
-      String trustStore = TestUtil.getResourcePath(CacheServerSSLConnectionDUnit.class, TRUSTED_STORE);
-      gemFireProps.put("javax.net.ssl.keyStoreType", "jks");
-      gemFireProps.put("javax.net.ssl.keyStore", keyStore);
-      gemFireProps.put("javax.net.ssl.keyStorePassword", "password");
-      gemFireProps.put("javax.net.ssl.trustStore", trustStore);
-      gemFireProps.put("javax.net.ssl.trustStorePassword", "password");
-      gemFireProps.put(DistributionConfig.LOCATORS_NAME, locators);
-    }
+    String keyStore = TestUtil.getResourcePath(CacheServerSSLConnectionDUnit.class, SERVER_KEY_STORE);
+    String trustStore = TestUtil.getResourcePath(CacheServerSSLConnectionDUnit.class, SERVER_TRUST_STORE);
+    gemFireProps.put(DistributionConfig.SERVER_SSL_KEYSTORE_TYPE_NAME, "jks");
+    gemFireProps.put(DistributionConfig.SERVER_SSL_KEYSTORE_NAME, keyStore);
+    gemFireProps.put(DistributionConfig.SERVER_SSL_KEYSTORE_PASSWORD_NAME, "password");
+    gemFireProps.put(DistributionConfig.SERVER_SSL_TRUSTSTORE_NAME, trustStore);
+    gemFireProps.put(DistributionConfig.SERVER_SSL_TRUSTSTORE_PASSWORD_NAME, "password");
     
     StringWriter sw = new StringWriter();
     PrintWriter writer = new PrintWriter(sw);
@@ -163,18 +130,9 @@ public class CacheServerSSLConnectionDUnit extends DistributedTestCase {
     r.put("serverkey", "servervalue");
   }
   
-  public static String makePath(String[] strings) {
-    StringBuilder sb = new StringBuilder();
-    for(int i=0;i<strings.length;i++){
-      sb.append(strings[i]);      
-      sb.append(File.separator);
-    }
-    return sb.toString();
-  }
-
   public void setUpClientVM(String host, int port,
       boolean cacheServerSslenabled, boolean cacheServerSslRequireAuth,
-      boolean p2pProps, String locators, String keyStore, String trustStore) {
+      String keyStore, String trustStore) {
 
     Properties gemFireProps = new Properties();
 
@@ -184,40 +142,21 @@ public class CacheServerSSLConnectionDUnit extends DistributedTestCase {
     String keyStorePath = TestUtil.getResourcePath(CacheServerSSLConnectionDUnit.class, keyStore);
     String trustStorePath = TestUtil.getResourcePath(CacheServerSSLConnectionDUnit.class, trustStore);
     //using new server-ssl-* properties
-    if (!p2pProps) {
-      gemFireProps.put(DistributionConfig.SERVER_SSL_ENABLED_NAME,
-          String.valueOf(cacheServerSslenabled));
-      gemFireProps.put(DistributionConfig.SERVER_SSL_PROTOCOLS_NAME,
-          cacheServerSslprotocols);
-      gemFireProps.put(DistributionConfig.SERVER_SSL_CIPHERS_NAME,
-          cacheServerSslciphers);
-      gemFireProps.put(
-          DistributionConfig.SERVER_SSL_REQUIRE_AUTHENTICATION_NAME,
-          String.valueOf(cacheServerSslRequireAuth));
-      
-      gemFireProps.put(DistributionConfig.SERVER_SSL_KEYSTORE_TYPE_NAME, "jks");
-      gemFireProps.put(DistributionConfig.SERVER_SSL_KEYSTORE_NAME, keyStorePath);
-      gemFireProps.put(DistributionConfig.SERVER_SSL_KEYSTORE_PASSWORD_NAME, "password");
-      gemFireProps.put(DistributionConfig.SERVER_SSL_TRUSTSTORE_NAME, trustStorePath);
-      gemFireProps.put(DistributionConfig.SERVER_SSL_TRUSTSTORE_PASSWORD_NAME, "password");
-    } else {
-      //using p2p ssl-* properties
-      gemFireProps.put(DistributionConfig.SSL_ENABLED_NAME,
-          String.valueOf(cacheServerSslenabled));
-      gemFireProps.put(DistributionConfig.SSL_PROTOCOLS_NAME,
-          cacheServerSslprotocols);
-      gemFireProps.put(DistributionConfig.SSL_CIPHERS_NAME,
-          cacheServerSslciphers);
-      gemFireProps.put(
-          DistributionConfig.SSL_REQUIRE_AUTHENTICATION_NAME,
-          String.valueOf(cacheServerSslRequireAuth));
+    gemFireProps.put(DistributionConfig.SERVER_SSL_ENABLED_NAME,
+        String.valueOf(cacheServerSslenabled));
+    gemFireProps.put(DistributionConfig.SERVER_SSL_PROTOCOLS_NAME,
+        cacheServerSslprotocols);
+    gemFireProps.put(DistributionConfig.SERVER_SSL_CIPHERS_NAME,
+        cacheServerSslciphers);
+    gemFireProps.put(
+        DistributionConfig.SERVER_SSL_REQUIRE_AUTHENTICATION_NAME,
+        String.valueOf(cacheServerSslRequireAuth));
 
-      gemFireProps.put("javax.net.ssl.keyStoreType", "jks");
-      gemFireProps.put("javax.net.ssl.keyStore", keyStorePath);
-      gemFireProps.put("javax.net.ssl.keyStorePassword", "password");
-      gemFireProps.put("javax.net.ssl.trustStore", trustStorePath);
-      gemFireProps.put("javax.net.ssl.trustStorePassword", "password");
-    }
+    gemFireProps.put(DistributionConfig.SERVER_SSL_KEYSTORE_TYPE_NAME, "jks");
+    gemFireProps.put(DistributionConfig.SERVER_SSL_KEYSTORE_NAME, keyStorePath);
+    gemFireProps.put(DistributionConfig.SERVER_SSL_KEYSTORE_PASSWORD_NAME, "password");
+    gemFireProps.put(DistributionConfig.SERVER_SSL_TRUSTSTORE_NAME, trustStorePath);
+    gemFireProps.put(DistributionConfig.SERVER_SSL_TRUSTSTORE_PASSWORD_NAME, "password");
 
     StringWriter sw = new StringWriter();
     PrintWriter writer = new PrintWriter(sw);
@@ -247,8 +186,8 @@ public class CacheServerSSLConnectionDUnit extends DistributedTestCase {
   }
   
   
-  public static void setUpServerVMTask(boolean cacheServerSslenabled, boolean p2pProps, String locators) throws Exception{
-    instance.setUpServerVM(cacheServerSslenabled,p2pProps,locators);
+  public static void setUpServerVMTask(boolean cacheServerSslenabled) throws Exception{
+    instance.setUpServerVM(cacheServerSslenabled);
   }
   
   public static void createServerTask() throws Exception {
@@ -256,10 +195,10 @@ public class CacheServerSSLConnectionDUnit extends DistributedTestCase {
   }
   
   public static void setUpClientVMTask(String host, int port,
-      boolean cacheServerSslenabled, boolean cacheServerSslRequireAuth, boolean p2pProps, String locators, String keyStore, String trustStore)
+      boolean cacheServerSslenabled, boolean cacheServerSslRequireAuth, String keyStore, String trustStore)
       throws Exception {
     instance.setUpClientVM(host, port, cacheServerSslenabled,
-        cacheServerSslRequireAuth,p2pProps,locators, keyStore, trustStore);
+        cacheServerSslRequireAuth, keyStore, trustStore);
   }
   
   public static void doClientRegionTestTask() {
@@ -289,160 +228,6 @@ public class CacheServerSSLConnectionDUnit extends DistributedTestCase {
     }
   }
   
-  public static void setUpSSLLocatorVMTask() throws Exception {
-    
-    Properties props = new Properties();
-    instance.locatorPort = AvailablePortHelper.getRandomAvailableTCPPort();
-    props.setProperty(DistributionConfig.MCAST_PORT_NAME,"0");
-    props.setProperty(DistributionConfig.LOG_LEVEL_NAME, getDUnitLogLevel());
-    
-    String cacheServerSslprotocols = "any";
-    String cacheServerSslciphers = "any";
-    
-    props.put(DistributionConfig.CLUSTER_SSL_ENABLED_NAME,
-        String.valueOf(true));
-    props.put(DistributionConfig.CLUSTER_SSL_PROTOCOLS_NAME,
-        cacheServerSslprotocols);
-    props.put(DistributionConfig.CLUSTER_SSL_CIPHERS_NAME,
-        cacheServerSslciphers);
-    
-    props.put(
-        DistributionConfig.CLUSTER_SSL_REQUIRE_AUTHENTICATION_NAME,
-        String.valueOf(true)); 
-    
-    props.put("javax.net.ssl.keyStoreType", "jks");
-    String keyStorePath = TestUtil.getResourcePath(CacheServerSSLConnectionDUnit.class, TRUSTED_STORE);
-    String trustStorePath = TestUtil.getResourcePath(CacheServerSSLConnectionDUnit.class, TRUSTED_STORE);
-    props.put("javax.net.ssl.keyStore", keyStorePath);
-    props.put("javax.net.ssl.keyStorePassword", "password");
-    props.put("javax.net.ssl.trustStore", trustStorePath);
-    props.put("javax.net.ssl.trustStorePassword", "password");
-    StringWriter sw = new StringWriter();
-    PrintWriter writer = new PrintWriter(sw);
-    props.list(writer);
-    getLogWriter().info("Starting locator ds with following properties \n" + sw.getBuffer());
-    
-    try {
-      File logFile = new File(testName + "-locator" + instance.locatorPort
-          + ".log");
-      InetAddress bindAddr = null;
-      try {
-        bindAddr = InetAddress.getLocalHost();
-      } catch (UnknownHostException uhe) {
-        fail("While resolving bind address ", uhe);
-      }
-      props.setProperty(DistributionConfig.ENABLE_CLUSTER_CONFIGURATION_NAME, "false");
-      instance.locator = Locator.startLocatorAndDS(instance.locatorPort, logFile, bindAddr, props);
-    } catch (IOException ex) {
-      fail("While starting locator on port " + instance.locatorPort, ex);
-    }    
-    //instance.getSystem(props);
-    getLogWriter().info("Locator has started ...");
-  }
-  
-  
-  public static String getLocatorPortTask() {    
-    return instance.locator.getBindAddress().getHostName() + "[" + instance.locatorPort +"]";
-  }
-  
-  public static void resetSSLPropertiesTask() {
-    System.clearProperty("javax.net.ssl.keyStoreType");
-    System.clearProperty("javax.net.ssl.keyStore");
-    System.clearProperty("javax.net.ssl.keyStorePassword");
-    System.clearProperty("javax.net.ssl.trustStore");
-    System.clearProperty("javax.net.ssl.trustStorePassword");    
-  }
-
-  
-  /*
-   * Tests that cacheserver started with ssl-enabled properties accepts connection with client configured with ssl-enabled property
-   */
-  public void DISABLEtestCacheServerSSL_OldWay_P2P() throws Exception {
-    final Host host = Host.getHost(0);
-    VM serverVM = host.getVM(1);
-    VM clientVM = host.getVM(2);
-    VM locatorVM = host.getVM(0);
-    
-    boolean cacheServerSslenabled = true;
-    boolean cacheClientSslenabled = true;
-    boolean cacheClientSslRequireAuth = true;
-    boolean useP2pSSLProperties = true;
-    
-    //start SSL Locator
-    locatorVM.invoke(CacheServerSSLConnectionDUnit.class, "setUpSSLLocatorVMTask");
-    String locatorport = (String)locatorVM.invoke(CacheServerSSLConnectionDUnit.class, "getLocatorPortTask");
-    
-    Thread.sleep(10);
-    
-    serverVM.invoke(CacheServerSSLConnectionDUnit.class, "setUpServerVMTask", new Object[]{cacheServerSslenabled, useP2pSSLProperties, locatorport});
-    serverVM.invoke(CacheServerSSLConnectionDUnit.class, "createServerTask");
-    
-    Object array[] = (Object[])serverVM.invoke(CacheServerSSLConnectionDUnit.class, "getCacheServerEndPointTask"); 
-    String hostName = (String)array[0];
-    int port = (Integer) array[1];
-    Object params[] = new Object[8];
-    params[0] = hostName;
-    params[1] = port;
-    params[2] = cacheClientSslenabled;
-    params[3] = cacheClientSslRequireAuth;
-    params[4] = useP2pSSLProperties;
-    params[5] = locatorport;
-    params[6] = TRUSTED_STORE;
-    params[7] = TRUSTED_STORE;
-    getLogWriter().info("Starting client with server endpoint " + hostName + ":" + port);
-    clientVM.invoke(CacheServerSSLConnectionDUnit.class, "setUpClientVMTask", params);
-    clientVM.invoke(CacheServerSSLConnectionDUnit.class, "doClientRegionTestTask");
-    serverVM.invoke(CacheServerSSLConnectionDUnit.class, "doServerRegionTestTask");
-    
-    locatorVM.invoke(CacheServerSSLConnectionDUnit.class, "resetSSLPropertiesTask");
-    
-  }
-  
-  /*
-   * Tests that cacheserver started with ssl-enabled properties  accepts connection with client configured with ssl-enabled property
-   */  
-  public void DISABLEtestCacheServerSSL_ServerOldWay_ClientNewWay() throws Exception {
-    final Host host = Host.getHost(0);
-    VM serverVM = host.getVM(1);
-    VM clientVM = host.getVM(2);
-    VM locatorVM = host.getVM(0);
-    
-    boolean cacheServerSslenabled = true;
-    boolean cacheClientSslenabled = true;
-    boolean cacheClientSslRequireAuth = true;
-    boolean useP2pSSLProperties = true;
-    
-    //start SSL Locator
-    locatorVM.invoke(CacheServerSSLConnectionDUnit.class, "setUpSSLLocatorVMTask");
-    String locatorport = (String)locatorVM.invoke(CacheServerSSLConnectionDUnit.class, "getLocatorPortTask");
-    
-    Thread.sleep(10);
-    
-    serverVM.invoke(CacheServerSSLConnectionDUnit.class, "setUpServerVMTask", new Object[]{cacheServerSslenabled, useP2pSSLProperties, locatorport});
-    serverVM.invoke(CacheServerSSLConnectionDUnit.class, "createServerTask");
-    
-    Object array[] = (Object[])serverVM.invoke(CacheServerSSLConnectionDUnit.class, "getCacheServerEndPointTask"); 
-    String hostName = (String)array[0];
-    int port = (Integer) array[1];
-    Object params[] = new Object[8];
-    params[0] = hostName;
-    params[1] = port;
-    params[2] = cacheClientSslenabled;
-    params[3] = cacheClientSslRequireAuth;
-    params[4] = !useP2pSSLProperties;
-    params[5] = locatorport;
-    params[6] = TRUSTED_STORE;
-    params[7] = TRUSTED_STORE;
-    getLogWriter().info("Starting client with server endpoint " + hostName + ":" + port);
-    clientVM.invoke(CacheServerSSLConnectionDUnit.class, "setUpClientVMTask", params);
-    clientVM.invoke(CacheServerSSLConnectionDUnit.class, "doClientRegionTestTask");
-    serverVM.invoke(CacheServerSSLConnectionDUnit.class, "doServerRegionTestTask");
-    
-    locatorVM.invoke(CacheServerSSLConnectionDUnit.class, "resetSSLPropertiesTask");
-    
-  }
-  
-  
   public void testCacheServerSSL() throws Exception {
     final Host host = Host.getHost(0);
     VM serverVM = host.getVM(1);
@@ -451,24 +236,21 @@ public class CacheServerSSLConnectionDUnit extends DistributedTestCase {
     boolean cacheServerSslenabled = true;
     boolean cacheClientSslenabled = true;
     boolean cacheClientSslRequireAuth = true;
-    boolean useP2pSSLProperties = true;
     
-    serverVM.invoke(CacheServerSSLConnectionDUnit.class, "setUpServerVMTask", new Object[]{cacheServerSslenabled, !useP2pSSLProperties,null});
+    serverVM.invoke(CacheServerSSLConnectionDUnit.class, "setUpServerVMTask", new Object[]{cacheServerSslenabled});
     serverVM.invoke(CacheServerSSLConnectionDUnit.class, "createServerTask");
     
     Object array[] = (Object[])serverVM.invoke(CacheServerSSLConnectionDUnit.class, "getCacheServerEndPointTask"); 
     String hostName = (String)array[0];
     int port = (Integer) array[1];
-    Object params[] = new Object[8];
+    Object params[] = new Object[6];
     params[0] = hostName;
     params[1] = port;
     params[2] = cacheClientSslenabled;
     params[3] = cacheClientSslRequireAuth;
-    params[4] = !useP2pSSLProperties; //using new server-ssl properties not p2p ssl properties
-    params[5] = null;
-    params[6] = CLIENT_KEY_STORE;
-    params[7] = CLIENT_TRUST_STORE;
-    getLogWriter().info("Starting client with server endpoint " + hostName + ":" + port);
+    params[4] = CLIENT_KEY_STORE;
+    params[5] = CLIENT_TRUST_STORE;
+    //getLogWriter().info("Starting client with server endpoint " + hostName + ":" + port);
     clientVM.invoke(CacheServerSSLConnectionDUnit.class, "setUpClientVMTask", params);
     clientVM.invoke(CacheServerSSLConnectionDUnit.class, "doClientRegionTestTask");
     serverVM.invoke(CacheServerSSLConnectionDUnit.class, "doServerRegionTestTask");
@@ -484,40 +266,37 @@ public class CacheServerSSLConnectionDUnit extends DistributedTestCase {
     boolean cacheServerSslenabled = true;
     boolean cacheClientSslenabled = false;
     boolean cacheClientSslRequireAuth = true;
-    boolean useP2pSSLProperties = true;
     
-    serverVM.invoke(CacheServerSSLConnectionDUnit.class, "setUpServerVMTask", new Object[]{cacheServerSslenabled, !useP2pSSLProperties, null});
+    serverVM.invoke(CacheServerSSLConnectionDUnit.class, "setUpServerVMTask", new Object[]{cacheServerSslenabled});
     serverVM.invoke(CacheServerSSLConnectionDUnit.class, "createServerTask");
     
     Object array[] = (Object[])serverVM.invoke(CacheServerSSLConnectionDUnit.class, "getCacheServerEndPointTask"); 
     String hostName = (String)array[0];
     int port = (Integer) array[1];
-    Object params[] = new Object[8];
+    Object params[] = new Object[6];
     params[0] = hostName;
     params[1] = port;
     params[2] = cacheClientSslenabled;
     params[3] = cacheClientSslRequireAuth;
-    params[4] = !useP2pSSLProperties; //using new server-ssl properties not p2p ssl properties
-    params[5] = null;
-    params[6] = TRUSTED_STORE;
-    params[7] = TRUSTED_STORE;
+    params[4] = TRUSTED_STORE;
+    params[5] = TRUSTED_STORE;
     ExpectedException expect = addExpectedException("javax.net.ssl.SSLException", serverVM);
     ExpectedException expect2 = addExpectedException("IOException", serverVM);
     try{
-      getLogWriter().info("Starting client with server endpoint " + hostName + ":" + port);    
+      //getLogWriter().info("Starting client with server endpoint " + hostName + ":" + port);    
       clientVM.invoke(CacheServerSSLConnectionDUnit.class, "setUpClientVMTask", params);
       clientVM.invoke(CacheServerSSLConnectionDUnit.class, "doClientRegionTestTask");
       serverVM.invoke(CacheServerSSLConnectionDUnit.class, "doServerRegionTestTask");
       fail("Test should fail as non-ssl client is trying to connect to ssl configured server");
     } catch (Exception rmiException) {
       Throwable e = rmiException.getCause();
-      getLogWriter().info("ExceptionCause at clientVM " + e);
+      //getLogWriter().info("ExceptionCause at clientVM " + e);
       if (e instanceof com.gemstone.gemfire.cache.client.ServerOperationException) {
         Throwable t = e.getCause();
-        getLogWriter().info("Cause is " + t);
+        //getLogWriter().info("Cause is " + t);
         assertTrue(t instanceof com.gemstone.gemfire.security.AuthenticationRequiredException);
       } else {
-        getLogWriter().error("Unexpected exception ", e);
+        //getLogWriter().error("Unexpected exception ", e);
         fail("Unexpected Exception...expected "
             + AuthenticationRequiredException.class);
       }
@@ -527,7 +306,6 @@ public class CacheServerSSLConnectionDUnit extends DistributedTestCase {
     }
   }
   
-  /* It seems it is allowed if client chooses to not insist on authentication. weird let this test fail??? */
   public void testSSLClientWithNoAuth() throws Exception {
     final Host host = Host.getHost(0);
     VM serverVM = host.getVM(1);
@@ -536,87 +314,39 @@ public class CacheServerSSLConnectionDUnit extends DistributedTestCase {
     boolean cacheServerSslenabled = true;
     boolean cacheClientSslenabled = true;
     boolean cacheClientSslRequireAuth = false;
-    boolean useP2pSSLProperties = true;
 
-    serverVM.invoke(CacheServerSSLConnectionDUnit.class, "setUpServerVMTask", new Object[]{cacheServerSslenabled, !useP2pSSLProperties,null});
+    serverVM.invoke(CacheServerSSLConnectionDUnit.class, "setUpServerVMTask", new Object[]{cacheServerSslenabled});
     serverVM.invoke(CacheServerSSLConnectionDUnit.class, "createServerTask");
 
     Object array[] = (Object[])serverVM.invoke(CacheServerSSLConnectionDUnit.class, "getCacheServerEndPointTask"); 
     String hostName = (String)array[0];
     int port = (Integer) array[1];
-    Object params[] = new Object[8];
+    Object params[] = new Object[6];
     params[0] = hostName;
     params[1] = port;
     params[2] = cacheClientSslenabled;
     params[3] = cacheClientSslRequireAuth;
-    params[4] = !useP2pSSLProperties; //using new server-ssl properties not p2p ssl properties
-    params[5] = null;
-    params[6] = CLIENT_KEY_STORE;
-    params[7] = CLIENT_TRUST_STORE;
-    getLogWriter().info("Starting client with server endpoint " + hostName + ":" + port);
+    params[4] = CLIENT_KEY_STORE;
+    params[5] = CLIENT_TRUST_STORE;
+    //getLogWriter().info("Starting client with server endpoint " + hostName + ":" + port);
     try {
       clientVM.invoke(CacheServerSSLConnectionDUnit.class, "setUpClientVMTask", params);
       clientVM.invoke(CacheServerSSLConnectionDUnit.class, "doClientRegionTestTask");
       serverVM.invoke(CacheServerSSLConnectionDUnit.class, "doServerRegionTestTask");
-      fail("Test should fail as ssl client with wrong config(SslRequireAuth=false) is trying to connect to ssl configured server");
     } catch (Exception rmiException) {
       Throwable e = rmiException.getCause();
-      getLogWriter().info("ExceptionCause at clientVM " + e);
+      //getLogWriter().info("ExceptionCause at clientVM " + e);
       if (e instanceof com.gemstone.gemfire.cache.client.ServerOperationException) {
         Throwable t = e.getCause();
-        getLogWriter().info("Cause is " + t);
+        //getLogWriter().info("Cause is " + t);
         assertTrue(t instanceof com.gemstone.gemfire.security.AuthenticationRequiredException);
       } else {
-        getLogWriter().error("Unexpected exception ", e);
+        //getLogWriter().error("Unexpected exception ", e);
         fail("Unexpected Exception...expected "
             + AuthenticationRequiredException.class);
       }
     }
   }
-//    final Host host = Host.getHost(0);
-//    VM serverVM = host.getVM(1);
-//    VM clientVM = host.getVM(2);
-//    
-//    boolean cacheServerSslenabled = true;
-//    boolean cacheClientSslenabled = true;
-//    boolean cacheClientSslRequireAuth = true;
-//    
-//    serverVM.invoke(CacheServerSSLConnectionDUnit.class, "setUpServerVMTask", new Object[]{cacheServerSslenabled, false, null});
-//    serverVM.invoke(CacheServerSSLConnectionDUnit.class, "createServerTask");
-//    
-//    Object array[] = (Object[])serverVM.invoke(CacheServerSSLConnectionDUnit.class, "getCacheServerEndPointTask"); 
-//    String hostName = (String)array[0];
-//    int port = (Integer) array[1];
-//    Object params[] = new Object[8];
-//    params[0] = hostName;
-//    params[1] = port;
-//    params[2] = cacheClientSslenabled;
-//    params[3] = cacheClientSslRequireAuth;
-//    params[4] = false;
-//    params[5] = null;
-//    params[6] = TRUSTED_STORE;
-//    params[7] = TRUSTED_STORE;
-//    try{
-//      getLogWriter().info("Starting client with server endpoint " + hostName + ":" + port);    
-//      clientVM.invoke(CacheServerSSLConnectionDUnit.class, "setUpClientVMTask", params);
-//      clientVM.invoke(CacheServerSSLConnectionDUnit.class, "doClientRegionTestTask");
-//      serverVM.invoke(CacheServerSSLConnectionDUnit.class, "doServerRegionTestTask");
-//      fail("Test should fail as ssl client with wrong config(SslRequireAuth=false) is trying to connect to ssl configured server");
-//    } catch (Exception rmiException) {
-//      Throwable e = rmiException.getCause();
-//      getLogWriter().info("ExceptionCause at clientVM " + e);
-//      if (e instanceof com.gemstone.gemfire.cache.client.ServerOperationException) {
-//        Throwable t = e.getCause();
-//        getLogWriter().info("Cause is " + t);
-//        assertTrue(t instanceof com.gemstone.gemfire.security.AuthenticationRequiredException);
-//      } else {
-//        getLogWriter().error("Unexpected exception ", e);
-//        fail("Unexpected Exception...expected "
-//            + AuthenticationRequiredException.class);
-//      }
-//    }
-//  }
-  
   
   public void testSSLClientWithNonSSLServer() throws Exception {
     final Host host = Host.getHost(0);
@@ -626,26 +356,23 @@ public class CacheServerSSLConnectionDUnit extends DistributedTestCase {
     boolean cacheServerSslenabled = false;
     boolean cacheClientSslenabled = true;
     boolean cacheClientSslRequireAuth = true;
-    boolean useP2pSSLProperties = true;
     
-    serverVM.invoke(CacheServerSSLConnectionDUnit.class, "setUpServerVMTask", new Object[]{cacheServerSslenabled, !useP2pSSLProperties, null});
+    serverVM.invoke(CacheServerSSLConnectionDUnit.class, "setUpServerVMTask", new Object[]{cacheServerSslenabled});
     serverVM.invoke(CacheServerSSLConnectionDUnit.class, "createServerTask");
     
     Object array[] = (Object[])serverVM.invoke(CacheServerSSLConnectionDUnit.class, "getCacheServerEndPointTask"); 
     String hostName = (String)array[0];
     int port = (Integer) array[1];
-    Object params[] = new Object[8];
+    Object params[] = new Object[6];
     params[0] = hostName;
     params[1] = port;
     params[2] = cacheClientSslenabled;
     params[3] = cacheClientSslRequireAuth;
-    params[4] = !useP2pSSLProperties;
-    params[5] = null;
-    params[6] = TRUSTED_STORE;
-    params[7] = TRUSTED_STORE;
+    params[4] = TRUSTED_STORE;
+    params[5] = TRUSTED_STORE;
     ExpectedException expect = addExpectedException("javax.net.ssl.SSLHandshakeException", serverVM);
     try{
-      getLogWriter().info("Starting client with server endpoint " + hostName + ":" + port);    
+      //getLogWriter().info("Starting client with server endpoint " + hostName + ":" + port);    
       clientVM.invoke(CacheServerSSLConnectionDUnit.class, "setUpClientVMTask", params);
       clientVM.invoke(CacheServerSSLConnectionDUnit.class, "doClientRegionTestTask");
       serverVM.invoke(CacheServerSSLConnectionDUnit.class, "doServerRegionTestTask");


[4/4] incubator-geode git commit: added unit test to verify client auth config is working

Posted by ds...@apache.org.
added unit test to verify client auth config is working


Project: http://git-wip-us.apache.org/repos/asf/incubator-geode/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-geode/commit/b023af4c
Tree: http://git-wip-us.apache.org/repos/asf/incubator-geode/tree/b023af4c
Diff: http://git-wip-us.apache.org/repos/asf/incubator-geode/diff/b023af4c

Branch: refs/heads/feature/GEODE-397
Commit: b023af4c953bde51222af0924307d0216950a88a
Parents: 8c1c911
Author: Darrel Schneider <ds...@pivotal.io>
Authored: Thu Oct 15 17:29:01 2015 -0700
Committer: Darrel Schneider <ds...@pivotal.io>
Committed: Thu Oct 15 17:29:01 2015 -0700

----------------------------------------------------------------------
 .../internal/SSLNoClientAuthDUnitTest.java      | 271 +++++++++++++++++++
 .../cache/client/internal/default.keystore      | Bin 0 -> 1115 bytes
 2 files changed, 271 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/b023af4c/gemfire-core/src/test/java/com/gemstone/gemfire/cache/client/internal/SSLNoClientAuthDUnitTest.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/test/java/com/gemstone/gemfire/cache/client/internal/SSLNoClientAuthDUnitTest.java b/gemfire-core/src/test/java/com/gemstone/gemfire/cache/client/internal/SSLNoClientAuthDUnitTest.java
new file mode 100644
index 0000000..390c285
--- /dev/null
+++ b/gemfire-core/src/test/java/com/gemstone/gemfire/cache/client/internal/SSLNoClientAuthDUnitTest.java
@@ -0,0 +1,271 @@
+/*=========================================================================
+ * Copyright (c) 2010-2014 Pivotal Software, Inc. All Rights Reserved.
+ * This product is protected by U.S. and international copyright
+ * and intellectual property laws. Pivotal products are covered by
+ * one or more patents listed at http://www.pivotal.io/patents.
+ *=========================================================================
+ */
+package com.gemstone.gemfire.cache.client.internal;
+
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.io.StringWriter;
+import java.util.Properties;
+import com.gemstone.gemfire.cache.Cache;
+import com.gemstone.gemfire.cache.CacheFactory;
+import com.gemstone.gemfire.cache.Region;
+import com.gemstone.gemfire.cache.RegionFactory;
+import com.gemstone.gemfire.cache.RegionShortcut;
+import com.gemstone.gemfire.cache.client.ClientCache;
+import com.gemstone.gemfire.cache.client.ClientCacheFactory;
+import com.gemstone.gemfire.cache.client.ClientRegionFactory;
+import com.gemstone.gemfire.cache.client.ClientRegionShortcut;
+import com.gemstone.gemfire.cache.server.CacheServer;
+import com.gemstone.gemfire.distributed.internal.DistributionConfig;
+import com.gemstone.gemfire.internal.AvailablePortHelper;
+import com.gemstone.gemfire.security.AuthenticationRequiredException;
+import com.gemstone.gemfire.util.test.TestUtil;
+
+import dunit.DistributedTestCase;
+import dunit.Host;
+import dunit.VM;
+
+/**
+ * Test for GEODE-396
+ */
+public class SSLNoClientAuthDUnitTest extends DistributedTestCase {
+  
+  private static final long serialVersionUID = 1L;
+  private Cache cache;
+  private CacheServer cacheServer;
+  private ClientCache clientCache;
+  private int cacheServerPort;
+  private String hostName;
+  
+  private static final String DEFAULT_STORE = "default.keystore";
+  
+  private static SSLNoClientAuthDUnitTest instance = new SSLNoClientAuthDUnitTest("SSLNoClientAuthDUnitTest");
+  
+  
+  public void setUp() throws Exception {
+    disconnectAllFromDS();
+    super.setUp();
+  }
+
+  public SSLNoClientAuthDUnitTest(String name) {
+    super(name);
+  }  
+
+  public Cache createCache(Properties props) throws Exception
+  {
+    props.setProperty("mcast-port", "0");
+    props.setProperty("locators", "");
+    cache = new CacheFactory(props).create();
+    if (cache == null) {
+      throw new Exception("CacheFactory.create() returned null ");
+    }
+    return cache;
+  }
+  
+  private void createServer() throws IOException{
+    cacheServerPort = AvailablePortHelper.getRandomAvailableTCPPort();
+    cacheServer = cache.addCacheServer();
+    cacheServer.setPort(cacheServerPort);
+    cacheServer.start();
+    hostName = cacheServer.getHostnameForClients();
+  }
+  
+  public int getCacheServerPort(){
+    return cacheServerPort;
+  }
+  
+  public String getCacheServerHost(){
+    return hostName;
+  }
+  
+  public void stopCacheServer(){
+    this.cacheServer.stop();
+  }
+  
+  
+  @SuppressWarnings("rawtypes")
+  public void setUpServerVM(boolean cacheServerSslenabled) throws Exception {
+    Properties gemFireProps = new Properties();
+
+    String cacheServerSslprotocols = "any";
+    String cacheServerSslciphers = "any";
+    boolean cacheServerSslRequireAuth = false;
+    gemFireProps.put(DistributionConfig.SERVER_SSL_ENABLED_NAME,
+        String.valueOf(cacheServerSslenabled));
+    gemFireProps.put(DistributionConfig.SERVER_SSL_PROTOCOLS_NAME,
+        cacheServerSslprotocols);
+    gemFireProps.put(DistributionConfig.SERVER_SSL_CIPHERS_NAME,
+        cacheServerSslciphers);
+    gemFireProps.put(
+        DistributionConfig.SERVER_SSL_REQUIRE_AUTHENTICATION_NAME,
+        String.valueOf(cacheServerSslRequireAuth));
+
+    String keyStore = TestUtil.getResourcePath(SSLNoClientAuthDUnitTest.class, DEFAULT_STORE);
+    String trustStore = TestUtil.getResourcePath(SSLNoClientAuthDUnitTest.class, DEFAULT_STORE);
+    gemFireProps.put(DistributionConfig.SERVER_SSL_KEYSTORE_TYPE_NAME, "jks");
+    gemFireProps.put(DistributionConfig.SERVER_SSL_KEYSTORE_NAME, keyStore);
+    gemFireProps.put(DistributionConfig.SERVER_SSL_KEYSTORE_PASSWORD_NAME, "password");
+    gemFireProps.put(DistributionConfig.SERVER_SSL_TRUSTSTORE_NAME, trustStore);
+    gemFireProps.put(DistributionConfig.SERVER_SSL_TRUSTSTORE_PASSWORD_NAME, "password");
+    
+    StringWriter sw = new StringWriter();
+    PrintWriter writer = new PrintWriter(sw);
+    gemFireProps.list(writer);
+    System.out.println("Starting cacheserver ds with following properties \n" + sw);
+    createCache(gemFireProps);
+    
+    RegionFactory factory = cache.createRegionFactory(RegionShortcut.REPLICATE);
+    Region r = factory.create("serverRegion");
+    r.put("serverkey", "servervalue");
+  }
+  
+  public void setUpClientVM(String host, int port,
+      boolean cacheServerSslenabled, boolean cacheServerSslRequireAuth,
+      String keyStore, String trustStore) {
+
+    Properties gemFireProps = new Properties();
+
+    String cacheServerSslprotocols = "any";
+    String cacheServerSslciphers = "any";
+
+    String keyStorePath = TestUtil.getResourcePath(SSLNoClientAuthDUnitTest.class, keyStore);
+    String trustStorePath = TestUtil.getResourcePath(SSLNoClientAuthDUnitTest.class, trustStore);
+    //using new server-ssl-* properties
+    gemFireProps.put(DistributionConfig.SERVER_SSL_ENABLED_NAME,
+        String.valueOf(cacheServerSslenabled));
+    gemFireProps.put(DistributionConfig.SERVER_SSL_PROTOCOLS_NAME,
+        cacheServerSslprotocols);
+    gemFireProps.put(DistributionConfig.SERVER_SSL_CIPHERS_NAME,
+        cacheServerSslciphers);
+    gemFireProps.put(
+        DistributionConfig.SERVER_SSL_REQUIRE_AUTHENTICATION_NAME,
+        String.valueOf(cacheServerSslRequireAuth));
+
+    gemFireProps.put(DistributionConfig.SERVER_SSL_KEYSTORE_TYPE_NAME, "jks");
+    gemFireProps.put(DistributionConfig.SERVER_SSL_KEYSTORE_NAME, keyStorePath);
+    gemFireProps.put(DistributionConfig.SERVER_SSL_KEYSTORE_PASSWORD_NAME, "password");
+    gemFireProps.put(DistributionConfig.SERVER_SSL_TRUSTSTORE_NAME, trustStorePath);
+    gemFireProps.put(DistributionConfig.SERVER_SSL_TRUSTSTORE_PASSWORD_NAME, "password");
+
+    StringWriter sw = new StringWriter();
+    PrintWriter writer = new PrintWriter(sw);
+    gemFireProps.list(writer);
+    System.out.println("Starting client ds with following properties \n" + sw.getBuffer());
+    
+    ClientCacheFactory clientCacheFactory = new ClientCacheFactory(gemFireProps);
+    clientCacheFactory.addPoolServer(host, port);
+    clientCache = clientCacheFactory.create();
+    
+    ClientRegionFactory<String,String> regionFactory = clientCache.createClientRegionFactory(ClientRegionShortcut.PROXY);
+    Region<String, String> region = regionFactory.create("serverRegion");  
+    assertNotNull(region);
+  }
+  
+  public void doClientRegionTest(){
+    Region<String, String> region = clientCache.getRegion("serverRegion");
+    assertEquals("servervalue",region.get("serverkey"));
+    region.put("clientkey", "clientvalue");
+    assertEquals("clientvalue",region.get("clientkey"));
+  }
+  
+  public void doServerRegionTest(){
+    Region<String, String> region = cache.getRegion("serverRegion");
+    assertEquals("servervalue",region.get("serverkey"));    
+    assertEquals("clientvalue",region.get("clientkey"));
+  }
+  
+  
+  public static void setUpServerVMTask(boolean cacheServerSslenabled) throws Exception{
+    instance.setUpServerVM(cacheServerSslenabled);
+  }
+  
+  public static void createServerTask() throws Exception {
+    instance.createServer();
+  }
+  
+  public static void setUpClientVMTask(String host, int port,
+      boolean cacheServerSslenabled, boolean cacheServerSslRequireAuth, String keyStore, String trustStore)
+      throws Exception {
+    instance.setUpClientVM(host, port, cacheServerSslenabled, cacheServerSslRequireAuth, keyStore, trustStore);
+  }
+  
+  public static void doClientRegionTestTask() {
+    instance.doClientRegionTest();
+  }
+  
+  public static void doServerRegionTestTask() {
+    instance.doServerRegionTest();
+  }
+  
+  public static Object[] getCacheServerEndPointTask() {
+    Object[] array = new Object[2];
+    array[0] = instance.getCacheServerHost();
+    array[1] = instance.getCacheServerPort();
+    return array;
+  }
+  
+  public static void closeCacheTask(){
+    if (instance != null && instance.cache != null) {
+      instance.cache.close();
+    }
+  }
+  
+  public static void closeClientCacheTask(){
+    if (instance != null && instance.clientCache != null) {
+      instance.clientCache.close();
+    }
+  }
+  
+  /**
+   * Test for GEODE-396
+   */
+  public void testSSLServerWithNoAuth() throws Exception {
+    final Host host = Host.getHost(0);
+    VM serverVM = host.getVM(1);
+    VM clientVM = host.getVM(2);
+
+    boolean cacheServerSslenabled = true;
+    boolean cacheClientSslenabled = true;
+    boolean cacheClientSslRequireAuth = true;
+
+    serverVM.invoke(SSLNoClientAuthDUnitTest.class, "setUpServerVMTask", new Object[]{cacheServerSslenabled});
+    serverVM.invoke(SSLNoClientAuthDUnitTest.class, "createServerTask");
+
+    Object array[] = (Object[])serverVM.invoke(SSLNoClientAuthDUnitTest.class, "getCacheServerEndPointTask"); 
+    String hostName = (String)array[0];
+    int port = (Integer) array[1];
+    Object params[] = new Object[6];
+    params[0] = hostName;
+    params[1] = port;
+    params[2] = cacheClientSslenabled;
+    params[3] = cacheClientSslRequireAuth;
+    params[4] = DEFAULT_STORE;
+    params[5] = DEFAULT_STORE;
+    //getLogWriter().info("Starting client with server endpoint " + hostName + ":" + port);
+    try {
+      clientVM.invoke(SSLNoClientAuthDUnitTest.class, "setUpClientVMTask", params);
+      clientVM.invoke(SSLNoClientAuthDUnitTest.class, "doClientRegionTestTask");
+      serverVM.invoke(SSLNoClientAuthDUnitTest.class, "doServerRegionTestTask");
+    } catch (Exception rmiException) {
+      Throwable e = rmiException.getCause();
+      //getLogWriter().info("ExceptionCause at clientVM " + e);
+      fail("Unexpected Exception " + e);
+    }
+  }
+  
+  public void tearDown2() throws Exception
+  {
+    final Host host = Host.getHost(0);
+    VM serverVM = host.getVM(1);
+    VM clientVM = host.getVM(2);
+    clientVM.invoke(SSLNoClientAuthDUnitTest.class, "closeClientCacheTask");
+    serverVM.invoke(SSLNoClientAuthDUnitTest.class, "closeCacheTask");
+    super.tearDown2();
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/b023af4c/gemfire-core/src/test/resources/com/gemstone/gemfire/cache/client/internal/default.keystore
----------------------------------------------------------------------
diff --git a/gemfire-core/src/test/resources/com/gemstone/gemfire/cache/client/internal/default.keystore b/gemfire-core/src/test/resources/com/gemstone/gemfire/cache/client/internal/default.keystore
new file mode 100644
index 0000000..9dbc135
Binary files /dev/null and b/gemfire-core/src/test/resources/com/gemstone/gemfire/cache/client/internal/default.keystore differ


[3/4] incubator-geode git commit: fixed name of dunit test

Posted by ds...@apache.org.
fixed name of dunit test


Project: http://git-wip-us.apache.org/repos/asf/incubator-geode/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-geode/commit/8c1c9115
Tree: http://git-wip-us.apache.org/repos/asf/incubator-geode/tree/8c1c9115
Diff: http://git-wip-us.apache.org/repos/asf/incubator-geode/diff/8c1c9115

Branch: refs/heads/feature/GEODE-397
Commit: 8c1c91155446239449edd5e1f967a7c9ef4d6410
Parents: 50d3b46
Author: Darrel Schneider <ds...@pivotal.io>
Authored: Thu Oct 15 16:01:52 2015 -0700
Committer: Darrel Schneider <ds...@pivotal.io>
Committed: Thu Oct 15 16:01:52 2015 -0700

----------------------------------------------------------------------
 .../internal/CacheServerSSLConnectionDUnit.java | 417 -------------------
 .../CacheServerSSLConnectionDUnitTest.java      | 417 +++++++++++++++++++
 2 files changed, 417 insertions(+), 417 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/8c1c9115/gemfire-core/src/test/java/com/gemstone/gemfire/cache/client/internal/CacheServerSSLConnectionDUnit.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/test/java/com/gemstone/gemfire/cache/client/internal/CacheServerSSLConnectionDUnit.java b/gemfire-core/src/test/java/com/gemstone/gemfire/cache/client/internal/CacheServerSSLConnectionDUnit.java
deleted file mode 100644
index d01866d..0000000
--- a/gemfire-core/src/test/java/com/gemstone/gemfire/cache/client/internal/CacheServerSSLConnectionDUnit.java
+++ /dev/null
@@ -1,417 +0,0 @@
-/*=========================================================================
- * Copyright (c) 2010-2014 Pivotal Software, Inc. All Rights Reserved.
- * This product is protected by U.S. and international copyright
- * and intellectual property laws. Pivotal products are covered by
- * one or more patents listed at http://www.pivotal.io/patents.
- *=========================================================================
- */
-package com.gemstone.gemfire.cache.client.internal;
-
-import java.io.IOException;
-import java.io.PrintWriter;
-import java.io.StringWriter;
-import java.util.Properties;
-import com.gemstone.gemfire.cache.Cache;
-import com.gemstone.gemfire.cache.CacheFactory;
-import com.gemstone.gemfire.cache.Region;
-import com.gemstone.gemfire.cache.RegionFactory;
-import com.gemstone.gemfire.cache.RegionShortcut;
-import com.gemstone.gemfire.cache.client.ClientCache;
-import com.gemstone.gemfire.cache.client.ClientCacheFactory;
-import com.gemstone.gemfire.cache.client.ClientRegionFactory;
-import com.gemstone.gemfire.cache.client.ClientRegionShortcut;
-import com.gemstone.gemfire.cache.server.CacheServer;
-import com.gemstone.gemfire.distributed.internal.DistributionConfig;
-import com.gemstone.gemfire.internal.AvailablePortHelper;
-import com.gemstone.gemfire.security.AuthenticationRequiredException;
-import com.gemstone.gemfire.util.test.TestUtil;
-
-import dunit.DistributedTestCase;
-import dunit.Host;
-import dunit.VM;
-
-/**
- * Tests cacheserver ssl support added. See https://svn.gemstone.com/trac/gemfire/ticket/48995 for details
- * @author tushark
- *
- */
-public class CacheServerSSLConnectionDUnit extends DistributedTestCase {
-  
-  private static final long serialVersionUID = 1L;
-  private Cache cache;
-  private CacheServer cacheServer;
-  private ClientCache clientCache;
-  private int cacheServerPort;
-  private String hostName;
-  
-  private static final String TRUSTED_STORE = "trusted.keystore";
-  private static final String CLIENT_KEY_STORE = "client.keystore";
-  private static final String CLIENT_TRUST_STORE = "client.truststore";
-  private static final String SERVER_KEY_STORE = "cacheserver.keystore";
-  private static final String SERVER_TRUST_STORE = "cacheserver.truststore";
-  
-  private static CacheServerSSLConnectionDUnit instance = new CacheServerSSLConnectionDUnit("CacheServerSSLConnectionDUnit");
-  
-  
-  public void setUp() throws Exception {
-    disconnectAllFromDS();
-    super.setUp();
-  }
-
-  public CacheServerSSLConnectionDUnit(String name) {
-    super(name);
-  }  
-
-  public Cache createCache(Properties props) throws Exception
-  {
-    props.setProperty("mcast-port", "0");
-    props.setProperty("locators", "");
-    cache = new CacheFactory(props).create();
-    if (cache == null) {
-      throw new Exception("CacheFactory.create() returned null ");
-    }
-    return cache;
-  }
-  
-  private void createServer() throws IOException{
-    cacheServerPort = AvailablePortHelper.getRandomAvailableTCPPort();
-    cacheServer = cache.addCacheServer();
-    cacheServer.setPort(cacheServerPort);
-    cacheServer.start();
-    hostName = cacheServer.getHostnameForClients();
-  }
-  
-  public int getCacheServerPort(){
-    return cacheServerPort;
-  }
-  
-  public String getCacheServerHost(){
-    return hostName;
-  }
-  
-  public void stopCacheServer(){
-    this.cacheServer.stop();
-  }
-  
-  
-  @SuppressWarnings("rawtypes")
-  public void setUpServerVM(boolean cacheServerSslenabled) throws Exception {
-    Properties gemFireProps = new Properties();
-
-    String cacheServerSslprotocols = "any";
-    String cacheServerSslciphers = "any";
-    boolean cacheServerSslRequireAuth = true;
-    gemFireProps.put(DistributionConfig.SERVER_SSL_ENABLED_NAME,
-        String.valueOf(cacheServerSslenabled));
-    gemFireProps.put(DistributionConfig.SERVER_SSL_PROTOCOLS_NAME,
-        cacheServerSslprotocols);
-    gemFireProps.put(DistributionConfig.SERVER_SSL_CIPHERS_NAME,
-        cacheServerSslciphers);
-    gemFireProps.put(
-        DistributionConfig.SERVER_SSL_REQUIRE_AUTHENTICATION_NAME,
-        String.valueOf(cacheServerSslRequireAuth));
-
-    String keyStore = TestUtil.getResourcePath(CacheServerSSLConnectionDUnit.class, SERVER_KEY_STORE);
-    String trustStore = TestUtil.getResourcePath(CacheServerSSLConnectionDUnit.class, SERVER_TRUST_STORE);
-    gemFireProps.put(DistributionConfig.SERVER_SSL_KEYSTORE_TYPE_NAME, "jks");
-    gemFireProps.put(DistributionConfig.SERVER_SSL_KEYSTORE_NAME, keyStore);
-    gemFireProps.put(DistributionConfig.SERVER_SSL_KEYSTORE_PASSWORD_NAME, "password");
-    gemFireProps.put(DistributionConfig.SERVER_SSL_TRUSTSTORE_NAME, trustStore);
-    gemFireProps.put(DistributionConfig.SERVER_SSL_TRUSTSTORE_PASSWORD_NAME, "password");
-    
-    StringWriter sw = new StringWriter();
-    PrintWriter writer = new PrintWriter(sw);
-    gemFireProps.list(writer);
-    System.out.println("Starting cacheserver ds with following properties \n" + sw);
-    createCache(gemFireProps);
-    
-    RegionFactory factory = cache.createRegionFactory(RegionShortcut.REPLICATE);
-    Region r = factory.create("serverRegion");
-    r.put("serverkey", "servervalue");
-  }
-  
-  public void setUpClientVM(String host, int port,
-      boolean cacheServerSslenabled, boolean cacheServerSslRequireAuth,
-      String keyStore, String trustStore, boolean subscription) {
-
-    Properties gemFireProps = new Properties();
-
-    String cacheServerSslprotocols = "any";
-    String cacheServerSslciphers = "any";
-
-    String keyStorePath = TestUtil.getResourcePath(CacheServerSSLConnectionDUnit.class, keyStore);
-    String trustStorePath = TestUtil.getResourcePath(CacheServerSSLConnectionDUnit.class, trustStore);
-    //using new server-ssl-* properties
-    gemFireProps.put(DistributionConfig.SERVER_SSL_ENABLED_NAME,
-        String.valueOf(cacheServerSslenabled));
-    gemFireProps.put(DistributionConfig.SERVER_SSL_PROTOCOLS_NAME,
-        cacheServerSslprotocols);
-    gemFireProps.put(DistributionConfig.SERVER_SSL_CIPHERS_NAME,
-        cacheServerSslciphers);
-    gemFireProps.put(
-        DistributionConfig.SERVER_SSL_REQUIRE_AUTHENTICATION_NAME,
-        String.valueOf(cacheServerSslRequireAuth));
-
-    gemFireProps.put(DistributionConfig.SERVER_SSL_KEYSTORE_TYPE_NAME, "jks");
-    gemFireProps.put(DistributionConfig.SERVER_SSL_KEYSTORE_NAME, keyStorePath);
-    gemFireProps.put(DistributionConfig.SERVER_SSL_KEYSTORE_PASSWORD_NAME, "password");
-    gemFireProps.put(DistributionConfig.SERVER_SSL_TRUSTSTORE_NAME, trustStorePath);
-    gemFireProps.put(DistributionConfig.SERVER_SSL_TRUSTSTORE_PASSWORD_NAME, "password");
-
-    StringWriter sw = new StringWriter();
-    PrintWriter writer = new PrintWriter(sw);
-    gemFireProps.list(writer);
-    System.out.println("Starting client ds with following properties \n" + sw.getBuffer());
-    
-    ClientCacheFactory clientCacheFactory = new ClientCacheFactory(gemFireProps);
-    clientCacheFactory.setPoolSubscriptionEnabled(subscription).addPoolServer(host, port);
-    clientCache = clientCacheFactory.create();
-    
-    ClientRegionFactory<String,String> regionFactory = clientCache.createClientRegionFactory(ClientRegionShortcut.PROXY);
-    Region<String, String> region = regionFactory.create("serverRegion");  
-    assertNotNull(region);
-  }
-  
-  public void doClientRegionTest(){
-    Region<String, String> region = clientCache.getRegion("serverRegion");
-    assertEquals("servervalue",region.get("serverkey"));
-    region.put("clientkey", "clientvalue");
-    assertEquals("clientvalue",region.get("clientkey"));
-  }
-  
-  public void doServerRegionTest(){
-    Region<String, String> region = cache.getRegion("serverRegion");
-    assertEquals("servervalue",region.get("serverkey"));    
-    assertEquals("clientvalue",region.get("clientkey"));
-  }
-  
-  
-  public static void setUpServerVMTask(boolean cacheServerSslenabled) throws Exception{
-    instance.setUpServerVM(cacheServerSslenabled);
-  }
-  
-  public static void createServerTask() throws Exception {
-    instance.createServer();
-  }
-  
-  public static void setUpClientVMTask(String host, int port,
-      boolean cacheServerSslenabled, boolean cacheServerSslRequireAuth, String keyStore, String trustStore)
-      throws Exception {
-    instance.setUpClientVM(host, port, cacheServerSslenabled,
-        cacheServerSslRequireAuth, keyStore, trustStore, true);
-  }
-  public static void setUpClientVMTaskNoSubscription(String host, int port,
-      boolean cacheServerSslenabled, boolean cacheServerSslRequireAuth, String keyStore, String trustStore)
-      throws Exception {
-    instance.setUpClientVM(host, port, cacheServerSslenabled,
-        cacheServerSslRequireAuth, keyStore, trustStore, false);
-  }
-  
-  public static void doClientRegionTestTask() {
-    instance.doClientRegionTest();
-  }
-  
-  public static void doServerRegionTestTask() {
-    instance.doServerRegionTest();
-  }
-  
-  public static Object[] getCacheServerEndPointTask() {
-    Object[] array = new Object[2];
-    array[0] = instance.getCacheServerHost();
-    array[1] = instance.getCacheServerPort();
-    return array;
-  }
-  
-  public static void closeCacheTask(){
-    if (instance != null && instance.cache != null) {
-      instance.cache.close();
-    }
-  }
-  
-  public static void closeClientCacheTask(){
-    if (instance != null && instance.clientCache != null) {
-      instance.clientCache.close();
-    }
-  }
-  
-  public void testCacheServerSSL() throws Exception {
-    final Host host = Host.getHost(0);
-    VM serverVM = host.getVM(1);
-    VM clientVM = host.getVM(2);
-    
-    boolean cacheServerSslenabled = true;
-    boolean cacheClientSslenabled = true;
-    boolean cacheClientSslRequireAuth = true;
-    
-    serverVM.invoke(CacheServerSSLConnectionDUnit.class, "setUpServerVMTask", new Object[]{cacheServerSslenabled});
-    serverVM.invoke(CacheServerSSLConnectionDUnit.class, "createServerTask");
-    
-    Object array[] = (Object[])serverVM.invoke(CacheServerSSLConnectionDUnit.class, "getCacheServerEndPointTask"); 
-    String hostName = (String)array[0];
-    int port = (Integer) array[1];
-    Object params[] = new Object[6];
-    params[0] = hostName;
-    params[1] = port;
-    params[2] = cacheClientSslenabled;
-    params[3] = cacheClientSslRequireAuth;
-    params[4] = CLIENT_KEY_STORE;
-    params[5] = CLIENT_TRUST_STORE;
-    //getLogWriter().info("Starting client with server endpoint " + hostName + ":" + port);
-    clientVM.invoke(CacheServerSSLConnectionDUnit.class, "setUpClientVMTask", params);
-    clientVM.invoke(CacheServerSSLConnectionDUnit.class, "doClientRegionTestTask");
-    serverVM.invoke(CacheServerSSLConnectionDUnit.class, "doServerRegionTestTask");
-    
-  }
-  
-  
-  public void testNonSSLClient() throws Exception {
-    final Host host = Host.getHost(0);
-    VM serverVM = host.getVM(1);
-    VM clientVM = host.getVM(2);
-    
-    boolean cacheServerSslenabled = true;
-    boolean cacheClientSslenabled = false;
-    boolean cacheClientSslRequireAuth = true;
-    
-    serverVM.invoke(CacheServerSSLConnectionDUnit.class, "setUpServerVMTask", new Object[]{cacheServerSslenabled});
-    serverVM.invoke(CacheServerSSLConnectionDUnit.class, "createServerTask");
-    
-    Object array[] = (Object[])serverVM.invoke(CacheServerSSLConnectionDUnit.class, "getCacheServerEndPointTask"); 
-    String hostName = (String)array[0];
-    int port = (Integer) array[1];
-    Object params[] = new Object[6];
-    params[0] = hostName;
-    params[1] = port;
-    params[2] = cacheClientSslenabled;
-    params[3] = cacheClientSslRequireAuth;
-    params[4] = TRUSTED_STORE;
-    params[5] = TRUSTED_STORE;
-    ExpectedException expect = addExpectedException("javax.net.ssl.SSLException", serverVM);
-    ExpectedException expect2 = addExpectedException("IOException", serverVM);
-    try{
-      //getLogWriter().info("Starting client with server endpoint " + hostName + ":" + port);    
-      clientVM.invoke(CacheServerSSLConnectionDUnit.class, "setUpClientVMTaskNoSubscription", params);
-      clientVM.invoke(CacheServerSSLConnectionDUnit.class, "doClientRegionTestTask");
-      serverVM.invoke(CacheServerSSLConnectionDUnit.class, "doServerRegionTestTask");
-      fail("Test should fail as non-ssl client is trying to connect to ssl configured server");
-    } catch (Exception rmiException) {
-      Throwable e = rmiException.getCause();
-      //getLogWriter().info("ExceptionCause at clientVM " + e);
-      if (e instanceof com.gemstone.gemfire.cache.client.ServerOperationException) {
-        Throwable t = e.getCause();
-        //getLogWriter().info("Cause is " + t);
-        assertTrue(t instanceof com.gemstone.gemfire.security.AuthenticationRequiredException);
-      } else {
-        //getLogWriter().error("Unexpected exception ", e);
-        fail("Unexpected Exception: " + e + " expected: "
-            + AuthenticationRequiredException.class);
-      }
-    } finally {
-      expect.remove();
-      expect2.remove();
-    }
-  }
-  
-  public void testSSLClientWithNoAuth() throws Exception {
-    final Host host = Host.getHost(0);
-    VM serverVM = host.getVM(1);
-    VM clientVM = host.getVM(2);
-
-    boolean cacheServerSslenabled = true;
-    boolean cacheClientSslenabled = true;
-    boolean cacheClientSslRequireAuth = false;
-
-    serverVM.invoke(CacheServerSSLConnectionDUnit.class, "setUpServerVMTask", new Object[]{cacheServerSslenabled});
-    serverVM.invoke(CacheServerSSLConnectionDUnit.class, "createServerTask");
-
-    Object array[] = (Object[])serverVM.invoke(CacheServerSSLConnectionDUnit.class, "getCacheServerEndPointTask"); 
-    String hostName = (String)array[0];
-    int port = (Integer) array[1];
-    Object params[] = new Object[6];
-    params[0] = hostName;
-    params[1] = port;
-    params[2] = cacheClientSslenabled;
-    params[3] = cacheClientSslRequireAuth;
-    params[4] = CLIENT_KEY_STORE;
-    params[5] = CLIENT_TRUST_STORE;
-    //getLogWriter().info("Starting client with server endpoint " + hostName + ":" + port);
-    try {
-      clientVM.invoke(CacheServerSSLConnectionDUnit.class, "setUpClientVMTask", params);
-      clientVM.invoke(CacheServerSSLConnectionDUnit.class, "doClientRegionTestTask");
-      serverVM.invoke(CacheServerSSLConnectionDUnit.class, "doServerRegionTestTask");
-    } catch (Exception rmiException) {
-      Throwable e = rmiException.getCause();
-      //getLogWriter().info("ExceptionCause at clientVM " + e);
-      if (e instanceof com.gemstone.gemfire.cache.client.ServerOperationException) {
-        Throwable t = e.getCause();
-        //getLogWriter().info("Cause is " + t);
-        assertTrue(t instanceof com.gemstone.gemfire.security.AuthenticationRequiredException);
-      } else {
-        //getLogWriter().error("Unexpected exception ", e);
-        fail("Unexpected Exception...expected "
-            + AuthenticationRequiredException.class);
-      }
-    }
-  }
-  
-  public void testSSLClientWithNonSSLServer() throws Exception {
-    final Host host = Host.getHost(0);
-    VM serverVM = host.getVM(1);
-    VM clientVM = host.getVM(2);
-    
-    boolean cacheServerSslenabled = false;
-    boolean cacheClientSslenabled = true;
-    boolean cacheClientSslRequireAuth = true;
-    
-    serverVM.invoke(CacheServerSSLConnectionDUnit.class, "setUpServerVMTask", new Object[]{cacheServerSslenabled});
-    serverVM.invoke(CacheServerSSLConnectionDUnit.class, "createServerTask");
-    
-    Object array[] = (Object[])serverVM.invoke(CacheServerSSLConnectionDUnit.class, "getCacheServerEndPointTask"); 
-    String hostName = (String)array[0];
-    int port = (Integer) array[1];
-    Object params[] = new Object[6];
-    params[0] = hostName;
-    params[1] = port;
-    params[2] = cacheClientSslenabled;
-    params[3] = cacheClientSslRequireAuth;
-    params[4] = TRUSTED_STORE;
-    params[5] = TRUSTED_STORE;
-    ExpectedException expect = addExpectedException("javax.net.ssl.SSLHandshakeException", serverVM);
-    try{
-      //getLogWriter().info("Starting client with server endpoint " + hostName + ":" + port);    
-      clientVM.invoke(CacheServerSSLConnectionDUnit.class, "setUpClientVMTask", params);
-      clientVM.invoke(CacheServerSSLConnectionDUnit.class, "doClientRegionTestTask");
-      serverVM.invoke(CacheServerSSLConnectionDUnit.class, "doServerRegionTestTask");
-      fail("Test should fail as ssl client with ssl enabled is trying to connect to server with ssl disabled");
-    }catch (Exception rmiException) {
-      
-      //ignore
-      
-      /*Throwable e = rmiException.getCause();
-      getLogWriter().info("ExceptionCause at clientVM " + e);
-      if (e instanceof com.gemstone.gemfire.cache.client.ServerOperationException) {
-        Throwable t = e.getCause();
-        getLogWriter().info("Cause is " + t);
-        assertTrue(t instanceof com.gemstone.gemfire.security.AuthenticationRequiredException);
-      } else {
-        getLogWriter().error("Unexpected exception ", e);
-        fail("Unexpected Exception...expected "
-            + AuthenticationRequiredException.class);
-      }*/
-    } finally {
-      expect.remove();
-    }
-  }
-  
-  public void tearDown2() throws Exception
-  {
-    final Host host = Host.getHost(0);
-    VM serverVM = host.getVM(1);
-    VM clientVM = host.getVM(2);
-    clientVM.invoke(CacheServerSSLConnectionDUnit.class, "closeClientCacheTask");
-    serverVM.invoke(CacheServerSSLConnectionDUnit.class, "closeCacheTask");
-    super.tearDown2();
-  }
-
-}
-

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/8c1c9115/gemfire-core/src/test/java/com/gemstone/gemfire/cache/client/internal/CacheServerSSLConnectionDUnitTest.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/test/java/com/gemstone/gemfire/cache/client/internal/CacheServerSSLConnectionDUnitTest.java b/gemfire-core/src/test/java/com/gemstone/gemfire/cache/client/internal/CacheServerSSLConnectionDUnitTest.java
new file mode 100644
index 0000000..5102a54
--- /dev/null
+++ b/gemfire-core/src/test/java/com/gemstone/gemfire/cache/client/internal/CacheServerSSLConnectionDUnitTest.java
@@ -0,0 +1,417 @@
+/*=========================================================================
+ * Copyright (c) 2010-2014 Pivotal Software, Inc. All Rights Reserved.
+ * This product is protected by U.S. and international copyright
+ * and intellectual property laws. Pivotal products are covered by
+ * one or more patents listed at http://www.pivotal.io/patents.
+ *=========================================================================
+ */
+package com.gemstone.gemfire.cache.client.internal;
+
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.io.StringWriter;
+import java.util.Properties;
+import com.gemstone.gemfire.cache.Cache;
+import com.gemstone.gemfire.cache.CacheFactory;
+import com.gemstone.gemfire.cache.Region;
+import com.gemstone.gemfire.cache.RegionFactory;
+import com.gemstone.gemfire.cache.RegionShortcut;
+import com.gemstone.gemfire.cache.client.ClientCache;
+import com.gemstone.gemfire.cache.client.ClientCacheFactory;
+import com.gemstone.gemfire.cache.client.ClientRegionFactory;
+import com.gemstone.gemfire.cache.client.ClientRegionShortcut;
+import com.gemstone.gemfire.cache.server.CacheServer;
+import com.gemstone.gemfire.distributed.internal.DistributionConfig;
+import com.gemstone.gemfire.internal.AvailablePortHelper;
+import com.gemstone.gemfire.security.AuthenticationRequiredException;
+import com.gemstone.gemfire.util.test.TestUtil;
+
+import dunit.DistributedTestCase;
+import dunit.Host;
+import dunit.VM;
+
+/**
+ * Tests cacheserver ssl support added. See https://svn.gemstone.com/trac/gemfire/ticket/48995 for details
+ * @author tushark
+ *
+ */
+public class CacheServerSSLConnectionDUnitTest extends DistributedTestCase {
+  
+  private static final long serialVersionUID = 1L;
+  private Cache cache;
+  private CacheServer cacheServer;
+  private ClientCache clientCache;
+  private int cacheServerPort;
+  private String hostName;
+  
+  private static final String TRUSTED_STORE = "trusted.keystore";
+  private static final String CLIENT_KEY_STORE = "client.keystore";
+  private static final String CLIENT_TRUST_STORE = "client.truststore";
+  private static final String SERVER_KEY_STORE = "cacheserver.keystore";
+  private static final String SERVER_TRUST_STORE = "cacheserver.truststore";
+  
+  private static CacheServerSSLConnectionDUnitTest instance = new CacheServerSSLConnectionDUnitTest("CacheServerSSLConnectionDUnit");
+  
+  
+  public void setUp() throws Exception {
+    disconnectAllFromDS();
+    super.setUp();
+  }
+
+  public CacheServerSSLConnectionDUnitTest(String name) {
+    super(name);
+  }  
+
+  public Cache createCache(Properties props) throws Exception
+  {
+    props.setProperty("mcast-port", "0");
+    props.setProperty("locators", "");
+    cache = new CacheFactory(props).create();
+    if (cache == null) {
+      throw new Exception("CacheFactory.create() returned null ");
+    }
+    return cache;
+  }
+  
+  private void createServer() throws IOException{
+    cacheServerPort = AvailablePortHelper.getRandomAvailableTCPPort();
+    cacheServer = cache.addCacheServer();
+    cacheServer.setPort(cacheServerPort);
+    cacheServer.start();
+    hostName = cacheServer.getHostnameForClients();
+  }
+  
+  public int getCacheServerPort(){
+    return cacheServerPort;
+  }
+  
+  public String getCacheServerHost(){
+    return hostName;
+  }
+  
+  public void stopCacheServer(){
+    this.cacheServer.stop();
+  }
+  
+  
+  @SuppressWarnings("rawtypes")
+  public void setUpServerVM(boolean cacheServerSslenabled) throws Exception {
+    Properties gemFireProps = new Properties();
+
+    String cacheServerSslprotocols = "any";
+    String cacheServerSslciphers = "any";
+    boolean cacheServerSslRequireAuth = true;
+    gemFireProps.put(DistributionConfig.SERVER_SSL_ENABLED_NAME,
+        String.valueOf(cacheServerSslenabled));
+    gemFireProps.put(DistributionConfig.SERVER_SSL_PROTOCOLS_NAME,
+        cacheServerSslprotocols);
+    gemFireProps.put(DistributionConfig.SERVER_SSL_CIPHERS_NAME,
+        cacheServerSslciphers);
+    gemFireProps.put(
+        DistributionConfig.SERVER_SSL_REQUIRE_AUTHENTICATION_NAME,
+        String.valueOf(cacheServerSslRequireAuth));
+
+    String keyStore = TestUtil.getResourcePath(CacheServerSSLConnectionDUnitTest.class, SERVER_KEY_STORE);
+    String trustStore = TestUtil.getResourcePath(CacheServerSSLConnectionDUnitTest.class, SERVER_TRUST_STORE);
+    gemFireProps.put(DistributionConfig.SERVER_SSL_KEYSTORE_TYPE_NAME, "jks");
+    gemFireProps.put(DistributionConfig.SERVER_SSL_KEYSTORE_NAME, keyStore);
+    gemFireProps.put(DistributionConfig.SERVER_SSL_KEYSTORE_PASSWORD_NAME, "password");
+    gemFireProps.put(DistributionConfig.SERVER_SSL_TRUSTSTORE_NAME, trustStore);
+    gemFireProps.put(DistributionConfig.SERVER_SSL_TRUSTSTORE_PASSWORD_NAME, "password");
+    
+    StringWriter sw = new StringWriter();
+    PrintWriter writer = new PrintWriter(sw);
+    gemFireProps.list(writer);
+    System.out.println("Starting cacheserver ds with following properties \n" + sw);
+    createCache(gemFireProps);
+    
+    RegionFactory factory = cache.createRegionFactory(RegionShortcut.REPLICATE);
+    Region r = factory.create("serverRegion");
+    r.put("serverkey", "servervalue");
+  }
+  
+  public void setUpClientVM(String host, int port,
+      boolean cacheServerSslenabled, boolean cacheServerSslRequireAuth,
+      String keyStore, String trustStore, boolean subscription) {
+
+    Properties gemFireProps = new Properties();
+
+    String cacheServerSslprotocols = "any";
+    String cacheServerSslciphers = "any";
+
+    String keyStorePath = TestUtil.getResourcePath(CacheServerSSLConnectionDUnitTest.class, keyStore);
+    String trustStorePath = TestUtil.getResourcePath(CacheServerSSLConnectionDUnitTest.class, trustStore);
+    //using new server-ssl-* properties
+    gemFireProps.put(DistributionConfig.SERVER_SSL_ENABLED_NAME,
+        String.valueOf(cacheServerSslenabled));
+    gemFireProps.put(DistributionConfig.SERVER_SSL_PROTOCOLS_NAME,
+        cacheServerSslprotocols);
+    gemFireProps.put(DistributionConfig.SERVER_SSL_CIPHERS_NAME,
+        cacheServerSslciphers);
+    gemFireProps.put(
+        DistributionConfig.SERVER_SSL_REQUIRE_AUTHENTICATION_NAME,
+        String.valueOf(cacheServerSslRequireAuth));
+
+    gemFireProps.put(DistributionConfig.SERVER_SSL_KEYSTORE_TYPE_NAME, "jks");
+    gemFireProps.put(DistributionConfig.SERVER_SSL_KEYSTORE_NAME, keyStorePath);
+    gemFireProps.put(DistributionConfig.SERVER_SSL_KEYSTORE_PASSWORD_NAME, "password");
+    gemFireProps.put(DistributionConfig.SERVER_SSL_TRUSTSTORE_NAME, trustStorePath);
+    gemFireProps.put(DistributionConfig.SERVER_SSL_TRUSTSTORE_PASSWORD_NAME, "password");
+
+    StringWriter sw = new StringWriter();
+    PrintWriter writer = new PrintWriter(sw);
+    gemFireProps.list(writer);
+    System.out.println("Starting client ds with following properties \n" + sw.getBuffer());
+    
+    ClientCacheFactory clientCacheFactory = new ClientCacheFactory(gemFireProps);
+    clientCacheFactory.setPoolSubscriptionEnabled(subscription).addPoolServer(host, port);
+    clientCache = clientCacheFactory.create();
+    
+    ClientRegionFactory<String,String> regionFactory = clientCache.createClientRegionFactory(ClientRegionShortcut.PROXY);
+    Region<String, String> region = regionFactory.create("serverRegion");  
+    assertNotNull(region);
+  }
+  
+  public void doClientRegionTest(){
+    Region<String, String> region = clientCache.getRegion("serverRegion");
+    assertEquals("servervalue",region.get("serverkey"));
+    region.put("clientkey", "clientvalue");
+    assertEquals("clientvalue",region.get("clientkey"));
+  }
+  
+  public void doServerRegionTest(){
+    Region<String, String> region = cache.getRegion("serverRegion");
+    assertEquals("servervalue",region.get("serverkey"));    
+    assertEquals("clientvalue",region.get("clientkey"));
+  }
+  
+  
+  public static void setUpServerVMTask(boolean cacheServerSslenabled) throws Exception{
+    instance.setUpServerVM(cacheServerSslenabled);
+  }
+  
+  public static void createServerTask() throws Exception {
+    instance.createServer();
+  }
+  
+  public static void setUpClientVMTask(String host, int port,
+      boolean cacheServerSslenabled, boolean cacheServerSslRequireAuth, String keyStore, String trustStore)
+      throws Exception {
+    instance.setUpClientVM(host, port, cacheServerSslenabled,
+        cacheServerSslRequireAuth, keyStore, trustStore, true);
+  }
+  public static void setUpClientVMTaskNoSubscription(String host, int port,
+      boolean cacheServerSslenabled, boolean cacheServerSslRequireAuth, String keyStore, String trustStore)
+      throws Exception {
+    instance.setUpClientVM(host, port, cacheServerSslenabled,
+        cacheServerSslRequireAuth, keyStore, trustStore, false);
+  }
+  
+  public static void doClientRegionTestTask() {
+    instance.doClientRegionTest();
+  }
+  
+  public static void doServerRegionTestTask() {
+    instance.doServerRegionTest();
+  }
+  
+  public static Object[] getCacheServerEndPointTask() {
+    Object[] array = new Object[2];
+    array[0] = instance.getCacheServerHost();
+    array[1] = instance.getCacheServerPort();
+    return array;
+  }
+  
+  public static void closeCacheTask(){
+    if (instance != null && instance.cache != null) {
+      instance.cache.close();
+    }
+  }
+  
+  public static void closeClientCacheTask(){
+    if (instance != null && instance.clientCache != null) {
+      instance.clientCache.close();
+    }
+  }
+  
+  public void testCacheServerSSL() throws Exception {
+    final Host host = Host.getHost(0);
+    VM serverVM = host.getVM(1);
+    VM clientVM = host.getVM(2);
+    
+    boolean cacheServerSslenabled = true;
+    boolean cacheClientSslenabled = true;
+    boolean cacheClientSslRequireAuth = true;
+    
+    serverVM.invoke(CacheServerSSLConnectionDUnitTest.class, "setUpServerVMTask", new Object[]{cacheServerSslenabled});
+    serverVM.invoke(CacheServerSSLConnectionDUnitTest.class, "createServerTask");
+    
+    Object array[] = (Object[])serverVM.invoke(CacheServerSSLConnectionDUnitTest.class, "getCacheServerEndPointTask"); 
+    String hostName = (String)array[0];
+    int port = (Integer) array[1];
+    Object params[] = new Object[6];
+    params[0] = hostName;
+    params[1] = port;
+    params[2] = cacheClientSslenabled;
+    params[3] = cacheClientSslRequireAuth;
+    params[4] = CLIENT_KEY_STORE;
+    params[5] = CLIENT_TRUST_STORE;
+    //getLogWriter().info("Starting client with server endpoint " + hostName + ":" + port);
+    clientVM.invoke(CacheServerSSLConnectionDUnitTest.class, "setUpClientVMTask", params);
+    clientVM.invoke(CacheServerSSLConnectionDUnitTest.class, "doClientRegionTestTask");
+    serverVM.invoke(CacheServerSSLConnectionDUnitTest.class, "doServerRegionTestTask");
+    
+  }
+  
+  
+  public void testNonSSLClient() throws Exception {
+    final Host host = Host.getHost(0);
+    VM serverVM = host.getVM(1);
+    VM clientVM = host.getVM(2);
+    
+    boolean cacheServerSslenabled = true;
+    boolean cacheClientSslenabled = false;
+    boolean cacheClientSslRequireAuth = true;
+    
+    serverVM.invoke(CacheServerSSLConnectionDUnitTest.class, "setUpServerVMTask", new Object[]{cacheServerSslenabled});
+    serverVM.invoke(CacheServerSSLConnectionDUnitTest.class, "createServerTask");
+    
+    Object array[] = (Object[])serverVM.invoke(CacheServerSSLConnectionDUnitTest.class, "getCacheServerEndPointTask"); 
+    String hostName = (String)array[0];
+    int port = (Integer) array[1];
+    Object params[] = new Object[6];
+    params[0] = hostName;
+    params[1] = port;
+    params[2] = cacheClientSslenabled;
+    params[3] = cacheClientSslRequireAuth;
+    params[4] = TRUSTED_STORE;
+    params[5] = TRUSTED_STORE;
+    ExpectedException expect = addExpectedException("javax.net.ssl.SSLException", serverVM);
+    ExpectedException expect2 = addExpectedException("IOException", serverVM);
+    try{
+      //getLogWriter().info("Starting client with server endpoint " + hostName + ":" + port);    
+      clientVM.invoke(CacheServerSSLConnectionDUnitTest.class, "setUpClientVMTaskNoSubscription", params);
+      clientVM.invoke(CacheServerSSLConnectionDUnitTest.class, "doClientRegionTestTask");
+      serverVM.invoke(CacheServerSSLConnectionDUnitTest.class, "doServerRegionTestTask");
+      fail("Test should fail as non-ssl client is trying to connect to ssl configured server");
+    } catch (Exception rmiException) {
+      Throwable e = rmiException.getCause();
+      //getLogWriter().info("ExceptionCause at clientVM " + e);
+      if (e instanceof com.gemstone.gemfire.cache.client.ServerOperationException) {
+        Throwable t = e.getCause();
+        //getLogWriter().info("Cause is " + t);
+        assertTrue(t instanceof com.gemstone.gemfire.security.AuthenticationRequiredException);
+      } else {
+        //getLogWriter().error("Unexpected exception ", e);
+        fail("Unexpected Exception: " + e + " expected: "
+            + AuthenticationRequiredException.class);
+      }
+    } finally {
+      expect.remove();
+      expect2.remove();
+    }
+  }
+  
+  public void testSSLClientWithNoAuth() throws Exception {
+    final Host host = Host.getHost(0);
+    VM serverVM = host.getVM(1);
+    VM clientVM = host.getVM(2);
+
+    boolean cacheServerSslenabled = true;
+    boolean cacheClientSslenabled = true;
+    boolean cacheClientSslRequireAuth = false;
+
+    serverVM.invoke(CacheServerSSLConnectionDUnitTest.class, "setUpServerVMTask", new Object[]{cacheServerSslenabled});
+    serverVM.invoke(CacheServerSSLConnectionDUnitTest.class, "createServerTask");
+
+    Object array[] = (Object[])serverVM.invoke(CacheServerSSLConnectionDUnitTest.class, "getCacheServerEndPointTask"); 
+    String hostName = (String)array[0];
+    int port = (Integer) array[1];
+    Object params[] = new Object[6];
+    params[0] = hostName;
+    params[1] = port;
+    params[2] = cacheClientSslenabled;
+    params[3] = cacheClientSslRequireAuth;
+    params[4] = CLIENT_KEY_STORE;
+    params[5] = CLIENT_TRUST_STORE;
+    //getLogWriter().info("Starting client with server endpoint " + hostName + ":" + port);
+    try {
+      clientVM.invoke(CacheServerSSLConnectionDUnitTest.class, "setUpClientVMTask", params);
+      clientVM.invoke(CacheServerSSLConnectionDUnitTest.class, "doClientRegionTestTask");
+      serverVM.invoke(CacheServerSSLConnectionDUnitTest.class, "doServerRegionTestTask");
+    } catch (Exception rmiException) {
+      Throwable e = rmiException.getCause();
+      //getLogWriter().info("ExceptionCause at clientVM " + e);
+      if (e instanceof com.gemstone.gemfire.cache.client.ServerOperationException) {
+        Throwable t = e.getCause();
+        //getLogWriter().info("Cause is " + t);
+        assertTrue(t instanceof com.gemstone.gemfire.security.AuthenticationRequiredException);
+      } else {
+        //getLogWriter().error("Unexpected exception ", e);
+        fail("Unexpected Exception...expected "
+            + AuthenticationRequiredException.class);
+      }
+    }
+  }
+  
+  public void testSSLClientWithNonSSLServer() throws Exception {
+    final Host host = Host.getHost(0);
+    VM serverVM = host.getVM(1);
+    VM clientVM = host.getVM(2);
+    
+    boolean cacheServerSslenabled = false;
+    boolean cacheClientSslenabled = true;
+    boolean cacheClientSslRequireAuth = true;
+    
+    serverVM.invoke(CacheServerSSLConnectionDUnitTest.class, "setUpServerVMTask", new Object[]{cacheServerSslenabled});
+    serverVM.invoke(CacheServerSSLConnectionDUnitTest.class, "createServerTask");
+    
+    Object array[] = (Object[])serverVM.invoke(CacheServerSSLConnectionDUnitTest.class, "getCacheServerEndPointTask"); 
+    String hostName = (String)array[0];
+    int port = (Integer) array[1];
+    Object params[] = new Object[6];
+    params[0] = hostName;
+    params[1] = port;
+    params[2] = cacheClientSslenabled;
+    params[3] = cacheClientSslRequireAuth;
+    params[4] = TRUSTED_STORE;
+    params[5] = TRUSTED_STORE;
+    ExpectedException expect = addExpectedException("javax.net.ssl.SSLHandshakeException", serverVM);
+    try{
+      //getLogWriter().info("Starting client with server endpoint " + hostName + ":" + port);    
+      clientVM.invoke(CacheServerSSLConnectionDUnitTest.class, "setUpClientVMTask", params);
+      clientVM.invoke(CacheServerSSLConnectionDUnitTest.class, "doClientRegionTestTask");
+      serverVM.invoke(CacheServerSSLConnectionDUnitTest.class, "doServerRegionTestTask");
+      fail("Test should fail as ssl client with ssl enabled is trying to connect to server with ssl disabled");
+    }catch (Exception rmiException) {
+      
+      //ignore
+      
+      /*Throwable e = rmiException.getCause();
+      getLogWriter().info("ExceptionCause at clientVM " + e);
+      if (e instanceof com.gemstone.gemfire.cache.client.ServerOperationException) {
+        Throwable t = e.getCause();
+        getLogWriter().info("Cause is " + t);
+        assertTrue(t instanceof com.gemstone.gemfire.security.AuthenticationRequiredException);
+      } else {
+        getLogWriter().error("Unexpected exception ", e);
+        fail("Unexpected Exception...expected "
+            + AuthenticationRequiredException.class);
+      }*/
+    } finally {
+      expect.remove();
+    }
+  }
+  
+  public void tearDown2() throws Exception
+  {
+    final Host host = Host.getHost(0);
+    VM serverVM = host.getVM(1);
+    VM clientVM = host.getVM(2);
+    clientVM.invoke(CacheServerSSLConnectionDUnitTest.class, "closeClientCacheTask");
+    serverVM.invoke(CacheServerSSLConnectionDUnitTest.class, "closeCacheTask");
+    super.tearDown2();
+  }
+
+}
+



[2/4] incubator-geode git commit: unit test now verifies that subscription sockets use ssl

Posted by ds...@apache.org.
unit test now verifies that subscription sockets use ssl


Project: http://git-wip-us.apache.org/repos/asf/incubator-geode/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-geode/commit/50d3b469
Tree: http://git-wip-us.apache.org/repos/asf/incubator-geode/tree/50d3b469
Diff: http://git-wip-us.apache.org/repos/asf/incubator-geode/diff/50d3b469

Branch: refs/heads/feature/GEODE-397
Commit: 50d3b469ee695aac765ab74fa96fbb634e83ad36
Parents: 1e13aad
Author: Darrel Schneider <ds...@pivotal.io>
Authored: Thu Oct 15 15:59:20 2015 -0700
Committer: Darrel Schneider <ds...@pivotal.io>
Committed: Thu Oct 15 15:59:20 2015 -0700

----------------------------------------------------------------------
 .../internal/CacheServerSSLConnectionDUnit.java     | 16 +++++++++++-----
 1 file changed, 11 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/50d3b469/gemfire-core/src/test/java/com/gemstone/gemfire/cache/client/internal/CacheServerSSLConnectionDUnit.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/test/java/com/gemstone/gemfire/cache/client/internal/CacheServerSSLConnectionDUnit.java b/gemfire-core/src/test/java/com/gemstone/gemfire/cache/client/internal/CacheServerSSLConnectionDUnit.java
index 0a13c75..d01866d 100644
--- a/gemfire-core/src/test/java/com/gemstone/gemfire/cache/client/internal/CacheServerSSLConnectionDUnit.java
+++ b/gemfire-core/src/test/java/com/gemstone/gemfire/cache/client/internal/CacheServerSSLConnectionDUnit.java
@@ -132,7 +132,7 @@ public class CacheServerSSLConnectionDUnit extends DistributedTestCase {
   
   public void setUpClientVM(String host, int port,
       boolean cacheServerSslenabled, boolean cacheServerSslRequireAuth,
-      String keyStore, String trustStore) {
+      String keyStore, String trustStore, boolean subscription) {
 
     Properties gemFireProps = new Properties();
 
@@ -164,7 +164,7 @@ public class CacheServerSSLConnectionDUnit extends DistributedTestCase {
     System.out.println("Starting client ds with following properties \n" + sw.getBuffer());
     
     ClientCacheFactory clientCacheFactory = new ClientCacheFactory(gemFireProps);
-    clientCacheFactory.addPoolServer(host, port);
+    clientCacheFactory.setPoolSubscriptionEnabled(subscription).addPoolServer(host, port);
     clientCache = clientCacheFactory.create();
     
     ClientRegionFactory<String,String> regionFactory = clientCache.createClientRegionFactory(ClientRegionShortcut.PROXY);
@@ -198,7 +198,13 @@ public class CacheServerSSLConnectionDUnit extends DistributedTestCase {
       boolean cacheServerSslenabled, boolean cacheServerSslRequireAuth, String keyStore, String trustStore)
       throws Exception {
     instance.setUpClientVM(host, port, cacheServerSslenabled,
-        cacheServerSslRequireAuth, keyStore, trustStore);
+        cacheServerSslRequireAuth, keyStore, trustStore, true);
+  }
+  public static void setUpClientVMTaskNoSubscription(String host, int port,
+      boolean cacheServerSslenabled, boolean cacheServerSslRequireAuth, String keyStore, String trustStore)
+      throws Exception {
+    instance.setUpClientVM(host, port, cacheServerSslenabled,
+        cacheServerSslRequireAuth, keyStore, trustStore, false);
   }
   
   public static void doClientRegionTestTask() {
@@ -284,7 +290,7 @@ public class CacheServerSSLConnectionDUnit extends DistributedTestCase {
     ExpectedException expect2 = addExpectedException("IOException", serverVM);
     try{
       //getLogWriter().info("Starting client with server endpoint " + hostName + ":" + port);    
-      clientVM.invoke(CacheServerSSLConnectionDUnit.class, "setUpClientVMTask", params);
+      clientVM.invoke(CacheServerSSLConnectionDUnit.class, "setUpClientVMTaskNoSubscription", params);
       clientVM.invoke(CacheServerSSLConnectionDUnit.class, "doClientRegionTestTask");
       serverVM.invoke(CacheServerSSLConnectionDUnit.class, "doServerRegionTestTask");
       fail("Test should fail as non-ssl client is trying to connect to ssl configured server");
@@ -297,7 +303,7 @@ public class CacheServerSSLConnectionDUnit extends DistributedTestCase {
         assertTrue(t instanceof com.gemstone.gemfire.security.AuthenticationRequiredException);
       } else {
         //getLogWriter().error("Unexpected exception ", e);
-        fail("Unexpected Exception...expected "
+        fail("Unexpected Exception: " + e + " expected: "
             + AuthenticationRequiredException.class);
       }
     } finally {