diff --git a/builtin/logical/ssh/backend_test.go b/builtin/logical/ssh/backend_test.go index 8ff3902e90..97592cf43a 100644 --- a/builtin/logical/ssh/backend_test.go +++ b/builtin/logical/ssh/backend_test.go @@ -9,6 +9,7 @@ import ( "golang.org/x/crypto/ssh" + "github.com/hashicorp/vault/api" "github.com/hashicorp/vault/logical" logicaltest "github.com/hashicorp/vault/logical/testing" "github.com/hashicorp/vault/vault" @@ -63,7 +64,7 @@ var testInstallScript string // Starts the server and initializes the servers IP address, // port and usernames to be used by the test cases. func init() { - addr, err := vault.StartTestServer() + addr, err := vault.StartSSHHostTestServer() if err != nil { panic(fmt.Sprintf("error starting mock server:%s", err)) } @@ -193,6 +194,44 @@ func TestSSHBackend_OTPCreate(t *testing.T) { }) } +func TestSSHBackend_VerifyEcho(t *testing.T) { + verifyData := map[string]interface{}{ + "otp": api.VerifyEchoRequest, + } + expectedData := map[string]interface{}{ + "message": api.VerifyEchoResponse, + } + logicaltest.Test(t, logicaltest.TestCase{ + Factory: Factory, + Steps: []logicaltest.TestStep{ + testVerifyWrite(t, verifyData, expectedData), + }, + }) +} + +func testVerifyWrite(t *testing.T, d map[string]interface{}, expected map[string]interface{}) logicaltest.TestStep { + return logicaltest.TestStep{ + Operation: logical.WriteOperation, + Path: fmt.Sprintf("verify"), + Data: d, + Check: func(resp *logical.Response) error { + var ac api.SSHVerifyResponse + if err := mapstructure.Decode(resp.Data, &ac); err != nil { + return err + } + var ex api.SSHVerifyResponse + if err := mapstructure.Decode(expected, &ex); err != nil { + return err + } + + if ac.Message != ex.Message || ac.IP != ex.IP || ac.Username != ex.Username { + return fmt.Errorf("Invalid response") + } + return nil + }, + } +} + func testCredsWrite(t *testing.T, name string) logicaltest.TestStep { data := map[string]interface{}{ "ip": testIP, diff --git a/command/ssh_test.go b/command/ssh_test.go index cfc2371d2d..992c8ddb8f 100644 --- a/command/ssh_test.go +++ b/command/ssh_test.go @@ -58,7 +58,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() { - addr, err := vault.StartTestServer() + addr, err := vault.StartSSHHostTestServer() if err != nil { panic(fmt.Sprintf("Error starting mock server:%s", err)) } diff --git a/vault/testing.go b/vault/testing.go index cdea18d0d4..73bf9ecbc1 100644 --- a/vault/testing.go +++ b/vault/testing.go @@ -135,7 +135,7 @@ var testLogicalBackends = map[string]logical.Factory{} // Starts the test server which responds to SSH authentication. // Used to test the SSH secret backend. -func StartTestServer() (string, error) { +func StartSSHHostTestServer() (string, error) { pubKey, _, _, _, err := ssh.ParseAuthorizedKey([]byte(testSharedPublicKey)) if err != nil { return "", fmt.Errorf("Error parsing public key")