From 264d094d8dce590d00fba1683cb7c74ff0c01a74 Mon Sep 17 00:00:00 2001 From: Máximo Cuadros Date: Mon, 11 Dec 2017 13:02:02 +0100 Subject: plumbing: transport ssh, ssh_config implementation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Máximo Cuadros --- plumbing/transport/ssh/common_test.go | 67 +++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) (limited to 'plumbing/transport/ssh/common_test.go') diff --git a/plumbing/transport/ssh/common_test.go b/plumbing/transport/ssh/common_test.go index 5315e28..faa0503 100644 --- a/plumbing/transport/ssh/common_test.go +++ b/plumbing/transport/ssh/common_test.go @@ -3,9 +3,12 @@ package ssh import ( "testing" + "github.com/kevinburke/ssh_config" + "golang.org/x/crypto/ssh" . "gopkg.in/check.v1" + "gopkg.in/src-d/go-git.v4/plumbing/transport" ) func Test(t *testing.T) { TestingT(t) } @@ -39,3 +42,67 @@ func (s *SuiteCommon) TestOverrideConfigKeep(c *C) { overrideConfig(config, target) c.Assert(target.User, Equals, "foo") } + +func (s *SuiteCommon) TestDefaultSSHConfig(c *C) { + defer func() { + DefaultSSHConfig = ssh_config.DefaultUserSettings + }() + + DefaultSSHConfig = &mockSSHConfig{map[string]map[string]string{ + "github.com": map[string]string{ + "Hostname": "foo.local", + "Port": "42", + }, + }} + + ep, err := transport.NewEndpoint("git@github.com:foo/bar.git") + c.Assert(err, IsNil) + + cmd := &command{endpoint: ep} + c.Assert(cmd.getHostWithPort(), Equals, "foo.local:42") +} + +func (s *SuiteCommon) TestDefaultSSHConfigNil(c *C) { + defer func() { + DefaultSSHConfig = ssh_config.DefaultUserSettings + }() + + DefaultSSHConfig = nil + + ep, err := transport.NewEndpoint("git@github.com:foo/bar.git") + c.Assert(err, IsNil) + + cmd := &command{endpoint: ep} + c.Assert(cmd.getHostWithPort(), Equals, "github.com:22") +} + +func (s *SuiteCommon) TestDefaultSSHConfigWildcard(c *C) { + defer func() { + DefaultSSHConfig = ssh_config.DefaultUserSettings + }() + + DefaultSSHConfig = &mockSSHConfig{Values: map[string]map[string]string{ + "*": map[string]string{ + "Port": "42", + }, + }} + + ep, err := transport.NewEndpoint("git@github.com:foo/bar.git") + c.Assert(err, IsNil) + + cmd := &command{endpoint: ep} + c.Assert(cmd.getHostWithPort(), Equals, "github.com:22") +} + +type mockSSHConfig struct { + Values map[string]map[string]string +} + +func (c *mockSSHConfig) Get(alias, key string) string { + a, ok := c.Values[alias] + if !ok { + return c.Values["*"][key] + } + + return a[key] +} -- cgit