From 645932a0df74db5092f63ed4f4ae0fd07bbbf725 Mon Sep 17 00:00:00 2001 From: Jeff Mitchell Date: Fri, 2 Oct 2015 18:43:38 -0700 Subject: [PATCH] Remove use of os/user as it cannot be run with CGO disabled --- builtin/logical/ssh/backend_test.go | 14 +++++++------- command/ssh_test.go | 13 ++++++------- 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/builtin/logical/ssh/backend_test.go b/builtin/logical/ssh/backend_test.go index 0bb0058e5..472774f09 100644 --- a/builtin/logical/ssh/backend_test.go +++ b/builtin/logical/ssh/backend_test.go @@ -2,7 +2,7 @@ package ssh import ( "fmt" - "os/user" + "os" "reflect" "strings" "testing" @@ -56,6 +56,7 @@ oOyBJU/HMVvBfv4g+OVFLVgSwwm6owwsouZ0+D/LasbuHqYyqYqdyPJQYzWA2Y+F ) func testingFactory(conf *logical.BackendConfig) (logical.Backend, error) { + initTest() defaultLeaseTTLVal := 2 * time.Minute maxLeaseTTLVal := 10 * time.Minute return Factory(&logical.BackendConfig{ @@ -77,7 +78,7 @@ var testDynamicRoleData map[string]interface{} // Starts the server and initializes the servers IP address, // port and usernames to be used by the test cases. -func init() { +func initTest() { addr, err := vault.StartSSHHostTestServer() if err != nil { panic(fmt.Sprintf("error starting mock server:%s", err)) @@ -85,12 +86,11 @@ func init() { input := strings.Split(addr, ":") testIP = input[0] - u, err := user.Current() - if err != nil { - panic(fmt.Sprintf("error getting current username: '%s'", err)) + testUserName := os.Getenv("VAULT_SSHTEST_USER") + if len(testUserName) == 0 { + panic("VAULT_SSHTEST_USER must be set to the desired user") } - testUserName = u.Username - testAdminUser = u.Username + testAdminUser = testUserName testOTPRoleData = map[string]interface{}{ "key_type": testOTPKeyType, diff --git a/command/ssh_test.go b/command/ssh_test.go index 992c8ddb8..03b8e03c1 100644 --- a/command/ssh_test.go +++ b/command/ssh_test.go @@ -5,7 +5,6 @@ import ( "fmt" "io" "os" - "os/user" "strings" "testing" @@ -57,7 +56,7 @@ var testAdminUser string // Starts the server and initializes the servers IP address, // port and usernames to be used by the test cases. -func init() { +func initTest() { addr, err := vault.StartSSHHostTestServer() if err != nil { panic(fmt.Sprintf("Error starting mock server:%s", err)) @@ -66,16 +65,16 @@ func init() { testIP = input[0] testPort = input[1] - u, err := user.Current() - if err != nil { - panic(fmt.Sprintf("Error getting current username: '%s'", err)) + testUserName := os.Getenv("VAULT_SSHTEST_USER") + if len(testUserName) == 0 { + panic("VAULT_SSHTEST_USER must be set to the desired user") } - testUserName = u.Username - testAdminUser = u.Username + testAdminUser = testUserName } // This test is broken. Hence temporarily disabling it. func testSSH(t *testing.T) { + initTest() // Add the SSH backend to the unsealed test core. // This should be done before the unsealed core is created. err := vault.AddTestLogicalBackend("ssh", logicalssh.Factory)