Repository: incubator-geode Updated Branches: refs/heads/develop 6ec3f884c -> fa88520b6
GEODE-1912: make ServerStarter and LocatorStarter as regular rules so that it's easier to use them in a RuleChain Project: http://git-wip-us.apache.org/repos/asf/incubator-geode/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-geode/commit/fa88520b Tree: http://git-wip-us.apache.org/repos/asf/incubator-geode/tree/fa88520b Diff: http://git-wip-us.apache.org/repos/asf/incubator-geode/diff/fa88520b Branch: refs/heads/develop Commit: fa88520b658dbf8ec74a83a63190bca8dc2bcff5 Parents: 6ec3f88 Author: Jinmei Liao <[email protected]> Authored: Thu Oct 27 10:24:07 2016 -0700 Committer: Jinmei Liao <[email protected]> Committed: Fri Oct 28 08:56:49 2016 -0700 ---------------------------------------------------------------------- .../web/RestSecurityIntegrationTest.java | 5 +- .../rest/internal/web/RestServersJUnitTest.java | 5 +- .../internal/web/SwaggerVerificationTest.java | 10 +- .../management/internal/cli/GfshParser.java | 42 ++++--- .../CacheServerMBeanShiroJUnitTest.java | 29 +++-- .../security/CacheServerStartupRule.java | 6 +- .../security/GfshCommandsPostProcessorTest.java | 26 +++-- .../security/GfshCommandsSecurityTest.java | 48 +++++--- .../security/GfshShellConnectionRule.java | 113 ------------------- .../security/JavaRmiServerNameTest.java | 22 ++-- .../security/AbstractSecureServerDUnitTest.java | 27 +++-- .../ClusterConfigWithoutSecurityDUnitTest.java | 6 +- .../security/PeerAuthenticatorDUnitTest.java | 4 +- ...eerSecurityWithEmbeddedLocatorDUnitTest.java | 6 +- .../SecurityClusterConfigDUnitTest.java | 12 +- .../SecurityWithoutClusterConfigDUnitTest.java | 4 +- .../security/StartServerAuthorizationTest.java | 6 +- .../dunit/rules/GfshShellConnectionRule.java | 111 ++++++++++++++++++ .../dunit/rules/LocatorServerStartupRule.java | 25 ++-- .../geode/test/dunit/rules/LocatorStarter.java | 72 ------------ .../test/dunit/rules/LocatorStarterRule.java | 75 ++++++++++++ .../geode/test/dunit/rules/ServerStarter.java | 97 ---------------- .../test/dunit/rules/ServerStarterRule.java | 110 ++++++++++++++++++ .../GfshCommandsOverHttpSecurityTest.java | 3 +- 24 files changed, 441 insertions(+), 423 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/fa88520b/geode-assembly/src/test/java/org/apache/geode/rest/internal/web/RestSecurityIntegrationTest.java ---------------------------------------------------------------------- diff --git a/geode-assembly/src/test/java/org/apache/geode/rest/internal/web/RestSecurityIntegrationTest.java b/geode-assembly/src/test/java/org/apache/geode/rest/internal/web/RestSecurityIntegrationTest.java index 2dffcb7..aee2560 100644 --- a/geode-assembly/src/test/java/org/apache/geode/rest/internal/web/RestSecurityIntegrationTest.java +++ b/geode-assembly/src/test/java/org/apache/geode/rest/internal/web/RestSecurityIntegrationTest.java @@ -25,7 +25,7 @@ import static org.junit.Assert.assertTrue; import org.apache.geode.cache.RegionShortcut; import org.apache.geode.internal.AvailablePortHelper; import org.apache.geode.security.templates.SampleSecurityManager; -import org.apache.geode.test.dunit.rules.ServerStarter; +import org.apache.geode.test.dunit.rules.ServerStarterRule; import org.apache.geode.test.junit.categories.IntegrationTest; import org.apache.geode.test.junit.categories.SecurityTest; import org.apache.http.HttpResponse; @@ -58,12 +58,11 @@ public class RestSecurityIntegrationTest { }; @ClassRule - public static ServerStarter serverStarter = new ServerStarter(properties); + public static ServerStarterRule serverStarter = new ServerStarterRule(properties); private final GeodeRestClient restClient = new GeodeRestClient("localhost", restPort); @BeforeClass public static void before() throws Exception { - serverStarter.startServer(); serverStarter.cache.createRegionFactory(RegionShortcut.REPLICATE).create(REGION_NAME); } http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/fa88520b/geode-assembly/src/test/java/org/apache/geode/rest/internal/web/RestServersJUnitTest.java ---------------------------------------------------------------------- diff --git a/geode-assembly/src/test/java/org/apache/geode/rest/internal/web/RestServersJUnitTest.java b/geode-assembly/src/test/java/org/apache/geode/rest/internal/web/RestServersJUnitTest.java index 552a184..b49e6ca 100644 --- a/geode-assembly/src/test/java/org/apache/geode/rest/internal/web/RestServersJUnitTest.java +++ b/geode-assembly/src/test/java/org/apache/geode/rest/internal/web/RestServersJUnitTest.java @@ -19,7 +19,7 @@ import static org.apache.geode.distributed.ConfigurationProperties.HTTP_SERVICE_ import static org.apache.geode.distributed.ConfigurationProperties.START_DEV_REST_API; import org.apache.geode.test.dunit.Assert; -import org.apache.geode.test.dunit.rules.ServerStarter; +import org.apache.geode.test.dunit.rules.ServerStarterRule; import org.apache.geode.test.junit.categories.IntegrationTest; import org.apache.http.HttpResponse; import org.json.JSONArray; @@ -42,12 +42,11 @@ public class RestServersJUnitTest { }; @ClassRule - public static ServerStarter serverStarter = new ServerStarter(properties); + public static ServerStarterRule serverStarter = new ServerStarterRule(properties); private static GeodeRestClient restClient; @BeforeClass public static void before() throws Exception { - serverStarter.startServer(); restClient = new GeodeRestClient("localhost", defaultPort); } http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/fa88520b/geode-assembly/src/test/java/org/apache/geode/rest/internal/web/SwaggerVerificationTest.java ---------------------------------------------------------------------- diff --git a/geode-assembly/src/test/java/org/apache/geode/rest/internal/web/SwaggerVerificationTest.java b/geode-assembly/src/test/java/org/apache/geode/rest/internal/web/SwaggerVerificationTest.java index b550e11..e706b0e 100644 --- a/geode-assembly/src/test/java/org/apache/geode/rest/internal/web/SwaggerVerificationTest.java +++ b/geode-assembly/src/test/java/org/apache/geode/rest/internal/web/SwaggerVerificationTest.java @@ -24,12 +24,11 @@ import static org.junit.Assert.assertThat; import org.apache.geode.internal.AvailablePortHelper; import org.apache.geode.internal.i18n.LocalizedStrings; +import org.apache.geode.test.dunit.rules.ServerStarterRule; import org.apache.geode.security.templates.SimpleSecurityManager; -import org.apache.geode.test.dunit.rules.ServerStarter; import org.apache.geode.test.junit.categories.IntegrationTest; import org.apache.http.HttpResponse; import org.json.JSONObject; -import org.junit.BeforeClass; import org.junit.ClassRule; import org.junit.Test; import org.junit.experimental.categories.Category; @@ -51,14 +50,9 @@ public class SwaggerVerificationTest { }; @ClassRule - public static ServerStarter serverStarter = new ServerStarter(properties); + public static ServerStarterRule serverStarter = new ServerStarterRule(properties); private final GeodeRestClient restClient = new GeodeRestClient("localhost", restPort); - @BeforeClass - public static void before() throws Exception { - serverStarter.startServer(); - } - @Test public void isSwaggerRunning() throws Exception { // Check the UI http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/fa88520b/geode-core/src/main/java/org/apache/geode/management/internal/cli/GfshParser.java ---------------------------------------------------------------------- diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/GfshParser.java b/geode-core/src/main/java/org/apache/geode/management/internal/cli/GfshParser.java index bc25567..a1d03e4 100755 --- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/GfshParser.java +++ b/geode-core/src/main/java/org/apache/geode/management/internal/cli/GfshParser.java @@ -14,28 +14,7 @@ */ package org.apache.geode.management.internal.cli; -import java.lang.reflect.InvocationTargetException; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.HashMap; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.TreeMap; -import java.util.TreeSet; -import java.util.logging.Logger; -import java.util.regex.Pattern; - import org.apache.commons.lang.StringUtils; -import org.springframework.shell.core.AbstractShell; -import org.springframework.shell.core.Completion; -import org.springframework.shell.core.Converter; -import org.springframework.shell.core.MethodTarget; -import org.springframework.shell.core.Parser; -import org.springframework.shell.event.ParseResult; - import org.apache.geode.management.cli.CommandProcessingException; import org.apache.geode.management.internal.cli.exceptions.CliCommandMultiModeOptionException; import org.apache.geode.management.internal.cli.exceptions.CliCommandOptionException; @@ -60,6 +39,26 @@ import org.apache.geode.management.internal.cli.parser.preprocessor.Preprocessor import org.apache.geode.management.internal.cli.parser.preprocessor.TrimmedInput; import org.apache.geode.management.internal.cli.shell.Gfsh; import org.apache.geode.management.internal.cli.util.CLIConsoleBufferUtil; +import org.springframework.shell.core.AbstractShell; +import org.springframework.shell.core.Completion; +import org.springframework.shell.core.Converter; +import org.springframework.shell.core.MethodTarget; +import org.springframework.shell.core.Parser; +import org.springframework.shell.event.ParseResult; + +import java.lang.reflect.InvocationTargetException; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.TreeMap; +import java.util.TreeSet; +import java.util.logging.Logger; +import java.util.regex.Pattern; /** * Implementation of the {@link Parser} interface for GemFire SHell (gfsh) requirements. @@ -927,7 +926,6 @@ public class GfshParser implements Parser { } } else { if (targets.size() == 1) { - OptionSet parse = null; List<MethodParameter> parameters = new ArrayList<MethodParameter>(); Map<String, String> paramValMap = new HashMap<String, String>(); http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/fa88520b/geode-core/src/test/java/org/apache/geode/management/internal/security/CacheServerMBeanShiroJUnitTest.java ---------------------------------------------------------------------- diff --git a/geode-core/src/test/java/org/apache/geode/management/internal/security/CacheServerMBeanShiroJUnitTest.java b/geode-core/src/test/java/org/apache/geode/management/internal/security/CacheServerMBeanShiroJUnitTest.java index 992c27d..3183aaf 100644 --- a/geode-core/src/test/java/org/apache/geode/management/internal/security/CacheServerMBeanShiroJUnitTest.java +++ b/geode-core/src/test/java/org/apache/geode/management/internal/security/CacheServerMBeanShiroJUnitTest.java @@ -14,24 +14,24 @@ */ package org.apache.geode.management.internal.security; -import static org.apache.geode.distributed.ConfigurationProperties.*; -import static org.assertj.core.api.Assertions.*; - -import java.util.Properties; - -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Rule; -import org.junit.Test; -import org.junit.experimental.categories.Category; +import static org.apache.geode.distributed.ConfigurationProperties.JMX_MANAGER_PORT; +import static org.apache.geode.distributed.ConfigurationProperties.SECURITY_SHIRO_INIT; +import static org.assertj.core.api.Assertions.assertThatThrownBy; import org.apache.geode.internal.AvailablePort; import org.apache.geode.management.CacheServerMXBean; import org.apache.geode.test.dunit.rules.ConnectionConfiguration; import org.apache.geode.test.dunit.rules.MBeanServerConnectionRule; -import org.apache.geode.test.dunit.rules.ServerStarter; +import org.apache.geode.test.dunit.rules.ServerStarterRule; import org.apache.geode.test.junit.categories.IntegrationTest; import org.apache.geode.test.junit.categories.SecurityTest; +import org.junit.Before; +import org.junit.ClassRule; +import org.junit.Rule; +import org.junit.Test; +import org.junit.experimental.categories.Category; + +import java.util.Properties; @Category({IntegrationTest.class, SecurityTest.class}) public class CacheServerMBeanShiroJUnitTest { @@ -45,11 +45,8 @@ public class CacheServerMBeanShiroJUnitTest { private CacheServerMXBean bean; - @BeforeClass - public static void before() throws Exception { - ServerStarter serverStarter = new ServerStarter(properties); - serverStarter.startServer(); - } + @ClassRule + public static ServerStarterRule serverStarter = new ServerStarterRule(properties); @Rule public MBeanServerConnectionRule connectionRule = new MBeanServerConnectionRule(jmxManagerPort); http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/fa88520b/geode-core/src/test/java/org/apache/geode/management/internal/security/CacheServerStartupRule.java ---------------------------------------------------------------------- diff --git a/geode-core/src/test/java/org/apache/geode/management/internal/security/CacheServerStartupRule.java b/geode-core/src/test/java/org/apache/geode/management/internal/security/CacheServerStartupRule.java index c9ae997..03f4e84 100644 --- a/geode-core/src/test/java/org/apache/geode/management/internal/security/CacheServerStartupRule.java +++ b/geode-core/src/test/java/org/apache/geode/management/internal/security/CacheServerStartupRule.java @@ -26,14 +26,14 @@ import org.junit.rules.ExternalResource; import org.apache.geode.cache.Cache; import org.apache.geode.security.templates.SampleSecurityManager; -import org.apache.geode.test.dunit.rules.ServerStarter; +import org.apache.geode.test.dunit.rules.ServerStarterRule; /** * this rule would help you start up a cache server with the given properties in the current VM */ public class CacheServerStartupRule extends ExternalResource implements Serializable { - private ServerStarter serverStarter; + private ServerStarterRule serverStarter; public static CacheServerStartupRule withDefaultSecurityJson(int jmxManagerPort) { return new CacheServerStartupRule(jmxManagerPort, @@ -49,7 +49,7 @@ public class CacheServerStartupRule extends ExternalResource implements Serializ properties.put(SECURITY_MANAGER, SampleSecurityManager.class.getName()); properties.put(SampleSecurityManager.SECURITY_JSON, jsonFile); } - serverStarter = new ServerStarter(properties); + serverStarter = new ServerStarterRule(properties); } @Before http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/fa88520b/geode-core/src/test/java/org/apache/geode/management/internal/security/GfshCommandsPostProcessorTest.java ---------------------------------------------------------------------- diff --git a/geode-core/src/test/java/org/apache/geode/management/internal/security/GfshCommandsPostProcessorTest.java b/geode-core/src/test/java/org/apache/geode/management/internal/security/GfshCommandsPostProcessorTest.java index 60f58da..d3390ba 100644 --- a/geode-core/src/test/java/org/apache/geode/management/internal/security/GfshCommandsPostProcessorTest.java +++ b/geode-core/src/test/java/org/apache/geode/management/internal/security/GfshCommandsPostProcessorTest.java @@ -14,16 +14,10 @@ */ package org.apache.geode.management.internal.security; -import static org.apache.geode.distributed.ConfigurationProperties.*; -import static org.apache.geode.internal.Assert.*; - -import java.util.Properties; - -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Rule; -import org.junit.Test; -import org.junit.experimental.categories.Category; +import static org.apache.geode.distributed.ConfigurationProperties.JMX_MANAGER_PORT; +import static org.apache.geode.distributed.ConfigurationProperties.SECURITY_MANAGER; +import static org.apache.geode.distributed.ConfigurationProperties.SECURITY_POST_PROCESSOR; +import static org.apache.geode.internal.Assert.assertTrue; import org.apache.geode.cache.RegionShortcut; import org.apache.geode.internal.AvailablePortHelper; @@ -31,9 +25,17 @@ import org.apache.geode.management.internal.cli.HeadlessGfsh; import org.apache.geode.security.templates.SamplePostProcessor; import org.apache.geode.security.templates.SampleSecurityManager; import org.apache.geode.test.dunit.rules.ConnectionConfiguration; -import org.apache.geode.test.dunit.rules.ServerStarter; +import org.apache.geode.test.dunit.rules.GfshShellConnectionRule; +import org.apache.geode.test.dunit.rules.ServerStarterRule; import org.apache.geode.test.junit.categories.IntegrationTest; import org.apache.geode.test.junit.categories.SecurityTest; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Rule; +import org.junit.Test; +import org.junit.experimental.categories.Category; + +import java.util.Properties; @Category({IntegrationTest.class, SecurityTest.class}) public class GfshCommandsPostProcessorTest { @@ -53,7 +55,7 @@ public class GfshCommandsPostProcessorTest { @BeforeClass public static void beforeClass() throws Exception { - ServerStarter serverStarter = new ServerStarter(properties); + ServerStarterRule serverStarter = new ServerStarterRule(properties); serverStarter.startServer(); serverStarter.cache.createRegionFactory(RegionShortcut.REPLICATE).create("region1"); } http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/fa88520b/geode-core/src/test/java/org/apache/geode/management/internal/security/GfshCommandsSecurityTest.java ---------------------------------------------------------------------- diff --git a/geode-core/src/test/java/org/apache/geode/management/internal/security/GfshCommandsSecurityTest.java b/geode-core/src/test/java/org/apache/geode/management/internal/security/GfshCommandsSecurityTest.java index ce9c21c..b2dc6fe 100644 --- a/geode-core/src/test/java/org/apache/geode/management/internal/security/GfshCommandsSecurityTest.java +++ b/geode-core/src/test/java/org/apache/geode/management/internal/security/GfshCommandsSecurityTest.java @@ -14,18 +14,14 @@ */ package org.apache.geode.management.internal.security; -import static org.apache.geode.distributed.ConfigurationProperties.*; -import static org.junit.Assert.*; - -import java.util.List; -import java.util.Properties; - -import org.apache.shiro.authz.permission.WildcardPermission; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Rule; -import org.junit.Test; -import org.junit.experimental.categories.Category; +import static org.apache.geode.distributed.ConfigurationProperties.HTTP_SERVICE_PORT; +import static org.apache.geode.distributed.ConfigurationProperties.JMX_MANAGER_PORT; +import static org.apache.geode.distributed.ConfigurationProperties.SECURITY_MANAGER; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; import org.apache.geode.cache.RegionShortcut; import org.apache.geode.internal.AvailablePortHelper; @@ -37,17 +33,38 @@ import org.apache.geode.management.internal.cli.result.ErrorResultData; import org.apache.geode.management.internal.cli.result.ResultBuilder; import org.apache.geode.security.templates.SampleSecurityManager; import org.apache.geode.test.dunit.rules.ConnectionConfiguration; -import org.apache.geode.test.dunit.rules.ServerStarter; +import org.apache.geode.test.dunit.rules.GfshShellConnectionRule; +import org.apache.geode.test.dunit.rules.ServerStarterRule; import org.apache.geode.test.junit.categories.IntegrationTest; import org.apache.geode.test.junit.categories.SecurityTest; +import org.apache.shiro.authz.permission.WildcardPermission; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Rule; +import org.junit.Test; +import org.junit.experimental.categories.Category; + +import java.util.List; +import java.util.Properties; @Category({IntegrationTest.class, SecurityTest.class}) +// @RunWith(Parameterized.class) +// @Parameterized.UseParametersRunnerFactory(CategoryWithParameterizedRunnerFactory.class) public class GfshCommandsSecurityTest { protected static int[] ports = AvailablePortHelper.getRandomAvailableTCPPorts(2); protected static int jmxPort = ports[0]; protected static int httpPort = ports[1]; + // can't do parameterized tests here since useHttp tests needs to be in geode-web project + // @Parameterized.Parameters + // public static Collection<Object> data() { + // return Arrays.asList(new Object[] {true, false}); + // } + // + // @Parameterized.Parameter + // public boolean useHttp; + static Properties properties = new Properties() { { setProperty(JMX_MANAGER_PORT, jmxPort + ""); @@ -62,14 +79,13 @@ public class GfshCommandsSecurityTest { @BeforeClass public static void beforeClass() throws Exception { - ServerStarter serverStarter = new ServerStarter(properties); + ServerStarterRule serverStarter = new ServerStarterRule(properties); serverStarter.startServer(); serverStarter.cache.createRegionFactory(RegionShortcut.REPLICATE).create("region1"); } @Rule - public GfshShellConnectionRule gfshConnection = - new GfshShellConnectionRule(jmxPort, httpPort, false); + public GfshShellConnectionRule gfshConnection = new GfshShellConnectionRule(jmxPort); @Before public void before() { http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/fa88520b/geode-core/src/test/java/org/apache/geode/management/internal/security/GfshShellConnectionRule.java ---------------------------------------------------------------------- diff --git a/geode-core/src/test/java/org/apache/geode/management/internal/security/GfshShellConnectionRule.java b/geode-core/src/test/java/org/apache/geode/management/internal/security/GfshShellConnectionRule.java deleted file mode 100644 index e7724f7..0000000 --- a/geode-core/src/test/java/org/apache/geode/management/internal/security/GfshShellConnectionRule.java +++ /dev/null @@ -1,113 +0,0 @@ -/* - * 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.management.internal.security; - -import org.junit.runner.Description; - -import org.apache.geode.management.internal.cli.CliUtil; -import org.apache.geode.management.internal.cli.HeadlessGfsh; -import org.apache.geode.management.internal.cli.i18n.CliStrings; -import org.apache.geode.management.internal.cli.result.CommandResult; -import org.apache.geode.management.internal.cli.result.ErrorResultData; -import org.apache.geode.management.internal.cli.result.ResultBuilder; -import org.apache.geode.management.internal.cli.util.CommandStringBuilder; -import org.apache.geode.test.dunit.rules.ConnectionConfiguration; -import org.apache.geode.test.junit.rules.DescribedExternalResource; - -/** - * Class which eases the creation of MBeans for security testing. When combined with - * {@link ConnectionConfiguration} it allows for the creation of per-test connections with different - * user/password combinations. - */ -public class GfshShellConnectionRule extends DescribedExternalResource { - - private int jmxPort = 0; - private int httpPort = 0; - private boolean useHttp = false; - private HeadlessGfsh gfsh; - private boolean authenticated; - - /** - * Rule constructor - */ - public GfshShellConnectionRule(int jmxPort, int httpPort, boolean useHttp) { - this.jmxPort = jmxPort; - this.httpPort = httpPort; - this.useHttp = useHttp; - } - - public GfshShellConnectionRule(int jmxPort) { - this.jmxPort = jmxPort; - } - - protected void before(Description description) throws Throwable { - ConnectionConfiguration config = description.getAnnotation(ConnectionConfiguration.class); - if (config == null) - return; - - CliUtil.isGfshVM = true; - String shellId = getClass().getSimpleName() + "_" + description.getMethodName(); - gfsh = new HeadlessGfsh(shellId, 30, "gfsh_files"); // TODO: move to TemporaryFolder - - final CommandStringBuilder connectCommand = new CommandStringBuilder(CliStrings.CONNECT); - connectCommand.addOption(CliStrings.CONNECT__USERNAME, config.user()); - connectCommand.addOption(CliStrings.CONNECT__PASSWORD, config.password()); - - String endpoint; - if (useHttp) { - endpoint = "http://localhost:" + httpPort + "/gemfire/v1"; - connectCommand.addOption(CliStrings.CONNECT__USE_HTTP, Boolean.TRUE.toString()); - connectCommand.addOption(CliStrings.CONNECT__URL, endpoint); - } else { - endpoint = "localhost[" + jmxPort + "]"; - connectCommand.addOption(CliStrings.CONNECT__JMX_MANAGER, endpoint); - } - System.out.println(getClass().getSimpleName() + " using endpoint: " + endpoint); - - gfsh.executeCommand(connectCommand.toString()); - - CommandResult result = (CommandResult) gfsh.getResult(); - if (result.getResultData() instanceof ErrorResultData) { - ErrorResultData errorResultData = (ErrorResultData) result.getResultData(); - this.authenticated = - !(errorResultData.getErrorCode() == ResultBuilder.ERRORCODE_CONNECTION_ERROR); - } else { - this.authenticated = true; - } - } - - /** - * Override to tear down your specific external resource. - */ - protected void after(Description description) throws Throwable { - if (gfsh != null) { - gfsh.clearEvents(); - gfsh.executeCommand("disconnect"); - gfsh.executeCommand("exit"); - gfsh.terminate(); - gfsh.setThreadLocalInstance(); - gfsh = null; - } - CliUtil.isGfshVM = false; - } - - public HeadlessGfsh getGfsh() { - return gfsh; - } - - public boolean isAuthenticated() { - return authenticated; - } -} http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/fa88520b/geode-core/src/test/java/org/apache/geode/management/internal/security/JavaRmiServerNameTest.java ---------------------------------------------------------------------- diff --git a/geode-core/src/test/java/org/apache/geode/management/internal/security/JavaRmiServerNameTest.java b/geode-core/src/test/java/org/apache/geode/management/internal/security/JavaRmiServerNameTest.java index f754f2e..2ae6140 100644 --- a/geode-core/src/test/java/org/apache/geode/management/internal/security/JavaRmiServerNameTest.java +++ b/geode-core/src/test/java/org/apache/geode/management/internal/security/JavaRmiServerNameTest.java @@ -16,19 +16,18 @@ package org.apache.geode.management.internal.security; -import static org.apache.geode.distributed.ConfigurationProperties.*; -import static org.junit.Assert.*; - -import java.util.Properties; +import static org.apache.geode.distributed.ConfigurationProperties.JMX_MANAGER_PORT; +import static org.junit.Assert.assertEquals; +import org.apache.geode.internal.AvailablePort; +import org.apache.geode.test.dunit.rules.ServerStarterRule; +import org.apache.geode.test.junit.categories.IntegrationTest; import org.junit.After; -import org.junit.BeforeClass; +import org.junit.ClassRule; import org.junit.Test; import org.junit.experimental.categories.Category; -import org.apache.geode.internal.AvailablePort; -import org.apache.geode.test.dunit.rules.ServerStarter; -import org.apache.geode.test.junit.categories.IntegrationTest; +import java.util.Properties; @Category(IntegrationTest.class) public class JavaRmiServerNameTest { @@ -44,11 +43,8 @@ public class JavaRmiServerNameTest { } }; - @BeforeClass - public static void beforeClass() throws Exception { - ServerStarter serverStarter = new ServerStarter(properties); - serverStarter.startServer(); - } + @ClassRule + public static ServerStarterRule serverStarter = new ServerStarterRule(properties); // https://issues.apache.org/jira/browse/GEODE-1548 @Test http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/fa88520b/geode-core/src/test/java/org/apache/geode/security/AbstractSecureServerDUnitTest.java ---------------------------------------------------------------------- diff --git a/geode-core/src/test/java/org/apache/geode/security/AbstractSecureServerDUnitTest.java b/geode-core/src/test/java/org/apache/geode/security/AbstractSecureServerDUnitTest.java index b9efe07..f43191d 100644 --- a/geode-core/src/test/java/org/apache/geode/security/AbstractSecureServerDUnitTest.java +++ b/geode-core/src/test/java/org/apache/geode/security/AbstractSecureServerDUnitTest.java @@ -15,16 +15,12 @@ package org.apache.geode.security; -import static org.apache.geode.distributed.ConfigurationProperties.*; -import static org.assertj.core.api.Assertions.*; - -import java.util.HashMap; -import java.util.Map; -import java.util.Map.Entry; -import java.util.Properties; - -import org.assertj.core.api.ThrowableAssert.ThrowingCallable; -import org.junit.Before; +import static org.apache.geode.distributed.ConfigurationProperties.LOCATORS; +import static org.apache.geode.distributed.ConfigurationProperties.LOG_LEVEL; +import static org.apache.geode.distributed.ConfigurationProperties.MCAST_PORT; +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 org.apache.geode.cache.Region; import org.apache.geode.cache.RegionShortcut; @@ -37,7 +33,14 @@ import org.apache.geode.test.dunit.Host; import org.apache.geode.test.dunit.IgnoredException; import org.apache.geode.test.dunit.VM; import org.apache.geode.test.dunit.internal.JUnit4DistributedTestCase; -import org.apache.geode.test.dunit.rules.ServerStarter; +import org.apache.geode.test.dunit.rules.ServerStarterRule; +import org.assertj.core.api.ThrowableAssert.ThrowingCallable; +import org.junit.Before; + +import java.util.HashMap; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Properties; public abstract class AbstractSecureServerDUnitTest extends JUnit4DistributedTestCase { @@ -71,7 +74,7 @@ public abstract class AbstractSecureServerDUnitTest extends JUnit4DistributedTes @Before public void before() throws Exception { - ServerStarter serverStarter = new ServerStarter(getProperties()); + ServerStarterRule serverStarter = new ServerStarterRule(getProperties()); serverStarter.startServer(0, pdxPersistent); serverPort = serverStarter.server.getPort(); Region region = http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/fa88520b/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 cbe4a3b..32a92a2 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 @@ -21,6 +21,7 @@ import static org.junit.Assert.*; import java.util.Properties; +import org.apache.geode.test.dunit.rules.ServerStarterRule; import org.junit.After; import org.junit.Before; import org.junit.Rule; @@ -34,7 +35,6 @@ import org.apache.geode.security.templates.SimpleSecurityManager; import org.apache.geode.test.dunit.IgnoredException; 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; @@ -71,7 +71,7 @@ public class ClusterConfigWithoutSecurityDUnitTest extends JUnit4DistributedTest props.setProperty("use-cluster-configuration", "false"); // initial security properties should only contain initial set of values - ServerStarter serverStarter = new ServerStarter(props); + ServerStarterRule serverStarter = new ServerStarterRule(props); serverStarter.startServer(lsRule.getPort(0)); DistributedSystem ds = serverStarter.cache.getDistributedSystem(); @@ -91,7 +91,7 @@ public class ClusterConfigWithoutSecurityDUnitTest extends JUnit4DistributedTest props.setProperty("security-manager", "mySecurityManager"); props.setProperty("use-cluster-configuration", "true"); - ServerStarter serverStarter = new ServerStarter(props); + ServerStarterRule serverStarter = new ServerStarterRule(props); assertThatThrownBy(() -> serverStarter.startServer(lsRule.getPort(0))) .isInstanceOf(GemFireConfigException.class) http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/fa88520b/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 84a4dd4..90cc6f1 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,6 +20,7 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy; import java.util.Properties; +import org.apache.geode.test.dunit.rules.ServerStarterRule; import org.junit.Before; import org.junit.Rule; import org.junit.Test; @@ -29,7 +30,6 @@ import org.apache.geode.security.templates.DummyAuthenticator; 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; @@ -61,7 +61,7 @@ public class PeerAuthenticatorDUnitTest extends JUnit4DistributedTestCase { VM server2 = lsRule.getNodeVM(2); server2.invoke(() -> { - ServerStarter serverStarter = new ServerStarter(server2Props); + ServerStarterRule serverStarter = new ServerStarterRule(server2Props); assertThatThrownBy(() -> serverStarter.startServer(locatorPort)) .isInstanceOf(GemFireSecurityException.class).hasMessageContaining("Invalid user name"); }); http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/fa88520b/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 index 577a7a1..fbbbf2b 100644 --- a/geode-core/src/test/java/org/apache/geode/security/PeerSecurityWithEmbeddedLocatorDUnitTest.java +++ b/geode-core/src/test/java/org/apache/geode/security/PeerSecurityWithEmbeddedLocatorDUnitTest.java @@ -30,7 +30,7 @@ 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.dunit.rules.ServerStarterRule; import org.apache.geode.test.junit.categories.DistributedTest; import org.apache.geode.test.junit.categories.SecurityTest; @@ -62,7 +62,7 @@ public class PeerSecurityWithEmbeddedLocatorDUnitTest extends JUnit4DistributedT VM server2 = lsRule.getNodeVM(2); server2.invoke(() -> { - ServerStarter serverStarter = new ServerStarter(server2Props); + ServerStarterRule serverStarter = new ServerStarterRule(server2Props); assertThatThrownBy(() -> serverStarter.startServer(locatorPort)) .isInstanceOf(GemFireSecurityException.class) .hasMessageContaining("Security check failed. Authentication error"); @@ -90,7 +90,7 @@ public class PeerSecurityWithEmbeddedLocatorDUnitTest extends JUnit4DistributedT VM server2 = lsRule.getNodeVM(2); server2.invoke(() -> { - ServerStarter serverStarter = new ServerStarter(server2Props); + ServerStarterRule serverStarter = new ServerStarterRule(server2Props); assertThatThrownBy(() -> serverStarter.startServer(locatorPort)) .isInstanceOf(GemFireSecurityException.class).hasMessageContaining("Invalid user name"); }); http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/fa88520b/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 a4b25f5..cce4fdb 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 @@ -21,6 +21,7 @@ import static org.junit.Assert.*; import java.util.Properties; +import org.apache.geode.test.dunit.rules.ServerStarterRule; import org.junit.Before; import org.junit.Rule; import org.junit.Test; @@ -33,7 +34,6 @@ import org.apache.geode.security.templates.SimpleSecurityManager; import org.apache.geode.test.dunit.IgnoredException; 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; @@ -67,7 +67,7 @@ public class SecurityClusterConfigDUnitTest extends JUnit4DistributedTestCase { props.setProperty("use-cluster-configuration", "true"); // initial security properties should only contain initial set of values - ServerStarter serverStarter = new ServerStarter(props); + ServerStarterRule serverStarter = new ServerStarterRule(props); serverStarter.startServer(lsRule.getPort(0)); DistributedSystem ds = serverStarter.cache.getDistributedSystem(); @@ -89,7 +89,7 @@ public class SecurityClusterConfigDUnitTest extends JUnit4DistributedTestCase { props.setProperty(SECURITY_MANAGER, SimpleSecurityManager.class.getName()); // initial security properties should only contain initial set of values - ServerStarter serverStarter = new ServerStarter(props); + ServerStarterRule serverStarter = new ServerStarterRule(props); serverStarter.startServer(lsRule.getPort(0)); DistributedSystem ds = serverStarter.cache.getDistributedSystem(); @@ -110,7 +110,7 @@ public class SecurityClusterConfigDUnitTest extends JUnit4DistributedTestCase { props.setProperty("use-cluster-configuration", "true"); // initial security properties should only contain initial set of values - ServerStarter serverStarter = new ServerStarter(props); + ServerStarterRule serverStarter = new ServerStarterRule(props); assertThatThrownBy(() -> serverStarter.startServer(lsRule.getPort(0))) .isInstanceOf(GemFireConfigException.class) @@ -129,7 +129,7 @@ public class SecurityClusterConfigDUnitTest extends JUnit4DistributedTestCase { props.setProperty("use-cluster-configuration", "true"); // initial security properties should only contain initial set of values - ServerStarter serverStarter = new ServerStarter(props); + ServerStarterRule serverStarter = new ServerStarterRule(props); assertThatThrownBy(() -> serverStarter.startServer(lsRule.getPort(0))) .isInstanceOf(GemFireConfigException.class) @@ -147,7 +147,7 @@ public class SecurityClusterConfigDUnitTest extends JUnit4DistributedTestCase { props.setProperty("security-manager", "mySecurityManager"); props.setProperty("use-cluster-configuration", "false"); - ServerStarter serverStarter = new ServerStarter(props); + ServerStarterRule serverStarter = new ServerStarterRule(props); assertThatThrownBy(() -> serverStarter.startServer(lsRule.getPort(0))) .isInstanceOf(GemFireConfigException.class) http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/fa88520b/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 87314ed..7af5d93 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 @@ -32,7 +32,7 @@ import org.apache.geode.security.templates.SimpleSecurityManager; import org.apache.geode.test.dunit.IgnoredException; 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.dunit.rules.ServerStarterRule; import org.apache.geode.test.junit.categories.DistributedTest; import org.apache.geode.test.junit.categories.SecurityTest; @@ -70,7 +70,7 @@ public class SecurityWithoutClusterConfigDUnitTest extends JUnit4DistributedTest props.setProperty("use-cluster-configuration", "true"); // initial security properties should only contain initial set of values - ServerStarter serverStarter = new ServerStarter(props); + ServerStarterRule serverStarter = new ServerStarterRule(props); 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/fa88520b/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 3cafdac..ed64f40 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 @@ -20,6 +20,7 @@ import static org.assertj.core.api.Assertions.*; import java.util.Properties; +import org.apache.geode.test.dunit.rules.ServerStarterRule; import org.junit.Before; import org.junit.Rule; import org.junit.Test; @@ -29,7 +30,6 @@ 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; @@ -55,7 +55,7 @@ public class StartServerAuthorizationTest extends JUnit4DistributedTestCase { VM server = lsRule.getNodeVM(1); server.invoke(() -> { - ServerStarter serverStarter = new ServerStarter(props); + ServerStarterRule serverStarter = new ServerStarterRule(props); assertThatThrownBy(() -> serverStarter.startServer(lsRule.getPort(0))) .isInstanceOf(GemFireSecurityException.class).hasMessageContaining( "Security check failed. Authentication error. Please check your credentials"); @@ -72,7 +72,7 @@ public class StartServerAuthorizationTest extends JUnit4DistributedTestCase { VM server = lsRule.getNodeVM(1); server.invoke(() -> { - ServerStarter serverStarter = new ServerStarter(props); + ServerStarterRule serverStarter = new ServerStarterRule(props); 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/fa88520b/geode-core/src/test/java/org/apache/geode/test/dunit/rules/GfshShellConnectionRule.java ---------------------------------------------------------------------- diff --git a/geode-core/src/test/java/org/apache/geode/test/dunit/rules/GfshShellConnectionRule.java b/geode-core/src/test/java/org/apache/geode/test/dunit/rules/GfshShellConnectionRule.java new file mode 100644 index 0000000..25780e6 --- /dev/null +++ b/geode-core/src/test/java/org/apache/geode/test/dunit/rules/GfshShellConnectionRule.java @@ -0,0 +1,111 @@ +/* + * 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.test.dunit.rules; + +import org.apache.geode.management.internal.cli.CliUtil; +import org.apache.geode.management.internal.cli.HeadlessGfsh; +import org.apache.geode.management.internal.cli.i18n.CliStrings; +import org.apache.geode.management.internal.cli.result.CommandResult; +import org.apache.geode.management.internal.cli.result.ErrorResultData; +import org.apache.geode.management.internal.cli.result.ResultBuilder; +import org.apache.geode.management.internal.cli.util.CommandStringBuilder; +import org.apache.geode.test.junit.rules.DescribedExternalResource; +import org.junit.runner.Description; + +/** + * Class which eases the connection to the jmxManager {@link ConnectionConfiguration} it allows for + * the creation of per-test connections with different user/password combinations, or no username + * and password + */ +public class GfshShellConnectionRule extends DescribedExternalResource { + + private int port = 0; + private boolean useHttp = false; + private HeadlessGfsh gfsh; + private boolean authenticated; + + /** + * Rule constructor + */ + + public GfshShellConnectionRule(int port) { + this.useHttp = false; + this.port = port; + } + + public GfshShellConnectionRule(int port, boolean useHttp) { + this.useHttp = useHttp; + this.port = port; + } + + protected void before(Description description) throws Throwable { + CliUtil.isGfshVM = true; + String shellId = getClass().getSimpleName() + "_" + description.getMethodName(); + gfsh = new HeadlessGfsh(shellId, 30, "gfsh_files"); // TODO: move to TemporaryFolder + + final CommandStringBuilder connectCommand = new CommandStringBuilder(CliStrings.CONNECT); + + ConnectionConfiguration config = description.getAnnotation(ConnectionConfiguration.class); + if (config != null) { + connectCommand.addOption(CliStrings.CONNECT__USERNAME, config.user()); + connectCommand.addOption(CliStrings.CONNECT__PASSWORD, config.password()); + } + + String endpoint; + if (useHttp) { + endpoint = "http://localhost:" + port + "/gemfire/v1"; + connectCommand.addOption(CliStrings.CONNECT__USE_HTTP, Boolean.TRUE.toString()); + connectCommand.addOption(CliStrings.CONNECT__URL, endpoint); + } else { + endpoint = "localhost[" + port + "]"; + connectCommand.addOption(CliStrings.CONNECT__JMX_MANAGER, endpoint); + } + System.out.println(getClass().getSimpleName() + " using endpoint: " + endpoint); + + gfsh.executeCommand(connectCommand.toString()); + + CommandResult result = (CommandResult) gfsh.getResult(); + if (result.getResultData() instanceof ErrorResultData) { + ErrorResultData errorResultData = (ErrorResultData) result.getResultData(); + this.authenticated = + !(errorResultData.getErrorCode() == ResultBuilder.ERRORCODE_CONNECTION_ERROR); + } else { + this.authenticated = true; + } + } + + /** + * Override to tear down your specific external resource. + */ + protected void after(Description description) throws Throwable { + if (gfsh != null) { + gfsh.clearEvents(); + gfsh.executeCommand("disconnect"); + gfsh.executeCommand("exit"); + gfsh.terminate(); + gfsh.setThreadLocalInstance(); + gfsh = null; + } + CliUtil.isGfshVM = false; + } + + public HeadlessGfsh getGfsh() { + return gfsh; + } + + public boolean isAuthenticated() { + return authenticated; + } +} http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/fa88520b/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 ba78fdc..4e10b0a 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 @@ -15,20 +15,19 @@ package org.apache.geode.test.dunit.rules; -import static org.apache.geode.distributed.ConfigurationProperties.*; -import static org.apache.geode.test.dunit.Host.*; - -import java.io.IOException; -import java.io.Serializable; -import java.util.Properties; +import static org.apache.geode.distributed.ConfigurationProperties.NAME; +import static org.apache.geode.test.dunit.Host.getHost; +import org.apache.geode.test.dunit.Host; +import org.apache.geode.test.dunit.Invoke; +import org.apache.geode.test.dunit.VM; import org.junit.After; import org.junit.Before; import org.junit.rules.ExternalResource; -import org.apache.geode.test.dunit.Host; -import org.apache.geode.test.dunit.Invoke; -import org.apache.geode.test.dunit.VM; +import java.io.IOException; +import java.io.Serializable; +import java.util.Properties; /** @@ -43,8 +42,8 @@ public class LocatorServerStartupRule extends ExternalResource implements Serial // these are only avaialbe in each VM - public static ServerStarter serverStarter; - public static LocatorStarter locatorStarter; + public static ServerStarterRule serverStarter; + public static LocatorStarterRule locatorStarter; @Before public void before() { @@ -69,7 +68,7 @@ public class LocatorServerStartupRule extends ExternalResource implements Serial public VM getLocatorVM(int index, Properties locatorProperties) throws IOException { VM locatorVM = host.getVM(index); int locatorPort = locatorVM.invoke(() -> { - locatorStarter = new LocatorStarter(locatorProperties); + locatorStarter = new LocatorStarterRule(locatorProperties); locatorStarter.startLocator(); return locatorStarter.locator.getPort(); }); @@ -99,7 +98,7 @@ public class LocatorServerStartupRule extends ExternalResource implements Serial VM nodeVM = getNodeVM(index); properties.setProperty(NAME, "server-" + index); int port = nodeVM.invoke(() -> { - serverStarter = new ServerStarter(properties); + serverStarter = new ServerStarterRule(properties); serverStarter.startServer(locatorPort); return serverStarter.server.getPort(); }); http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/fa88520b/geode-core/src/test/java/org/apache/geode/test/dunit/rules/LocatorStarter.java ---------------------------------------------------------------------- diff --git a/geode-core/src/test/java/org/apache/geode/test/dunit/rules/LocatorStarter.java b/geode-core/src/test/java/org/apache/geode/test/dunit/rules/LocatorStarter.java deleted file mode 100644 index 216acef..0000000 --- a/geode-core/src/test/java/org/apache/geode/test/dunit/rules/LocatorStarter.java +++ /dev/null @@ -1,72 +0,0 @@ -/* - * 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.test.dunit.rules; - -import static org.apache.geode.distributed.ConfigurationProperties.*; -import static org.junit.Assert.*; - -import java.io.Serializable; -import java.util.Properties; -import java.util.concurrent.TimeUnit; - -import com.jayway.awaitility.Awaitility; -import org.junit.rules.ExternalResource; - -import org.apache.geode.distributed.Locator; -import org.apache.geode.distributed.internal.InternalLocator; - -/** - * This is a rule to start up a locator in your current VM. It's useful for your Integration Tests. - * - * If you need a rule to start a server/locator in different VM for Distribution tests, You should - * use LocatorServerStartupRule - * - * This rule does not have a before(), because you may choose to start a locator in different time - * of your tests. You may choose to use this class not as a rule or use it in your own rule, (see - * LocatorServerStartupRule) you will need to call after() manually in that case. - */ - -public class LocatorStarter extends ExternalResource implements Serializable { - - public InternalLocator locator; - - private Properties properties; - - public LocatorStarter(Properties properties) { - this.properties = properties; - } - - public void startLocator() throws Exception { - if (!properties.containsKey(MCAST_PORT)) { - properties.setProperty(MCAST_PORT, "0"); - } - locator = (InternalLocator) Locator.startLocatorAndDS(0, null, properties); - int locatorPort = locator.getPort(); - locator.resetInternalLocatorFileNamesWithCorrectPortNumber(locatorPort); - - if (locator.getConfig().getEnableClusterConfiguration()) { - Awaitility.await().atMost(65, TimeUnit.SECONDS) - .until(() -> assertTrue(locator.isSharedConfigurationRunning())); - } - } - - @Override - public void after() { - if (locator != null) { - locator.stop(); - } - } -} http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/fa88520b/geode-core/src/test/java/org/apache/geode/test/dunit/rules/LocatorStarterRule.java ---------------------------------------------------------------------- diff --git a/geode-core/src/test/java/org/apache/geode/test/dunit/rules/LocatorStarterRule.java b/geode-core/src/test/java/org/apache/geode/test/dunit/rules/LocatorStarterRule.java new file mode 100644 index 0000000..72627a0 --- /dev/null +++ b/geode-core/src/test/java/org/apache/geode/test/dunit/rules/LocatorStarterRule.java @@ -0,0 +1,75 @@ +/* + * 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.test.dunit.rules; + +import static org.apache.geode.distributed.ConfigurationProperties.MCAST_PORT; +import static org.junit.Assert.assertTrue; + +import com.jayway.awaitility.Awaitility; +import org.apache.geode.distributed.Locator; +import org.apache.geode.distributed.internal.InternalLocator; +import org.junit.rules.ExternalResource; + +import java.io.Serializable; +import java.util.Properties; +import java.util.concurrent.TimeUnit; + +/** + * This is a rule to start up a locator in your current VM. It's useful for your Integration Tests. + * + * If you need a rule to start a server/locator in different VM for Distribution tests, You should + * use LocatorServerStartupRule + * + * You may choose to use this class not as a rule or use it in your own rule, (see + * LocatorServerStartupRule) you will need to call startLocator() and after() manually in that case. + */ + +public class LocatorStarterRule extends ExternalResource implements Serializable { + + public InternalLocator locator; + + private Properties properties; + + public LocatorStarterRule(Properties properties) { + this.properties = properties; + } + + public void startLocator() throws Exception { + if (!properties.containsKey(MCAST_PORT)) { + properties.setProperty(MCAST_PORT, "0"); + } + locator = (InternalLocator) Locator.startLocatorAndDS(0, null, properties); + int locatorPort = locator.getPort(); + locator.resetInternalLocatorFileNamesWithCorrectPortNumber(locatorPort); + + if (locator.getConfig().getEnableClusterConfiguration()) { + Awaitility.await().atMost(65, TimeUnit.SECONDS) + .until(() -> assertTrue(locator.isSharedConfigurationRunning())); + } + } + + @Override + protected void before() throws Throwable { + startLocator(); + } + + @Override + protected void after() { + if (locator != null) { + locator.stop(); + } + } +} http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/fa88520b/geode-core/src/test/java/org/apache/geode/test/dunit/rules/ServerStarter.java ---------------------------------------------------------------------- diff --git a/geode-core/src/test/java/org/apache/geode/test/dunit/rules/ServerStarter.java b/geode-core/src/test/java/org/apache/geode/test/dunit/rules/ServerStarter.java deleted file mode 100644 index 22d3c56..0000000 --- a/geode-core/src/test/java/org/apache/geode/test/dunit/rules/ServerStarter.java +++ /dev/null @@ -1,97 +0,0 @@ -/* - * 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.test.dunit.rules; - -import static org.apache.geode.distributed.ConfigurationProperties.*; - -import java.io.Serializable; -import java.util.Properties; - -import org.junit.rules.ExternalResource; - -import org.apache.geode.cache.Cache; -import org.apache.geode.cache.CacheFactory; -import org.apache.geode.cache.server.CacheServer; - - -/** - * This is a rule to start up a server in your current VM. It's useful for your Integration Tests. - * - * If you need a rule to start a server/locator in different VM for Distribution tests, You should - * use LocatorServerStartupRule - * - * This rule does not have a before(), because you may choose to start a server in different time of - * your tests. You may choose to use this class not as a rule or use it in your own rule, (see - * LocatorServerStartupRule) you will need to call after() manually in that case. - */ -public class ServerStarter extends ExternalResource implements Serializable { - - public Cache cache; - public CacheServer server; - - private Properties properties; - - public ServerStarter(Properties properties) { - this.properties = properties; - } - - public void startServer() throws Exception { - startServer(0, false); - } - - public void startServer(int locatorPort) throws Exception { - startServer(locatorPort, false); - } - - public void startServer(int locatorPort, boolean pdxPersistent) throws Exception { - if (!properties.containsKey(MCAST_PORT)) { - properties.setProperty(MCAST_PORT, "0"); - } - if (!properties.containsKey(NAME)) { - properties.setProperty(NAME, this.getClass().getName()); - } - if (locatorPort > 0) { - properties.setProperty(LOCATORS, "localhost[" + locatorPort + "]"); - } else { - properties.setProperty(LOCATORS, ""); - } - if (properties.containsKey(JMX_MANAGER_PORT)) { - int jmxPort = Integer.parseInt(properties.getProperty(JMX_MANAGER_PORT)); - if (jmxPort > 0) { - if (!properties.containsKey(JMX_MANAGER)) - properties.put(JMX_MANAGER, "true"); - if (!properties.containsKey(JMX_MANAGER_START)) - properties.put(JMX_MANAGER_START, "true"); - } - } - - CacheFactory cf = new CacheFactory(properties); - cf.setPdxReadSerialized(pdxPersistent); - cf.setPdxPersistent(pdxPersistent); - - cache = cf.create(); - server = cache.addCacheServer(); - server.setPort(0); - server.start(); - } - - public void after() { - if (cache != null) - cache.close(); - if (server != null) - server.stop(); - } -} http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/fa88520b/geode-core/src/test/java/org/apache/geode/test/dunit/rules/ServerStarterRule.java ---------------------------------------------------------------------- diff --git a/geode-core/src/test/java/org/apache/geode/test/dunit/rules/ServerStarterRule.java b/geode-core/src/test/java/org/apache/geode/test/dunit/rules/ServerStarterRule.java new file mode 100644 index 0000000..8da0778 --- /dev/null +++ b/geode-core/src/test/java/org/apache/geode/test/dunit/rules/ServerStarterRule.java @@ -0,0 +1,110 @@ +/* + * 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.test.dunit.rules; + +import static org.apache.geode.distributed.ConfigurationProperties.JMX_MANAGER; +import static org.apache.geode.distributed.ConfigurationProperties.JMX_MANAGER_PORT; +import static org.apache.geode.distributed.ConfigurationProperties.JMX_MANAGER_START; +import static org.apache.geode.distributed.ConfigurationProperties.LOCATORS; +import static org.apache.geode.distributed.ConfigurationProperties.MCAST_PORT; +import static org.apache.geode.distributed.ConfigurationProperties.NAME; + +import org.apache.geode.cache.Cache; +import org.apache.geode.cache.CacheFactory; +import org.apache.geode.cache.server.CacheServer; +import org.junit.rules.ExternalResource; + +import java.io.Serializable; +import java.util.Properties; + + +/** + * This is a rule to start up a server in your current VM. It's useful for your Integration Tests. + * + * If you need a rule to start a server/locator in different VM for Distribution tests, You should + * use LocatorServerStartupRule + * + * You may choose to use this class not as a rule or use it in your own rule, (see + * LocatorServerStartupRule) you will need to call startServer and after() manually in that case. + */ +public class ServerStarterRule extends ExternalResource implements Serializable { + + public Cache cache; + public CacheServer server; + + private Properties properties; + + public ServerStarterRule(Properties properties) { + this.properties = properties; + } + + public void startServer() throws Exception { + startServer(0, false); + } + + public void startServer(int locatorPort) throws Exception { + startServer(locatorPort, false); + } + + public void startServer(int locatorPort, boolean pdxPersistent) throws Exception { + if (!properties.containsKey(MCAST_PORT)) { + properties.setProperty(MCAST_PORT, "0"); + } + if (!properties.containsKey(NAME)) { + properties.setProperty(NAME, this.getClass().getName()); + } + if (locatorPort > 0) { + properties.setProperty(LOCATORS, "localhost[" + locatorPort + "]"); + } else { + properties.setProperty(LOCATORS, ""); + } + if (properties.containsKey(JMX_MANAGER_PORT)) { + int jmxPort = Integer.parseInt(properties.getProperty(JMX_MANAGER_PORT)); + if (jmxPort > 0) { + if (!properties.containsKey(JMX_MANAGER)) + properties.put(JMX_MANAGER, "true"); + if (!properties.containsKey(JMX_MANAGER_START)) + properties.put(JMX_MANAGER_START, "true"); + } + } + + CacheFactory cf = new CacheFactory(properties); + cf.setPdxReadSerialized(pdxPersistent); + cf.setPdxPersistent(pdxPersistent); + + cache = cf.create(); + server = cache.addCacheServer(); + server.setPort(0); + server.start(); + } + + /** + * if you use this class as a rule, the default startServer will be called in the before. You need + * to make sure your properties to start the server with has the locator information it needs to + * connect to, otherwise, this server won't connect to any locator + */ + protected void before() throws Throwable { + startServer(); + } + + @Override + public void after() { + if (cache != null) + cache.close(); + if (server != null) + server.stop(); + } +} http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/fa88520b/geode-web/src/test/java/org/apache/geode/management/internal/security/GfshCommandsOverHttpSecurityTest.java ---------------------------------------------------------------------- diff --git a/geode-web/src/test/java/org/apache/geode/management/internal/security/GfshCommandsOverHttpSecurityTest.java b/geode-web/src/test/java/org/apache/geode/management/internal/security/GfshCommandsOverHttpSecurityTest.java index a4162fd..d477565 100644 --- a/geode-web/src/test/java/org/apache/geode/management/internal/security/GfshCommandsOverHttpSecurityTest.java +++ b/geode-web/src/test/java/org/apache/geode/management/internal/security/GfshCommandsOverHttpSecurityTest.java @@ -15,6 +15,7 @@ package org.apache.geode.management.internal.security; +import org.apache.geode.test.dunit.rules.GfshShellConnectionRule; import org.apache.geode.test.junit.categories.IntegrationTest; import org.apache.geode.test.junit.categories.SecurityTest; @@ -23,6 +24,6 @@ import org.junit.experimental.categories.Category; @Category({IntegrationTest.class, SecurityTest.class}) public class GfshCommandsOverHttpSecurityTest extends GfshCommandsSecurityTest { public GfshCommandsOverHttpSecurityTest() { - gfshConnection = new GfshShellConnectionRule(jmxPort, httpPort, true); + gfshConnection = new GfshShellConnectionRule(httpPort, true); } }
