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 (
"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,

View File

@ -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)