Reviewers: golang-dev_googlegroups.com,
Message:
Hello golang-dev@googlegroups.com,
I'd like you to review this change to
https://code.google.com/p/go.crypto
Description:
go.crypto/ssh: make tests work on OpenBSD
OpenBSD does not have a working user.Current() since this currently
requires CGO support. Attempt to get the username via the USER
environment variable instead.
Please review this at http://codereview.appspot.com/6819113/
Affected files:
M ssh/test/test_unix_test.go
Index: ssh/test/test_unix_test.go
===================================================================
--- a/ssh/test/test_unix_test.go
+++ b/ssh/test/test_unix_test.go
@@ -23,6 +23,7 @@
"os/exec"
"os/user"
"path/filepath"
+ "runtime"
"testing"
"text/template"
"time"
@@ -151,14 +152,25 @@
}
func clientConfig() *ssh.ClientConfig {
- user, err := user.Current()
- if err != nil {
- panic(err)
+ var username string
+ if runtime.GOOS == "openbsd" {
+ // OpenBSD does not have a working user.Current() since this
+ // currently requires CGO support.
+ username = os.Getenv("USER")
+ } else {
+ user, err := user.Current()
+ if err != nil {
+ panic(err)
+ }
+ username = user.Username
+ }
+ if username == "" {
+ panic("Unable to get username")
}
kc := new(keychain)
kc.keys = append(kc.keys, rsakey)
config := &ssh.ClientConfig{
- User: user.Username,
+ User: username,
Auth: []ssh.ClientAuth{
ssh.ClientAuthKeyring(kc),
},