Support IPv6 in SFTP backend
The previous code was doing its own hostname:port splitting, which caused IPv6 addresses to be misinterpreted.
This commit is contained in:
parent
f2bf06a419
commit
6ac6bca7a1
5 changed files with 60 additions and 22 deletions
|
@ -21,23 +21,35 @@ var sshcmdTests = []struct {
|
|||
[]string{"host", "-s", "sftp"},
|
||||
},
|
||||
{
|
||||
Config{Host: "host:10022", Path: "/dir/subdir"},
|
||||
Config{Host: "host", Port: "10022", Path: "/dir/subdir"},
|
||||
"ssh",
|
||||
[]string{"host", "-p", "10022", "-s", "sftp"},
|
||||
},
|
||||
{
|
||||
Config{User: "user", Host: "host:10022", Path: "/dir/subdir"},
|
||||
Config{User: "user", Host: "host", Port: "10022", Path: "/dir/subdir"},
|
||||
"ssh",
|
||||
[]string{"host", "-p", "10022", "-l", "user", "-s", "sftp"},
|
||||
},
|
||||
{
|
||||
// IPv6 address.
|
||||
Config{User: "user", Host: "::1", Path: "dir"},
|
||||
"ssh",
|
||||
[]string{"::1", "-l", "user", "-s", "sftp"},
|
||||
},
|
||||
{
|
||||
// IPv6 address with zone and port.
|
||||
Config{User: "user", Host: "::1%lo0", Port: "22", Path: "dir"},
|
||||
"ssh",
|
||||
[]string{"::1%lo0", "-p", "22", "-l", "user", "-s", "sftp"},
|
||||
},
|
||||
}
|
||||
|
||||
func TestBuildSSHCommand(t *testing.T) {
|
||||
for _, test := range sshcmdTests {
|
||||
for i, test := range sshcmdTests {
|
||||
t.Run("", func(t *testing.T) {
|
||||
cmd, args, err := buildSSHCommand(test.cfg)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
t.Fatalf("%v in test %d", err, i)
|
||||
}
|
||||
|
||||
if cmd != test.cmd {
|
||||
|
@ -45,7 +57,8 @@ func TestBuildSSHCommand(t *testing.T) {
|
|||
}
|
||||
|
||||
if !reflect.DeepEqual(test.args, args) {
|
||||
t.Fatalf("wrong args, want:\n %v\ngot:\n %v", test.args, args)
|
||||
t.Fatalf("wrong args in test %d, want:\n %v\ngot:\n %v",
|
||||
i, test.args, args)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue