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

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


The following commit(s) were added to refs/heads/develop by this push:
     new 6820a3f  GEODE-6364: Deploy of invalid jar file does not write file 
contents to config on locator (#3164)
6820a3f is described below

commit 6820a3f1744ea017e5181f364caf578557e80886
Author: Jens Deppe <jde...@pivotal.io>
AuthorDate: Thu Feb 7 06:52:17 2019 -0800

    GEODE-6364: Deploy of invalid jar file does not write file contents to 
config on locator (#3164)
---
 .../ClusterConfigDeployJarDUnitTest.java           | 32 ++++++++++++++++++++++
 .../internal/cli/commands/DeployCommand.java       | 13 +++++++++
 2 files changed, 45 insertions(+)

diff --git 
a/geode-core/src/distributedTest/java/org/apache/geode/management/internal/configuration/ClusterConfigDeployJarDUnitTest.java
 
b/geode-core/src/distributedTest/java/org/apache/geode/management/internal/configuration/ClusterConfigDeployJarDUnitTest.java
index 185cf14..3d3e225 100644
--- 
a/geode-core/src/distributedTest/java/org/apache/geode/management/internal/configuration/ClusterConfigDeployJarDUnitTest.java
+++ 
b/geode-core/src/distributedTest/java/org/apache/geode/management/internal/configuration/ClusterConfigDeployJarDUnitTest.java
@@ -18,10 +18,14 @@ import static 
org.apache.geode.distributed.ConfigurationProperties.GROUPS;
 import static org.apache.geode.distributed.ConfigurationProperties.LOG_LEVEL;
 import static org.assertj.core.api.Assertions.assertThat;
 
+import java.io.File;
+import java.io.FileWriter;
+
 import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
 
+import org.apache.geode.test.dunit.IgnoredException;
 import org.apache.geode.test.dunit.rules.ClusterStartupRule;
 import org.apache.geode.test.dunit.rules.MemberVM;
 import org.apache.geode.test.junit.rules.GfshCommandRule;
@@ -133,6 +137,34 @@ public class ClusterConfigDeployJarDUnitTest extends 
ClusterConfigTestBase {
   }
 
   @Test
+  public void testInvalidJarDeploy() throws Exception {
+    IgnoredException.addIgnoredException(IllegalArgumentException.class);
+
+    // set up the locator/servers
+    MemberVM locator = lsRule.startLocatorVM(0, locatorProps);
+    // server1 in no group
+    MemberVM server1 = lsRule.startServerVM(1, serverProps, locator.getPort());
+
+    gfshConnector.connect(locator);
+    assertThat(gfshConnector.isConnected()).isTrue();
+
+    File junkFile = temporaryFolder.newFile("junk");
+    FileWriter writer = new FileWriter(junkFile);
+    writer.write("this is not a real jar");
+    writer.close();
+
+    // We want to ensure that a mix of good and bad jars does not produce a 
'partial' deploy.
+    gfshConnector.executeAndAssertThat("deploy --jar=" + clusterJar + ","
+        + junkFile.getAbsolutePath()).statusIsError();
+    gfshConnector.executeAndAssertThat("list deployed").statusIsSuccess()
+        .containsOutput("No JAR Files Found");
+
+    ConfigGroup cluster = new ConfigGroup("cluster").jars();
+    ClusterConfig expectedClusterConfig = new ClusterConfig(cluster);
+    expectedClusterConfig.verify(locator);
+  }
+
+  @Test
   public void testUndeploy() throws Exception {
     // set up the locator/servers
     MemberVM locator = lsRule.startLocatorVM(0, locatorProps);
diff --git 
a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/DeployCommand.java
 
b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/DeployCommand.java
index 39efca0..090f73a 100644
--- 
a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/DeployCommand.java
+++ 
b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/DeployCommand.java
@@ -37,6 +37,7 @@ import org.springframework.shell.core.annotation.CliOption;
 import org.apache.geode.cache.execute.ResultCollector;
 import org.apache.geode.distributed.DistributedMember;
 import 
org.apache.geode.distributed.internal.InternalConfigurationPersistenceService;
+import org.apache.geode.internal.DeployedJar;
 import org.apache.geode.management.cli.CliMetaData;
 import org.apache.geode.management.cli.ConverterHint;
 import org.apache.geode.management.cli.Result;
@@ -84,6 +85,8 @@ public class DeployCommand extends InternalGfshCommand {
 
     List<String> jarFullPaths = CommandExecutionContext.getFilePathFromShell();
 
+    verifyJarContent(jarFullPaths);
+
     Set<DistributedMember> targetMembers;
     targetMembers = findMembers(groups, null);
 
@@ -148,6 +151,16 @@ public class DeployCommand extends InternalGfshCommand {
     return result;
   }
 
+  private void verifyJarContent(List<String> jarNames) {
+    for (String jarName : jarNames) {
+      File jar = new File(jarName);
+      if (!DeployedJar.hasValidJarContent(jar)) {
+        throw new IllegalArgumentException(
+            "File does not contain valid JAR content: " + jar.getName());
+      }
+    }
+  }
+
   /**
    * Interceptor used by gfsh to intercept execution of deploy command at 
"shell".
    */

Reply via email to