diff --git a/pkg/git/options.go b/pkg/git/options.go index bc943608..64458f5e 100644 --- a/pkg/git/options.go +++ b/pkg/git/options.go @@ -78,6 +78,9 @@ func (o AuthOptions) Validate() error { return fmt.Errorf("invalid '%s' auth option: 'password' requires 'username' to be set", o.Transport) } case SSH: + if o.Host == "" { + return fmt.Errorf("invalid '%s' auth option: 'host' is required", o.Transport) + } if len(o.Identity) == 0 { return fmt.Errorf("invalid '%s' auth option: 'identity' is required", o.Transport) } diff --git a/pkg/git/options_test.go b/pkg/git/options_test.go index 3ab3ee59..17defd94 100644 --- a/pkg/git/options_test.go +++ b/pkg/git/options_test.go @@ -106,10 +106,18 @@ func TestAuthOptions_Validate(t *testing.T) { Transport: HTTPS, }, }, + { + name: "SSH transport requires host", + opts: AuthOptions{ + Transport: SSH, + }, + wantErr: "invalid 'ssh' auth option: 'host' is required", + }, { name: "SSH transport requires identity", opts: AuthOptions{ Transport: SSH, + Host: "github.com:22", }, wantErr: "invalid 'ssh' auth option: 'identity' is required", }, @@ -117,6 +125,7 @@ func TestAuthOptions_Validate(t *testing.T) { name: "SSH transport requires known_hosts", opts: AuthOptions{ Transport: SSH, + Host: "github.com:22", Identity: []byte(privateKeyFixture), }, wantErr: "invalid 'ssh' auth option: 'known_hosts' is required", @@ -129,6 +138,7 @@ func TestAuthOptions_Validate(t *testing.T) { { name: "Valid SSH transport", opts: AuthOptions{ + Host: "github.com:22", Transport: SSH, Identity: []byte(privateKeyPassphraseFixture), Password: "foobar",