Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
This commit is contained in:
Bo-Yi Wu 2024-01-20 22:02:59 +08:00
parent 4e6f9a0ce0
commit 79fdc99c81
No known key found for this signature in database
2 changed files with 20 additions and 3 deletions

View File

@ -61,7 +61,9 @@ func escapeArg(arg string) string {
func (p Plugin) hostPort(host string) (string, string) { func (p Plugin) hostPort(host string) (string, string) {
hosts := strings.Split(host, ":") hosts := strings.Split(host, ":")
port := strconv.Itoa(p.Config.Port) port := strconv.Itoa(p.Config.Port)
if len(hosts) > 1 { if len(hosts) > 1 &&
(p.Config.Protocol == easyssh.PROTOCOL_TCP ||
p.Config.Protocol == easyssh.PROTOCOL_TCP4) {
host = hosts[0] host = hosts[0]
port = hosts[1] port = hosts[1]
} }

View File

@ -798,6 +798,7 @@ func TestPlugin_hostPort(t *testing.T) {
fields: fields{ fields: fields{
Config: Config{ Config: Config{
Port: 22, Port: 22,
Protocol: easyssh.PROTOCOL_TCP4,
}, },
}, },
args: args{ args: args{
@ -806,6 +807,20 @@ func TestPlugin_hostPort(t *testing.T) {
wantHost: "localhost", wantHost: "localhost",
wantPort: "443", wantPort: "443",
}, },
{
name: "ipv6",
fields: fields{
Config: Config{
Port: 22,
Protocol: easyssh.PROTOCOL_TCP6,
},
},
args: args{
h: "::1",
},
wantHost: "::1",
wantPort: "22",
},
} }
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(t *testing.T) {
@ -963,7 +978,7 @@ func TestCommandWithIPv6(t *testing.T) {
plugin := Plugin{ plugin := Plugin{
Config: Config{ Config: Config{
Host: []string{"127.0.0.1"}, Host: []string{"::1"},
Username: "drone-scp", Username: "drone-scp",
Port: 22, Port: 22,
KeyPath: "./tests/.ssh/id_rsa", KeyPath: "./tests/.ssh/id_rsa",