go.crypto/ssh: make tests work on non-cgo platforms.
user.Current() currently requires cgo - if an error is returned attempt to get the username from the environment. R=golang-dev, minux.ma, bradfitz, dave CC=golang-dev https://golang.org/cl/6819113
This commit is contained in:
@@ -150,15 +150,26 @@ type server struct {
|
|||||||
output bytes.Buffer // holds stderr from sshd process
|
output bytes.Buffer // holds stderr from sshd process
|
||||||
}
|
}
|
||||||
|
|
||||||
func clientConfig() *ssh.ClientConfig {
|
func username() string {
|
||||||
user, err := user.Current()
|
var username string
|
||||||
if err != nil {
|
if user, err := user.Current(); err == nil {
|
||||||
panic(err)
|
username = user.Username
|
||||||
|
} else {
|
||||||
|
// user.Current() currently requires cgo. If an error is
|
||||||
|
// returned attempt to get the username from the environment.
|
||||||
|
username = os.Getenv("USER")
|
||||||
}
|
}
|
||||||
|
if username == "" {
|
||||||
|
panic("Unable to get username")
|
||||||
|
}
|
||||||
|
return username
|
||||||
|
}
|
||||||
|
|
||||||
|
func clientConfig() *ssh.ClientConfig {
|
||||||
kc := new(keychain)
|
kc := new(keychain)
|
||||||
kc.keys = append(kc.keys, rsakey)
|
kc.keys = append(kc.keys, rsakey)
|
||||||
config := &ssh.ClientConfig{
|
config := &ssh.ClientConfig{
|
||||||
User: user.Username,
|
User: username(),
|
||||||
Auth: []ssh.ClientAuth{
|
Auth: []ssh.ClientAuth{
|
||||||
ssh.ClientAuthKeyring(kc),
|
ssh.ClientAuthKeyring(kc),
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user