diff options
author | Máximo Cuadros <mcuadros@gmail.com> | 2017-07-28 21:58:40 +0200 |
---|---|---|
committer | Máximo Cuadros <mcuadros@gmail.com> | 2017-07-28 21:58:40 +0200 |
commit | 8ddbecf782c2e340fd85bb4ba4d00dc73d749f87 (patch) | |
tree | b4cfbd1727ad5609801a3f12504077b409b72361 /plumbing | |
parent | 11a403e8af2f5f1f2d5fd3bc73c1ff943ccb7c96 (diff) | |
download | go-git-8ddbecf782c2e340fd85bb4ba4d00dc73d749f87.tar.gz |
transport: fix ssh override config, fixes #519v4.0.0-rc13
Diffstat (limited to 'plumbing')
-rw-r--r-- | plumbing/transport/ssh/common.go | 13 | ||||
-rw-r--r-- | plumbing/transport/ssh/common_test.go | 32 |
2 files changed, 40 insertions, 5 deletions
diff --git a/plumbing/transport/ssh/common.go b/plumbing/transport/ssh/common.go index 6d1c51b..af79dfb 100644 --- a/plumbing/transport/ssh/common.go +++ b/plumbing/transport/ssh/common.go @@ -146,11 +146,14 @@ func overrideConfig(overrides *ssh.ClientConfig, c *ssh.ClientConfig) { return } - vo := reflect.ValueOf(*overrides) - vc := reflect.ValueOf(*c) - for i := 0; i < vc.Type().NumField(); i++ { - vcf := vc.Field(i) - vof := vo.Field(i) + t := reflect.TypeOf(*c) + vc := reflect.ValueOf(c).Elem() + vo := reflect.ValueOf(overrides).Elem() + + for i := 0; i < t.NumField(); i++ { + f := t.Field(i) + vcf := vc.FieldByName(f.Name) + vof := vo.FieldByName(f.Name) if isZeroValue(vcf) { vcf.Set(vof) } diff --git a/plumbing/transport/ssh/common_test.go b/plumbing/transport/ssh/common_test.go index da99148..1b07eee 100644 --- a/plumbing/transport/ssh/common_test.go +++ b/plumbing/transport/ssh/common_test.go @@ -3,7 +3,39 @@ package ssh import ( "testing" + "golang.org/x/crypto/ssh" + . "gopkg.in/check.v1" ) func Test(t *testing.T) { TestingT(t) } + +func (s *SuiteCommon) TestOverrideConfig(c *C) { + config := &ssh.ClientConfig{ + User: "foo", + Auth: []ssh.AuthMethod{ + ssh.Password("yourpassword"), + }, + HostKeyCallback: ssh.FixedHostKey(nil), + } + + target := &ssh.ClientConfig{} + overrideConfig(config, target) + + c.Assert(target.User, Equals, "foo") + c.Assert(target.Auth, HasLen, 1) + c.Assert(target.HostKeyCallback, NotNil) +} + +func (s *SuiteCommon) TestOverrideConfigKeep(c *C) { + config := &ssh.ClientConfig{ + User: "foo", + } + + target := &ssh.ClientConfig{ + User: "bar", + } + + overrideConfig(config, target) + c.Assert(target.User, Equals, "bar") +} |