You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by ji...@apache.org on 2018/08/09 15:59:59 UTC

[geode] branch develop updated: GEODE-5540: add backward compatibility to client authentication tests using SecurityManager (#2280)

This is an automated email from the ASF dual-hosted git repository.

jinmeiliao pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/geode.git


The following commit(s) were added to refs/heads/develop by this push:
     new c90e503  GEODE-5540: add backward compatibility to client authentication tests using SecurityManager (#2280)
c90e503 is described below

commit c90e5034f5a7af99777b5849c1c3e5967ba11d70
Author: jinmeiliao <ji...@pivotal.io>
AuthorDate: Thu Aug 9 08:59:53 2018 -0700

    GEODE-5540: add backward compatibility to client authentication tests using SecurityManager (#2280)
---
 .../apache/geode/security/ClientAuthDUnitTest.java | 65 +++++++++++++++++++++-
 .../security/ClientAuthenticationDUnitTest.java    |  2 +-
 2 files changed, 63 insertions(+), 4 deletions(-)

diff --git a/geode-core/src/distributedTest/java/org/apache/geode/security/ClientAuthDUnitTest.java b/geode-core/src/distributedTest/java/org/apache/geode/security/ClientAuthDUnitTest.java
index f81a8c7..e3298d7 100644
--- a/geode-core/src/distributedTest/java/org/apache/geode/security/ClientAuthDUnitTest.java
+++ b/geode-core/src/distributedTest/java/org/apache/geode/security/ClientAuthDUnitTest.java
@@ -14,12 +14,19 @@
  */
 package org.apache.geode.security;
 
+import static org.apache.geode.distributed.ConfigurationProperties.SECURITY_CLIENT_AUTH_INIT;
 import static org.apache.geode.distributed.ConfigurationProperties.SECURITY_MANAGER;
 import static org.assertj.core.api.Assertions.assertThatThrownBy;
 
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Properties;
+
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.experimental.categories.Category;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
 
 import org.apache.geode.cache.Region;
 import org.apache.geode.cache.RegionShortcut;
@@ -27,14 +34,28 @@ import org.apache.geode.cache.client.ClientCache;
 import org.apache.geode.cache.client.ClientRegionFactory;
 import org.apache.geode.cache.client.ClientRegionShortcut;
 import org.apache.geode.cache.client.ServerOperationException;
+import org.apache.geode.security.templates.UserPasswordAuthInit;
 import org.apache.geode.test.dunit.IgnoredException;
 import org.apache.geode.test.dunit.rules.ClientVM;
 import org.apache.geode.test.dunit.rules.ClusterStartupRule;
+import org.apache.geode.test.dunit.standalone.VersionManager;
 import org.apache.geode.test.junit.categories.SecurityTest;
 import org.apache.geode.test.junit.rules.ServerStarterRule;
+import org.apache.geode.test.junit.runners.CategoryWithParameterizedRunnerFactory;
 
 @Category({SecurityTest.class})
+@RunWith(Parameterized.class)
+@Parameterized.UseParametersRunnerFactory(CategoryWithParameterizedRunnerFactory.class)
 public class ClientAuthDUnitTest {
+
+  @Parameterized.Parameter
+  public String clientVersion;
+
+  @Parameterized.Parameters(name = "{0}")
+  public static Collection<String> data() {
+    return VersionManager.getInstance().getVersions();
+  }
+
   @Rule
   public ClusterStartupRule lsRule = new ClusterStartupRule();
 
@@ -45,7 +66,12 @@ public class ClientAuthDUnitTest {
 
   @Test
   public void authWithCorrectPasswordShouldPass() throws Exception {
-    ClientVM clientVM = lsRule.startClientVM(0, "data", "data", true, server.getPort());
+    int serverPort = server.getPort();
+    ClientVM clientVM = lsRule.startClientVM(0, getClientAuthProperties("data", "data"), ccf -> {
+      ccf.setPoolSubscriptionEnabled(true);
+      ccf.addPoolServer("localhost", serverPort);
+    }, clientVersion);
+
     clientVM.invoke(() -> {
       ClientCache clientCache = ClusterStartupRule.getClientCache();
       ClientRegionFactory clientRegionFactory =
@@ -57,8 +83,27 @@ public class ClientAuthDUnitTest {
 
   @Test
   public void authWithIncorrectPasswordWithSubscriptionEnabled() throws Exception {
+    int serverPort = server.getPort();
     IgnoredException.addIgnoredException(AuthenticationFailedException.class.getName());
-    ClientVM clientVM = lsRule.startClientVM(0, "test", "invalidPassword", true, server.getPort());
+
+    // for older version of client when we did not implement lazy initialization of the pool, the
+    // authentication error will happen at this step.
+    if (Arrays.asList("100", "110", "111", "120", "130", "140").contains(clientVersion)) {
+      assertThatThrownBy(
+          () -> lsRule.startClientVM(0, getClientAuthProperties("test", "invalidPassword"), ccf -> {
+            ccf.setPoolSubscriptionEnabled(true);
+            ccf.addPoolServer("localhost", serverPort);
+          }, clientVersion))
+              .isInstanceOf(AuthenticationFailedException.class);
+      return;
+    }
+
+    ClientVM clientVM =
+        lsRule.startClientVM(0, getClientAuthProperties("test", "invalidPassword"), ccf -> {
+          ccf.setPoolSubscriptionEnabled(true);
+          ccf.addPoolServer("localhost", serverPort);
+        }, clientVersion);
+
     clientVM.invoke(() -> {
       ClientCache clientCache = ClusterStartupRule.getClientCache();
       ClientRegionFactory clientRegionFactory =
@@ -70,8 +115,14 @@ public class ClientAuthDUnitTest {
 
   @Test
   public void authWithIncorrectPasswordWithSubscriptionNotEnabled() throws Exception {
+    int serverPort = server.getPort();
     IgnoredException.addIgnoredException(AuthenticationFailedException.class.getName());
-    ClientVM clientVM = lsRule.startClientVM(0, "test", "invalidPassword", false, server.getPort());
+    ClientVM clientVM =
+        lsRule.startClientVM(0, getClientAuthProperties("test", "invalidPassword"), ccf -> {
+          ccf.setPoolSubscriptionEnabled(false);
+          ccf.addPoolServer("localhost", serverPort);
+        }, clientVersion);
+
     clientVM.invoke(() -> {
       ClientCache clientCache = ClusterStartupRule.getClientCache();
       ClientRegionFactory clientRegionFactory =
@@ -81,4 +132,12 @@ public class ClientAuthDUnitTest {
           .hasCauseInstanceOf(AuthenticationFailedException.class);
     });
   }
+
+  private Properties getClientAuthProperties(String username, String password) {
+    Properties props = new Properties();
+    props.setProperty(UserPasswordAuthInit.USER_NAME, username);
+    props.setProperty(UserPasswordAuthInit.PASSWORD, password);
+    props.setProperty(SECURITY_CLIENT_AUTH_INIT, UserPasswordAuthInit.class.getName());
+    return props;
+  }
 }
diff --git a/geode-core/src/distributedTest/java/org/apache/geode/security/ClientAuthenticationDUnitTest.java b/geode-core/src/distributedTest/java/org/apache/geode/security/ClientAuthenticationDUnitTest.java
index d69dbd2..4ee981e 100644
--- a/geode-core/src/distributedTest/java/org/apache/geode/security/ClientAuthenticationDUnitTest.java
+++ b/geode-core/src/distributedTest/java/org/apache/geode/security/ClientAuthenticationDUnitTest.java
@@ -38,7 +38,7 @@ import org.apache.geode.test.junit.runners.CategoryWithParameterizedRunnerFactor
 @RunWith(Parameterized.class)
 @Parameterized.UseParametersRunnerFactory(CategoryWithParameterizedRunnerFactory.class)
 public class ClientAuthenticationDUnitTest extends ClientAuthenticationTestCase {
-  @Parameterized.Parameters
+  @Parameterized.Parameters(name = "{0}")
   public static Collection<String> data() {
     List<String> result = VersionManager.getInstance().getVersions();
     if (result.size() < 1) {