Fixes Run SSH script for passwords with special characters (as parentheses)

This commit is contained in:
Dani Estevez 2018-05-11 10:52:15 -04:00 committed by Ignasi Barrera
parent 053dfd0134
commit 8228994850
2 changed files with 3 additions and 2 deletions

View File

@ -112,7 +112,8 @@ public class RunScriptOnNodeUsingSsh implements RunScriptOnNode {
public String execAsRoot(String command) {
if (node.getCredentials().identity.equals("root")) {
} else if (node.getCredentials().shouldAuthenticateSudo()) {
command = String.format("sudo -S sh <<'%s'\n%s\n%s%s\n", MARKER, node.getCredentials().getOptionalPassword().get(), command, MARKER);
command = String.format("sudo -S sh <<'%s'\n'%s'\n%s%s\n", MARKER, node.getCredentials().getOptionalPassword
().get(), command, MARKER);
} else {
command = String.format("sudo sh <<'%s'\n%s%s\n", MARKER, command, MARKER);
}

View File

@ -103,7 +103,7 @@ public class RunScriptOnNodeUsingSshTest {
expect(sshClient.getUsername()).andReturn("tester");
expect(sshClient.getHostAddress()).andReturn("somewhere.example.com");
expect(
sshClient.exec("sudo -S sh <<'RUN_SCRIPT_AS_ROOT_SSH'\n" + "testpassword!\n" + "echo $USER\n"
sshClient.exec("sudo -S sh <<'RUN_SCRIPT_AS_ROOT_SSH'\n" + "'testpassword!'\n" + "echo $USER\n"
+ "echo $USER\n" + "RUN_SCRIPT_AS_ROOT_SSH\n")).andReturn(new ExecResponse("root\nroot\n", null, 0));
sshClient.disconnect();
replay(sshClient);