Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion gb-ssh/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
/.project
/.classpath
/.factorypath
/test.properties
/*.properties
4 changes: 3 additions & 1 deletion gb-ssh/src/main/java/com/g2forge/gearbox/ssh/SSHRunner.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import com.g2forge.alexandria.annotations.note.NoteType;
import com.g2forge.alexandria.command.invocation.CommandInvocation;
import com.g2forge.alexandria.command.invocation.environment.SystemEnvironment;
import com.g2forge.alexandria.command.invocation.format.ICommandFormat;
import com.g2forge.alexandria.java.close.ICloseable;
import com.g2forge.alexandria.java.core.error.NotYetImplementedError;
import com.g2forge.alexandria.java.io.RuntimeIOException;
Expand Down Expand Up @@ -69,7 +70,8 @@ public IProcess apply(CommandInvocation<IRedirect, IRedirect> commandInvocation)
ChannelExec _channel = null;
Throwable _launchException = null;
try {
final String command = commandInvocation.getArguments().stream().collect(Collectors.joining(" "));
final ICommandFormat format = commandInvocation.getFormat();
final String command = commandInvocation.getArguments().stream().map(format::quote).collect(Collectors.joining(" "));
_channel = session.createExecChannel(command);
if (!_channel.open().await()) throw new RuntimeIOException();
} catch (Throwable throwable) {
Expand Down
22 changes: 22 additions & 0 deletions gb-ssh/src/test/java/com/g2forge/gearbox/ssh/TestSSHRunner.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

import java.nio.file.Paths;
import java.time.Duration;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import org.junit.After;
import org.junit.Test;
Expand All @@ -14,9 +18,11 @@
import com.g2forge.alexandria.wizard.PropertyStringInput;
import com.g2forge.alexandria.wizard.UserStringInput;
import com.g2forge.gearbox.command.converter.ICommandConverterR_;
import com.g2forge.gearbox.command.converter.dumb.Command;
import com.g2forge.gearbox.command.converter.dumb.DumbCommandConverter;
import com.g2forge.gearbox.command.process.IProcess;
import com.g2forge.gearbox.command.process.redirect.IRedirect;
import com.g2forge.gearbox.command.proxy.method.ICommandInterface;
import com.g2forge.gearbox.command.test.ATestCommand;

public class TestSSHRunner extends ATestCommand {
Expand Down Expand Up @@ -55,6 +61,22 @@ public void hostname() {
HAssert.assertEquals(hostname, getUtils().echo(false, "${HOSTNAME}").trim());
}

@Test
public void quoting() {
HAssume.assumeNotNull(TestSSH.getConfig());
final String executable = HAssume.assumeNoException(new PropertyStringInput("sshtest.clireport").fallback(new UserStringInput("SSH Test CLIReport executable", false)));
final ICLIReport clireport = getFactory().apply(ICLIReport.class);

final List<String> lines = new ArrayList<>(clireport.clireport(executable, "A", "B C").map(String::strip).collect(Collectors.toList()));
lines.remove(1); // Remove the executable itself from the output, since it might be in a weird path during testing
HAssert.assertEquals("CLIReport: 3 arguments\n0001: A\n0003: B C", lines.stream().collect(Collectors.joining("\n")));
}

public interface ICLIReport extends ICommandInterface {
@Command({})
public Stream<String> clireport(String executable, String... args);
}

protected boolean isValid() {
return TestSSH.getConfig() != null;
}
Expand Down