aboutsummaryrefslogtreecommitdiffstats
path: root/plumbing
diff options
context:
space:
mode:
Diffstat (limited to 'plumbing')
-rw-r--r--plumbing/transport/ssh/common.go8
-rw-r--r--plumbing/transport/ssh/upload_pack_test.go19
2 files changed, 22 insertions, 5 deletions
diff --git a/plumbing/transport/ssh/common.go b/plumbing/transport/ssh/common.go
index 9b484f9..7b44a91 100644
--- a/plumbing/transport/ssh/common.go
+++ b/plumbing/transport/ssh/common.go
@@ -14,6 +14,12 @@ import (
// DefaultClient is the default SSH client.
var DefaultClient = common.NewClient(&runner{})
+// DefaultAuthBuilder is the function used to create a default AuthMethod, when
+// the user doesn't provide any.
+var DefaultAuthBuilder = func(user string) (AuthMethod, error) {
+ return NewSSHAgentAuth(user)
+}
+
type runner struct{}
func (r *runner) Command(cmd string, ep transport.Endpoint, auth transport.AuthMethod) (common.Command, error) {
@@ -119,7 +125,7 @@ func (c *command) setAuthFromEndpoint() error {
}
var err error
- c.auth, err = NewSSHAgentAuth(u)
+ c.auth, err = DefaultAuthBuilder(u)
return err
}
diff --git a/plumbing/transport/ssh/upload_pack_test.go b/plumbing/transport/ssh/upload_pack_test.go
index 54d523a..cb9baa5 100644
--- a/plumbing/transport/ssh/upload_pack_test.go
+++ b/plumbing/transport/ssh/upload_pack_test.go
@@ -16,10 +16,7 @@ type UploadPackSuite struct {
var _ = Suite(&UploadPackSuite{})
func (s *UploadPackSuite) SetUpSuite(c *C) {
- if os.Getenv("SSH_AUTH_SOCK") == "" {
- c.Skip("SSH_AUTH_SOCK is not set")
- }
-
+ s.setAuthBuilder(c)
s.UploadPackSuite.Client = DefaultClient
ep, err := transport.NewEndpoint("git@github.com:git-fixtures/basic.git")
@@ -34,3 +31,17 @@ func (s *UploadPackSuite) SetUpSuite(c *C) {
c.Assert(err, IsNil)
s.UploadPackSuite.NonExistentEndpoint = ep
}
+
+func (s *UploadPackSuite) setAuthBuilder(c *C) {
+ privateKey := os.Getenv("SSH_TEST_PRIVATE_KEY")
+ if privateKey != "" {
+ DefaultAuthBuilder = func(user string) (AuthMethod, error) {
+ return NewPublicKeysFromFile(user, privateKey, "")
+ }
+ }
+
+ if privateKey == "" && os.Getenv("SSH_AUTH_SOCK") == "" {
+ c.Skip("SSH_AUTH_SOCK or SSH_TEST_PRIVATE_KEY are required")
+ return
+ }
+}