Skip to content

Commit 38f3c27

Browse files
Einsfierkatiehockman
authored andcommitted
ssh: return missing user field in NewClientConn
Fix golang/go#45249 Change-Id: I27ef2976586ad481d832c6e46695a91f1bb50373 GitHub-Last-Rev: 9f631b8 GitHub-Pull-Request: golang#180 Reviewed-on: https://go-review.googlesource.com/c/crypto/+/304990 Reviewed-by: Emmanuel Odeke <[email protected]> Reviewed-by: Katie Hockman <[email protected]> Trust: Emmanuel Odeke <[email protected]> Trust: Katie Hockman <[email protected]> Run-TryBot: Emmanuel Odeke <[email protected]> TryBot-Result: Go Bot <[email protected]>
1 parent 3497b51 commit 38f3c27

File tree

2 files changed

+50
-1
lines changed

2 files changed

+50
-1
lines changed

ssh/client.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ func NewClientConn(c net.Conn, addr string, config *ClientConfig) (Conn, <-chan
7777
}
7878

7979
conn := &connection{
80-
sshConn: sshConn{conn: c},
80+
sshConn: sshConn{conn: c, user: fullConf.User},
8181
}
8282

8383
if err := conn.clientHandshake(addr, &fullConf); err != nil {

ssh/client_test.go

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,3 +164,52 @@ func TestBannerCallback(t *testing.T) {
164164
t.Fatalf("got %s; want %s", receivedBanner, expected)
165165
}
166166
}
167+
168+
func TestNewClientConn(t *testing.T) {
169+
for _, tt := range []struct {
170+
name string
171+
user string
172+
}{
173+
{
174+
name: "good user field for ConnMetadata",
175+
user: "testuser",
176+
},
177+
{
178+
name: "empty user field for ConnMetadata",
179+
user: "",
180+
},
181+
} {
182+
t.Run(tt.name, func(t *testing.T) {
183+
c1, c2, err := netPipe()
184+
if err != nil {
185+
t.Fatalf("netPipe: %v", err)
186+
}
187+
defer c1.Close()
188+
defer c2.Close()
189+
190+
serverConf := &ServerConfig{
191+
PasswordCallback: func(conn ConnMetadata, password []byte) (*Permissions, error) {
192+
return &Permissions{}, nil
193+
},
194+
}
195+
serverConf.AddHostKey(testSigners["rsa"])
196+
go NewServerConn(c1, serverConf)
197+
198+
clientConf := &ClientConfig{
199+
User: tt.user,
200+
Auth: []AuthMethod{
201+
Password("testpw"),
202+
},
203+
HostKeyCallback: InsecureIgnoreHostKey(),
204+
}
205+
clientConn, _, _, err := NewClientConn(c2, "", clientConf)
206+
if err != nil {
207+
t.Fatal(err)
208+
}
209+
210+
if userGot := clientConn.User(); userGot != tt.user {
211+
t.Errorf("got user %q; want user %q", userGot, tt.user)
212+
}
213+
})
214+
}
215+
}

0 commit comments

Comments
 (0)