From 4f583c1acff1ecae44ec71d68da5662f077d1680 Mon Sep 17 00:00:00 2001 From: Iliad Shaghaghi Date: Tue, 13 Dec 2022 22:40:30 +0000 Subject: [PATCH 1/4] wrap command tokens with quotes --- src/main/java/bio/terra/cli/app/CommandRunner.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/main/java/bio/terra/cli/app/CommandRunner.java b/src/main/java/bio/terra/cli/app/CommandRunner.java index 15ee00fe1..76864d25d 100644 --- a/src/main/java/bio/terra/cli/app/CommandRunner.java +++ b/src/main/java/bio/terra/cli/app/CommandRunner.java @@ -8,6 +8,7 @@ import java.util.List; import java.util.Map; import java.util.Optional; +import java.util.stream.Collectors; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -31,7 +32,13 @@ protected static String buildFullCommand(List command) { String fullCommand = ""; if (command != null && command.size() > 0) { final String argSeparator = " "; - fullCommand += argSeparator + String.join(argSeparator, command); + fullCommand += + argSeparator + + String.join( + argSeparator, + command.stream() + .map(i -> "\"" + i.replace("\"", "\\\"") + "\"") + .collect(Collectors.toList())); } return fullCommand; } From 2d8db27b5a161755dd45f2906155e3dae7f172c7 Mon Sep 17 00:00:00 2001 From: Iliad Shaghaghi Date: Wed, 14 Dec 2022 17:52:17 +0000 Subject: [PATCH 2/4] test --- src/test/java/unit/PassthroughApps.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/test/java/unit/PassthroughApps.java b/src/test/java/unit/PassthroughApps.java index b08655141..991cc6a50 100644 --- a/src/test/java/unit/PassthroughApps.java +++ b/src/test/java/unit/PassthroughApps.java @@ -86,6 +86,16 @@ void appList() throws IOException { assertTrue(appList.containsAll(Arrays.asList("gcloud", "gsutil", "bq", "nextflow", "git"))); } + @Test + @DisplayName("app execute respects arguments with spaces") + void appExecuteSpace() throws IOException { + // `terra app execute sh -c "echo Hello World"` + TestCommand.Result cmd = TestCommand.runCommand("app", "execute", "sh", "-c", "echo Hello World"); + + // Check that the output was printed + assertThat("Output is correct", cmd.stdOut, CoreMatchers.containsString("Hello World")); + } + @Test @DisplayName("env vars include terra user and workspace cloud project") void workspaceEnvVars() throws IOException { From 416ae2a6d396c887d4d738a50ef73aefb097e914 Mon Sep 17 00:00:00 2001 From: Iliad Shaghaghi Date: Wed, 14 Dec 2022 17:53:48 +0000 Subject: [PATCH 3/4] lint --- src/test/java/unit/PassthroughApps.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/test/java/unit/PassthroughApps.java b/src/test/java/unit/PassthroughApps.java index 991cc6a50..3936de6c1 100644 --- a/src/test/java/unit/PassthroughApps.java +++ b/src/test/java/unit/PassthroughApps.java @@ -90,7 +90,8 @@ void appList() throws IOException { @DisplayName("app execute respects arguments with spaces") void appExecuteSpace() throws IOException { // `terra app execute sh -c "echo Hello World"` - TestCommand.Result cmd = TestCommand.runCommand("app", "execute", "sh", "-c", "echo Hello World"); + TestCommand.Result cmd = + TestCommand.runCommand("app", "execute", "sh", "-c", "echo Hello World"); // Check that the output was printed assertThat("Output is correct", cmd.stdOut, CoreMatchers.containsString("Hello World")); From edf3d38cf1eeeb551fb2e7b2f2c710b0cbe8ce90 Mon Sep 17 00:00:00 2001 From: Iliad Shaghaghi Date: Wed, 14 Dec 2022 18:54:50 +0000 Subject: [PATCH 4/4] fix test --- src/test/java/unit/PassthroughApps.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/test/java/unit/PassthroughApps.java b/src/test/java/unit/PassthroughApps.java index 3936de6c1..a4cbaee55 100644 --- a/src/test/java/unit/PassthroughApps.java +++ b/src/test/java/unit/PassthroughApps.java @@ -89,9 +89,15 @@ void appList() throws IOException { @Test @DisplayName("app execute respects arguments with spaces") void appExecuteSpace() throws IOException { + workspaceCreator.login(/*writeGcloudAuthFiles=*/ true); + + // `terra workspace set --id=$id` + TestCommand.runAndParseCommandExpectSuccess( + UFWorkspace.class, "workspace", "set", "--id=" + getUserFacingId()); + // `terra app execute sh -c "echo Hello World"` TestCommand.Result cmd = - TestCommand.runCommand("app", "execute", "sh", "-c", "echo Hello World"); + TestCommand.runCommand("app", "execute", "sh", "-c", "\"echo Hello World\""); // Check that the output was printed assertThat("Output is correct", cmd.stdOut, CoreMatchers.containsString("Hello World"));