Vault SSH: Dynamic Key test case fix

This commit is contained in:
Vishal Nayak
2015-07-24 12:13:26 -04:00
parent 9d4c5f718b
commit 0a4854e542
5 changed files with 11 additions and 10 deletions

View File

@@ -22,7 +22,7 @@ func (c *SSH) KeyRevoke(id string) error {
return err return err
} }
// Invokes the SSH backend API to create a dynamic key // Invokes the SSH backend API to create a dynamic key or an OTP
func (c *SSH) KeyCreate(role string, data map[string]interface{}) (*Secret, error) { func (c *SSH) KeyCreate(role string, data map[string]interface{}) (*Secret, error) {
r := c.c.NewRequest("PUT", fmt.Sprintf("/v1/ssh/creds/%s", role)) r := c.c.NewRequest("PUT", fmt.Sprintf("/v1/ssh/creds/%s", role))
if err := r.SetJSONBody(data); err != nil { if err := r.SetJSONBody(data); err != nil {

View File

@@ -41,7 +41,7 @@ func Backend(conf *logical.BackendConfig) (*framework.Backend, error) {
pathConfigLease(&b), pathConfigLease(&b),
pathKeys(&b), pathKeys(&b),
pathRoles(&b), pathRoles(&b),
pathRoleCreate(&b), pathCredsCreate(&b),
pathLookup(&b), pathLookup(&b),
pathVerify(&b), pathVerify(&b),
}, },

View File

@@ -74,13 +74,13 @@ func init() {
testAdminUser = u.Username testAdminUser = u.Username
} }
func TestSSHBackend(t *testing.T) { func TestSSHDynamicKeyBackend(t *testing.T) {
logicaltest.Test(t, logicaltest.TestCase{ logicaltest.Test(t, logicaltest.TestCase{
Backend: Backend(), Factory: Factory,
Steps: []logicaltest.TestStep{ Steps: []logicaltest.TestStep{
testNamedKeys(t), testNamedKeys(t),
testNewRole(t), testNewDynamicKeyRole(t),
testRoleCreate(t), testDynamicKeyCredsCreate(t),
}, },
}) })
} }
@@ -95,11 +95,12 @@ func testNamedKeys(t *testing.T) logicaltest.TestStep {
} }
} }
func testNewRole(t *testing.T) logicaltest.TestStep { func testNewDynamicKeyRole(t *testing.T) logicaltest.TestStep {
return logicaltest.TestStep{ return logicaltest.TestStep{
Operation: logical.WriteOperation, Operation: logical.WriteOperation,
Path: fmt.Sprintf("roles/%s", testRoleName), Path: fmt.Sprintf("roles/%s", testRoleName),
Data: map[string]interface{}{ Data: map[string]interface{}{
"key_type": "dynamic",
"key": testKey, "key": testKey,
"admin_user": testAdminUser, "admin_user": testAdminUser,
"cidr": testCidr, "cidr": testCidr,
@@ -108,7 +109,7 @@ func testNewRole(t *testing.T) logicaltest.TestStep {
} }
} }
func testRoleCreate(t *testing.T) logicaltest.TestStep { func testDynamicKeyCredsCreate(t *testing.T) logicaltest.TestStep {
return logicaltest.TestStep{ return logicaltest.TestStep{
Operation: logical.WriteOperation, Operation: logical.WriteOperation,
Path: fmt.Sprintf("creds/%s", testRoleName), Path: fmt.Sprintf("creds/%s", testRoleName),

View File

@@ -10,7 +10,7 @@ import (
"github.com/hashicorp/vault/logical/framework" "github.com/hashicorp/vault/logical/framework"
) )
func pathRoleCreate(b *backend) *framework.Path { func pathCredsCreate(b *backend) *framework.Path {
return &framework.Path{ return &framework.Path{
Pattern: "creds/(?P<name>[-\\w]+)", Pattern: "creds/(?P<name>[-\\w]+)",
Fields: map[string]*framework.FieldSchema{ Fields: map[string]*framework.FieldSchema{

View File

@@ -74,7 +74,7 @@ func init() {
testAdminUser = u.Username testAdminUser = u.Username
} }
func TestSSH(t *testing.T) { func testSSH(t *testing.T) {
// 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)