Remove use of os/user as it cannot be run with CGO disabled

This commit is contained in:
Jeff Mitchell 2015-10-02 18:43:38 -07:00
parent 8f27c250d6
commit 645932a0df
2 changed files with 13 additions and 14 deletions

View File

@ -2,7 +2,7 @@ package ssh
import ( import (
"fmt" "fmt"
"os/user" "os"
"reflect" "reflect"
"strings" "strings"
"testing" "testing"
@ -56,6 +56,7 @@ oOyBJU/HMVvBfv4g+OVFLVgSwwm6owwsouZ0+D/LasbuHqYyqYqdyPJQYzWA2Y+F
) )
func testingFactory(conf *logical.BackendConfig) (logical.Backend, error) { func testingFactory(conf *logical.BackendConfig) (logical.Backend, error) {
initTest()
defaultLeaseTTLVal := 2 * time.Minute defaultLeaseTTLVal := 2 * time.Minute
maxLeaseTTLVal := 10 * time.Minute maxLeaseTTLVal := 10 * time.Minute
return Factory(&logical.BackendConfig{ return Factory(&logical.BackendConfig{
@ -77,7 +78,7 @@ var testDynamicRoleData map[string]interface{}
// Starts the server and initializes the servers IP address, // Starts the server and initializes the servers IP address,
// port and usernames to be used by the test cases. // port and usernames to be used by the test cases.
func init() { func initTest() {
addr, err := vault.StartSSHHostTestServer() addr, err := vault.StartSSHHostTestServer()
if err != nil { if err != nil {
panic(fmt.Sprintf("error starting mock server:%s", err)) panic(fmt.Sprintf("error starting mock server:%s", err))
@ -85,12 +86,11 @@ func init() {
input := strings.Split(addr, ":") input := strings.Split(addr, ":")
testIP = input[0] testIP = input[0]
u, err := user.Current() testUserName := os.Getenv("VAULT_SSHTEST_USER")
if err != nil { if len(testUserName) == 0 {
panic(fmt.Sprintf("error getting current username: '%s'", err)) panic("VAULT_SSHTEST_USER must be set to the desired user")
} }
testUserName = u.Username testAdminUser = testUserName
testAdminUser = u.Username
testOTPRoleData = map[string]interface{}{ testOTPRoleData = map[string]interface{}{
"key_type": testOTPKeyType, "key_type": testOTPKeyType,

View File

@ -5,7 +5,6 @@ import (
"fmt" "fmt"
"io" "io"
"os" "os"
"os/user"
"strings" "strings"
"testing" "testing"
@ -57,7 +56,7 @@ var testAdminUser string
// Starts the server and initializes the servers IP address, // Starts the server and initializes the servers IP address,
// port and usernames to be used by the test cases. // port and usernames to be used by the test cases.
func init() { func initTest() {
addr, err := vault.StartSSHHostTestServer() addr, err := vault.StartSSHHostTestServer()
if err != nil { if err != nil {
panic(fmt.Sprintf("Error starting mock server:%s", err)) panic(fmt.Sprintf("Error starting mock server:%s", err))
@ -66,16 +65,16 @@ func init() {
testIP = input[0] testIP = input[0]
testPort = input[1] testPort = input[1]
u, err := user.Current() testUserName := os.Getenv("VAULT_SSHTEST_USER")
if err != nil { if len(testUserName) == 0 {
panic(fmt.Sprintf("Error getting current username: '%s'", err)) panic("VAULT_SSHTEST_USER must be set to the desired user")
} }
testUserName = u.Username testAdminUser = testUserName
testAdminUser = u.Username
} }
// This test is broken. Hence temporarily disabling it. // This test is broken. Hence temporarily disabling it.
func testSSH(t *testing.T) { func testSSH(t *testing.T) {
initTest()
// Add the SSH backend to the unsealed test core. // Add the SSH backend to the unsealed test core.
// This should be done before the unsealed core is created. // This should be done before the unsealed core is created.
err := vault.AddTestLogicalBackend("ssh", logicalssh.Factory) err := vault.AddTestLogicalBackend("ssh", logicalssh.Factory)