parse ssh commands with shlex

instead of use our bugged home made method.

Fixes #72
This commit is contained in:
Nicola Murino
2020-02-14 16:17:32 +01:00
parent 3479a7e438
commit 0b7be1175d
5 changed files with 23 additions and 16 deletions

View File

@@ -606,7 +606,7 @@ func TestSSHCommandPath(t *testing.T) {
}
func TestSSHParseCommandPayload(t *testing.T) {
cmd := "command -a -f some\\ spaces\\ \\ .txt"
cmd := "command -a -f /ab\\ à/some\\ spaces\\ \\ \\(\\).txt"
name, args, _ := parseCommandPayload(cmd)
if name != "command" {
t.Errorf("unexpected command: %v", name)
@@ -614,9 +614,13 @@ func TestSSHParseCommandPayload(t *testing.T) {
if len(args) != 3 {
t.Errorf("unexpected number of arguments %v/3", len(args))
}
if !utils.IsStringInSlice("some spaces .txt", args) {
if args[2] != "/ab à/some spaces ().txt" {
t.Errorf("command parsing error, expected arguments not found: %v", args)
}
_, _, err := parseCommandPayload("")
if err == nil {
t.Error("parsing invalid command must fail")
}
}
func TestSSHCommandErrors(t *testing.T) {