2015-03-21 16:19:37 +00:00
|
|
|
package consul
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/base64"
|
2015-04-27 18:08:37 +00:00
|
|
|
"fmt"
|
2015-03-21 16:19:37 +00:00
|
|
|
"log"
|
|
|
|
"os"
|
2016-05-24 21:28:19 +00:00
|
|
|
"reflect"
|
2016-07-01 17:59:56 +00:00
|
|
|
"sync"
|
2015-03-21 16:19:37 +00:00
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
2016-07-01 17:59:56 +00:00
|
|
|
consulapi "github.com/hashicorp/consul/api"
|
2015-03-21 16:19:37 +00:00
|
|
|
"github.com/hashicorp/vault/logical"
|
|
|
|
logicaltest "github.com/hashicorp/vault/logical/testing"
|
|
|
|
"github.com/mitchellh/mapstructure"
|
2017-01-09 18:46:54 +00:00
|
|
|
dockertest "gopkg.in/ory-am/dockertest.v2"
|
2015-03-21 16:19:37 +00:00
|
|
|
)
|
|
|
|
|
2016-07-01 17:59:56 +00:00
|
|
|
var (
|
|
|
|
testImagePull sync.Once
|
|
|
|
)
|
|
|
|
|
|
|
|
func prepareTestContainer(t *testing.T, s logical.Storage, b logical.Backend) (cid dockertest.ContainerID, retAddress string) {
|
|
|
|
if os.Getenv("CONSUL_ADDR") != "" {
|
|
|
|
return "", os.Getenv("CONSUL_ADDR")
|
2016-05-26 02:52:36 +00:00
|
|
|
}
|
|
|
|
|
2016-07-01 17:59:56 +00:00
|
|
|
// Without this the checks for whether the container has started seem to
|
|
|
|
// never actually pass. There's really no reason to expose the test
|
|
|
|
// containers, so don't.
|
|
|
|
dockertest.BindDockerToLocalhost = "yep"
|
2016-05-24 21:28:19 +00:00
|
|
|
|
2016-07-01 17:59:56 +00:00
|
|
|
testImagePull.Do(func() {
|
|
|
|
dockertest.Pull(dockertest.ConsulImageName)
|
|
|
|
})
|
|
|
|
|
|
|
|
try := 0
|
|
|
|
cid, connErr := dockertest.ConnectToConsul(60, 500*time.Millisecond, func(connAddress string) bool {
|
|
|
|
try += 1
|
|
|
|
// Build a client and verify that the credentials work
|
|
|
|
config := consulapi.DefaultConfig()
|
|
|
|
config.Address = connAddress
|
|
|
|
config.Token = dockertest.ConsulACLMasterToken
|
|
|
|
client, err := consulapi.NewClient(config)
|
|
|
|
if err != nil {
|
|
|
|
if try > 50 {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
_, err = client.KV().Put(&consulapi.KVPair{
|
|
|
|
Key: "setuptest",
|
|
|
|
Value: []byte("setuptest"),
|
|
|
|
}, nil)
|
|
|
|
if err != nil {
|
|
|
|
if try > 50 {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
retAddress = connAddress
|
|
|
|
return true
|
|
|
|
})
|
|
|
|
|
|
|
|
if connErr != nil {
|
|
|
|
t.Fatalf("could not connect to consul: %v", connErr)
|
|
|
|
}
|
|
|
|
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
func cleanupTestContainer(t *testing.T, cid dockertest.ContainerID) {
|
|
|
|
err := cid.KillRemove()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|
2016-05-24 21:28:19 +00:00
|
|
|
|
2016-07-01 17:59:56 +00:00
|
|
|
func TestBackend_config_access(t *testing.T) {
|
|
|
|
config := logical.TestBackendConfig()
|
|
|
|
config.StorageView = &logical.InmemStorage{}
|
|
|
|
b, err := Factory(config)
|
2016-05-24 21:28:19 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2016-07-01 17:59:56 +00:00
|
|
|
cid, connURL := prepareTestContainer(t, config.StorageView, b)
|
|
|
|
if cid != "" {
|
|
|
|
defer cleanupTestContainer(t, cid)
|
|
|
|
}
|
|
|
|
connData := map[string]interface{}{
|
|
|
|
"address": connURL,
|
|
|
|
"token": dockertest.ConsulACLMasterToken,
|
|
|
|
}
|
|
|
|
|
2016-05-24 21:28:19 +00:00
|
|
|
confReq := &logical.Request{
|
|
|
|
Operation: logical.UpdateOperation,
|
|
|
|
Path: "config/access",
|
2016-07-01 17:59:56 +00:00
|
|
|
Storage: config.StorageView,
|
|
|
|
Data: connData,
|
2016-05-24 21:28:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
resp, err := b.HandleRequest(confReq)
|
|
|
|
if err != nil || (resp != nil && resp.IsError()) || resp != nil {
|
|
|
|
t.Fatalf("failed to write configuration: resp:%#v err:%s", resp, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
confReq.Operation = logical.ReadOperation
|
|
|
|
resp, err = b.HandleRequest(confReq)
|
|
|
|
if err != nil || (resp != nil && resp.IsError()) {
|
|
|
|
t.Fatalf("failed to write configuration: resp:%#v err:%s", resp, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
expected := map[string]interface{}{
|
2016-07-01 17:59:56 +00:00
|
|
|
"address": connData["address"].(string),
|
2016-05-24 21:28:19 +00:00
|
|
|
"scheme": "http",
|
|
|
|
}
|
|
|
|
if !reflect.DeepEqual(expected, resp.Data) {
|
|
|
|
t.Fatalf("bad: expected:%#v\nactual:%#v\n", expected, resp.Data)
|
|
|
|
}
|
|
|
|
if resp.Data["token"] != nil {
|
|
|
|
t.Fatalf("token should not be set in the response")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-21 16:19:37 +00:00
|
|
|
func TestBackend_basic(t *testing.T) {
|
2016-07-01 17:59:56 +00:00
|
|
|
config := logical.TestBackendConfig()
|
|
|
|
config.StorageView = &logical.InmemStorage{}
|
|
|
|
b, err := Factory(config)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
2016-02-29 19:58:06 +00:00
|
|
|
}
|
|
|
|
|
2016-07-01 17:59:56 +00:00
|
|
|
cid, connURL := prepareTestContainer(t, config.StorageView, b)
|
|
|
|
if cid != "" {
|
|
|
|
defer cleanupTestContainer(t, cid)
|
|
|
|
}
|
|
|
|
connData := map[string]interface{}{
|
|
|
|
"address": connURL,
|
|
|
|
"token": dockertest.ConsulACLMasterToken,
|
|
|
|
}
|
2015-03-21 16:19:37 +00:00
|
|
|
|
|
|
|
logicaltest.Test(t, logicaltest.TestCase{
|
2016-07-01 17:59:56 +00:00
|
|
|
Backend: b,
|
2015-03-21 16:19:37 +00:00
|
|
|
Steps: []logicaltest.TestStep{
|
2016-07-01 17:59:56 +00:00
|
|
|
testAccStepConfig(t, connData),
|
2015-05-26 00:33:31 +00:00
|
|
|
testAccStepWritePolicy(t, "test", testPolicy, ""),
|
2016-07-01 17:59:56 +00:00
|
|
|
testAccStepReadToken(t, "test", connData),
|
2015-03-21 16:19:37 +00:00
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2016-05-27 15:27:53 +00:00
|
|
|
func TestBackend_renew_revoke(t *testing.T) {
|
2016-07-01 17:59:56 +00:00
|
|
|
config := logical.TestBackendConfig()
|
|
|
|
config.StorageView = &logical.InmemStorage{}
|
|
|
|
b, err := Factory(config)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
2016-05-27 15:27:53 +00:00
|
|
|
}
|
|
|
|
|
2016-07-01 17:59:56 +00:00
|
|
|
cid, connURL := prepareTestContainer(t, config.StorageView, b)
|
|
|
|
if cid != "" {
|
|
|
|
defer cleanupTestContainer(t, cid)
|
|
|
|
}
|
|
|
|
connData := map[string]interface{}{
|
|
|
|
"address": connURL,
|
|
|
|
"token": dockertest.ConsulACLMasterToken,
|
|
|
|
}
|
2016-05-27 15:27:53 +00:00
|
|
|
|
|
|
|
req := &logical.Request{
|
2016-07-01 17:59:56 +00:00
|
|
|
Storage: config.StorageView,
|
2016-05-27 15:27:53 +00:00
|
|
|
Operation: logical.UpdateOperation,
|
|
|
|
Path: "config/access",
|
2016-07-01 17:59:56 +00:00
|
|
|
Data: connData,
|
2016-05-27 15:27:53 +00:00
|
|
|
}
|
|
|
|
resp, err := b.HandleRequest(req)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
req.Path = "roles/test"
|
|
|
|
req.Data = map[string]interface{}{
|
|
|
|
"policy": base64.StdEncoding.EncodeToString([]byte(testPolicy)),
|
|
|
|
"lease": "6h",
|
|
|
|
}
|
|
|
|
resp, err = b.HandleRequest(req)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
req.Operation = logical.ReadOperation
|
|
|
|
req.Path = "creds/test"
|
|
|
|
resp, err = b.HandleRequest(req)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2016-07-01 17:59:56 +00:00
|
|
|
if resp == nil {
|
|
|
|
t.Fatal("resp nil")
|
|
|
|
}
|
|
|
|
if resp.IsError() {
|
|
|
|
t.Fatalf("resp is error: %v", resp.Error())
|
2016-05-27 15:27:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
generatedSecret := resp.Secret
|
|
|
|
generatedSecret.IssueTime = time.Now()
|
|
|
|
generatedSecret.TTL = 6 * time.Hour
|
|
|
|
|
|
|
|
var d struct {
|
|
|
|
Token string `mapstructure:"token"`
|
|
|
|
}
|
|
|
|
if err := mapstructure.Decode(resp.Data, &d); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
log.Printf("[WARN] Generated token: %s", d.Token)
|
|
|
|
|
|
|
|
// Build a client and verify that the credentials work
|
2016-07-01 17:59:56 +00:00
|
|
|
consulapiConfig := consulapi.DefaultConfig()
|
|
|
|
consulapiConfig.Address = connData["address"].(string)
|
|
|
|
consulapiConfig.Token = d.Token
|
|
|
|
client, err := consulapi.NewClient(consulapiConfig)
|
2016-05-27 15:27:53 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
log.Printf("[WARN] Verifying that the generated token works...")
|
2016-07-01 17:59:56 +00:00
|
|
|
_, err = client.KV().Put(&consulapi.KVPair{
|
2016-05-27 15:27:53 +00:00
|
|
|
Key: "foo",
|
|
|
|
Value: []byte("bar"),
|
|
|
|
}, nil)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
req.Operation = logical.RenewOperation
|
|
|
|
req.Secret = generatedSecret
|
|
|
|
resp, err = b.HandleRequest(req)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
if resp == nil {
|
|
|
|
t.Fatal("got nil response from renew")
|
|
|
|
}
|
|
|
|
|
|
|
|
req.Operation = logical.RevokeOperation
|
|
|
|
resp, err = b.HandleRequest(req)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
log.Printf("[WARN] Verifying that the generated token does not work...")
|
2016-07-01 17:59:56 +00:00
|
|
|
_, err = client.KV().Put(&consulapi.KVPair{
|
2016-05-27 15:27:53 +00:00
|
|
|
Key: "foo",
|
|
|
|
Value: []byte("bar"),
|
|
|
|
}, nil)
|
|
|
|
if err == nil {
|
|
|
|
t.Fatal("expected error")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-02 21:16:51 +00:00
|
|
|
func TestBackend_management(t *testing.T) {
|
2016-07-01 17:59:56 +00:00
|
|
|
config := logical.TestBackendConfig()
|
|
|
|
config.StorageView = &logical.InmemStorage{}
|
|
|
|
b, err := Factory(config)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
2016-02-29 19:58:06 +00:00
|
|
|
}
|
|
|
|
|
2016-07-01 17:59:56 +00:00
|
|
|
cid, connURL := prepareTestContainer(t, config.StorageView, b)
|
|
|
|
if cid != "" {
|
|
|
|
defer cleanupTestContainer(t, cid)
|
|
|
|
}
|
|
|
|
connData := map[string]interface{}{
|
|
|
|
"address": connURL,
|
|
|
|
"token": dockertest.ConsulACLMasterToken,
|
|
|
|
}
|
2015-11-02 21:16:51 +00:00
|
|
|
|
|
|
|
logicaltest.Test(t, logicaltest.TestCase{
|
2016-07-01 17:59:56 +00:00
|
|
|
Backend: b,
|
2015-11-02 21:16:51 +00:00
|
|
|
Steps: []logicaltest.TestStep{
|
2016-07-01 17:59:56 +00:00
|
|
|
testAccStepConfig(t, connData),
|
2015-11-02 21:16:51 +00:00
|
|
|
testAccStepWriteManagementPolicy(t, "test", ""),
|
2016-07-01 17:59:56 +00:00
|
|
|
testAccStepReadManagementToken(t, "test", connData),
|
2015-11-02 21:16:51 +00:00
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2015-04-27 18:08:37 +00:00
|
|
|
func TestBackend_crud(t *testing.T) {
|
2015-11-02 21:16:51 +00:00
|
|
|
b, _ := Factory(logical.TestBackendConfig())
|
2015-04-27 18:08:37 +00:00
|
|
|
logicaltest.Test(t, logicaltest.TestCase{
|
2016-07-01 17:59:56 +00:00
|
|
|
Backend: b,
|
2015-04-27 18:08:37 +00:00
|
|
|
Steps: []logicaltest.TestStep{
|
2015-05-26 00:33:31 +00:00
|
|
|
testAccStepWritePolicy(t, "test", testPolicy, ""),
|
2016-11-04 16:35:16 +00:00
|
|
|
testAccStepWritePolicy(t, "test2", testPolicy, ""),
|
|
|
|
testAccStepWritePolicy(t, "test3", testPolicy, ""),
|
2016-01-30 01:45:38 +00:00
|
|
|
testAccStepReadPolicy(t, "test", testPolicy, 0),
|
2016-11-04 16:35:16 +00:00
|
|
|
testAccStepListPolicy(t, []string{"test", "test2", "test3"}),
|
2015-05-26 00:33:31 +00:00
|
|
|
testAccStepDeletePolicy(t, "test"),
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestBackend_role_lease(t *testing.T) {
|
2015-11-02 21:16:51 +00:00
|
|
|
b, _ := Factory(logical.TestBackendConfig())
|
2015-05-26 00:33:31 +00:00
|
|
|
logicaltest.Test(t, logicaltest.TestCase{
|
2016-07-01 17:59:56 +00:00
|
|
|
Backend: b,
|
2015-05-26 00:33:31 +00:00
|
|
|
Steps: []logicaltest.TestStep{
|
|
|
|
testAccStepWritePolicy(t, "test", testPolicy, "6h"),
|
|
|
|
testAccStepReadPolicy(t, "test", testPolicy, 6*time.Hour),
|
2015-04-27 18:08:37 +00:00
|
|
|
testAccStepDeletePolicy(t, "test"),
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2015-03-21 16:19:37 +00:00
|
|
|
func testAccStepConfig(
|
|
|
|
t *testing.T, config map[string]interface{}) logicaltest.TestStep {
|
|
|
|
return logicaltest.TestStep{
|
2016-01-07 15:30:47 +00:00
|
|
|
Operation: logical.UpdateOperation,
|
2015-04-19 05:28:53 +00:00
|
|
|
Path: "config/access",
|
2015-03-21 16:19:37 +00:00
|
|
|
Data: config,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-21 16:23:44 +00:00
|
|
|
func testAccStepReadToken(
|
|
|
|
t *testing.T, name string, conf map[string]interface{}) logicaltest.TestStep {
|
2015-03-21 16:19:37 +00:00
|
|
|
return logicaltest.TestStep{
|
|
|
|
Operation: logical.ReadOperation,
|
2015-04-27 20:59:56 +00:00
|
|
|
Path: "creds/" + name,
|
2015-03-21 16:19:37 +00:00
|
|
|
Check: func(resp *logical.Response) error {
|
|
|
|
var d struct {
|
|
|
|
Token string `mapstructure:"token"`
|
|
|
|
}
|
|
|
|
if err := mapstructure.Decode(resp.Data, &d); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
log.Printf("[WARN] Generated token: %s", d.Token)
|
|
|
|
|
2015-03-21 16:23:44 +00:00
|
|
|
// Build a client and verify that the credentials work
|
2016-07-01 17:59:56 +00:00
|
|
|
config := consulapi.DefaultConfig()
|
2015-03-21 16:23:44 +00:00
|
|
|
config.Address = conf["address"].(string)
|
|
|
|
config.Token = d.Token
|
2016-07-01 17:59:56 +00:00
|
|
|
client, err := consulapi.NewClient(config)
|
2015-03-21 16:23:44 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
log.Printf("[WARN] Verifying that the generated token works...")
|
2016-07-01 17:59:56 +00:00
|
|
|
_, err = client.KV().Put(&consulapi.KVPair{
|
2015-03-21 16:23:44 +00:00
|
|
|
Key: "foo",
|
|
|
|
Value: []byte("bar"),
|
|
|
|
}, nil)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2015-03-21 16:19:37 +00:00
|
|
|
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-02 21:16:51 +00:00
|
|
|
func testAccStepReadManagementToken(
|
|
|
|
t *testing.T, name string, conf map[string]interface{}) logicaltest.TestStep {
|
|
|
|
return logicaltest.TestStep{
|
|
|
|
Operation: logical.ReadOperation,
|
|
|
|
Path: "creds/" + name,
|
|
|
|
Check: func(resp *logical.Response) error {
|
|
|
|
var d struct {
|
|
|
|
Token string `mapstructure:"token"`
|
|
|
|
}
|
|
|
|
if err := mapstructure.Decode(resp.Data, &d); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
log.Printf("[WARN] Generated token: %s", d.Token)
|
|
|
|
|
|
|
|
// Build a client and verify that the credentials work
|
2016-07-01 17:59:56 +00:00
|
|
|
config := consulapi.DefaultConfig()
|
2015-11-02 21:16:51 +00:00
|
|
|
config.Address = conf["address"].(string)
|
|
|
|
config.Token = d.Token
|
2016-07-01 17:59:56 +00:00
|
|
|
client, err := consulapi.NewClient(config)
|
2015-11-02 21:16:51 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
log.Printf("[WARN] Verifying that the generated token works...")
|
2016-07-01 17:59:56 +00:00
|
|
|
_, _, err = client.ACL().Create(&consulapi.ACLEntry{
|
2015-11-02 21:16:51 +00:00
|
|
|
Type: "management",
|
|
|
|
Name: "test2",
|
|
|
|
}, nil)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-26 00:33:31 +00:00
|
|
|
func testAccStepWritePolicy(t *testing.T, name string, policy string, lease string) logicaltest.TestStep {
|
2015-03-21 16:19:37 +00:00
|
|
|
return logicaltest.TestStep{
|
2016-01-07 15:30:47 +00:00
|
|
|
Operation: logical.UpdateOperation,
|
2015-04-27 20:59:56 +00:00
|
|
|
Path: "roles/" + name,
|
2015-03-21 16:19:37 +00:00
|
|
|
Data: map[string]interface{}{
|
|
|
|
"policy": base64.StdEncoding.EncodeToString([]byte(policy)),
|
2015-05-26 00:33:31 +00:00
|
|
|
"lease": lease,
|
2015-03-21 16:19:37 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-02 21:16:51 +00:00
|
|
|
func testAccStepWriteManagementPolicy(t *testing.T, name string, lease string) logicaltest.TestStep {
|
|
|
|
return logicaltest.TestStep{
|
2016-01-07 15:30:47 +00:00
|
|
|
Operation: logical.UpdateOperation,
|
2015-11-02 21:16:51 +00:00
|
|
|
Path: "roles/" + name,
|
|
|
|
Data: map[string]interface{}{
|
|
|
|
"token_type": "management",
|
|
|
|
"lease": lease,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-26 00:33:31 +00:00
|
|
|
func testAccStepReadPolicy(t *testing.T, name string, policy string, lease time.Duration) logicaltest.TestStep {
|
2015-04-27 18:08:37 +00:00
|
|
|
return logicaltest.TestStep{
|
|
|
|
Operation: logical.ReadOperation,
|
2015-04-27 20:59:56 +00:00
|
|
|
Path: "roles/" + name,
|
2015-04-27 18:08:37 +00:00
|
|
|
Check: func(resp *logical.Response) error {
|
|
|
|
policyRaw := resp.Data["policy"].(string)
|
|
|
|
out, err := base64.StdEncoding.DecodeString(policyRaw)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if string(out) != policy {
|
|
|
|
return fmt.Errorf("mismatch: %s %s", out, policy)
|
|
|
|
}
|
2015-05-26 00:33:31 +00:00
|
|
|
|
|
|
|
leaseRaw := resp.Data["lease"].(string)
|
|
|
|
l, err := time.ParseDuration(leaseRaw)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if l != lease {
|
|
|
|
return fmt.Errorf("mismatch: %v %v", l, lease)
|
|
|
|
}
|
2015-04-27 18:08:37 +00:00
|
|
|
return nil
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-04 16:35:16 +00:00
|
|
|
func testAccStepListPolicy(t *testing.T, names []string) logicaltest.TestStep {
|
|
|
|
return logicaltest.TestStep{
|
|
|
|
Operation: logical.ListOperation,
|
|
|
|
Path: "roles/",
|
|
|
|
Check: func(resp *logical.Response) error {
|
|
|
|
respKeys := resp.Data["keys"].([]string)
|
|
|
|
if !reflect.DeepEqual(respKeys, names) {
|
|
|
|
return fmt.Errorf("mismatch: %#v %#v", respKeys, names)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-27 18:08:37 +00:00
|
|
|
func testAccStepDeletePolicy(t *testing.T, name string) logicaltest.TestStep {
|
|
|
|
return logicaltest.TestStep{
|
|
|
|
Operation: logical.DeleteOperation,
|
2015-04-27 20:59:56 +00:00
|
|
|
Path: "roles/" + name,
|
2015-04-27 18:08:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-21 16:19:37 +00:00
|
|
|
const testPolicy = `
|
|
|
|
key "" {
|
|
|
|
policy = "write"
|
|
|
|
}
|
|
|
|
`
|