Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 0C11A200B38 for ; Fri, 8 Jul 2016 20:45:53 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 0AB0E160A5A; Fri, 8 Jul 2016 18:45:53 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 2CD08160A77 for ; Fri, 8 Jul 2016 20:45:52 +0200 (CEST) Received: (qmail 48987 invoked by uid 500); 8 Jul 2016 18:45:51 -0000 Mailing-List: contact commits-help@geode.incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@geode.incubator.apache.org Delivered-To: mailing list commits@geode.incubator.apache.org Received: (qmail 48978 invoked by uid 99); 8 Jul 2016 18:45:51 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd4-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 08 Jul 2016 18:45:51 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd4-us-west.apache.org (ASF Mail Server at spamd4-us-west.apache.org) with ESMTP id E6624C034D for ; Fri, 8 Jul 2016 18:45:50 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd4-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: -4.646 X-Spam-Level: X-Spam-Status: No, score=-4.646 tagged_above=-999 required=6.31 tests=[KAM_ASCII_DIVIDERS=0.8, KAM_LAZY_DOMAIN_SECURITY=1, RCVD_IN_DNSWL_HI=-5, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, RP_MATCHES_RCVD=-1.426] autolearn=disabled Received: from mx2-lw-us.apache.org ([10.40.0.8]) by localhost (spamd4-us-west.apache.org [10.40.0.11]) (amavisd-new, port 10024) with ESMTP id bu6fcbTgtwGV for ; Fri, 8 Jul 2016 18:45:49 +0000 (UTC) Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx2-lw-us.apache.org (ASF Mail Server at mx2-lw-us.apache.org) with SMTP id 46C915F47B for ; Fri, 8 Jul 2016 18:45:49 +0000 (UTC) Received: (qmail 48925 invoked by uid 99); 8 Jul 2016 18:45:48 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 08 Jul 2016 18:45:48 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 77DEBDFFF8; Fri, 8 Jul 2016 18:45:48 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: klund@apache.org To: commits@geode.incubator.apache.org Message-Id: <568ce4938e644fe887d5db73f5ff9254@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: incubator-geode git commit: GEODE-1571: Write DUnit test for SecurityManager init() and close() Date: Fri, 8 Jul 2016 18:45:48 +0000 (UTC) archived-at: Fri, 08 Jul 2016 18:45:53 -0000 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 Authored: Fri Jul 8 11:36:50 2016 -0700 Committer: Kirk Lund 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++; + } + } +}