Skip to content

Commit

Permalink
fix aws config tests
Browse files Browse the repository at this point in the history
  • Loading branch information
vinay-gopalan committed Jan 6, 2025
1 parent cbba982 commit 1d93da9
Showing 1 changed file with 57 additions and 39 deletions.
96 changes: 57 additions & 39 deletions builtin/logical/aws/path_config_root_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,23 @@ func TestBackend_PathConfigRoot(t *testing.T) {
}

configData := map[string]interface{}{
"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",
"sts_region": "",
"sts_fallback_endpoints": []string{},
"sts_fallback_regions": []string{},
"max_retries": 10,
"username_template": defaultUserNameTemplate,
"role_arn": "",
"identity_token_audience": "",
"identity_token_ttl": int64(0),
"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",
"sts_region": "",
"sts_fallback_endpoints": []string{},
"sts_fallback_regions": []string{},
"max_retries": 10,
"username_template": defaultUserNameTemplate,
"role_arn": "",
"identity_token_audience": "",
"identity_token_ttl": int64(0),
"rotation_schedule": "",
"rotation_window": 0,
"rotation_id": "",
"disable_automated_rotation": false,
}

configReq := &logical.Request{
Expand All @@ -65,6 +69,8 @@ func TestBackend_PathConfigRoot(t *testing.T) {
}

delete(configData, "secret_key")
// remove rotation_ttl from response for comparison with original config
delete(resp.Data, "rotation_ttl")
require.Equal(t, configData, resp.Data)
if !reflect.DeepEqual(resp.Data, configData) {
t.Errorf("bad: expected to read config root as %#v, got %#v instead", configData, resp.Data)
Expand All @@ -83,19 +89,23 @@ func TestBackend_PathConfigRoot_STSFallback(t *testing.T) {
}

configData := map[string]interface{}{
"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",
"sts_region": "",
"sts_fallback_endpoints": []string{"192.168.1.1", "127.0.0.1"},
"sts_fallback_regions": []string{"my-house-1", "my-house-2"},
"max_retries": 10,
"username_template": defaultUserNameTemplate,
"role_arn": "",
"identity_token_audience": "",
"identity_token_ttl": int64(0),
"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",
"sts_region": "",
"sts_fallback_endpoints": []string{"192.168.1.1", "127.0.0.1"},
"sts_fallback_regions": []string{"my-house-1", "my-house-2"},
"max_retries": 10,
"username_template": defaultUserNameTemplate,
"role_arn": "",
"identity_token_audience": "",
"identity_token_ttl": int64(0),
"rotation_schedule": "",
"rotation_window": 0,
"rotation_id": "",
"disable_automated_rotation": false,
}

configReq := &logical.Request{
Expand All @@ -120,26 +130,32 @@ func TestBackend_PathConfigRoot_STSFallback(t *testing.T) {
}

delete(configData, "secret_key")
// remove rotation_ttl from response for comparison with original config
delete(resp.Data, "rotation_ttl")
require.Equal(t, configData, resp.Data)
if !reflect.DeepEqual(resp.Data, configData) {
t.Errorf("bad: expected to read config root as %#v, got %#v instead", configData, resp.Data)
}

// test we can handle comma separated strings, per CommaStringSlice
configData = map[string]interface{}{
"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",
"sts_region": "",
"sts_fallback_endpoints": "1.1.1.1,8.8.8.8",
"sts_fallback_regions": "zone-1,zone-2",
"max_retries": 10,
"username_template": defaultUserNameTemplate,
"role_arn": "",
"identity_token_audience": "",
"identity_token_ttl": int64(0),
"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",
"sts_region": "",
"sts_fallback_endpoints": "1.1.1.1,8.8.8.8",
"sts_fallback_regions": "zone-1,zone-2",
"max_retries": 10,
"username_template": defaultUserNameTemplate,
"role_arn": "",
"identity_token_audience": "",
"identity_token_ttl": int64(0),
"rotation_schedule": "",
"rotation_window": 0,
"rotation_id": "",
"disable_automated_rotation": false,
}

configReq = &logical.Request{
Expand All @@ -164,6 +180,8 @@ func TestBackend_PathConfigRoot_STSFallback(t *testing.T) {
}

delete(configData, "secret_key")
// remove rotation_ttl from response for comparison with original config
delete(resp.Data, "rotation_ttl")
configData["sts_fallback_endpoints"] = []string{"1.1.1.1", "8.8.8.8"}
configData["sts_fallback_regions"] = []string{"zone-1", "zone-2"}
require.Equal(t, configData, resp.Data)
Expand Down

0 comments on commit 1d93da9

Please sign in to comment.