geode-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kl...@apache.org
Subject [19/50] [abbrv] incubator-geode git commit: GEODE-1993: allow LocatorServerStartupRule to save server's ports as well.
Date Mon, 31 Oct 2016 20:55:59 GMT
GEODE-1993: allow LocatorServerStartupRule to save server's ports as well.

* added more tetss


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

Branch: refs/heads/feature/GEODE-1930
Commit: 5abe957ca1cd42eeaf82549c275711e6e94dddec
Parents: 1fb0d0a
Author: Jinmei Liao <jiliao@pivotal.io>
Authored: Mon Oct 17 08:08:39 2016 -0700
Committer: Jinmei Liao <jiliao@pivotal.io>
Committed: Mon Oct 17 08:08:39 2016 -0700

----------------------------------------------------------------------
 .../ClusterConfigWithoutSecurityDUnitTest.java  |   4 +-
 .../security/PeerAuthenticatorDUnitTest.java    |  63 ++++--------
 ...eerSecurityWithEmbeddedLocatorDUnitTest.java | 102 +++++++++++++++++++
 .../SecurityClusterConfigDUnitTest.java         |  10 +-
 .../SecurityWithoutClusterConfigDUnitTest.java  |   2 +-
 .../security/StartServerAuthorizationTest.java  |   4 +-
 .../dunit/rules/LocatorServerStartupRule.java   |  12 ++-
 .../LuceneClusterConfigurationDUnitTest.java    |   2 +-
 8 files changed, 140 insertions(+), 59 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/5abe957c/geode-core/src/test/java/org/apache/geode/security/ClusterConfigWithoutSecurityDUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/security/ClusterConfigWithoutSecurityDUnitTest.java
b/geode-core/src/test/java/org/apache/geode/security/ClusterConfigWithoutSecurityDUnitTest.java
index 72dbd1a..1bbfa0f 100644
--- a/geode-core/src/test/java/org/apache/geode/security/ClusterConfigWithoutSecurityDUnitTest.java
+++ b/geode-core/src/test/java/org/apache/geode/security/ClusterConfigWithoutSecurityDUnitTest.java
@@ -71,7 +71,7 @@ public class ClusterConfigWithoutSecurityDUnitTest extends JUnit4DistributedTest
 
     // initial security properties should only contain initial set of values
     ServerStarter serverStarter = new ServerStarter(props);
-    serverStarter.startServer(lsRule.getLocatorPort(0));
+    serverStarter.startServer(lsRule.getPort(0));
     DistributedSystem ds = serverStarter.cache.getDistributedSystem();
 
     // after cache is created, the configuration won't chagne
@@ -92,7 +92,7 @@ public class ClusterConfigWithoutSecurityDUnitTest extends JUnit4DistributedTest
 
     ServerStarter serverStarter = new ServerStarter(props);
 
-    assertThatThrownBy(() -> serverStarter.startServer(lsRule.getLocatorPort(0)))
+    assertThatThrownBy(() -> serverStarter.startServer(lsRule.getPort(0)))
       .isInstanceOf(GemFireConfigException.class)
       .hasMessage(LocalizedStrings.GEMFIRE_CACHE_SECURITY_MISCONFIGURATION.toLocalizedString());
   }

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/5abe957c/geode-core/src/test/java/org/apache/geode/security/PeerAuthenticatorDUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/security/PeerAuthenticatorDUnitTest.java
b/geode-core/src/test/java/org/apache/geode/security/PeerAuthenticatorDUnitTest.java
index bb147c7..b12ea43 100644
--- a/geode-core/src/test/java/org/apache/geode/security/PeerAuthenticatorDUnitTest.java
+++ b/geode-core/src/test/java/org/apache/geode/security/PeerAuthenticatorDUnitTest.java
@@ -20,73 +20,50 @@ package org.apache.geode.security;
 import static org.apache.geode.distributed.ConfigurationProperties.*;
 import static org.assertj.core.api.Assertions.assertThatThrownBy;
 
-import java.io.File;
 import java.util.Properties;
 
 import org.junit.Before;
+import org.junit.Rule;
 import org.junit.Test;
 import org.junit.experimental.categories.Category;
 
-import org.apache.geode.distributed.Locator;
-import org.apache.geode.distributed.internal.InternalDistributedSystem;
 import org.apache.geode.security.templates.DummyAuthenticator;
-import org.apache.geode.test.dunit.Host;
 import org.apache.geode.test.dunit.VM;
 import org.apache.geode.test.dunit.internal.JUnit4DistributedTestCase;
+import org.apache.geode.test.dunit.rules.LocatorServerStartupRule;
+import org.apache.geode.test.dunit.rules.ServerStarter;
 import org.apache.geode.test.junit.categories.DistributedTest;
 import org.apache.geode.test.junit.categories.SecurityTest;
 
 @Category({ DistributedTest.class, SecurityTest.class })
 public class PeerAuthenticatorDUnitTest extends JUnit4DistributedTestCase {
-  protected VM locator = null;
-  protected VM server = null;
-  protected VM server1 = null;
+  @Rule
+  public LocatorServerStartupRule lsRule = new LocatorServerStartupRule();
 
   @Before
   public void before() throws Exception {
-    final Host host = Host.getHost(0);
-    this.locator = host.getVM(0);
-    this.server = host.getVM(1);
-    this.server1 = host.getVM(2);
+    Properties props = new Properties();
+    props.setProperty(SECURITY_PEER_AUTHENTICATOR, DummyAuthenticator.class.getName());
+    lsRule.getLocatorVM(0, props);
   }
-
   @Test
   public void testPeerAuthenticator() throws Exception{
-    int locatorPort = locator.invoke(()->{
-      Properties props = new Properties();
-      props.setProperty(SECURITY_PEER_AUTHENTICATOR, DummyAuthenticator.class.getName());
-      props.setProperty(MCAST_PORT, "0");
-      props.put(JMX_MANAGER, "true");
-      props.put(JMX_MANAGER_START, "true");
-      props.put(JMX_MANAGER_PORT, "0");
-      Locator locatorObj = Locator.startLocatorAndDS(0, new File("locator.log"), props);
-      return locatorObj.getPort();
-    });
 
-    // set up server with security
-    String locators = "localhost[" + locatorPort + "]";
-    server.invoke(()->{
-      Properties props = new Properties();
-      props.setProperty(MCAST_PORT, "0");
-      props.setProperty(LOCATORS, locators);
-
-      // the following are needed for peer-to-peer authentication
-      props.setProperty("security-username", "user");
-      props.setProperty("security-password", "user");
-      // this should execute without exception
-      InternalDistributedSystem ds = getSystem(props);
-    });
+    int locatorPort = lsRule.getPort(0);
+    Properties server1Props = new Properties();
+    server1Props.setProperty("security-username", "user");
+    server1Props.setProperty("security-password", "user");
+    lsRule.getServerVM(1, server1Props, locatorPort);
 
-    server1.invoke(()->{
-      Properties props = new Properties();
-      props.setProperty(MCAST_PORT, "0");
-      props.setProperty(LOCATORS, locators);
 
-      // the following are needed for peer-to-peer authentication
-      props.setProperty("security-username", "bogus");
-      props.setProperty("security-password", "user");
+    Properties server2Props = new Properties();
+    server2Props.setProperty("security-username", "bogus");
+    server2Props.setProperty("security-password", "user");
+    VM server2 = lsRule.getNodeVM(2);
 
-      assertThatThrownBy(()->getSystem(props)).isInstanceOf(GemFireSecurityException.class);
+    server2.invoke(()->{
+      ServerStarter serverStarter = new ServerStarter(server2Props);
+      assertThatThrownBy(()->serverStarter.startServer(locatorPort)).isInstanceOf(GemFireSecurityException.class).hasMessageContaining("Invalid
user name");
     });
   }
 

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/5abe957c/geode-core/src/test/java/org/apache/geode/security/PeerSecurityWithEmbeddedLocatorDUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/security/PeerSecurityWithEmbeddedLocatorDUnitTest.java
b/geode-core/src/test/java/org/apache/geode/security/PeerSecurityWithEmbeddedLocatorDUnitTest.java
new file mode 100644
index 0000000..a42f6db
--- /dev/null
+++ b/geode-core/src/test/java/org/apache/geode/security/PeerSecurityWithEmbeddedLocatorDUnitTest.java
@@ -0,0 +1,102 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.geode.security;
+
+import static org.apache.geode.distributed.ConfigurationProperties.*;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+import java.util.Properties;
+
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+import org.apache.geode.internal.AvailablePortHelper;
+import org.apache.geode.security.templates.DummyAuthenticator;
+import org.apache.geode.security.templates.SimpleSecurityManager;
+import org.apache.geode.test.dunit.VM;
+import org.apache.geode.test.dunit.internal.JUnit4DistributedTestCase;
+import org.apache.geode.test.dunit.rules.LocatorServerStartupRule;
+import org.apache.geode.test.dunit.rules.ServerStarter;
+import org.apache.geode.test.junit.categories.DistributedTest;
+import org.apache.geode.test.junit.categories.SecurityTest;
+
+@Category({ DistributedTest.class, SecurityTest.class })
+public class PeerSecurityWithEmbeddedLocatorDUnitTest extends JUnit4DistributedTestCase {
+
+  @Rule
+  public LocatorServerStartupRule lsRule = new LocatorServerStartupRule();
+
+
+  @Test
+  public void testPeerSecurityManager() throws Exception{
+    int locatorPort = AvailablePortHelper.getRandomAvailableTCPPort();
+
+    Properties server0Props = new Properties();
+    server0Props.setProperty(SECURITY_MANAGER, SimpleSecurityManager.class.getName());
+    server0Props.setProperty("start-locator", "localhost["+locatorPort+"]");
+    lsRule.getServerVM(0, server0Props);
+
+
+    Properties server1Props = new Properties();
+    server1Props.setProperty("security-username", "cluster");
+    server1Props.setProperty("security-password", "cluster");
+    lsRule.getServerVM(1, server1Props, locatorPort);
+
+    Properties server2Props = new Properties();
+    server2Props.setProperty("security-username", "user");
+    server2Props.setProperty("security-password", "wrongPwd");
+
+    VM server2 = lsRule.getNodeVM(2);
+    server2.invoke(()->{
+      ServerStarter serverStarter = new ServerStarter(server2Props);
+      assertThatThrownBy(()->serverStarter.startServer(locatorPort))
+        .isInstanceOf(GemFireSecurityException.class)
+        .hasMessageContaining("Security check failed. Authentication error");
+    });
+  }
+
+  @Test
+  public void testPeerAuthenticator() throws Exception{
+    int locatorPort = AvailablePortHelper.getRandomAvailableTCPPort();
+
+    Properties server0Props = new Properties();
+    server0Props.setProperty(SECURITY_PEER_AUTHENTICATOR, DummyAuthenticator.class.getName());
+    server0Props.setProperty("start-locator", "localhost["+locatorPort+"]");
+    lsRule.getServerVM(0, server0Props);
+
+
+    Properties server1Props = new Properties();
+    server1Props.setProperty("security-username", "user");
+    server1Props.setProperty("security-password", "user");
+    lsRule.getServerVM(1, server1Props, locatorPort);
+
+    Properties server2Props = new Properties();
+    server2Props.setProperty("security-username", "bogus");
+    server2Props.setProperty("security-password", "user");
+
+    VM server2 = lsRule.getNodeVM(2);
+    server2.invoke(()->{
+      ServerStarter serverStarter = new ServerStarter(server2Props);
+      assertThatThrownBy(()->serverStarter.startServer(locatorPort))
+        .isInstanceOf(GemFireSecurityException.class)
+        .hasMessageContaining("Invalid user name");
+    });
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/5abe957c/geode-core/src/test/java/org/apache/geode/security/SecurityClusterConfigDUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/security/SecurityClusterConfigDUnitTest.java
b/geode-core/src/test/java/org/apache/geode/security/SecurityClusterConfigDUnitTest.java
index 5364c91..07ac8be 100644
--- a/geode-core/src/test/java/org/apache/geode/security/SecurityClusterConfigDUnitTest.java
+++ b/geode-core/src/test/java/org/apache/geode/security/SecurityClusterConfigDUnitTest.java
@@ -68,7 +68,7 @@ public class SecurityClusterConfigDUnitTest extends JUnit4DistributedTestCase
{
 
     // initial security properties should only contain initial set of values
     ServerStarter serverStarter = new ServerStarter(props);
-    serverStarter.startServer(lsRule.getLocatorPort(0));
+    serverStarter.startServer(lsRule.getPort(0));
     DistributedSystem ds = serverStarter.cache.getDistributedSystem();
 
     // after cache is created, we got the security props passed in by cluster config
@@ -90,7 +90,7 @@ public class SecurityClusterConfigDUnitTest extends JUnit4DistributedTestCase
{
 
     // initial security properties should only contain initial set of values
     ServerStarter serverStarter = new ServerStarter(props);
-    serverStarter.startServer(lsRule.getLocatorPort(0));
+    serverStarter.startServer(lsRule.getPort(0));
     DistributedSystem ds = serverStarter.cache.getDistributedSystem();
 
     // after cache is created, we got the security props passed in by cluster config
@@ -112,7 +112,7 @@ public class SecurityClusterConfigDUnitTest extends JUnit4DistributedTestCase
{
     // initial security properties should only contain initial set of values
     ServerStarter serverStarter = new ServerStarter(props);
 
-    assertThatThrownBy(() -> serverStarter.startServer(lsRule.getLocatorPort(0)))
+    assertThatThrownBy(() -> serverStarter.startServer(lsRule.getPort(0)))
       .isInstanceOf(GemFireConfigException.class)
       .hasMessage(LocalizedStrings.GEMFIRE_CACHE_SECURITY_MISCONFIGURATION
         .toLocalizedString());
@@ -132,7 +132,7 @@ public class SecurityClusterConfigDUnitTest extends JUnit4DistributedTestCase
{
     // initial security properties should only contain initial set of values
     ServerStarter serverStarter = new ServerStarter(props);
 
-    assertThatThrownBy(() -> serverStarter.startServer(lsRule.getLocatorPort(0)))
+    assertThatThrownBy(() -> serverStarter.startServer(lsRule.getPort(0)))
       .isInstanceOf(GemFireConfigException.class)
       .hasMessage(LocalizedStrings.GEMFIRE_CACHE_SECURITY_MISCONFIGURATION
                                                        .toLocalizedString());
@@ -151,7 +151,7 @@ public class SecurityClusterConfigDUnitTest extends JUnit4DistributedTestCase
{
 
     ServerStarter serverStarter = new ServerStarter(props);
 
-    assertThatThrownBy(() -> serverStarter.startServer(lsRule.getLocatorPort(0)))
+    assertThatThrownBy(() -> serverStarter.startServer(lsRule.getPort(0)))
       .isInstanceOf(GemFireConfigException.class)
       .hasMessage(LocalizedStrings.GEMFIRE_CACHE_SECURITY_MISCONFIGURATION_2
                                                        .toLocalizedString());

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/5abe957c/geode-core/src/test/java/org/apache/geode/security/SecurityWithoutClusterConfigDUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/security/SecurityWithoutClusterConfigDUnitTest.java
b/geode-core/src/test/java/org/apache/geode/security/SecurityWithoutClusterConfigDUnitTest.java
index d3ed823..f715cb2 100644
--- a/geode-core/src/test/java/org/apache/geode/security/SecurityWithoutClusterConfigDUnitTest.java
+++ b/geode-core/src/test/java/org/apache/geode/security/SecurityWithoutClusterConfigDUnitTest.java
@@ -70,7 +70,7 @@ public class SecurityWithoutClusterConfigDUnitTest extends JUnit4DistributedTest
 
     // initial security properties should only contain initial set of values
     ServerStarter serverStarter = new ServerStarter(props);
-    serverStarter.startServer(lsRule.getLocatorPort(0));
+    serverStarter.startServer(lsRule.getPort(0));
     DistributedSystem ds = serverStarter.cache.getDistributedSystem();
     assertEquals(3, ds.getSecurityProperties().size());
 

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/5abe957c/geode-core/src/test/java/org/apache/geode/security/StartServerAuthorizationTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/security/StartServerAuthorizationTest.java
b/geode-core/src/test/java/org/apache/geode/security/StartServerAuthorizationTest.java
index f6928bf..a001493 100644
--- a/geode-core/src/test/java/org/apache/geode/security/StartServerAuthorizationTest.java
+++ b/geode-core/src/test/java/org/apache/geode/security/StartServerAuthorizationTest.java
@@ -58,7 +58,7 @@ public class StartServerAuthorizationTest extends JUnit4DistributedTestCase
{
     VM server = lsRule.getNodeVM(1);
     server.invoke(()->{
       ServerStarter serverStarter = new ServerStarter(props);
-      assertThatThrownBy(()->serverStarter.startServer(lsRule.getLocatorPort(0))).isInstanceOf(GemFireSecurityException.class).hasMessageContaining("Security
check failed. Authentication error. Please check your credentials");
+      assertThatThrownBy(()->serverStarter.startServer(lsRule.getPort(0))).isInstanceOf(GemFireSecurityException.class).hasMessageContaining("Security
check failed. Authentication error. Please check your credentials");
     });
   }
 
@@ -73,7 +73,7 @@ public class StartServerAuthorizationTest extends JUnit4DistributedTestCase
{
     VM server = lsRule.getNodeVM(1);
     server.invoke(()->{
       ServerStarter serverStarter = new ServerStarter(props);
-      assertThatThrownBy(()->serverStarter.startServer(lsRule.getLocatorPort(0))).isInstanceOf(GemFireSecurityException.class).hasMessageContaining("user
not authorized for CLUSTER:MANAGE");
+      assertThatThrownBy(()->serverStarter.startServer(lsRule.getPort(0))).isInstanceOf(GemFireSecurityException.class).hasMessageContaining("user
not authorized for CLUSTER:MANAGE");
     });
 
 

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/5abe957c/geode-core/src/test/java/org/apache/geode/test/dunit/rules/LocatorServerStartupRule.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/test/dunit/rules/LocatorServerStartupRule.java
b/geode-core/src/test/java/org/apache/geode/test/dunit/rules/LocatorServerStartupRule.java
index 71894c8..41326e0 100644
--- a/geode-core/src/test/java/org/apache/geode/test/dunit/rules/LocatorServerStartupRule.java
+++ b/geode-core/src/test/java/org/apache/geode/test/dunit/rules/LocatorServerStartupRule.java
@@ -41,7 +41,7 @@ public class LocatorServerStartupRule extends ExternalResource implements
Serial
 
   private Host host = getHost(0);
 
-  public int[] locatorPorts = new int[4];
+  public int[] ports = new int[4];
 
 
   // these are only avaialbe in each VM
@@ -75,7 +75,7 @@ public class LocatorServerStartupRule extends ExternalResource implements
Serial
       locatorStarter.startLocator();
       return locatorStarter.locator.getPort();
     });
-    locatorPorts[index] = locatorPort;
+    ports[index] = locatorPort;
     return locatorVM;
   }
 
@@ -98,10 +98,12 @@ public class LocatorServerStartupRule extends ExternalResource implements
Serial
   public VM getServerVM(int index, Properties properties, int locatorPort) {
     VM nodeVM = getNodeVM(index);
     properties.setProperty(NAME, "server-"+index);
-    nodeVM.invoke(() -> {
+    int port = nodeVM.invoke(() -> {
       serverStarter = new ServerStarter(properties);
       serverStarter.startServer(locatorPort);
+      return serverStarter.server.getPort();
     });
+    ports[index] = port;
     return nodeVM;
   }
 
@@ -116,8 +118,8 @@ public class LocatorServerStartupRule extends ExternalResource implements
Serial
     return host.getVM(index);
   }
 
-  public int getLocatorPort(int index){
-    return locatorPorts[index];
+  public int getPort(int index){
+    return ports[index];
   }
 
 

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/5abe957c/geode-lucene/src/test/java/org/apache/geode/cache/lucene/internal/configuration/LuceneClusterConfigurationDUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-lucene/src/test/java/org/apache/geode/cache/lucene/internal/configuration/LuceneClusterConfigurationDUnitTest.java
b/geode-lucene/src/test/java/org/apache/geode/cache/lucene/internal/configuration/LuceneClusterConfigurationDUnitTest.java
index bcc5ab3..8dc5e0f 100755
--- a/geode-lucene/src/test/java/org/apache/geode/cache/lucene/internal/configuration/LuceneClusterConfigurationDUnitTest.java
+++ b/geode-lucene/src/test/java/org/apache/geode/cache/lucene/internal/configuration/LuceneClusterConfigurationDUnitTest.java
@@ -241,7 +241,7 @@ public class LuceneClusterConfigurationDUnitTest extends CliCommandTestBase
{
     if (addGroup) {
       nodeProperties.setProperty(GROUPS, groupName);
     }
-    return ls.getServerVM(vmIndex, nodeProperties, ls.getLocatorPort(0));
+    return ls.getServerVM(vmIndex, nodeProperties, ls.getPort(0));
   }
 
   private VM startLocatorWithClusterConfigurationEnabled() throws Exception {


Mime
View raw message