[RemoteUtil] Fix output from Windows SSH commands (#90)

Adds an ArchType argument to many RemoteUtil methods, which is used to
replace -tt (forced pseudo-TTY allocation) by -T (no pseudo-TTY
allocation). The -tt option adds tons of ANSI escape sequences to the
output and makes it unparsable, even after removing the sequences, as
some sequences like "delete the last X characters" are not honoured.

An exception is BuildProcessStartInfoForSshPortForward, where
replacing -tt by -T would make the port forwarding process exit
immediately.
This commit is contained in:
Lutz Justen
2023-02-06 18:42:00 +01:00
committed by GitHub
parent 5b82722ec1
commit 24906eb36e
8 changed files with 83 additions and 31 deletions
+10 -5
View File
@@ -59,8 +59,12 @@ class RemoteUtilTest : public ::testing::Test {
};
TEST_F(RemoteUtilTest, BuildProcessStartInfoForSsh) {
ProcessStartInfo si = util_.BuildProcessStartInfoForSsh(kCommand);
ExpectContains(si.command, {"ssh", kUserHostArg, kCommand});
ProcessStartInfo si =
util_.BuildProcessStartInfoForSsh(kCommand, ArchType::kLinux_x86_64);
ExpectContains(si.command, {"ssh", "-tt", kUserHostArg, kCommand});
si = util_.BuildProcessStartInfoForSsh(kCommand, ArchType::kWindows_x86_64);
ExpectContains(si.command, {"ssh", "-T", kUserHostArg, kCommand});
}
TEST_F(RemoteUtilTest, BuildProcessStartInfoForSshPortForward) {
@@ -75,19 +79,20 @@ TEST_F(RemoteUtilTest, BuildProcessStartInfoForSshPortForward) {
TEST_F(RemoteUtilTest, BuildProcessStartInfoForSshPortForwardAndCommand) {
ProcessStartInfo si = util_.BuildProcessStartInfoForSshPortForwardAndCommand(
kLocalPort, kRemotePort, kRegular, kCommand);
kLocalPort, kRemotePort, kRegular, kCommand, ArchType::kLinux_x86_64);
ExpectContains(si.command,
{"ssh", kUserHostArg, kPortForwardingArg, kCommand});
si = util_.BuildProcessStartInfoForSshPortForwardAndCommand(
kLocalPort, kRemotePort, kReverse, kCommand);
kLocalPort, kRemotePort, kReverse, kCommand, ArchType::kLinux_x86_64);
ExpectContains(si.command,
{"ssh", kUserHostArg, kReversePortForwardingArg, kCommand});
}
TEST_F(RemoteUtilTest, BuildProcessStartInfoForSshWithCustomCommand) {
constexpr char kCustomSshCmd[] = "C:\\path\\to\\ssh.exe --fooarg --bararg=42";
util_.SetSshCommand(kCustomSshCmd);
ProcessStartInfo si = util_.BuildProcessStartInfoForSsh(kCommand);
ProcessStartInfo si =
util_.BuildProcessStartInfoForSsh(kCommand, ArchType::kLinux_x86_64);
ExpectContains(si.command, {kCustomSshCmd});
}