Skip to content
This repository was archived by the owner on Sep 11, 2020. It is now read-only.

Commit 1107000

Browse files
committed
ssh: fix test without SSH_AUTH_SOCK
1 parent 06a9b19 commit 1107000

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

plumbing/transport/ssh/auth_method_test.go

+19
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,30 @@ func (s *SuiteCommon) TestPublicKeysCallbackString(c *C) {
9494
c.Assert(a.String(), Equals, fmt.Sprintf("user: test, name: %s", PublicKeysCallbackName))
9595
}
9696
func (s *SuiteCommon) TestNewSSHAgentAuth(c *C) {
97+
if os.Getenv("SSH_AUTH_SOCK") == "" {
98+
c.Skip("SSH_AUTH_SOCK or SSH_TEST_PRIVATE_KEY are required")
99+
}
100+
97101
auth, err := NewSSHAgentAuth("foo")
98102
c.Assert(err, IsNil)
99103
c.Assert(auth, NotNil)
100104
}
101105

106+
func (s *SuiteCommon) TestNewSSHAgentAuthNoAgent(c *C) {
107+
addr := os.Getenv("SSH_AUTH_SOCK")
108+
err := os.Unsetenv("SSH_AUTH_SOCK")
109+
c.Assert(err, IsNil)
110+
111+
defer func() {
112+
err := os.Setenv("SSH_AUTH_SOCK", addr)
113+
c.Assert(err, IsNil)
114+
}()
115+
116+
k, err := NewSSHAgentAuth("foo")
117+
c.Assert(k, IsNil)
118+
c.Assert(err, ErrorMatches, ".*SSH_AUTH_SOCK.*")
119+
}
120+
102121
func (*SuiteCommon) TestNewPublicKeys(c *C) {
103122
auth, err := NewPublicKeys("foo", testdata.PEMBytes["rsa"], "")
104123
c.Assert(err, IsNil)

0 commit comments

Comments
 (0)