Skip to content

Commit dda76ed

Browse files
committed
Add Host field check in AuthOptions.Validate()
For ssh, Host field is required in AuthOptions. Signed-off-by: Sunny <[email protected]>
1 parent 3861d0e commit dda76ed

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

pkg/git/options.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,9 @@ func (o AuthOptions) Validate() error {
7878
return fmt.Errorf("invalid '%s' auth option: 'password' requires 'username' to be set", o.Transport)
7979
}
8080
case SSH:
81+
if o.Host == "" {
82+
return fmt.Errorf("invalid '%s' auth option: 'host' is required", o.Transport)
83+
}
8184
if len(o.Identity) == 0 {
8285
return fmt.Errorf("invalid '%s' auth option: 'identity' is required", o.Transport)
8386
}

pkg/git/options_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,17 +106,26 @@ func TestAuthOptions_Validate(t *testing.T) {
106106
Transport: HTTPS,
107107
},
108108
},
109+
{
110+
name: "SSH transport requires host",
111+
opts: AuthOptions{
112+
Transport: SSH,
113+
},
114+
wantErr: "invalid 'ssh' auth option: 'host' is required",
115+
},
109116
{
110117
name: "SSH transport requires identity",
111118
opts: AuthOptions{
112119
Transport: SSH,
120+
Host: "github.com:22",
113121
},
114122
wantErr: "invalid 'ssh' auth option: 'identity' is required",
115123
},
116124
{
117125
name: "SSH transport requires known_hosts",
118126
opts: AuthOptions{
119127
Transport: SSH,
128+
Host: "github.com:22",
120129
Identity: []byte(privateKeyFixture),
121130
},
122131
wantErr: "invalid 'ssh' auth option: 'known_hosts' is required",
@@ -129,6 +138,7 @@ func TestAuthOptions_Validate(t *testing.T) {
129138
{
130139
name: "Valid SSH transport",
131140
opts: AuthOptions{
141+
Host: "github.com:22",
132142
Transport: SSH,
133143
Identity: []byte(privateKeyPassphraseFixture),
134144
Password: "foobar",

0 commit comments

Comments
 (0)