2017-04-24 19:15:50 +00:00
|
|
|
package awsauth
|
|
|
|
|
|
|
|
import (
|
2018-01-08 18:31:38 +00:00
|
|
|
"context"
|
2017-04-24 19:15:50 +00:00
|
|
|
"testing"
|
|
|
|
|
2019-04-12 21:54:35 +00:00
|
|
|
"github.com/hashicorp/vault/sdk/logical"
|
2017-04-24 19:15:50 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestBackend_pathConfigClient(t *testing.T) {
|
|
|
|
config := logical.TestBackendConfig()
|
|
|
|
storage := &logical.InmemStorage{}
|
|
|
|
config.StorageView = storage
|
|
|
|
|
|
|
|
b, err := Backend(config)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2018-01-19 06:44:44 +00:00
|
|
|
|
|
|
|
err = b.Setup(context.Background(), config)
|
2017-04-24 19:15:50 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// make sure we start with empty roles, which gives us confidence that the read later
|
|
|
|
// actually is the two roles we created
|
2018-01-08 18:31:38 +00:00
|
|
|
resp, err := b.HandleRequest(context.Background(), &logical.Request{
|
2017-04-24 19:15:50 +00:00
|
|
|
Operation: logical.ReadOperation,
|
|
|
|
Path: "config/client",
|
|
|
|
Storage: storage,
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
// at this point, resp == nil is valid as no client config exists
|
|
|
|
// if resp != nil, then resp.Data must have EndPoint and IAMServerIdHeaderValue as nil
|
|
|
|
if resp != nil {
|
|
|
|
if resp.IsError() {
|
|
|
|
t.Fatalf("failed to read client config entry")
|
|
|
|
} else if resp.Data["endpoint"] != nil || resp.Data["iam_server_id_header_value"] != nil {
|
|
|
|
t.Fatalf("returned endpoint or iam_server_id_header_value non-nil")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
data := map[string]interface{}{
|
|
|
|
"sts_endpoint": "https://my-custom-sts-endpoint.example.com",
|
|
|
|
"iam_server_id_header_value": "vault_server_identification_314159",
|
|
|
|
}
|
2018-01-08 18:31:38 +00:00
|
|
|
resp, err = b.HandleRequest(context.Background(), &logical.Request{
|
2017-04-24 19:15:50 +00:00
|
|
|
Operation: logical.CreateOperation,
|
|
|
|
Path: "config/client",
|
|
|
|
Data: data,
|
|
|
|
Storage: storage,
|
|
|
|
})
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
if resp != nil && resp.IsError() {
|
|
|
|
t.Fatal("failed to create the client config entry")
|
|
|
|
}
|
|
|
|
|
2018-01-08 18:31:38 +00:00
|
|
|
resp, err = b.HandleRequest(context.Background(), &logical.Request{
|
2017-04-24 19:15:50 +00:00
|
|
|
Operation: logical.ReadOperation,
|
|
|
|
Path: "config/client",
|
|
|
|
Storage: storage,
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
if resp == nil || resp.IsError() {
|
|
|
|
t.Fatal("failed to read the client config entry")
|
|
|
|
}
|
|
|
|
if resp.Data["iam_server_id_header_value"] != data["iam_server_id_header_value"] {
|
|
|
|
t.Fatalf("expected iam_server_id_header_value: '%#v'; returned iam_server_id_header_value: '%#v'",
|
|
|
|
data["iam_server_id_header_value"], resp.Data["iam_server_id_header_value"])
|
|
|
|
}
|
2017-07-17 15:08:57 +00:00
|
|
|
|
|
|
|
data = map[string]interface{}{
|
|
|
|
"iam_server_id_header_value": "vault_server_identification_2718281",
|
|
|
|
}
|
2018-01-08 18:31:38 +00:00
|
|
|
resp, err = b.HandleRequest(context.Background(), &logical.Request{
|
2017-07-17 15:08:57 +00:00
|
|
|
Operation: logical.UpdateOperation,
|
|
|
|
Path: "config/client",
|
|
|
|
Data: data,
|
|
|
|
Storage: storage,
|
|
|
|
})
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
if resp != nil && resp.IsError() {
|
|
|
|
t.Fatal("failed to update the client config entry")
|
|
|
|
}
|
|
|
|
|
2018-01-08 18:31:38 +00:00
|
|
|
resp, err = b.HandleRequest(context.Background(), &logical.Request{
|
2017-07-17 15:08:57 +00:00
|
|
|
Operation: logical.ReadOperation,
|
|
|
|
Path: "config/client",
|
|
|
|
Storage: storage,
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
if resp == nil || resp.IsError() {
|
|
|
|
t.Fatal("failed to read the client config entry")
|
|
|
|
}
|
|
|
|
if resp.Data["iam_server_id_header_value"] != data["iam_server_id_header_value"] {
|
|
|
|
t.Fatalf("expected iam_server_id_header_value: '%#v'; returned iam_server_id_header_value: '%#v'",
|
|
|
|
data["iam_server_id_header_value"], resp.Data["iam_server_id_header_value"])
|
|
|
|
}
|
2017-04-24 19:15:50 +00:00
|
|
|
}
|