2019-09-13 17:07:04 +00:00
|
|
|
package aws
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"reflect"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/hashicorp/vault/sdk/logical"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestBackend_PathConfigRoot(t *testing.T) {
|
|
|
|
config := logical.TestBackendConfig()
|
|
|
|
config.StorageView = &logical.InmemStorage{}
|
|
|
|
|
|
|
|
b := Backend()
|
|
|
|
if err := b.Setup(context.Background(), config); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
configData := map[string]interface{}{
|
2021-07-20 16:48:29 +00:00
|
|
|
"access_key": "AKIAEXAMPLE",
|
|
|
|
"secret_key": "RandomData",
|
|
|
|
"region": "us-west-2",
|
|
|
|
"iam_endpoint": "https://iam.amazonaws.com",
|
|
|
|
"sts_endpoint": "https://sts.us-west-2.amazonaws.com",
|
|
|
|
"max_retries": 10,
|
|
|
|
"username_template": defaultUserNameTemplate,
|
2019-09-13 17:07:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
configReq := &logical.Request{
|
|
|
|
Operation: logical.UpdateOperation,
|
|
|
|
Storage: config.StorageView,
|
|
|
|
Path: "config/root",
|
|
|
|
Data: configData,
|
|
|
|
}
|
|
|
|
|
|
|
|
resp, err := b.HandleRequest(context.Background(), configReq)
|
|
|
|
if err != nil || (resp != nil && resp.IsError()) {
|
|
|
|
t.Fatalf("bad: config writing failed: resp:%#v\n err: %v", resp, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
resp, err = b.HandleRequest(context.Background(), &logical.Request{
|
|
|
|
Operation: logical.ReadOperation,
|
|
|
|
Storage: config.StorageView,
|
|
|
|
Path: "config/root",
|
|
|
|
})
|
|
|
|
if err != nil || (resp != nil && resp.IsError()) {
|
|
|
|
t.Fatalf("bad: config reading failed: resp:%#v\n err: %v", resp, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
delete(configData, "secret_key")
|
|
|
|
if !reflect.DeepEqual(resp.Data, configData) {
|
|
|
|
t.Errorf("bad: expected to read config root as %#v, got %#v instead", configData, resp.Data)
|
|
|
|
}
|
|
|
|
}
|