-
Notifications
You must be signed in to change notification settings - Fork 372
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Ignore principals order when comparing policies
AWS returns items in a random order so provider-aws should ignore it to not consider policies changed. Signed-off-by: Max Melentyev <[email protected]>
- Loading branch information
1 parent
bddb183
commit 8faf89e
Showing
9 changed files
with
258 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
{ | ||
"Version": "2012-10-17", | ||
"Statement": [{ | ||
"Effect": "Allow", | ||
"Principal": { | ||
"Service": [ | ||
"eks.amazonaws.com", | ||
"sqs.amazonaws.com" | ||
], | ||
"AWS": [ | ||
"arn:aws:iam::123456789012:bbb", | ||
"arn:aws:iam::123456789012:aaa" | ||
] | ||
}, | ||
"NotPrincipal": { | ||
"Service": [ | ||
"s3.amazonaws.com", | ||
"ec2.amazonaws.com" | ||
], | ||
"AWS": [ | ||
"arn:aws:iam::123456789012:ddd", | ||
"arn:aws:iam::123456789012:ccc" | ||
] | ||
}, | ||
"Action": ["sts:AssumeRole"] | ||
}] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
{ | ||
"Version": "2012-10-17", | ||
"Statement": [{ | ||
"Effect": "Allow", | ||
"Principal": { | ||
"Service": [ | ||
"sqs.amazonaws.com", | ||
"eks.amazonaws.com" | ||
], | ||
"AWS": [ | ||
"arn:aws:iam::123456789012:aaa", | ||
"arn:aws:iam::123456789012:bbb" | ||
] | ||
}, | ||
"NotPrincipal": { | ||
"Service": [ | ||
"ec2.amazonaws.com", | ||
"s3.amazonaws.com" | ||
], | ||
"AWS": [ | ||
"arn:aws:iam::123456789012:ccc", | ||
"arn:aws:iam::123456789012:ddd" | ||
] | ||
}, | ||
"Action": ["sts:AssumeRole"] | ||
}] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
{ | ||
"Version": "2012-10-17", | ||
"Statement": [{ | ||
"Effect": "Allow", | ||
"Principal": { | ||
"Service": [ | ||
"sqs.amazonaws.com", | ||
"eks.amazonaws.com" | ||
], | ||
"AWS": [ | ||
"arn:aws:iam::123456789012:aaa", | ||
"arn:aws:iam::123456789012:bbb" | ||
] | ||
}, | ||
"NotPrincipal": { | ||
"Service": [ | ||
"ec2.amazonaws.com", | ||
"s3.amazonaws.com" | ||
], | ||
"AWS": [ | ||
"arn:aws:iam::123456789012:ccc", | ||
"arn:aws:iam::123456789012:eee", | ||
"arn:aws:iam::123456789012:ddd" | ||
] | ||
}, | ||
"Action": ["sts:AssumeRole"] | ||
}] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
package policy | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/google/go-cmp/cmp" | ||
) | ||
|
||
func TestStringOrSet_Equal(t *testing.T) { | ||
cases := map[string]struct { | ||
a, b StringOrSet | ||
equal bool | ||
}{ | ||
"BothNil": { | ||
a: nil, | ||
b: nil, | ||
equal: true, | ||
}, | ||
"BothEmpty": { | ||
a: NewStringOrSet(), | ||
b: NewStringOrSet(), | ||
equal: true, | ||
}, | ||
"EqualDifferentOrder": { | ||
a: NewStringOrSet("a", "b"), | ||
b: NewStringOrSet("b", "a"), | ||
equal: true, | ||
}, | ||
"NotEqual": { | ||
a: NewStringOrSet("a", "b"), | ||
b: NewStringOrSet("a", "c"), | ||
equal: false, | ||
}, | ||
} | ||
|
||
for name, tc := range cases { | ||
t.Run(name, func(t *testing.T) { | ||
if diff := cmp.Diff(tc.a, tc.b); (diff == "") != tc.equal { | ||
t.Errorf("diff: %s", diff) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func TestStringOrSet_MarshalJSON(t *testing.T) { | ||
cases := map[string]struct { | ||
set StringOrSet | ||
want string | ||
}{ | ||
"nil": { | ||
set: nil, | ||
want: "null", | ||
}, | ||
"Empty": { | ||
set: NewStringOrSet(), | ||
want: "[]", | ||
}, | ||
"Single": { | ||
set: NewStringOrSet("a"), | ||
want: `["a"]`, | ||
}, | ||
"Multiple": { | ||
set: NewStringOrSet("a", "c", "b"), | ||
want: `["a","b","c"]`, | ||
}, | ||
} | ||
|
||
for name, tc := range cases { | ||
t.Run(name, func(t *testing.T) { | ||
b, err := tc.set.MarshalJSON() | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
if string(b) != tc.want { | ||
t.Errorf("got %s, want %s", b, tc.want) | ||
} | ||
}) | ||
} | ||
} |