Allow vault ssh to work with single ssh args like -v (#4825)

This commit is contained in:
Michael Russell
2018-07-16 16:11:56 +02:00
committed by Jeff Mitchell
parent 5d26376460
commit e32ba81b52
2 changed files with 85 additions and 3 deletions

View File

@@ -133,6 +133,31 @@ func TestParseSSHCommand(t *testing.T) {
"",
nil,
},
{
"Allow single args which don't have a value",
[]string{
"-v",
"hostname",
},
"hostname",
"",
"",
nil,
},
{
"Allow single args before and after the hostname and command",
[]string{
"-v",
"hostname",
"-v",
"command",
"-v",
},
"hostname",
"",
"",
nil,
},
}
for _, test := range tests {
@@ -154,3 +179,39 @@ func TestParseSSHCommand(t *testing.T) {
})
}
}
func TestIsSingleSSHArg(t *testing.T) {
t.Parallel()
_, cmd := testSSHCommand(t)
var tests = []struct {
name string
arg string
want bool
}{
{
"-v is a single ssh arg",
"-v",
true,
},
{
"-o is NOT a single ssh arg",
"-o",
false,
},
{
"Repeated args like -vvv is still a single ssh arg",
"-vvv",
true,
},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
got := cmd.isSingleSSHArg(test.arg)
if got != test.want {
t.Errorf("arg %q got %v want %v", test.arg, got, test.want)
}
})
}
}