Skip to content

Commit

Permalink
Merge pull request #8 from hashicorp/b-condition-with-empty-array
Browse files Browse the repository at this point in the history
Treat `Condition`s with empty array values as empty string values
  • Loading branch information
ewbankkit committed Jan 12, 2022
2 parents 853611c + 1180d9d commit bd206d4
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
3 changes: 3 additions & 0 deletions aws_policy_equivalence.go
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,9 @@ func newStringSet(members interface{}) stringSet {
return nil
}
}
if len(actions) == 0 {
return stringSet{}
}
return stringSet(actions)
default:
return nil
Expand Down
44 changes: 44 additions & 0 deletions aws_policy_equivalence_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,12 @@ func TestPolicyEquivalence(t *testing.T) {
policy2: policyTest37b,
equivalent: true,
},
{
name: "Condition containing empty array",
policy1: policyTest38a,
policy2: policyTest38b,
equivalent: true,
},
}

for _, tc := range cases {
Expand Down Expand Up @@ -1484,6 +1490,44 @@ const policyTest37b = `{
]
}`

const policyTest38a = `{
"Id":"sqspolicy",
"Statement":[
{
"Action":"sqs:SendMessage",
"Condition":{
"ArnEquals":{
"aws:SourceArn":[]
}
},
"Effect":"Allow",
"Principal":"*",
"Resource":"arn:aws:sqs:***:redacted:redacted",
"Sid":"AllowSNSSubscriptions"
}
],
"Version":"2012-10-17"
}`

const policyTest38b = `{
"Version":"2012-10-17",
"Id":"sqspolicy",
"Statement":[
{
"Sid":"AllowSNSSubscriptions",
"Effect":"Allow",
"Principal":"*",
"Action":"sqs:SendMessage",
"Resource":"arn:aws:sqs:***:redacted:redacted",
"Condition":{
"ArnEquals":{
"aws:SourceArn":[]
}
}
}
]
}`

func TestStringValueSlicesEqualIgnoreOrder(t *testing.T) {
equal := []interface{}{
[]interface{}{
Expand Down

0 comments on commit bd206d4

Please sign in to comment.