Skip to content

Commit

Permalink
ssh: return missing user field in NewClientConn
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
povsister authored and katiehockman committed May 6, 2021
1 parent 3497b51 commit 38f3c27
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 1 deletion.
2 changes: 1 addition & 1 deletion ssh/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func NewClientConn(c net.Conn, addr string, config *ClientConfig) (Conn, <-chan
}

conn := &connection{
sshConn: sshConn{conn: c},
sshConn: sshConn{conn: c, user: fullConf.User},
}

if err := conn.clientHandshake(addr, &fullConf); err != nil {
Expand Down
49 changes: 49 additions & 0 deletions ssh/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,3 +164,52 @@ func TestBannerCallback(t *testing.T) {
t.Fatalf("got %s; want %s", receivedBanner, expected)
}
}

func TestNewClientConn(t *testing.T) {
for _, tt := range []struct {
name string
user string
}{
{
name: "good user field for ConnMetadata",
user: "testuser",
},
{
name: "empty user field for ConnMetadata",
user: "",
},
} {
t.Run(tt.name, func(t *testing.T) {
c1, c2, err := netPipe()
if err != nil {
t.Fatalf("netPipe: %v", err)
}
defer c1.Close()
defer c2.Close()

serverConf := &ServerConfig{
PasswordCallback: func(conn ConnMetadata, password []byte) (*Permissions, error) {
return &Permissions{}, nil
},
}
serverConf.AddHostKey(testSigners["rsa"])
go NewServerConn(c1, serverConf)

clientConf := &ClientConfig{
User: tt.user,
Auth: []AuthMethod{
Password("testpw"),
},
HostKeyCallback: InsecureIgnoreHostKey(),
}
clientConn, _, _, err := NewClientConn(c2, "", clientConf)
if err != nil {
t.Fatal(err)
}

if userGot := clientConn.User(); userGot != tt.user {
t.Errorf("got user %q; want user %q", userGot, tt.user)
}
})
}
}

0 comments on commit 38f3c27

Please sign in to comment.