Skip to content

Commit

Permalink
transportAuth(): Add checks for invalid transports
Browse files Browse the repository at this point in the history
Signed-off-by: Sunny <darkowlzz@protonmail.com>
  • Loading branch information
darkowlzz committed Oct 26, 2021
1 parent f9a3404 commit 0110664
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
6 changes: 6 additions & 0 deletions pkg/git/gogit/transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ limitations under the License.
package gogit

import (
"fmt"

"github.com/go-git/go-git/v5/plumbing/transport"
"github.com/go-git/go-git/v5/plumbing/transport/http"
"github.com/go-git/go-git/v5/plumbing/transport/ssh"
Expand Down Expand Up @@ -53,6 +55,10 @@ func transportAuth(opts *git.AuthOptions) (transport.AuthMethod, error) {
}
return pk, nil
}
case "":
return nil, fmt.Errorf("no transport type set")
default:
return nil, fmt.Errorf("unknown transport '%s'", opts.Transport)
}
return nil, nil
}
Expand Down
14 changes: 9 additions & 5 deletions pkg/git/gogit/transport_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,12 +168,16 @@ func Test_transportAuth(t *testing.T) {
wantErr: errors.New("knownhosts: knownhosts: missing host pattern"),
},
{
name: "Empty",
opts: &git.AuthOptions{},
wantFunc: func(g *WithT, t transport.AuthMethod, opts *git.AuthOptions) {
g.Expect(t).To(BeNil())
name: "Empty",
opts: &git.AuthOptions{},
wantErr: errors.New("no transport type set"),
},
{
name: "Unknown transport",
opts: &git.AuthOptions{
Transport: "foo",
},
wantErr: nil,
wantErr: errors.New("unknown transport 'foo'"),
},
}
for _, tt := range tests {
Expand Down

0 comments on commit 0110664

Please sign in to comment.