Skip to content

Commit ad01095

Browse files
authored
Merge pull request #1790 from MisterMX/backport-1789-to-release-0.41
2 parents 6a78699 + 6d34a80 commit ad01095

2 files changed

Lines changed: 42 additions & 2 deletions

File tree

pkg/clients/iam/policy.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package iam
22

33
import (
44
"context"
5+
"net/url"
56

67
"github.com/crossplane-contrib/provider-aws/apis/iam/v1beta1"
78

@@ -49,7 +50,11 @@ func IsPolicyUpToDate(in v1beta1.PolicyParameters, policy iamtypes.PolicyVersion
4950
return false, "", nil
5051
}
5152

52-
externpolicy, err := policyutils.ParsePolicyString(externalPolicyRaw)
53+
unescapedPolicy, err := url.QueryUnescape(aws.ToString(policy.Document))
54+
if err != nil {
55+
return false, "", err
56+
}
57+
externpolicy, err := policyutils.ParsePolicyString(unescapedPolicy)
5358
if err != nil {
5459
return false, "", err
5560
}

pkg/controller/iam/policy/controller_test.go

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package policy
1818

1919
import (
2020
"context"
21+
"net/url"
2122

2223
"testing"
2324

@@ -61,7 +62,8 @@ var (
6162
}
6263
]
6364
}`
64-
boolFalse = false
65+
documentURLEscaped = url.QueryEscape(document)
66+
boolFalse = false
6567

6668
errBoom = errors.New("boom")
6769

@@ -209,6 +211,39 @@ func TestObserve(t *testing.T) {
209211
},
210212
},
211213
},
214+
"SuccessfulURLEscapedPolicy": {
215+
args: args{
216+
iam: &fake.MockPolicyClient{
217+
MockGetPolicy: func(ctx context.Context, input *awsiam.GetPolicyInput, opts []func(*awsiam.Options)) (*awsiam.GetPolicyOutput, error) {
218+
return &awsiam.GetPolicyOutput{
219+
Policy: &awsiamtypes.Policy{},
220+
}, nil
221+
},
222+
MockGetPolicyVersion: func(ctx context.Context, input *awsiam.GetPolicyVersionInput, opts []func(*awsiam.Options)) (*awsiam.GetPolicyVersionOutput, error) {
223+
return &awsiam.GetPolicyVersionOutput{
224+
PolicyVersion: &awsiamtypes.PolicyVersion{
225+
Document: &documentURLEscaped,
226+
},
227+
}, nil
228+
},
229+
},
230+
cr: policy(withSpec(v1beta1.PolicyParameters{
231+
Document: document,
232+
Name: name,
233+
}), withExternalName(policyArn)),
234+
},
235+
want: want{
236+
cr: policy(withSpec(v1beta1.PolicyParameters{
237+
Document: document,
238+
Name: name,
239+
}), withExternalName(policyArn),
240+
withConditions(xpv1.Available())),
241+
result: managed.ExternalObservation{
242+
ResourceExists: true,
243+
ResourceUpToDate: true,
244+
},
245+
},
246+
},
212247
"InValidInput": {
213248
args: args{
214249
cr: unexpectedItem,

0 commit comments

Comments
 (0)