geode-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kl...@apache.org
Subject incubator-geode git commit: GEODE-1571: Write DUnit test for SecurityManager init() and close()
Date Fri, 08 Jul 2016 18:45:48 GMT
Repository: incubator-geode
Updated Branches:
  refs/heads/develop dfd481e0b -> 617d31327


GEODE-1571: Write DUnit test for SecurityManager init() and close()

This closes #192


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

Branch: refs/heads/develop
Commit: 617d31327abaa85150b7a6795ee04d1dfd542ce1
Parents: dfd481e
Author: gmeilen <gracemeilen@gmail.com>
Authored: Fri Jul 8 11:36:50 2016 -0700
Committer: Kirk Lund <klund@apache.org>
Committed: Fri Jul 8 11:40:19 2016 -0700

----------------------------------------------------------------------
 ...edSecurityCacheLifecycleDistributedTest.java | 146 +++++++++++++++++++
 1 file changed, 146 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/617d3132/geode-core/src/test/java/com/gemstone/gemfire/security/IntegratedSecurityCacheLifecycleDistributedTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/security/IntegratedSecurityCacheLifecycleDistributedTest.java
b/geode-core/src/test/java/com/gemstone/gemfire/security/IntegratedSecurityCacheLifecycleDistributedTest.java
new file mode 100644
index 0000000..7649f89
--- /dev/null
+++ b/geode-core/src/test/java/com/gemstone/gemfire/security/IntegratedSecurityCacheLifecycleDistributedTest.java
@@ -0,0 +1,146 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.gemstone.gemfire.security;
+
+
+import static com.gemstone.gemfire.distributed.ConfigurationProperties.*;
+import static org.assertj.core.api.Assertions.*;
+
+import java.security.Principal;
+import java.util.Properties;
+
+import com.gemstone.gemfire.cache.Region;
+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.ClientRegionShortcut;
+import com.gemstone.gemfire.cache.server.CacheServer;
+import com.gemstone.gemfire.distributed.internal.InternalLocator;
+import com.gemstone.gemfire.internal.AvailablePort;
+import com.gemstone.gemfire.management.internal.security.JSONAuthorization;
+import com.gemstone.gemfire.security.templates.UserPasswordAuthInit;
+import com.gemstone.gemfire.test.dunit.DistributedTestUtils;
+import com.gemstone.gemfire.test.dunit.Host;
+import com.gemstone.gemfire.test.dunit.NetworkUtils;
+import com.gemstone.gemfire.test.dunit.VM;
+import com.gemstone.gemfire.test.dunit.cache.internal.JUnit4CacheTestCase;
+import com.gemstone.gemfire.test.junit.categories.DistributedTest;
+import com.gemstone.gemfire.test.junit.categories.SecurityTest;
+
+import org.assertj.core.api.ThrowableAssert.ThrowingCallable;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+import org.mockito.Spy;
+
+@Category({DistributedTest.class, SecurityTest.class})
+public class IntegratedSecurityCacheLifecycleDistributedTest extends JUnit4CacheTestCase
{
+
+  private static SpySecurityManager spySecurityManager;
+
+  private VM locator;
+
+  @Override
+  public final void postSetUp() throws Exception {
+    Host host = Host.getHost(0);
+    locator = host.getVM(0);
+    JSONAuthorization.setUpWithJsonFile("clientServer.json");
+    int locatorPort = AvailablePort.getRandomAvailablePort(AvailablePort.SOCKET);
+    String locators =  NetworkUtils.getServerHostName(host) + "[" + locatorPort + "]";
+
+    spySecurityManager = new SpySecurityManager();
+
+    locator.invoke(() -> {
+      spySecurityManager = new SpySecurityManager();
+      DistributedTestUtils.deleteLocatorStateFile(locatorPort);
+
+      final Properties properties = new Properties();
+      properties.setProperty(MCAST_PORT, "0");
+      properties.setProperty(START_LOCATOR, locators);
+      properties.setProperty(SECURITY_MANAGER, SpySecurityManager.class.getName()+".create");
+      properties.setProperty(USE_CLUSTER_CONFIGURATION, "false");
+      getSystem(properties);
+      getCache();
+    });
+
+    final Properties properties = new Properties();
+    properties.setProperty(MCAST_PORT, "0");
+    properties.setProperty(SECURITY_MANAGER, SpySecurityManager.class.getName()+".create");
+    properties.setProperty(LOCATORS, locators);
+    properties.setProperty(USE_CLUSTER_CONFIGURATION, "false");
+    getSystem(properties);
+
+    CacheServer server1 = getCache().addCacheServer();
+    server1.setPort(0);
+    server1.start();
+
+    getCache();
+  }
+
+  @Test
+  public void initAndCloseTest () {
+    locator.invoke(() -> {
+      verifyInitInvoked();
+    });
+    verifyInitInvoked();
+    getCache().close();
+    verifyCloseInvoked();
+    locator.invoke(() -> {
+      getCache().close();
+      verifyCloseInvoked();
+    });
+  }
+
+  @Override
+  public void postTearDownCacheTestCase() throws Exception {
+    closeAllCache();
+  }
+
+  private static void verifyInitInvoked() {
+    assertThat(spySecurityManager.initInvoked).isEqualTo(1);
+  }
+
+  private static void verifyCloseInvoked() {
+    assertThat(spySecurityManager.closeInvoked).isEqualTo(1);
+  }
+
+
+  public static class SpySecurityManager extends JSONAuthorization {
+
+    private static int initInvoked = 0;
+    private static int closeInvoked = 0;
+
+    public static SpySecurityManager create() {
+      return spySecurityManager;
+    }
+
+    @Override
+    public void init(final Properties securityProps) {
+      initInvoked++;
+      super.init(securityProps);
+    }
+
+    @Override
+    public Principal authenticate(final Properties props) throws AuthenticationFailedException
{
+      return null;
+    }
+
+    @Override
+    public void close() {
+      closeInvoked++;
+    }
+  }
+}


Mime
View raw message