Skip to content

Commit

Permalink
test: fix no policy issue
Browse files Browse the repository at this point in the history
  • Loading branch information
JacksonTian authored and yndu13 committed Sep 27, 2023
1 parent bdc156f commit d5fd386
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 13 deletions.
28 changes: 15 additions & 13 deletions integration/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,17 @@ import (
)

var role_doc = `{
"Statement": [{
"Action": "sts:AssumeRole",
"Effect": "Allow",
"Principal": {
"RAM": [
"acs:ram::%s:root"
]
"Statement": [
{
"Action": "sts:AssumeRole",
"Effect": "Allow",
"Principal": {
"RAM": [
"acs:ram::%s:root"
]
}
}
}],
],
"Version": "1"
}`

Expand Down Expand Up @@ -181,29 +183,29 @@ func createAccessKey() (id string, secret string, err error) {
func createAssumeRole() (response *sts.AssumeRoleResponse, err error) {
err = createUser()
if err != nil {
return nil, err
return
}

subaccesskeyid, subaccesskeysecret, err := createAccessKey()
if err != nil {
return nil, err
return
}

_, _, err = createRole(os.Getenv("USER_ID"))
if err != nil {
return nil, err
return
}
err = createAttachPolicyToUser()
if err != nil {
return nil, err
return
}
request := sts.CreateAssumeRoleRequest()
request.RoleArn = rolearn
request.RoleSessionName = "alice_test"
request.Scheme = "HTTPS"
client, err := sts.NewClientWithAccessKey(os.Getenv("REGION_ID"), subaccesskeyid, subaccesskeysecret)
if err != nil {
return nil, err
return
}
response, err = client.AssumeRole(request)
return
Expand Down
4 changes: 4 additions & 0 deletions integration/core_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,10 @@ func Test_DescribeClustersWithCommonRequestWithSignatureDostNotMatch(t *testing.
func Test_DescribeClustersWithCommonRequestWithROAWithSTStoken(t *testing.T) {
assumeresponse, err := createAssumeRole()
assert.Nil(t, err)

err = createAttachPolicyToRole()
assert.Nil(t, err)

credential := assumeresponse.Credentials
client, err := sdk.NewClientWithStsToken(os.Getenv("REGION_ID"), credential.AccessKeyId, credential.AccessKeySecret, credential.SecurityToken)
assert.Nil(t, err)
Expand Down

0 comments on commit d5fd386

Please sign in to comment.