Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
plumbing: check setAuth error. Fixes #185
  • Loading branch information
nodivbyzero committed Dec 14, 2023
commit ced1b81e32f971a80e474e9661b9c1b9c96569e7
4 changes: 3 additions & 1 deletion plumbing/transport/ssh/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ type runner struct {
func (r *runner) Command(cmd string, ep *transport.Endpoint, auth transport.AuthMethod) (common.Command, error) {
c := &command{command: cmd, endpoint: ep, config: r.config}
if auth != nil {
c.setAuth(auth)
if err := c.setAuth(auth); err != nil {
return nil, err
}
}

if err := c.connect(); err != nil {
Expand Down
23 changes: 23 additions & 0 deletions plumbing/transport/ssh/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,3 +206,26 @@ func (c *mockSSHConfig) Get(alias, key string) string {

return a[key]
}

type invalidAuthMethod struct {
}

func (a *invalidAuthMethod) Name() string {
return "invalid"
}

func (a *invalidAuthMethod) String() string {
return "invalid"
}

func (s *SuiteCommon) TestCommandWithInvalidAuthMethod(c *C) {
uploadPack := &UploadPackSuite{}
uploadPack.SetUpSuite(c)
r := &runner{}
auth := &invalidAuthMethod{}

_, err := r.Command("command", uploadPack.newEndpoint(c, "endpoint"), auth)

c.Assert(err, NotNil)
c.Assert(err, ErrorMatches, "invalid auth method")
}