Fixed duration type and added acceptance test for sts
This commit is contained in:
parent
71afb7cff0
commit
1cf8153dfd
|
@ -36,6 +36,18 @@ func TestBackend_basic(t *testing.T) {
|
|||
})
|
||||
}
|
||||
|
||||
func TestBackend_basicSTS(t *testing.T) {
|
||||
logicaltest.Test(t, logicaltest.TestCase{
|
||||
PreCheck: func() { testAccPreCheck(t) },
|
||||
Backend: getBackend(t),
|
||||
Steps: []logicaltest.TestStep{
|
||||
testAccStepConfig(t),
|
||||
testAccStepWritePolicy(t, "test", testPolicy),
|
||||
testAccStepReadSTS(t, "test"),
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func TestBackend_policyCrud(t *testing.T) {
|
||||
var compacted bytes.Buffer
|
||||
if err := json.Compact(&compacted, []byte(testPolicy)); err != nil {
|
||||
|
@ -119,6 +131,42 @@ func testAccStepReadUser(t *testing.T, name string) logicaltest.TestStep {
|
|||
}
|
||||
}
|
||||
|
||||
func testAccStepReadSTS(t *testing.T, name string) logicaltest.TestStep {
|
||||
return logicaltest.TestStep{
|
||||
Operation: logical.ReadOperation,
|
||||
Path: "sts/" + name,
|
||||
Check: func(resp *logical.Response) error {
|
||||
var d struct {
|
||||
AccessKey string `mapstructure:"access_key"`
|
||||
SecretKey string `mapstructure:"secret_key"`
|
||||
STSToken string `mapstructure:"security_token"`
|
||||
}
|
||||
if err := mapstructure.Decode(resp.Data, &d); err != nil {
|
||||
return err
|
||||
}
|
||||
log.Printf("[WARN] Generated credentials: %v", d)
|
||||
|
||||
// Build a client and verify that the credentials work
|
||||
creds := credentials.NewStaticCredentials(d.AccessKey, d.SecretKey, d.STSToken)
|
||||
awsConfig := &aws.Config{
|
||||
Credentials: creds,
|
||||
Region: aws.String("us-east-1"),
|
||||
HTTPClient: cleanhttp.DefaultClient(),
|
||||
}
|
||||
client := ec2.New(session.New(awsConfig))
|
||||
|
||||
log.Printf("[WARN] Verifying that the generated credentials work...")
|
||||
_, err := client.DescribeInstances(&ec2.DescribeInstancesInput{})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
func testAccStepWritePolicy(t *testing.T, name string, policy string) logicaltest.TestStep {
|
||||
return logicaltest.TestStep{
|
||||
Operation: logical.UpdateOperation,
|
||||
|
|
|
@ -34,7 +34,7 @@ func pathSTS(b *backend) *framework.Path {
|
|||
func (b *backend) pathSTSRead(
|
||||
req *logical.Request, d *framework.FieldData) (*logical.Response, error) {
|
||||
policyName := d.Get("name").(string)
|
||||
duration := d.Get("duration").(int64)
|
||||
duration := int64(d.Get("duration").(int))
|
||||
|
||||
// Read the policy
|
||||
policy, err := req.Storage.Get("policy/" + policyName)
|
||||
|
|
|
@ -9,7 +9,6 @@ import (
|
|||
|
||||
var rollbackMap = map[string]framework.RollbackFunc{
|
||||
"user": pathUserRollback,
|
||||
"sts": pathUserRollback,
|
||||
}
|
||||
|
||||
func rollback(req *logical.Request, kind string, data interface{}) error {
|
||||
|
|
Loading…
Reference in New Issue