aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.travis.yml15
-rwxr-xr-x[-rw-r--r--].travis/install_key.sh12
-rw-r--r--plumbing/transport/ssh/common.go8
-rw-r--r--plumbing/transport/ssh/upload_pack_test.go19
4 files changed, 41 insertions, 13 deletions
diff --git a/.travis.yml b/.travis.yml
index e527225..0086733 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -25,15 +25,18 @@ before_script:
- make build-git
before_install:
- - eval "$(ssh-agent -s)"
- # we only decrypt the SSH key when we aren't in a pull request
- #- 'if [ "$TRAVIS_PULL_REQUEST" = "false" ]; then bash .travis/install_key.sh; fi'
- #- 'if [ "$TRAVIS_PULL_REQUEST" != "false" ]; then export SSH_AUTH_SOCK="" ; fi'\
- # temporal fix skip of SSH test
- - export SSH_AUTH_SOCK=""
- git config --global user.email "travis@example.com"
- git config --global user.name "Travis CI"
+ # we only decrypt the SSH key when we aren't in a pull request
+ - >
+ if [ "$TRAVIS_PULL_REQUEST" = "false" ] ; then \
+ bash .travis/install_key.sh; \
+ SSH_TEST_PRIVATE_KEY=$HOME/.travis/deploy.pem; \
+ else \
+ export SSH_AUTH_SOCK=""; \
+ fi
+
install:
- go get -v -t ./...
diff --git a/.travis/install_key.sh b/.travis/install_key.sh
index b035092..f2df1ab 100644..100755
--- a/.travis/install_key.sh
+++ b/.travis/install_key.sh
@@ -1,3 +1,11 @@
-openssl aes-256-cbc -K $encrypted_1477e58fe67a_key -iv $encrypted_1477e58fe67a_iv -in .travis/deploy.pem.enc -out .travis/deploy.pem -d
+#!/bin/bash
+export SSH_TEST_PRIVATE_KEY=$PWD/.travis/deploy.pem
+
+openssl aes-256-cbc \
+ -K $encrypted_1477e58fe67a_key \
+ -iv $encrypted_1477e58fe67a_iv \
+ -in .travis/deploy.pem.enc \
+ -out .travis/deploy.pem -d
+
chmod 600 .travis/deploy.pem
-ssh-add .travis/deploy.pem
+
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..85a3d9d 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
+ }
+}