mirror of
https://github.com/optim-enterprises-bv/vault.git
synced 2025-11-01 11:08:10 +00:00
Vault SSH: verify echo test
This commit is contained in:
@@ -9,6 +9,7 @@ import (
|
|||||||
|
|
||||||
"golang.org/x/crypto/ssh"
|
"golang.org/x/crypto/ssh"
|
||||||
|
|
||||||
|
"github.com/hashicorp/vault/api"
|
||||||
"github.com/hashicorp/vault/logical"
|
"github.com/hashicorp/vault/logical"
|
||||||
logicaltest "github.com/hashicorp/vault/logical/testing"
|
logicaltest "github.com/hashicorp/vault/logical/testing"
|
||||||
"github.com/hashicorp/vault/vault"
|
"github.com/hashicorp/vault/vault"
|
||||||
@@ -63,7 +64,7 @@ var testInstallScript 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 init() {
|
||||||
addr, err := vault.StartTestServer()
|
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))
|
||||||
}
|
}
|
||||||
@@ -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 {
|
func testCredsWrite(t *testing.T, name string) logicaltest.TestStep {
|
||||||
data := map[string]interface{}{
|
data := map[string]interface{}{
|
||||||
"ip": testIP,
|
"ip": testIP,
|
||||||
|
|||||||
@@ -58,7 +58,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 init() {
|
||||||
addr, err := vault.StartTestServer()
|
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))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -135,7 +135,7 @@ var testLogicalBackends = map[string]logical.Factory{}
|
|||||||
|
|
||||||
// Starts the test server which responds to SSH authentication.
|
// Starts the test server which responds to SSH authentication.
|
||||||
// Used to test the SSH secret backend.
|
// Used to test the SSH secret backend.
|
||||||
func StartTestServer() (string, error) {
|
func StartSSHHostTestServer() (string, error) {
|
||||||
pubKey, _, _, _, err := ssh.ParseAuthorizedKey([]byte(testSharedPublicKey))
|
pubKey, _, _, _, err := ssh.ParseAuthorizedKey([]byte(testSharedPublicKey))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", fmt.Errorf("Error parsing public key")
|
return "", fmt.Errorf("Error parsing public key")
|
||||||
|
|||||||
Reference in New Issue
Block a user