logical/consul: actual test that the token works

This commit is contained in:
Mitchell Hashimoto 2015-03-21 17:23:44 +01:00
parent 55a3423c60
commit 3270349456
1 changed files with 20 additions and 12 deletions

View File

@ -10,6 +10,7 @@ import (
"testing" "testing"
"time" "time"
"github.com/hashicorp/consul/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/mitchellh/mapstructure" "github.com/mitchellh/mapstructure"
@ -25,7 +26,7 @@ func TestBackend_basic(t *testing.T) {
Steps: []logicaltest.TestStep{ Steps: []logicaltest.TestStep{
testAccStepConfig(t, config), testAccStepConfig(t, config),
testAccStepWritePolicy(t, "test", testPolicy), testAccStepWritePolicy(t, "test", testPolicy),
testAccStepReadToken(t, "test"), testAccStepReadToken(t, "test", config),
}, },
}) })
} }
@ -84,7 +85,8 @@ func testAccStepConfig(
} }
} }
func testAccStepReadToken(t *testing.T, name string) logicaltest.TestStep { func testAccStepReadToken(
t *testing.T, name string, conf map[string]interface{}) logicaltest.TestStep {
return logicaltest.TestStep{ return logicaltest.TestStep{
Operation: logical.ReadOperation, Operation: logical.ReadOperation,
Path: name, Path: name,
@ -97,17 +99,23 @@ func testAccStepReadToken(t *testing.T, name string) logicaltest.TestStep {
} }
log.Printf("[WARN] Generated token: %s", d.Token) log.Printf("[WARN] Generated token: %s", d.Token)
/* // Build a client and verify that the credentials work
// Build a client and verify that the credentials work config := api.DefaultConfig()
creds := aws.Creds(d.AccessKey, d.SecretKey, "") config.Address = conf["address"].(string)
client := ec2.New(creds, "us-east-1", nil) config.Token = d.Token
client, err := api.NewClient(config)
if err != nil {
return err
}
log.Printf("[WARN] Verifying that the generated credentials work...") log.Printf("[WARN] Verifying that the generated token works...")
_, err := client.DescribeInstances(&ec2.DescribeInstancesRequest{}) _, err = client.KV().Put(&api.KVPair{
if err != nil { Key: "foo",
return err Value: []byte("bar"),
} }, nil)
*/ if err != nil {
return err
}
return nil return nil
}, },