Add Host field check in AuthOptions.Validate()
For ssh, Host field is required in AuthOptions. Signed-off-by: Sunny <darkowlzz@protonmail.com>
This commit is contained in:
parent
562af6d658
commit
5bd08a6960
|
@ -78,6 +78,9 @@ func (o AuthOptions) Validate() error {
|
||||||
return fmt.Errorf("invalid '%s' auth option: 'password' requires 'username' to be set", o.Transport)
|
return fmt.Errorf("invalid '%s' auth option: 'password' requires 'username' to be set", o.Transport)
|
||||||
}
|
}
|
||||||
case SSH:
|
case SSH:
|
||||||
|
if o.Host == "" {
|
||||||
|
return fmt.Errorf("invalid '%s' auth option: 'host' is required", o.Transport)
|
||||||
|
}
|
||||||
if len(o.Identity) == 0 {
|
if len(o.Identity) == 0 {
|
||||||
return fmt.Errorf("invalid '%s' auth option: 'identity' is required", o.Transport)
|
return fmt.Errorf("invalid '%s' auth option: 'identity' is required", o.Transport)
|
||||||
}
|
}
|
||||||
|
|
|
@ -106,10 +106,18 @@ func TestAuthOptions_Validate(t *testing.T) {
|
||||||
Transport: HTTPS,
|
Transport: HTTPS,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "SSH transport requires host",
|
||||||
|
opts: AuthOptions{
|
||||||
|
Transport: SSH,
|
||||||
|
},
|
||||||
|
wantErr: "invalid 'ssh' auth option: 'host' is required",
|
||||||
|
},
|
||||||
{
|
{
|
||||||
name: "SSH transport requires identity",
|
name: "SSH transport requires identity",
|
||||||
opts: AuthOptions{
|
opts: AuthOptions{
|
||||||
Transport: SSH,
|
Transport: SSH,
|
||||||
|
Host: "github.com:22",
|
||||||
},
|
},
|
||||||
wantErr: "invalid 'ssh' auth option: 'identity' is required",
|
wantErr: "invalid 'ssh' auth option: 'identity' is required",
|
||||||
},
|
},
|
||||||
|
@ -117,6 +125,7 @@ func TestAuthOptions_Validate(t *testing.T) {
|
||||||
name: "SSH transport requires known_hosts",
|
name: "SSH transport requires known_hosts",
|
||||||
opts: AuthOptions{
|
opts: AuthOptions{
|
||||||
Transport: SSH,
|
Transport: SSH,
|
||||||
|
Host: "github.com:22",
|
||||||
Identity: []byte(privateKeyFixture),
|
Identity: []byte(privateKeyFixture),
|
||||||
},
|
},
|
||||||
wantErr: "invalid 'ssh' auth option: 'known_hosts' is required",
|
wantErr: "invalid 'ssh' auth option: 'known_hosts' is required",
|
||||||
|
@ -129,6 +138,7 @@ func TestAuthOptions_Validate(t *testing.T) {
|
||||||
{
|
{
|
||||||
name: "Valid SSH transport",
|
name: "Valid SSH transport",
|
||||||
opts: AuthOptions{
|
opts: AuthOptions{
|
||||||
|
Host: "github.com:22",
|
||||||
Transport: SSH,
|
Transport: SSH,
|
||||||
Identity: []byte(privateKeyPassphraseFixture),
|
Identity: []byte(privateKeyPassphraseFixture),
|
||||||
Password: "foobar",
|
Password: "foobar",
|
||||||
|
|
Loading…
Reference in New Issue