http://git-wip-us.apache.org/repos/asf/geode/blob/7352fcc7/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/StartMemberUtils.java ---------------------------------------------------------------------- diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/StartMemberUtils.java b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/StartMemberUtils.java index fd95387..3e1053a 100644 --- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/StartMemberUtils.java +++ b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/StartMemberUtils.java @@ -83,16 +83,17 @@ public class StartMemberUtils { } static void addGemFirePropertyFile(final List<String> commandLine, - final String gemfirePropertiesPathname) { - if (org.apache.geode.internal.lang.StringUtils.isNotBlank(gemfirePropertiesPathname)) { - commandLine.add("-DgemfirePropertyFile=" + gemfirePropertiesPathname); + final File gemfirePropertiesFile) { + if (gemfirePropertiesFile != null) { + commandLine.add("-DgemfirePropertyFile=" + gemfirePropertiesFile.getAbsolutePath()); } } static void addGemFireSecurityPropertyFile(final List<String> commandLine, - final String gemfireSecurityPropertiesPathname) { - if (org.apache.geode.internal.lang.StringUtils.isNotBlank(gemfireSecurityPropertiesPathname)) { - commandLine.add("-DgemfireSecurityPropertyFile=" + gemfireSecurityPropertiesPathname); + final File gemfireSecurityPropertiesFile) { + if (gemfireSecurityPropertiesFile != null) { + commandLine + .add("-DgemfireSecurityPropertyFile=" + gemfireSecurityPropertiesFile.getAbsolutePath()); } }
http://git-wip-us.apache.org/repos/asf/geode/blob/7352fcc7/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/StartServerCommand.java ---------------------------------------------------------------------- diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/StartServerCommand.java b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/StartServerCommand.java index 432a065..9b743c8 100644 --- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/StartServerCommand.java +++ b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/StartServerCommand.java @@ -142,14 +142,14 @@ public class StartServerCommand implements GfshCommand { help = CliStrings.START_SERVER__MESSAGE__TIME__TO__LIVE__HELP) final Integer messageTimeToLive, @CliOption(key = CliStrings.START_SERVER__OFF_HEAP_MEMORY_SIZE, help = CliStrings.START_SERVER__OFF_HEAP_MEMORY_SIZE__HELP) final String offHeapMemorySize, - @CliOption(key = CliStrings.START_SERVER__PROPERTIES, optionContext = ConverterHint.FILE_PATH, - help = CliStrings.START_SERVER__PROPERTIES__HELP) String gemfirePropertiesPathname, + @CliOption(key = CliStrings.START_SERVER__PROPERTIES, optionContext = ConverterHint.FILE, + help = CliStrings.START_SERVER__PROPERTIES__HELP) File gemfirePropertiesFile, @CliOption(key = CliStrings.START_SERVER__REBALANCE, unspecifiedDefaultValue = "false", specifiedDefaultValue = "true", help = CliStrings.START_SERVER__REBALANCE__HELP) final Boolean rebalance, @CliOption(key = CliStrings.START_SERVER__SECURITY_PROPERTIES, - optionContext = ConverterHint.FILE_PATH, - help = CliStrings.START_SERVER__SECURITY_PROPERTIES__HELP) String gemfireSecurityPropertiesPathname, + optionContext = ConverterHint.FILE, + help = CliStrings.START_SERVER__SECURITY_PROPERTIES__HELP) File gemfireSecurityPropertiesFile, @CliOption(key = CliStrings.START_SERVER__SERVER_BIND_ADDRESS, unspecifiedDefaultValue = CacheServer.DEFAULT_BIND_ADDRESS, help = CliStrings.START_SERVER__SERVER_BIND_ADDRESS__HELP) final String serverBindAddress, @@ -206,23 +206,16 @@ public class StartServerCommand implements GfshCommand { CliStrings.format(CliStrings.CACHE_XML_NOT_FOUND_MESSAGE, cacheXmlPathname)); } - gemfirePropertiesPathname = CliUtil.resolvePathname(gemfirePropertiesPathname); - - if (StringUtils.isNotBlank(gemfirePropertiesPathname) - && !IOUtils.isExistingPathname(gemfirePropertiesPathname)) { + if (gemfirePropertiesFile != null && !gemfirePropertiesFile.exists()) { return ResultBuilder.createUserErrorResult( CliStrings.format(CliStrings.GEODE_0_PROPERTIES_1_NOT_FOUND_MESSAGE, StringUtils.EMPTY, - gemfirePropertiesPathname)); + gemfirePropertiesFile.getAbsolutePath())); } - gemfireSecurityPropertiesPathname = - CliUtil.resolvePathname(gemfireSecurityPropertiesPathname); - - if (StringUtils.isNotBlank(gemfireSecurityPropertiesPathname) - && !IOUtils.isExistingPathname(gemfireSecurityPropertiesPathname)) { + if (gemfireSecurityPropertiesFile != null && !gemfireSecurityPropertiesFile.exists()) { return ResultBuilder.createUserErrorResult( CliStrings.format(CliStrings.GEODE_0_PROPERTIES_1_NOT_FOUND_MESSAGE, "Security ", - gemfireSecurityPropertiesPathname)); + gemfireSecurityPropertiesFile.getAbsolutePath())); } File serverPidFile = new File(workingDirectory, ProcessType.SERVER.getPidFileName()); @@ -309,9 +302,8 @@ public class StartServerCommand implements GfshCommand { ServerLauncher serverLauncher = serverLauncherBuilder.build(); String[] serverCommandLine = createStartServerCommandLine(serverLauncher, - gemfirePropertiesPathname, gemfireSecurityPropertiesPathname, gemfireProperties, - classpath, includeSystemClasspath, jvmArgsOpts, disableExitWhenOutOfMemory, initialHeap, - maxHeap); + gemfirePropertiesFile, gemfireSecurityPropertiesFile, gemfireProperties, classpath, + includeSystemClasspath, jvmArgsOpts, disableExitWhenOutOfMemory, initialHeap, maxHeap); if (getGfsh().getDebug()) { getGfsh().logInfo(StringUtils.join(serverCommandLine, StringUtils.SPACE), null); @@ -428,7 +420,7 @@ public class StartServerCommand implements GfshCommand { } String[] createStartServerCommandLine(final ServerLauncher launcher, - final String gemfirePropertiesPathname, final String gemfireSecurityPropertiesPathname, + final File gemfirePropertiesFile, final File gemfireSecurityPropertiesFile, final Properties gemfireProperties, final String userClasspath, final Boolean includeSystemClasspath, final String[] jvmArgsOpts, final Boolean disableExitWhenOutOfMemory, final String initialHeap, final String maxHeap) @@ -441,8 +433,8 @@ public class StartServerCommand implements GfshCommand { commandLine.add(getServerClasspath(Boolean.TRUE.equals(includeSystemClasspath), userClasspath)); StartMemberUtils.addCurrentLocators(this, commandLine, gemfireProperties); - StartMemberUtils.addGemFirePropertyFile(commandLine, gemfirePropertiesPathname); - StartMemberUtils.addGemFireSecurityPropertyFile(commandLine, gemfireSecurityPropertiesPathname); + StartMemberUtils.addGemFirePropertyFile(commandLine, gemfirePropertiesFile); + StartMemberUtils.addGemFireSecurityPropertyFile(commandLine, gemfireSecurityPropertiesFile); StartMemberUtils.addGemFireSystemProperties(commandLine, gemfireProperties); StartMemberUtils.addJvmArgumentsAndOptions(commandLine, jvmArgsOpts); http://git-wip-us.apache.org/repos/asf/geode/blob/7352fcc7/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/UserInputProperty.java ---------------------------------------------------------------------- diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/UserInputProperty.java b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/UserInputProperty.java new file mode 100644 index 0000000..5169dab --- /dev/null +++ b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/UserInputProperty.java @@ -0,0 +1,120 @@ +/* + * 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.cli.commands; + +import static org.apache.geode.distributed.ConfigurationProperties.SSL_CIPHERS; +import static org.apache.geode.distributed.ConfigurationProperties.SSL_ENABLED_COMPONENTS; +import static org.apache.geode.distributed.ConfigurationProperties.SSL_KEYSTORE; +import static org.apache.geode.distributed.ConfigurationProperties.SSL_KEYSTORE_PASSWORD; +import static org.apache.geode.distributed.ConfigurationProperties.SSL_KEYSTORE_TYPE; +import static org.apache.geode.distributed.ConfigurationProperties.SSL_PROTOCOLS; +import static org.apache.geode.distributed.ConfigurationProperties.SSL_TRUSTSTORE; +import static org.apache.geode.distributed.ConfigurationProperties.SSL_TRUSTSTORE_PASSWORD; +import static org.apache.geode.distributed.ConfigurationProperties.SSL_TRUSTSTORE_TYPE; + +import org.apache.commons.lang.StringUtils; + +import org.apache.geode.distributed.internal.DistributionConfig; +import org.apache.geode.internal.security.SecurableCommunicationChannel; +import org.apache.geode.management.internal.cli.shell.Gfsh; +import org.apache.geode.management.internal.security.ResourceConstants; + +public class UserInputProperty { + public static UserInputProperty USERNAME = + new UserInputProperty(ResourceConstants.USER_NAME, "user", false); + public static UserInputProperty PASSWORD = + new UserInputProperty(ResourceConstants.PASSWORD, "password", "", true); + public static UserInputProperty KEYSTORE = + new UserInputProperty(SSL_KEYSTORE, "key-store", "", false); + public static UserInputProperty KEYSTORE_PASSWORD = + new UserInputProperty(SSL_KEYSTORE_PASSWORD, "key-store-password", "", true); + public static UserInputProperty KEYSTORE_TYPE = + new UserInputProperty(SSL_KEYSTORE_TYPE, "key-store-type", "JKS", false); + public static UserInputProperty TRUSTSTORE = + new UserInputProperty(SSL_TRUSTSTORE, "trust-store", "", false); + public static UserInputProperty TRUSTSTORE_PASSWORD = + new UserInputProperty(SSL_TRUSTSTORE_PASSWORD, "trust-store-password", "", true); + public static UserInputProperty TRUSTSTORE_TYPE = + new UserInputProperty(SSL_TRUSTSTORE_TYPE, "trust-store-type", "JKS", false); + public static UserInputProperty CIPHERS = new UserInputProperty(SSL_CIPHERS, "ssl-ciphers", + DistributionConfig.DEFAULT_SSL_CIPHERS, false); + public static UserInputProperty PROTOCOL = new UserInputProperty(SSL_PROTOCOLS, "ssl-protocols", + DistributionConfig.DEFAULT_SSL_PROTOCOLS, false); + public static UserInputProperty COMPONENT = new UserInputProperty(SSL_ENABLED_COMPONENTS, + "ssl-enabled-components", SecurableCommunicationChannel.ALL.getConstant(), false); + + private final String key; + private final String prompt; + private final boolean isMasked; + private final String defaultValue; + + // use this if this property does not allow an empty string and has no default value + UserInputProperty(String key, String prompt, boolean isMasked) { + this(key, prompt, null, isMasked); + } + + // if you allow an empty string for this property, supply a default value of "" + UserInputProperty(String key, String prompt, String defaultValue, boolean isMasked) { + this.key = key; + this.prompt = prompt; + this.defaultValue = defaultValue; + this.isMasked = isMasked; + } + + public String promptForAcceptableValue(Gfsh gfsh) { + if (gfsh.isQuietMode() || gfsh.isHeadlessMode()) { + return defaultValue == null ? "" : defaultValue; + } + + String value = promptForUserInput(gfsh); + + if (value.length() > 0) { + return value; + } + + // when user input an empty string and a default value is supplied, return the default value + if (value.length() == 0 && defaultValue != null) { + return defaultValue; + } + + // otherwise prompt till we get a non-empty value, only when this property has no default value + while (value.length() == 0) { + value = promptForUserInput(gfsh); + } + return value; + } + + private String promptForUserInput(Gfsh gfsh) { + String promptText = (StringUtils.isBlank(defaultValue)) ? prompt + ": " + : prompt + "(default: " + defaultValue + ")" + ": "; + String value; + + if (isMasked) { + value = gfsh.readPassword(promptText); + } else { + value = gfsh.readText(promptText); + } + // when gfsh is mocked or quiet mode, the above would return null + if (value == null) { + value = ""; + } + return value; + } + + public String getKey() { + return key; + } +} http://git-wip-us.apache.org/repos/asf/geode/blob/7352fcc7/geode-core/src/main/java/org/apache/geode/management/internal/cli/i18n/CliStrings.java ---------------------------------------------------------------------- diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/i18n/CliStrings.java b/geode-core/src/main/java/org/apache/geode/management/internal/cli/i18n/CliStrings.java index 58c8ef7..7562005 100644 --- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/i18n/CliStrings.java +++ b/geode-core/src/main/java/org/apache/geode/management/internal/cli/i18n/CliStrings.java @@ -544,9 +544,9 @@ public class CliStrings { "Network address of the Locator in the form: host[port]."; public static final String CONNECT__URL = "url"; public static final String CONNECT__DEFAULT_BASE_URL = - "http://localhost:" + DistributionConfig.DEFAULT_HTTP_SERVICE_PORT + "/gemfire/v1"; + "http://localhost:" + DistributionConfig.DEFAULT_HTTP_SERVICE_PORT + "/geode-mgmt/v1"; public static final String CONNECT__DEFAULT_SSL_BASE_URL = - "https://localhost:" + DistributionConfig.DEFAULT_HTTP_SERVICE_PORT + "/gemfire/v1"; + "https://localhost:" + DistributionConfig.DEFAULT_HTTP_SERVICE_PORT + "/geode-mgmt/v1"; public static final String CONNECT__URL__HELP = "Indicates the base URL to the Manager's HTTP service. For example: 'http://<host>:<port>/gemfire/v1' Default is '" + CONNECT__DEFAULT_BASE_URL + "'"; http://git-wip-us.apache.org/repos/asf/geode/blob/7352fcc7/geode-core/src/main/java/org/apache/geode/management/internal/cli/shell/Gfsh.java ---------------------------------------------------------------------- diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/shell/Gfsh.java b/geode-core/src/main/java/org/apache/geode/management/internal/cli/shell/Gfsh.java index a69ce36..503c252 100755 --- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/shell/Gfsh.java +++ b/geode-core/src/main/java/org/apache/geode/management/internal/cli/shell/Gfsh.java @@ -475,14 +475,14 @@ public class Gfsh extends JLineShell { return signalHandler; } - public String readPassword(String textToPrompt) throws IOException { + public String readPassword(String textToPrompt) { if (isHeadlessMode && isQuietMode()) return null; return readWithMask(textToPrompt, '*'); } - public String readText(String textToPrompt) throws IOException { + public String readText(String textToPrompt) { if (isHeadlessMode && isQuietMode()) return null; @@ -618,12 +618,20 @@ public class Gfsh extends JLineShell { return success; } - public String interact(String textToPrompt) throws IOException { - return reader.readLine(textToPrompt); + public String interact(String textToPrompt) { + try { + return reader.readLine(textToPrompt); + } catch (IOException e) { + throw new RuntimeException(e); + } } - public String readWithMask(String textToPrompt, Character mask) throws IOException { - return reader.readLine(textToPrompt, mask); + public String readWithMask(String textToPrompt, Character mask) { + try { + return reader.readLine(textToPrompt, mask); + } catch (IOException e) { + throw new RuntimeException(e); + } } @Override http://git-wip-us.apache.org/repos/asf/geode/blob/7352fcc7/geode-core/src/main/java/org/apache/geode/management/internal/cli/shell/JmxOperationInvoker.java ---------------------------------------------------------------------- diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/shell/JmxOperationInvoker.java b/geode-core/src/main/java/org/apache/geode/management/internal/cli/shell/JmxOperationInvoker.java index 7ae7c3b..5066496 100644 --- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/shell/JmxOperationInvoker.java +++ b/geode-core/src/main/java/org/apache/geode/management/internal/cli/shell/JmxOperationInvoker.java @@ -17,35 +17,17 @@ package org.apache.geode.management.internal.cli.shell; import static org.apache.geode.distributed.ConfigurationProperties.CLUSTER_SSL_PREFIX; import static org.apache.geode.distributed.ConfigurationProperties.JMX_MANAGER_SSL_PREFIX; -import org.apache.commons.lang.StringUtils; -import org.apache.geode.distributed.internal.DistributionConfig; -import org.apache.geode.internal.util.ArrayUtils; -import org.apache.geode.internal.util.IOUtils; -import org.apache.geode.management.DistributedSystemMXBean; -import org.apache.geode.management.MemberMXBean; -import org.apache.geode.management.internal.MBeanJMXAdapter; -import org.apache.geode.management.internal.ManagementConstants; -import org.apache.geode.management.internal.cli.CliUtil; -import org.apache.geode.management.internal.cli.CommandRequest; -import org.apache.geode.management.internal.cli.LogWrapper; -import org.apache.geode.management.internal.cli.commands.ShellCommands; -import org.apache.geode.management.internal.cli.i18n.CliStrings; - -import java.io.File; import java.io.IOException; -import java.io.InputStream; import java.net.MalformedURLException; -import java.net.URL; import java.text.MessageFormat; import java.util.Arrays; import java.util.HashMap; -import java.util.Iterator; import java.util.Map; -import java.util.Map.Entry; import java.util.Properties; import java.util.Set; import java.util.TreeSet; import java.util.concurrent.atomic.AtomicBoolean; + import javax.management.AttributeNotFoundException; import javax.management.InstanceNotFoundException; import javax.management.JMX; @@ -63,6 +45,18 @@ import javax.management.remote.JMXConnectorFactory; import javax.management.remote.JMXServiceURL; import javax.rmi.ssl.SslRMIClientSocketFactory; +import org.apache.geode.distributed.internal.DistributionConfig; +import org.apache.geode.internal.admin.SSLConfig; +import org.apache.geode.internal.net.SSLConfigurationFactory; +import org.apache.geode.internal.security.SecurableCommunicationChannel; +import org.apache.geode.internal.util.ArrayUtils; +import org.apache.geode.management.DistributedSystemMXBean; +import org.apache.geode.management.MemberMXBean; +import org.apache.geode.management.internal.MBeanJMXAdapter; +import org.apache.geode.management.internal.ManagementConstants; +import org.apache.geode.management.internal.cli.CommandRequest; +import org.apache.geode.management.internal.cli.LogWrapper; + /** * OperationInvoker JMX Implementation * @@ -99,9 +93,8 @@ public class JmxOperationInvoker implements OperationInvoker { private int clusterId = CLUSTER_ID_WHEN_NOT_CONNECTED; - public JmxOperationInvoker(final String host, final int port, final String userName, - final String password, final Map<String, String> sslConfigProps, - String gfSecurityPropertiesPath) throws Exception { + public JmxOperationInvoker(final String host, final int port, Properties gfProperties) + throws Exception { final Set<String> propsToClear = new TreeSet<String>(); try { this.managerHost = host; @@ -112,36 +105,41 @@ public class JmxOperationInvoker implements OperationInvoker { final Map<String, Object> env = new HashMap<String, Object>(); env.put(JMXConnectionListener.CHECK_PERIOD_PROP, JMXConnectionListener.CHECK_PERIOD); + env.put(JMXConnector.CREDENTIALS, gfProperties); - if (userName != null && userName.length() > 0) { - env.put(JMXConnector.CREDENTIALS, new String[] {userName, password}); - } - Set<Entry<String, String>> entrySet = sslConfigProps.entrySet(); - for (Iterator<Entry<String, String>> it = entrySet.iterator(); it.hasNext();) { - Entry<String, String> entry = it.next(); - String key = entry.getKey(); - String value = entry.getValue(); - key = checkforSystemPropertyPrefix(key); - if ((key.equals(Gfsh.SSL_ENABLED_CIPHERS) || key.equals(Gfsh.SSL_ENABLED_PROTOCOLS)) - && "any".equals(value)) { - continue; - } - System.setProperty(key, value); - propsToClear.add(key); - } + SSLConfig sslConfig = SSLConfigurationFactory.getSSLConfigForComponent(gfProperties, + SecurableCommunicationChannel.JMX); - if (!sslConfigProps.isEmpty()) { - if (System.getProperty(Gfsh.SSL_KEYSTORE) != null - || System.getProperty(Gfsh.SSL_TRUSTSTORE) != null) { - // use ssl to connect - env.put("com.sun.jndi.rmi.factory.socket", new SslRMIClientSocketFactory()); + if (sslConfig.isEnabled()) { + if (sslConfig.getKeystore() != null) { + System.setProperty(SSLConfigurationFactory.JAVAX_KEYSTORE, sslConfig.getKeystore()); + propsToClear.add(SSLConfigurationFactory.JAVAX_KEYSTORE); } - } - - // Check for JMX Credentials if empty put properties instance directly so that - // jmx management interceptor can read it for custom security properties - if (!env.containsKey(JMXConnector.CREDENTIALS)) { - env.put(JMXConnector.CREDENTIALS, readProperties(gfSecurityPropertiesPath)); + if (sslConfig.getKeystorePassword() != null) { + System.setProperty(SSLConfigurationFactory.JAVAX_KEYSTORE_PASSWORD, + sslConfig.getKeystorePassword()); + propsToClear.add(SSLConfigurationFactory.JAVAX_KEYSTORE_PASSWORD); + } + if (sslConfig.getKeystoreType() != null) { + System.setProperty(SSLConfigurationFactory.JAVAX_KEYSTORE_TYPE, + sslConfig.getKeystoreType()); + propsToClear.add(SSLConfigurationFactory.JAVAX_KEYSTORE_TYPE); + } + if (sslConfig.getTruststore() != null) { + System.setProperty(SSLConfigurationFactory.JAVAX_TRUSTSTORE, sslConfig.getTruststore()); + propsToClear.add(SSLConfigurationFactory.JAVAX_TRUSTSTORE); + } + if (sslConfig.getTruststorePassword() != null) { + System.setProperty(SSLConfigurationFactory.JAVAX_TRUSTSTORE_PASSWORD, + sslConfig.getTruststorePassword()); + propsToClear.add(SSLConfigurationFactory.JAVAX_TRUSTSTORE_PASSWORD); + } + if (sslConfig.getTruststoreType() != null) { + System.setProperty(SSLConfigurationFactory.JAVAX_TRUSTSTORE_TYPE, + sslConfig.getTruststoreType()); + propsToClear.add(SSLConfigurationFactory.JAVAX_TRUSTSTORE_TYPE); + } + env.put("com.sun.jndi.rmi.factory.socket", new SslRMIClientSocketFactory()); } this.url = new JMXServiceURL(MessageFormat.format(JMX_URL_FORMAT, @@ -184,57 +182,6 @@ public class JmxOperationInvoker implements OperationInvoker { } } - // Copied from ShellCommands.java - private Properties readProperties(String gfSecurityPropertiesPath) throws MalformedURLException { - Gfsh gfshInstance = Gfsh.getCurrentInstance(); - // reference to hold resolved gfSecurityPropertiesPath - String gfSecurityPropertiesPathToUse = CliUtil.resolvePathname(gfSecurityPropertiesPath); - URL gfSecurityPropertiesUrl = null; - - // Case 1: User has specified gfSecurity properties file - if (StringUtils.isNotBlank(gfSecurityPropertiesPathToUse)) { - // User specified gfSecurity properties doesn't exist - if (!IOUtils.isExistingPathname(gfSecurityPropertiesPathToUse)) { - gfshInstance - .printAsSevere(CliStrings.format(CliStrings.GEODE_0_PROPERTIES_1_NOT_FOUND_MESSAGE, - "Security ", gfSecurityPropertiesPathToUse)); - } else { - gfSecurityPropertiesUrl = new File(gfSecurityPropertiesPathToUse).toURI().toURL(); - } - } else if (gfSecurityPropertiesPath == null) { - // Use default "gfsecurity.properties" - // in current dir, user's home or classpath - gfSecurityPropertiesUrl = ShellCommands.getFileUrl("gfsecurity.properties"); - } - // if 'gfSecurityPropertiesPath' OR gfsecurity.properties has resolvable path - if (gfSecurityPropertiesUrl != null) { - gfshInstance.logToFile("Using security properties file : " - + CliUtil.decodeWithDefaultCharSet(gfSecurityPropertiesUrl.getPath()), null); - return loadPropertiesFromURL(gfSecurityPropertiesUrl); - } - return null; - } - - static Properties loadPropertiesFromURL(URL gfSecurityPropertiesUrl) { - Properties props = new Properties(); - if (gfSecurityPropertiesUrl != null) { - InputStream inputStream = null; - try { - - inputStream = gfSecurityPropertiesUrl.openStream(); - props.load(inputStream); - } catch (IOException io) { - throw new RuntimeException( - CliStrings.format(CliStrings.CONNECT__MSG__COULD_NOT_READ_CONFIG_FROM_0, - CliUtil.decodeWithDefaultCharSet(gfSecurityPropertiesUrl.getPath())), - io); - } finally { - IOUtils.close(inputStream); - } - } - return props; - } - private String checkforSystemPropertyPrefix(String key) { String returnKey = key; if (key.startsWith("javax.")) { http://git-wip-us.apache.org/repos/asf/geode/blob/7352fcc7/geode-core/src/main/java/org/apache/geode/management/internal/cli/util/GfshConsoleReader.java ---------------------------------------------------------------------- diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/util/GfshConsoleReader.java b/geode-core/src/main/java/org/apache/geode/management/internal/cli/util/GfshConsoleReader.java index 9251d7e..a635c50 100644 --- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/util/GfshConsoleReader.java +++ b/geode-core/src/main/java/org/apache/geode/management/internal/cli/util/GfshConsoleReader.java @@ -15,8 +15,6 @@ package org.apache.geode.management.internal.cli.util; -import java.io.IOException; - import org.apache.geode.internal.GfeConsoleReaderFactory.GfeConsoleReader; import org.apache.geode.management.internal.cli.shell.Gfsh; @@ -44,11 +42,7 @@ public class GfshConsoleReader extends GfeConsoleReader { public String readLine(String textToPrompt) { String lineRead = null; if (isSupported()) { - try { - lineRead = gfsh.interact(textToPrompt); - } catch (IOException e) { - lineRead = null; - } + lineRead = gfsh.interact(textToPrompt); } return lineRead; } @@ -56,12 +50,8 @@ public class GfshConsoleReader extends GfeConsoleReader { public char[] readPassword(String textToPrompt) { char[] password = null; if (isSupported()) { - try { - String passwordString = gfsh.readWithMask(textToPrompt, '*'); - password = passwordString.toCharArray(); - } catch (IOException e) { - password = null; - } + String passwordString = gfsh.readWithMask(textToPrompt, '*'); + password = passwordString.toCharArray(); } return password; } http://git-wip-us.apache.org/repos/asf/geode/blob/7352fcc7/geode-core/src/main/java/org/apache/geode/management/internal/configuration/utils/ClusterConfigurationStatusRetriever.java ---------------------------------------------------------------------- diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/configuration/utils/ClusterConfigurationStatusRetriever.java b/geode-core/src/main/java/org/apache/geode/management/internal/configuration/utils/ClusterConfigurationStatusRetriever.java index 3080809..86681b1 100644 --- a/geode-core/src/main/java/org/apache/geode/management/internal/configuration/utils/ClusterConfigurationStatusRetriever.java +++ b/geode-core/src/main/java/org/apache/geode/management/internal/configuration/utils/ClusterConfigurationStatusRetriever.java @@ -14,6 +14,11 @@ */ package org.apache.geode.management.internal.configuration.utils; +import java.io.IOException; +import java.net.InetAddress; +import java.util.Properties; +import java.util.Set; + import org.apache.geode.distributed.LocatorLauncher; import org.apache.geode.distributed.internal.tcpserver.TcpClient; import org.apache.geode.internal.cache.persistence.PersistentMemberPattern; @@ -21,22 +26,17 @@ import org.apache.geode.management.internal.cli.shell.Gfsh; import org.apache.geode.management.internal.configuration.messages.SharedConfigurationStatusRequest; import org.apache.geode.management.internal.configuration.messages.SharedConfigurationStatusResponse; -import java.io.IOException; -import java.net.InetAddress; -import java.net.InetSocketAddress; -import java.util.Set; - public class ClusterConfigurationStatusRetriever { private static final int NUM_ATTEMPTS_FOR_SHARED_CONFIGURATION_STATUS = 3; - public static String fromLocator(String locatorHostName, int locatorPort) + public static String fromLocator(String locatorHostName, int locatorPort, Properties configProps) throws ClassNotFoundException, IOException { final StringBuilder buffer = new StringBuilder(); try { final InetAddress networkAddress = InetAddress.getByName(locatorHostName); - TcpClient client = new TcpClient(); + TcpClient client = new TcpClient(configProps); SharedConfigurationStatusResponse statusResponse = (SharedConfigurationStatusResponse) client.requestToServer(networkAddress, locatorPort, new SharedConfigurationStatusRequest(), 10000, true); @@ -114,6 +114,7 @@ public class ClusterConfigurationStatusRetriever { public static String fromLocator(LocatorLauncher.LocatorState locatorState) throws ClassNotFoundException, IOException { - return fromLocator(locatorState.getHost(), Integer.parseInt(locatorState.getPort())); + return fromLocator(locatorState.getHost(), Integer.parseInt(locatorState.getPort()), + new Properties()); } } http://git-wip-us.apache.org/repos/asf/geode/blob/7352fcc7/geode-core/src/test/java/org/apache/geode/internal/net/SSLConfigurationFactoryJUnitTest.java ---------------------------------------------------------------------- diff --git a/geode-core/src/test/java/org/apache/geode/internal/net/SSLConfigurationFactoryJUnitTest.java b/geode-core/src/test/java/org/apache/geode/internal/net/SSLConfigurationFactoryJUnitTest.java index 31c2469..47f0d2b 100644 --- a/geode-core/src/test/java/org/apache/geode/internal/net/SSLConfigurationFactoryJUnitTest.java +++ b/geode-core/src/test/java/org/apache/geode/internal/net/SSLConfigurationFactoryJUnitTest.java @@ -32,22 +32,24 @@ import static org.apache.geode.distributed.ConfigurationProperties.SSL_TRUSTSTOR import static org.apache.geode.distributed.ConfigurationProperties.SSL_TRUSTSTORE_PASSWORD; import static org.apache.geode.distributed.ConfigurationProperties.SSL_WEB_ALIAS; import static org.apache.geode.distributed.ConfigurationProperties.SSL_WEB_SERVICE_REQUIRE_AUTHENTICATION; +import static org.assertj.core.api.Assertions.assertThat; import static org.junit.Assert.assertEquals; +import java.util.Properties; + import org.apache.commons.lang.StringUtils; -import org.apache.geode.distributed.internal.DistributionConfig; -import org.apache.geode.distributed.internal.DistributionConfigImpl; -import org.apache.geode.internal.admin.SSLConfig; -import org.apache.geode.internal.security.SecurableCommunicationChannel; -import org.apache.geode.test.junit.categories.MembershipTest; -import org.apache.geode.test.junit.categories.UnitTest; import org.junit.After; import org.junit.Rule; import org.junit.Test; import org.junit.contrib.java.lang.system.RestoreSystemProperties; import org.junit.experimental.categories.Category; -import java.util.Properties; +import org.apache.geode.distributed.internal.DistributionConfig; +import org.apache.geode.distributed.internal.DistributionConfigImpl; +import org.apache.geode.internal.admin.SSLConfig; +import org.apache.geode.internal.security.SecurableCommunicationChannel; +import org.apache.geode.test.junit.categories.MembershipTest; +import org.apache.geode.test.junit.categories.UnitTest; @Category({UnitTest.class, MembershipTest.class}) public class SSLConfigurationFactoryJUnitTest { @@ -280,6 +282,27 @@ public class SSLConfigurationFactoryJUnitTest { assertEquals(true, sslConfig.isEnabled()); } + @Test + public void setDistributionConfig() throws Exception { + Properties properties = new Properties(); + properties.setProperty(SSL_ENABLED_COMPONENTS, "all"); + properties.setProperty(SSL_KEYSTORE, "someKeyStore"); + DistributionConfigImpl distributionConfig = new DistributionConfigImpl(properties); + SSLConfigurationFactory.setDistributionConfig(distributionConfig); + + SSLConfig sslConfig = + SSLConfigurationFactory.getSSLConfigForComponent(SecurableCommunicationChannel.LOCATOR); + assertThat(sslConfig.isEnabled()).isTrue(); + assertThat(sslConfig.getKeystore()).isEqualTo("someKeyStore"); + + properties.setProperty(SSL_ENABLED_COMPONENTS, SecurableCommunicationChannel.JMX.getConstant()); + properties.setProperty(SSL_KEYSTORE, "someOtherKeyStore"); + sslConfig = SSLConfigurationFactory.getSSLConfigForComponent(properties, + SecurableCommunicationChannel.LOCATOR); + assertThat(sslConfig.isEnabled()).isFalse(); + assertThat(sslConfig.getKeystore()).isEqualTo("someOtherKeyStore"); + } + private void assertSSLConfig(final Properties properties, final SSLConfig sslConfig, final SecurableCommunicationChannel expectedSecurableComponent, final DistributionConfigImpl distributionConfig) { http://git-wip-us.apache.org/repos/asf/geode/blob/7352fcc7/geode-core/src/test/java/org/apache/geode/management/ConnectToLocatorSSLDUnitTest.java ---------------------------------------------------------------------- diff --git a/geode-core/src/test/java/org/apache/geode/management/ConnectToLocatorSSLDUnitTest.java b/geode-core/src/test/java/org/apache/geode/management/ConnectToLocatorSSLDUnitTest.java deleted file mode 100644 index 866f4ef..0000000 --- a/geode-core/src/test/java/org/apache/geode/management/ConnectToLocatorSSLDUnitTest.java +++ /dev/null @@ -1,104 +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; - -import static org.apache.geode.distributed.ConfigurationProperties.SSL_CIPHERS; -import static org.apache.geode.distributed.ConfigurationProperties.SSL_ENABLED_COMPONENTS; -import static org.apache.geode.distributed.ConfigurationProperties.SSL_KEYSTORE; -import static org.apache.geode.distributed.ConfigurationProperties.SSL_KEYSTORE_PASSWORD; -import static org.apache.geode.distributed.ConfigurationProperties.SSL_PROTOCOLS; -import static org.apache.geode.distributed.ConfigurationProperties.SSL_TRUSTSTORE; -import static org.apache.geode.distributed.ConfigurationProperties.SSL_TRUSTSTORE_PASSWORD; -import static org.apache.geode.util.test.TestUtil.getResourcePath; - -import java.io.File; -import java.io.FileOutputStream; -import java.io.OutputStream; -import java.util.Properties; - -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.experimental.categories.Category; -import org.junit.rules.RuleChain; -import org.junit.rules.TemporaryFolder; - -import org.apache.geode.management.internal.cli.i18n.CliStrings; -import org.apache.geode.security.SecurableCommunicationChannels; -import org.apache.geode.test.dunit.Host; -import org.apache.geode.test.dunit.rules.CleanupDUnitVMsRule; -import org.apache.geode.test.dunit.rules.GfshShellConnectionRule; -import org.apache.geode.test.dunit.rules.LocatorServerStartupRule; -import org.apache.geode.test.dunit.rules.MemberVM; -import org.apache.geode.test.junit.categories.DistributedTest; -import org.apache.geode.test.junit.rules.serializable.SerializableTemporaryFolder; - -@Category(DistributedTest.class) -public class ConnectToLocatorSSLDUnitTest { - private TemporaryFolder folder = new SerializableTemporaryFolder(); - private LocatorServerStartupRule lsRule = new LocatorServerStartupRule(); - private CleanupDUnitVMsRule cleanupDUnitVMsRule = new CleanupDUnitVMsRule(); - - @Rule - public RuleChain ruleChain = - RuleChain.outerRule(folder).around(cleanupDUnitVMsRule).around(lsRule); - - private File jks = null; - protected File securityPropsFile = null; - private Properties securityProps; - protected MemberVM locator; - - @Before - public void before() throws Exception { - jks = new File(getResourcePath(getClass(), "/ssl/trusted.keystore")); - securityPropsFile = folder.newFile("security.properties"); - securityProps = new Properties(); - } - - protected void connect() throws Exception { - final int locatorPort = locator.getPort(); - final String securityPropsFilePath = securityPropsFile.getCanonicalPath(); - - // when gfsh uses SSL, it leaves SSL state behind to contaminate other tests. So we pushed - // gfsh into a VM and uses a CleanupDUnitVM rule to clean it up after each test. - Host.getHost(0).getVM(1).invoke(() -> { - GfshShellConnectionRule gfshConnector = new GfshShellConnectionRule(); - gfshConnector.connectAndVerify(locatorPort, GfshShellConnectionRule.PortType.locator, - CliStrings.CONNECT__SECURITY_PROPERTIES, securityPropsFilePath); - gfshConnector.executeAndVerifyCommand("list members"); - gfshConnector.close(); - }); - - } - - @Test - public void testConnectToLocator_withSSL() throws Exception { - securityProps.setProperty(SSL_ENABLED_COMPONENTS, SecurableCommunicationChannels.ALL); - securityProps.setProperty(SSL_KEYSTORE, jks.getCanonicalPath()); - securityProps.setProperty(SSL_KEYSTORE_PASSWORD, "password"); - securityProps.setProperty(SSL_TRUSTSTORE, jks.getCanonicalPath()); - securityProps.setProperty(SSL_TRUSTSTORE_PASSWORD, "password"); - securityProps.setProperty(SSL_PROTOCOLS, "TLSv1.2"); - securityProps.setProperty(SSL_CIPHERS, "any"); - - // start up the locator - locator = lsRule.startLocatorVM(0, securityProps); - // saving the securityProps to a file - OutputStream out = new FileOutputStream(securityPropsFile); - securityProps.store(out, null); - - connect(); - } -} http://git-wip-us.apache.org/repos/asf/geode/blob/7352fcc7/geode-core/src/test/java/org/apache/geode/management/ConnectToLocatorWithLegacySSLDUnitTest.java ---------------------------------------------------------------------- diff --git a/geode-core/src/test/java/org/apache/geode/management/ConnectToLocatorWithLegacySSLDUnitTest.java b/geode-core/src/test/java/org/apache/geode/management/ConnectToLocatorWithLegacySSLDUnitTest.java deleted file mode 100644 index d7db489..0000000 --- a/geode-core/src/test/java/org/apache/geode/management/ConnectToLocatorWithLegacySSLDUnitTest.java +++ /dev/null @@ -1,118 +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; - -import static org.apache.geode.distributed.ConfigurationProperties.CLUSTER_SSL_ENABLED; -import static org.apache.geode.distributed.ConfigurationProperties.CLUSTER_SSL_KEYSTORE; -import static org.apache.geode.distributed.ConfigurationProperties.CLUSTER_SSL_KEYSTORE_PASSWORD; -import static org.apache.geode.distributed.ConfigurationProperties.CLUSTER_SSL_KEYSTORE_TYPE; -import static org.apache.geode.distributed.ConfigurationProperties.CLUSTER_SSL_TRUSTSTORE; -import static org.apache.geode.distributed.ConfigurationProperties.CLUSTER_SSL_TRUSTSTORE_PASSWORD; -import static org.apache.geode.distributed.ConfigurationProperties.JMX_MANAGER_SSL_ENABLED; -import static org.apache.geode.distributed.ConfigurationProperties.JMX_MANAGER_SSL_KEYSTORE; -import static org.apache.geode.distributed.ConfigurationProperties.JMX_MANAGER_SSL_KEYSTORE_PASSWORD; -import static org.apache.geode.distributed.ConfigurationProperties.JMX_MANAGER_SSL_KEYSTORE_TYPE; -import static org.apache.geode.distributed.ConfigurationProperties.JMX_MANAGER_SSL_TRUSTSTORE; -import static org.apache.geode.distributed.ConfigurationProperties.JMX_MANAGER_SSL_TRUSTSTORE_PASSWORD; -import static org.apache.geode.util.test.TestUtil.getResourcePath; - -import java.io.File; -import java.io.FileOutputStream; -import java.io.OutputStream; -import java.util.Properties; - -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.experimental.categories.Category; -import org.junit.rules.RuleChain; -import org.junit.rules.TemporaryFolder; - -import org.apache.geode.management.internal.cli.i18n.CliStrings; -import org.apache.geode.test.dunit.Host; -import org.apache.geode.test.dunit.rules.CleanupDUnitVMsRule; -import org.apache.geode.test.dunit.rules.GfshShellConnectionRule; -import org.apache.geode.test.dunit.rules.LocatorServerStartupRule; -import org.apache.geode.test.dunit.rules.MemberVM; -import org.apache.geode.test.junit.categories.DistributedTest; -import org.apache.geode.test.junit.rules.serializable.SerializableTemporaryFolder; - -@Category(DistributedTest.class) -public class ConnectToLocatorWithLegacySSLDUnitTest { - private TemporaryFolder folder = new SerializableTemporaryFolder(); - private LocatorServerStartupRule lsRule = new LocatorServerStartupRule(); - private CleanupDUnitVMsRule cleanupDUnitVMsRule = new CleanupDUnitVMsRule(); - - @Rule - public RuleChain ruleChain = - RuleChain.outerRule(folder).around(cleanupDUnitVMsRule).around(lsRule); - - private File jks = null; - protected File securityPropsFile = null; - private Properties securityProps; - protected MemberVM locator; - - @Before - public void before() throws Exception { - jks = new File(getResourcePath(getClass(), "/ssl/trusted.keystore")); - securityPropsFile = folder.newFile("security.properties"); - securityProps = new Properties(); - } - - protected void startUpLocatorAndConnect(Properties properties) throws Exception { - locator = lsRule.startLocatorVM(0, securityProps); - // saving the securityProps to a file - OutputStream out = new FileOutputStream(securityPropsFile); - securityProps.store(out, null); - - final int locatorPort = locator.getPort(); - final String securityPropsFilePath = securityPropsFile.getCanonicalPath(); - - // when gfsh uses SSL, it leaves SSL state behind to contaminate other tests. So we pushed - // gfsh into a VM and uses a CleanupDUnitVM rule to clean it up after each test. - Host.getHost(0).getVM(1).invoke(() -> { - GfshShellConnectionRule gfshConnector = new GfshShellConnectionRule(); - gfshConnector.connectAndVerify(locatorPort, GfshShellConnectionRule.PortType.locator, - CliStrings.CONNECT__SECURITY_PROPERTIES, securityPropsFilePath); - gfshConnector.executeAndVerifyCommand("list members"); - gfshConnector.close(); - }); - } - - @Test - public void testConnectToLocator_withLegacyClusterSSL() throws Exception { - securityProps.setProperty(CLUSTER_SSL_ENABLED, "true"); - securityProps.setProperty(CLUSTER_SSL_KEYSTORE, jks.getCanonicalPath()); - securityProps.setProperty(CLUSTER_SSL_KEYSTORE_PASSWORD, "password"); - securityProps.setProperty(CLUSTER_SSL_KEYSTORE_TYPE, "JKS"); - securityProps.setProperty(CLUSTER_SSL_TRUSTSTORE, jks.getCanonicalPath()); - securityProps.setProperty(CLUSTER_SSL_TRUSTSTORE_PASSWORD, "password"); - - startUpLocatorAndConnect(securityProps); - } - - @Test - public void testConnectToLocator_withLegacyJMXManagerSSL() throws Exception { - securityProps.setProperty(JMX_MANAGER_SSL_ENABLED, "true"); - securityProps.setProperty(JMX_MANAGER_SSL_KEYSTORE, jks.getCanonicalPath()); - securityProps.setProperty(JMX_MANAGER_SSL_KEYSTORE_PASSWORD, "password"); - securityProps.setProperty(JMX_MANAGER_SSL_KEYSTORE_TYPE, "JKS"); - securityProps.setProperty(JMX_MANAGER_SSL_TRUSTSTORE, jks.getCanonicalPath()); - securityProps.setProperty(JMX_MANAGER_SSL_TRUSTSTORE_PASSWORD, "password"); - - startUpLocatorAndConnect(securityProps); - } - -} http://git-wip-us.apache.org/repos/asf/geode/blob/7352fcc7/geode-core/src/test/java/org/apache/geode/management/internal/cli/GfshParserConverterTest.java ---------------------------------------------------------------------- diff --git a/geode-core/src/test/java/org/apache/geode/management/internal/cli/GfshParserConverterTest.java b/geode-core/src/test/java/org/apache/geode/management/internal/cli/GfshParserConverterTest.java index 3c42e0b..1ad22d4 100644 --- a/geode-core/src/test/java/org/apache/geode/management/internal/cli/GfshParserConverterTest.java +++ b/geode-core/src/test/java/org/apache/geode/management/internal/cli/GfshParserConverterTest.java @@ -17,7 +17,16 @@ package org.apache.geode.management.internal.cli; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Matchers.any; import static org.mockito.Mockito.doReturn; -import static org.mockito.Mockito.spy; + +import java.util.Arrays; +import java.util.List; +import java.util.Set; +import java.util.stream.Collectors; + +import org.junit.ClassRule; +import org.junit.Test; +import org.junit.experimental.categories.Category; +import org.springframework.shell.event.ParseResult; import org.apache.geode.management.internal.cli.converters.DiskStoreNameConverter; import org.apache.geode.management.internal.cli.converters.FilePathConverter; @@ -25,15 +34,6 @@ import org.apache.geode.management.internal.cli.converters.FilePathStringConvert import org.apache.geode.management.internal.cli.converters.RegionPathConverter; import org.apache.geode.test.dunit.rules.GfshParserRule; import org.apache.geode.test.junit.categories.IntegrationTest; -import org.junit.ClassRule; -import org.junit.Test; -import org.junit.experimental.categories.Category; -import org.springframework.shell.event.ParseResult; - -import java.util.Arrays; -import java.util.List; -import java.util.Set; -import java.util.stream.Collectors; @Category(IntegrationTest.class) public class GfshParserConverterTest { @@ -152,12 +152,12 @@ public class GfshParserConverterTest { doReturn(roots).when(spy).getRoots(); doReturn(siblings).when(spy).getSiblings(any()); - String command = "start server --properties-file="; + String command = "start server --cache-xml-file="; commandCandidate = parser.complete(command); assertThat(commandCandidate.size()).isEqualTo(2); assertThat(commandCandidate.getFirstCandidate()).isEqualTo(command + "/logs"); - command = "start server --properties-file=sibling"; + command = "start server --cache-xml-file=sibling"; commandCandidate = parser.complete(command); assertThat(commandCandidate.size()).isEqualTo(2); assertThat(commandCandidate.getFirstCandidate()).isEqualTo(command + "1"); @@ -170,6 +170,7 @@ public class GfshParserConverterTest { assertThat(commandCandidate.getFirstCandidate()).isEqualTo(command + "1"); } + @Test public void testRegionPathConverter() throws Exception { RegionPathConverter spy = parser.spyConverter(RegionPathConverter.class); http://git-wip-us.apache.org/repos/asf/geode/blob/7352fcc7/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/ConnectCommandTest.java ---------------------------------------------------------------------- diff --git a/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/ConnectCommandTest.java b/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/ConnectCommandTest.java new file mode 100644 index 0000000..3a5c584 --- /dev/null +++ b/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/ConnectCommandTest.java @@ -0,0 +1,300 @@ +/* + * 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.cli.commands; + +import static org.apache.geode.distributed.ConfigurationProperties.CLUSTER_SSL_KEYSTORE; +import static org.apache.geode.distributed.ConfigurationProperties.HTTP_SERVICE_SSL_KEYSTORE; +import static org.apache.geode.distributed.ConfigurationProperties.JMX_MANAGER_SSL_KEYSTORE; +import static org.apache.geode.distributed.ConfigurationProperties.SSL_KEYSTORE; +import static org.apache.geode.distributed.ConfigurationProperties.SSL_KEYSTORE_PASSWORD; +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyBoolean; +import static org.mockito.Mockito.doCallRealMethod; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.spy; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import java.io.File; +import java.util.Properties; + +import org.junit.Before; +import org.junit.ClassRule; +import org.junit.Test; +import org.junit.experimental.categories.Category; +import org.mockito.ArgumentCaptor; + +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.shell.Gfsh; +import org.apache.geode.management.internal.cli.shell.OperationInvoker; +import org.apache.geode.test.dunit.rules.GfshParserRule; +import org.apache.geode.test.junit.categories.UnitTest; + +@Category(UnitTest.class) +public class ConnectCommandTest { + + @ClassRule + public static GfshParserRule gfshParserRule = new GfshParserRule(); + + private ConnectCommand connectCommand; + + private Gfsh gfsh = mock(Gfsh.class); + + private CommandResult result; + private Properties properties; + private ArgumentCaptor<File> fileCaptor; + + @Before + public void before() throws Exception { + properties = new Properties(); + when(gfsh.getOperationInvoker()).thenReturn(mock(OperationInvoker.class)); + // using spy instead of mock because we want to call the real method when we do connect + connectCommand = spy(ConnectCommand.class); + when(connectCommand.getGfsh()).thenReturn(gfsh); + doReturn(properties).when(connectCommand).loadProperties(any()); + CommandResult result = mock(CommandResult.class); + when(connectCommand.httpConnect(any(), any())).thenReturn(result); + when(connectCommand.jmxConnect(any(), anyBoolean(), any(), any(), anyBoolean())) + .thenReturn(result); + fileCaptor = ArgumentCaptor.forClass(File.class); + } + + @Test + public void whenGfshIsAlreadyConnected() throws Exception { + when(gfsh.isConnectedAndReady()).thenReturn(true); + result = gfshParserRule.executeCommandWithInstance(connectCommand, "connect"); + assertThat(result.nextLine()).contains("Already connected to"); + } + + @Test + public void promptForPasswordIfUsernameIsGiven() throws Exception { + doReturn(properties).when(connectCommand).resolveSslProperties(any(), anyBoolean(), any(), + any()); + result = gfshParserRule.executeCommandWithInstance(connectCommand, "connect --user=user"); + verify(gfsh).readPassword(CliStrings.CONNECT__PASSWORD + ": "); + + assertThat(properties.getProperty("security-username")).isEqualTo("user"); + assertThat(properties.getProperty("security-password")).isEqualTo(""); + } + + @Test + public void notPromptForPasswordIfUsernameIsGiven() throws Exception { + doReturn(properties).when(connectCommand).resolveSslProperties(any(), anyBoolean(), any(), + any()); + result = gfshParserRule.executeCommandWithInstance(connectCommand, + "connect --user=user --password=pass"); + verify(gfsh, times(0)).readPassword(CliStrings.CONNECT__PASSWORD + ": "); + + assertThat(properties.getProperty("security-username")).isEqualTo("user"); + assertThat(properties.getProperty("security-password")).isEqualTo("pass"); + } + + @Test + public void notPromptForPasswordIfuserNameisGivenInFile() throws Exception { + // username specified in property file won't promot for password + properties.setProperty("security-username", "user"); + doReturn(properties).when(connectCommand).loadProperties(any(File.class)); + + result = gfshParserRule.executeCommandWithInstance(connectCommand, "connect"); + verify(gfsh, times(0)).readPassword(CliStrings.CONNECT__PASSWORD + ": "); + + assertThat(properties).doesNotContainKey("security-password"); + } + + @Test + public void plainConnectNotLoadFileNotPrompt() throws Exception { + result = gfshParserRule.executeCommandWithInstance(connectCommand, "connect"); + // will not try to load from any file + verify(connectCommand).loadProperties(null, null); + + // will not try to prompt + verify(gfsh, times(0)).readText(any()); + verify(gfsh, times(0)).readPassword(any()); + } + + @Test + public void connectUseSsl() throws Exception { + result = gfshParserRule.executeCommandWithInstance(connectCommand, "connect --use-ssl"); + + // will not try to load from any file + verify(connectCommand).loadProperties(null, null); + + // gfsh will prompt for the all the ssl properties + verify(gfsh).readText("key-store: "); + verify(gfsh).readPassword("key-store-password: "); + verify(gfsh).readText("key-store-type(default: JKS): "); + verify(gfsh).readText("trust-store: "); + verify(gfsh).readPassword("trust-store-password: "); + verify(gfsh).readText("trust-store-type(default: JKS): "); + verify(gfsh).readText("ssl-ciphers(default: any): "); + verify(gfsh).readText("ssl-protocols(default: any): "); + + // verify the resulting properties has correct values + assertThat(properties).hasSize(9); + assertThat(properties.getProperty("ssl-keystore")).isEqualTo(""); + assertThat(properties.getProperty("ssl-keystore-password")).isEqualTo(""); + assertThat(properties.getProperty("ssl-keystore-type")).isEqualTo("JKS"); + assertThat(properties.getProperty("ssl-truststore")).isEqualTo(""); + assertThat(properties.getProperty("ssl-truststore-password")).isEqualTo(""); + assertThat(properties.getProperty("ssl-truststore-type")).isEqualTo("JKS"); + assertThat(properties.getProperty("ssl-ciphers")).isEqualTo("any"); + assertThat(properties.getProperty("ssl-protocols")).isEqualTo("any"); + assertThat(properties.getProperty("ssl-enabled-components")).isEqualTo("all"); + } + + @Test + public void securityFileContainsSSLPropsAndNoUseSSL() throws Exception { + properties.setProperty(SSL_KEYSTORE, "keystore"); + result = gfshParserRule.executeCommandWithInstance(connectCommand, + "connect --security-properties-file=test"); + + // will try to load from this file + verify(connectCommand).loadProperties(any(), fileCaptor.capture()); + assertThat(fileCaptor.getValue()).hasName("test"); + + // it will prompt for missing properties + verify(gfsh, times(6)).readText(any()); + verify(gfsh, times(2)).readPassword(any()); + } + + @Test + public void securityFileContainsNoSSLPropsAndNoUseSSL() throws Exception { + result = gfshParserRule.executeCommandWithInstance(connectCommand, + "connect --security-properties-file=test"); + + // will try to load from this file + verify(connectCommand).loadProperties(any(), fileCaptor.capture()); + assertThat(fileCaptor.getValue()).hasName("test"); + + // it will prompt for missing properties + verify(gfsh, times(0)).readText(any()); + verify(gfsh, times(0)).readPassword(any()); + } + + @Test + public void connectUseLegacySecurityPropertiesFile() throws Exception { + properties.setProperty(JMX_MANAGER_SSL_KEYSTORE, "jmx-keystore"); + result = gfshParserRule.executeCommandWithInstance(connectCommand, + "connect --security-properties-file=test --key-store=keystore --key-store-password=password"); + + // wil try to load from this file + verify(connectCommand).loadProperties(fileCaptor.capture()); + assertThat(fileCaptor.getValue()).hasName("test"); + + // it will not prompt for missing properties + verify(gfsh, times(0)).readText(any()); + verify(gfsh, times(0)).readPassword(any()); + + // the command option will be ignored + assertThat(properties).hasSize(1); + assertThat(properties.get(JMX_MANAGER_SSL_KEYSTORE)).isEqualTo("jmx-keystore"); + } + + @Test + public void connectUseSecurityPropertiesFile_promptForMissing() throws Exception { + properties.setProperty(SSL_KEYSTORE, "keystore"); + properties.setProperty(SSL_KEYSTORE_PASSWORD, "password"); + result = gfshParserRule.executeCommandWithInstance(connectCommand, + "connect --security-properties-file=test"); + + // since nothing is loaded, will prompt for all missing values + verify(gfsh, times(6)).readText(any()); + verify(gfsh, times(1)).readPassword(any()); + } + + @Test + public void connectUseSecurityPropertiesFileAndOption_promptForMissing() throws Exception { + properties.setProperty(SSL_KEYSTORE, "keystore"); + properties.setProperty(SSL_KEYSTORE_PASSWORD, "password"); + result = gfshParserRule.executeCommandWithInstance(connectCommand, + "connect --security-properties-file=test --key-store=keystore2 --trust-store=truststore2"); + + // since nothing is loaded, will prompt for all missing values + verify(gfsh, times(5)).readText(any()); + verify(gfsh, times(1)).readPassword(any()); + + assertThat(properties).hasSize(9); + assertThat(properties.getProperty("ssl-keystore")).isEqualTo("keystore2"); + assertThat(properties.getProperty("ssl-keystore-password")).isEqualTo("password"); + assertThat(properties.getProperty("ssl-keystore-type")).isEqualTo("JKS"); + assertThat(properties.getProperty("ssl-truststore")).isEqualTo("truststore2"); + assertThat(properties.getProperty("ssl-truststore-password")).isEqualTo(""); + assertThat(properties.getProperty("ssl-truststore-type")).isEqualTo("JKS"); + assertThat(properties.getProperty("ssl-ciphers")).isEqualTo("any"); + assertThat(properties.getProperty("ssl-protocols")).isEqualTo("any"); + assertThat(properties.getProperty("ssl-enabled-components")).isEqualTo("all"); + } + + @Test + public void containsLegacySSLConfigTest_ssl() throws Exception { + properties.setProperty(SSL_KEYSTORE, "keystore"); + assertThat(connectCommand.containsLegacySSLConfig(properties)).isFalse(); + } + + @Test + public void containsLegacySSLConfigTest_cluster() throws Exception { + properties.setProperty(CLUSTER_SSL_KEYSTORE, "cluster-keystore"); + assertThat(connectCommand.containsLegacySSLConfig(properties)).isTrue(); + } + + @Test + public void containsLegacySSLConfigTest_jmx() throws Exception { + properties.setProperty(JMX_MANAGER_SSL_KEYSTORE, "jmx-keystore"); + assertThat(connectCommand.containsLegacySSLConfig(properties)).isTrue(); + } + + @Test + public void containsLegacySSLConfigTest_http() throws Exception { + properties.setProperty(HTTP_SERVICE_SSL_KEYSTORE, "http-keystore"); + assertThat(connectCommand.containsLegacySSLConfig(properties)).isTrue(); + } + + @Test + public void loadPropertiesWithNull() throws Exception { + doCallRealMethod().when(connectCommand).loadProperties(any()); + assertThat(connectCommand.loadProperties(null, null)).isEmpty(); + } + + @Test + public void isSslImpliedByOptions() throws Exception { + assertThat(connectCommand.isSslImpliedBySslOptions(null)).isFalse(); + + assertThat(connectCommand.isSslImpliedBySslOptions(null, null, null)).isFalse(); + + assertThat(connectCommand.isSslImpliedBySslOptions(null, "test")).isTrue(); + } + + @Test + public void resolveSslProperties() throws Exception { + // assume properties loaded from either file has an ssl property + properties.setProperty(SSL_KEYSTORE, "keystore"); + properties = connectCommand.resolveSslProperties(gfsh, false, null, null); + assertThat(properties).hasSize(9); + + properties.clear(); + + properties.setProperty(SSL_KEYSTORE, "keystore"); + properties = + connectCommand.resolveSslProperties(gfsh, false, null, null, "keystore2", "password"); + assertThat(properties).hasSize(9); + assertThat(properties.getProperty(SSL_KEYSTORE)).isEqualTo("keystore2"); + assertThat(properties.getProperty(SSL_KEYSTORE_PASSWORD)).isEqualTo("password"); + } +} http://git-wip-us.apache.org/repos/asf/geode/blob/7352fcc7/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/GfshCommandJUnitTest.java ---------------------------------------------------------------------- diff --git a/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/GfshCommandJUnitTest.java b/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/GfshCommandJUnitTest.java index 67c3f5a..da60c7a 100644 --- a/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/GfshCommandJUnitTest.java +++ b/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/GfshCommandJUnitTest.java @@ -29,6 +29,24 @@ import static org.junit.Assert.assertNull; import static org.junit.Assert.assertSame; import static org.junit.Assert.assertTrue; +import java.io.File; +import java.io.PrintWriter; +import java.io.StringWriter; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Properties; +import java.util.Set; + +import org.jmock.Expectations; +import org.jmock.Mockery; +import org.jmock.lib.concurrent.Synchroniser; +import org.jmock.lib.legacy.ClassImposteriser; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.junit.experimental.categories.Category; + import org.apache.geode.cache.execute.Function; import org.apache.geode.cache.execute.FunctionService; import org.apache.geode.distributed.DistributedMember; @@ -41,23 +59,6 @@ import org.apache.geode.management.cli.CliMetaData; import org.apache.geode.management.internal.cli.i18n.CliStrings; import org.apache.geode.management.internal.cli.util.MemberNotFoundException; import org.apache.geode.test.junit.categories.UnitTest; -import org.jmock.Expectations; -import org.jmock.Mockery; -import org.jmock.lib.concurrent.Synchroniser; -import org.jmock.lib.legacy.ClassImposteriser; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.junit.experimental.categories.Category; - -import java.io.File; -import java.io.PrintWriter; -import java.io.StringWriter; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.Properties; -import java.util.Set; /** * The GfshCommandJUnitTest class is a test suite of test cases testing the contract and @@ -412,11 +413,7 @@ public class GfshCommandJUnitTest { assertTrue(commandLine.isEmpty()); StartMemberUtils.addGemFirePropertyFile(commandLine, null); assertTrue(commandLine.isEmpty()); - StartMemberUtils.addGemFirePropertyFile(commandLine, org.apache.commons.lang.StringUtils.EMPTY); - assertTrue(commandLine.isEmpty()); - StartMemberUtils.addGemFirePropertyFile(commandLine, " "); - assertTrue(commandLine.isEmpty()); - StartMemberUtils.addGemFirePropertyFile(commandLine, "/path/to/gemfire.properties"); + StartMemberUtils.addGemFirePropertyFile(commandLine, new File("/path/to/gemfire.properties")); assertFalse(commandLine.isEmpty()); assertTrue(commandLine.contains("-DgemfirePropertyFile=/path/to/gemfire.properties")); } http://git-wip-us.apache.org/repos/asf/geode/blob/7352fcc7/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/UserInputPropertyTest.java ---------------------------------------------------------------------- diff --git a/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/UserInputPropertyTest.java b/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/UserInputPropertyTest.java new file mode 100644 index 0000000..3527afd --- /dev/null +++ b/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/UserInputPropertyTest.java @@ -0,0 +1,102 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license + * agreements. See the NOTICE file distributed with this work for additional information regarding + * copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the License. You may obtain a + * copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing permissions and limitations under + * the License. + */ + +package org.apache.geode.management.internal.cli.commands; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import org.junit.Before; +import org.junit.Test; +import org.junit.experimental.categories.Category; + +import org.apache.geode.management.internal.cli.shell.Gfsh; +import org.apache.geode.test.junit.categories.UnitTest; + +@Category(UnitTest.class) +public class UserInputPropertyTest { + + private UserInputProperty userInputProperty; + private Gfsh gfsh; + + @Before + public void setUp() throws Exception { + gfsh = mock(Gfsh.class); + } + + @Test + public void propertyWithNoDefaultVaueWillPromptTillAValueIsSupplied_interactive() + throws Exception { + userInputProperty = new UserInputProperty("key", "prompt", false); + + when(gfsh.readText(any())).thenReturn("").thenReturn("").thenReturn("value"); + String input = userInputProperty.promptForAcceptableValue(gfsh); + + assertThat(input).isEqualTo("value"); + verify(gfsh, times(0)).readPassword(any()); + verify(gfsh, times(3)).readText(any()); + } + + @Test + public void propertyWithNoDefaultValue_quietMode() throws Exception { + when(gfsh.isQuietMode()).thenReturn(true); + userInputProperty = new UserInputProperty("key", "prompt", false); + String input = userInputProperty.promptForAcceptableValue(gfsh); + assertThat(input).isEqualTo(""); + verify(gfsh, times(0)).readPassword(any()); + verify(gfsh, times(0)).readText(any()); + } + + @Test + public void propertyWithDefaultValue_Interactive() throws Exception { + userInputProperty = new UserInputProperty("key", "prompt", "value", false); + String input = userInputProperty.promptForAcceptableValue(gfsh); + assertThat(input).isEqualTo("value"); + verify(gfsh, times(0)).readPassword(any()); + verify(gfsh).readText(any()); + } + + @Test + public void propertyWithEmptyDefaultValue_Interactive() throws Exception { + userInputProperty = new UserInputProperty("key", "prompt", "", false); + String input = userInputProperty.promptForAcceptableValue(gfsh); + assertThat(input).isEqualTo(""); + verify(gfsh, times(0)).readPassword(any()); + verify(gfsh).readText(any()); + } + + @Test + public void propertyWithDefaultValue_Interactive_masked() throws Exception { + userInputProperty = new UserInputProperty("key", "prompt", "value", true); + String input = userInputProperty.promptForAcceptableValue(gfsh); + assertThat(input).isEqualTo("value"); + verify(gfsh).readPassword(any()); + verify(gfsh, times(0)).readText(any()); + } + + @Test + public void propertyWithDefaultValue_Quiet() throws Exception { + when(gfsh.isQuietMode()).thenReturn(true); + userInputProperty = new UserInputProperty("key", "prompt", "value", false); + String input = userInputProperty.promptForAcceptableValue(gfsh); + assertThat(input).isEqualTo("value"); + verify(gfsh, times(0)).readPassword(any()); + verify(gfsh, times(0)).readText(any()); + } +} http://git-wip-us.apache.org/repos/asf/geode/blob/7352fcc7/geode-cq/src/test/java/org/apache/geode/management/CacheServerManagementDUnitTest.java ---------------------------------------------------------------------- diff --git a/geode-cq/src/test/java/org/apache/geode/management/CacheServerManagementDUnitTest.java b/geode-cq/src/test/java/org/apache/geode/management/CacheServerManagementDUnitTest.java index 2cd69dd..a8d3997 100644 --- a/geode-cq/src/test/java/org/apache/geode/management/CacheServerManagementDUnitTest.java +++ b/geode-cq/src/test/java/org/apache/geode/management/CacheServerManagementDUnitTest.java @@ -14,17 +14,41 @@ */ package org.apache.geode.management; -import org.junit.Ignore; -import org.junit.experimental.categories.Category; -import org.junit.Test; +import static org.apache.geode.distributed.ConfigurationProperties.ENABLE_CLUSTER_CONFIGURATION; +import static org.apache.geode.distributed.ConfigurationProperties.JMX_MANAGER_HTTP_PORT; +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.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; -import static org.junit.Assert.*; +import java.io.File; +import java.io.IOException; +import java.net.InetAddress; +import java.net.UnknownHostException; +import java.util.Properties; -import org.apache.geode.test.junit.categories.DistributedTest; +import javax.management.InstanceNotFoundException; +import javax.management.MBeanServer; +import javax.management.Notification; +import javax.management.NotificationListener; +import javax.management.ObjectName; + +import org.junit.Ignore; +import org.junit.Test; +import org.junit.experimental.categories.Category; import org.apache.geode.cache.Cache; import org.apache.geode.cache.client.internal.LocatorTestBase; -import org.apache.geode.cache.query.*; +import org.apache.geode.cache.query.IndexExistsException; +import org.apache.geode.cache.query.IndexInvalidException; +import org.apache.geode.cache.query.IndexNameConflictException; +import org.apache.geode.cache.query.QueryService; +import org.apache.geode.cache.query.RegionNotFoundException; import org.apache.geode.cache.query.cq.dunit.CqQueryDUnitTest; import org.apache.geode.cache.query.internal.cq.CqService; import org.apache.geode.cache.server.CacheServer; @@ -36,17 +60,15 @@ import org.apache.geode.internal.cache.GemFireCacheImpl; import org.apache.geode.management.internal.JmxManagerLocatorRequest; import org.apache.geode.management.internal.MBeanJMXAdapter; import org.apache.geode.management.internal.SystemManagementService; -import org.apache.geode.test.dunit.*; - -import javax.management.*; -import java.io.File; -import java.io.IOException; -import java.net.InetAddress; -import java.net.UnknownHostException; -import java.util.Collections; -import java.util.Properties; - -import static org.apache.geode.distributed.ConfigurationProperties.*; +import org.apache.geode.test.dunit.Assert; +import org.apache.geode.test.dunit.Host; +import org.apache.geode.test.dunit.LogWriterUtils; +import org.apache.geode.test.dunit.NetworkUtils; +import org.apache.geode.test.dunit.SerializableRunnable; +import org.apache.geode.test.dunit.VM; +import org.apache.geode.test.dunit.Wait; +import org.apache.geode.test.dunit.WaitCriterion; +import org.apache.geode.test.junit.categories.DistributedTest; /** * Cache Server related management test cases @@ -219,7 +241,7 @@ public class CacheServerManagementDUnitTest extends LocatorTestBase { // Step 4: JmxManagerLocatorRequest.send(locator.getHost().getHostName(), locatorPort, - CONNECT_LOCATOR_TIMEOUT_MS, Collections.<String, String>emptyMap()); + CONNECT_LOCATOR_TIMEOUT_MS, new Properties()); // Step 5: locator.invoke("Check locator", () -> { http://git-wip-us.apache.org/repos/asf/geode/blob/7352fcc7/geode-web/src/test/java/org/apache/geode/management/internal/cli/commands/ConnectCommandIntegrationTest.java ---------------------------------------------------------------------- diff --git a/geode-web/src/test/java/org/apache/geode/management/internal/cli/commands/ConnectCommandIntegrationTest.java b/geode-web/src/test/java/org/apache/geode/management/internal/cli/commands/ConnectCommandIntegrationTest.java new file mode 100644 index 0000000..bead33d --- /dev/null +++ b/geode-web/src/test/java/org/apache/geode/management/internal/cli/commands/ConnectCommandIntegrationTest.java @@ -0,0 +1,50 @@ +/* + * 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.cli.commands; + +import org.junit.ClassRule; +import org.junit.Rule; +import org.junit.Test; +import org.junit.experimental.categories.Category; + +import org.apache.geode.test.dunit.rules.GfshShellConnectionRule; +import org.apache.geode.test.dunit.rules.LocatorStarterRule; +import org.apache.geode.test.junit.categories.IntegrationTest; + +@Category(IntegrationTest.class) +public class ConnectCommandIntegrationTest { + + @ClassRule + public static LocatorStarterRule locator = new LocatorStarterRule().withAutoStart(); + + @Rule + public GfshShellConnectionRule gfsh = new GfshShellConnectionRule(); + + @Test + public void connectToLocator() throws Exception { + gfsh.connectAndVerify(locator); + } + + @Test + public void connectOverJmx() throws Exception { + gfsh.connectAndVerify(locator.getJmxPort(), GfshShellConnectionRule.PortType.jmxManger); + } + + @Test + public void connectOverHttp() throws Exception { + gfsh.connectAndVerify(locator.getHttpPort(), GfshShellConnectionRule.PortType.http); + } +}