2023-03-15 16:00:52 +00:00
|
|
|
// Copyright (c) HashiCorp, Inc.
|
|
|
|
// SPDX-License-Identifier: MPL-2.0
|
|
|
|
|
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",
|
2019-12-11 00:02:04 +00:00
|
|
|
"sts_region": "us-east-2",
|
2017-04-24 19:15:50 +00:00
|
|
|
"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"])
|
|
|
|
}
|
2019-12-11 00:02:04 +00:00
|
|
|
if resp.Data["sts_endpoint"] != data["sts_endpoint"] {
|
|
|
|
t.Fatalf("expected sts_endpoint: '%#v'; returned sts_endpoint: '%#v'",
|
|
|
|
data["sts_endpoint"], resp.Data["sts_endpoint"])
|
|
|
|
}
|
|
|
|
if resp.Data["sts_region"] != data["sts_region"] {
|
|
|
|
t.Fatalf("expected sts_region: '%#v'; returned sts_region: '%#v'",
|
|
|
|
data["sts_region"], resp.Data["sts_region"])
|
|
|
|
}
|
2017-07-17 15:08:57 +00:00
|
|
|
|
|
|
|
data = map[string]interface{}{
|
2019-12-11 00:02:04 +00:00
|
|
|
"sts_endpoint": "https://my-custom-sts-endpoint2.example.com",
|
|
|
|
"sts_region": "us-west-1",
|
2017-07-17 15:08:57 +00:00
|
|
|
"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"])
|
|
|
|
}
|
2019-12-11 00:02:04 +00:00
|
|
|
if resp.Data["sts_endpoint"] != data["sts_endpoint"] {
|
|
|
|
t.Fatalf("expected sts_endpoint: '%#v'; returned sts_endpoint: '%#v'",
|
|
|
|
data["sts_endpoint"], resp.Data["sts_endpoint"])
|
|
|
|
}
|
|
|
|
if resp.Data["sts_region"] != data["sts_region"] {
|
|
|
|
t.Fatalf("expected sts_region: '%#v'; returned sts_region: '%#v'",
|
|
|
|
data["sts_region"], resp.Data["sts_region"])
|
|
|
|
}
|
2017-04-24 19:15:50 +00:00
|
|
|
}
|