2016-09-28 17:53:07 +00:00
|
|
|
package approle
|
|
|
|
|
|
|
|
import (
|
2018-01-08 18:31:38 +00:00
|
|
|
"context"
|
2016-09-28 17:53:07 +00:00
|
|
|
"testing"
|
|
|
|
|
2019-04-12 21:54:35 +00:00
|
|
|
"github.com/hashicorp/vault/sdk/logical"
|
2016-09-28 17:53:07 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestAppRole_SecretIDNumUsesUpgrade(t *testing.T) {
|
|
|
|
var resp *logical.Response
|
|
|
|
var err error
|
|
|
|
|
|
|
|
b, storage := createBackendWithStorage(t)
|
|
|
|
|
|
|
|
roleData := map[string]interface{}{
|
|
|
|
"secret_id_num_uses": 10,
|
|
|
|
}
|
|
|
|
|
|
|
|
roleReq := &logical.Request{
|
|
|
|
Operation: logical.CreateOperation,
|
|
|
|
Path: "role/role1",
|
|
|
|
Storage: storage,
|
|
|
|
Data: roleData,
|
|
|
|
}
|
|
|
|
|
2018-01-08 18:31:38 +00:00
|
|
|
resp, err = b.HandleRequest(context.Background(), roleReq)
|
2016-09-28 17:53:07 +00:00
|
|
|
if err != nil || (resp != nil && resp.IsError()) {
|
|
|
|
t.Fatalf("err:%v resp:%#v", err, resp)
|
|
|
|
}
|
|
|
|
|
|
|
|
secretIDReq := &logical.Request{
|
|
|
|
Operation: logical.UpdateOperation,
|
|
|
|
Path: "role/role1/secret-id",
|
|
|
|
Storage: storage,
|
|
|
|
}
|
|
|
|
|
2018-01-08 18:31:38 +00:00
|
|
|
resp, err = b.HandleRequest(context.Background(), secretIDReq)
|
2016-09-28 17:53:07 +00:00
|
|
|
if err != nil || (resp != nil && resp.IsError()) {
|
|
|
|
t.Fatalf("err:%v resp:%#v", err, resp)
|
|
|
|
}
|
|
|
|
|
2016-09-29 00:22:37 +00:00
|
|
|
secretIDReq.Operation = logical.UpdateOperation
|
|
|
|
secretIDReq.Path = "role/role1/secret-id/lookup"
|
|
|
|
secretIDReq.Data = map[string]interface{}{
|
|
|
|
"secret_id": resp.Data["secret_id"].(string),
|
2016-09-28 17:53:07 +00:00
|
|
|
}
|
2018-01-08 18:31:38 +00:00
|
|
|
resp, err = b.HandleRequest(context.Background(), secretIDReq)
|
2016-09-28 17:53:07 +00:00
|
|
|
if err != nil || (resp != nil && resp.IsError()) {
|
|
|
|
t.Fatalf("err:%v resp:%#v", err, resp)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check if the response contains the value set for secret_id_num_uses
|
2018-06-05 20:12:11 +00:00
|
|
|
if resp.Data["secret_id_num_uses"] != 10 {
|
2016-09-28 17:53:07 +00:00
|
|
|
t.Fatal("invalid secret_id_num_uses")
|
|
|
|
}
|
|
|
|
}
|