8000 Add additional tests · localstack/localstack@4c623ae · GitHub
[go: up one dir, main page]

Skip to content

Commit 4c623ae

Browse files
committed
Add additional tests
1 parent 8c0e6cf commit 4c623ae

File tree

4 files changed

+178
-7
lines changed

4 files changed

+178
-7
lines changed

localstack-core/localstack/testing/snapshots/transformer_utility.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,7 @@ def iam_api():
345345
TransformerUtility.key_value("RoleName"),
346346
TransformerUtility.key_value("PolicyName"),
347347
TransformerUtility.key_value("PolicyId"),
348+
TransformerUtility.key_value("GroupName"),
348349
]
349350

350351
@staticmethod

tests/aws/services/iam/test_iam.py

Lines changed: 80 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -744,8 +744,10 @@ def test_user_attach_policy(self, snapshot, aws_client, create_user, create_poli
744744
)
745745
snapshot.match("valid_policy_arn", attach_policy_response)
746746

747+
748+
class TestIAMPolicyEncoding:
747749
@markers.aws.validated
748-
def test_put_policy_encoding(self, snapshot, aws_client, create_user, region_name):
750+
def test_put_user_policy_encoding(self, snapshot, aws_client, create_user, region_name):
749751
snapshot.add_transformer(snapshot.transform.iam_api())
750752

751753
target_arn = quote_plus(f"arn:aws:apigateway:{region_name}::/restapis/aaeeieije")
@@ -760,7 +762,7 @@ def test_put_policy_encoding(self, snapshot, aws_client, create_user, region_nam
760762
],
761763
}
762764

763-
user_name = f"test-role-{short_uid()}"
765+
user_name = f"test-user-{short_uid()}"
764766
policy_name = f"test-policy-{short_uid()}"
765767
create_user(UserName=user_name)
766768

@@ -771,3 +773,79 @@ def test_put_policy_encoding(self, snapshot, aws_client, create_user, region_nam
771773
UserName=user_name, PolicyName=policy_name
772774
)
773775
snapshot.match("get-policy-response", get_policy_response)
776+
777+
@markers.aws.validated
778+
def test_put_role_policy_encoding(self, snapshot, aws_client, create_role, region_name):
779+
snapshot.add_transformer(snapshot.transform.iam_api())
780+
781+
target_arn = quote_plus(f"arn:aws:apigateway:{region_name}::/restapis/aaeeieije")
782+
policy_document = {
783+
"Version": "2012-10-17",
784+
"Statement": [
785+
{
786+
"Effect": "Allow",
787+
"Action": ["apigatway:PUT"],
788+
"Resource": [f"arn:aws:apigateway:{region_name}::/tags/{target_arn}"],
789+
}
790+
],
791+
}
792+
assume_policy_document = {
793+
"Version": "2012-10-17",
794+
"Statement": [
795+
{
796+
"Action": "sts:AssumeRole",
797+
"Principal": {"Service": "lambda.amazonaws.com"},
798+
"Effect": "Allow",
799+
"Condition": {"StringEquals": {"aws:SourceArn": target_arn}},
800+
}
801+
],
802+
}
803+
804+
role_name = f"test-role-{short_uid()}"
805+
policy_name = f"test-policy-{short_uid()}"
806+
create_role(RoleName=role_name, AssumeRolePolicyDocument=json.dumps(assume_policy_document))
807+
808+
aws_client.iam.put_role_policy(
809+
RoleName=role_name, PolicyName=policy_name, PolicyDocument=json.dumps(policy_document)
810+
)
811+
get_policy_response = aws_client.iam.get_role_policy(
812+
RoleName=role_name, PolicyName=policy_name
813+
)
814+
snapshot.match("get-policy-response", get_policy_response)
815+
816+
get_role_response = aws_client.iam.get_role(RoleName=role_name)
817+
snapshot.match("get-role-response", get_role_response)
818+
819+
@markers.aws.validated
820+
def test_put_group_policy_encoding(self, snapshot, aws_client, region_name, cleanups):
821+
snapshot.add_transformer(snapshot.transform.iam_api())
822+
823+
# create quoted target arn
824+
target_arn = quote_plus(f"arn:aws:apigateway:{region_name}::/restapis/aaeeieije")
825+
policy_document = {
826+
"Version": "2012-10-17",
827+
"Statement": [
828+
{
829+
"Effect": "Allow",
830+
"Action": ["apigatway:PUT"],
831+
"Resource": [f"arn:aws:apigateway:{region_name}::/tags/{target_arn}"],
832+
}
833+
],
834+
}
835+
836+
group_name = f"test-group-{short_uid()}"
837+
policy_name = f"test-policy-{short_uid()}"
838+
aws_client.iam.create_group(GroupName=group_name)
839+
cleanups.append(lambda: aws_client.iam.delete_group(GroupName=group_name))
840+
841+
aws_client.iam.put_group_policy(
842+
GroupName=group_name, PolicyName=policy_name, PolicyDocument=json.dumps(policy_document)
843+
)
844+
cleanups.append(
845+
lambda: aws_client.iam.delete_group_policy(GroupName=group_name, PolicyName=policy_name)
846+
)
847+
848+
get_policy_response = aws_client.iam.get_group_policy(
849+
GroupName=group_name, PolicyName=policy_name
850+
)
851+
snapshot.match("get-policy-response", get_policy_response)

tests/aws/services/iam/test_iam.snapshot.json

Lines changed: 88 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -387,8 +387,8 @@
387387
}
388388
}
389389
},
390-
"tests/aws/services/iam/test_iam.py::TestIAMIntegrations::test_put_policy_encoding": {
391-
"recorded-date": "23-09-2024, 12:33:47",
390+
"tests/aws/services/iam/test_iam.py::TestIAMPolicyEncoding::test_put_user_policy_encoding": {
391+
"recorded-date": "25-09-2024, 15:10:45",
392392
"recorded-content": {
393393
"get-policy-response": {
394394
"PolicyDocument": {
@@ -413,5 +413,91 @@
413413
}
414414
}
415415
}
416+
},
417+
"tests/aws/services/iam/test_iam.py::TestIAMPolicyEncoding::test_put_role_policy_encoding": {
418+
"recorded-date": "25-09-2024, 15:10:46",
419+
"recorded-content": {
420+
"get-policy-response": {
421+
"PolicyDocument": {
422+
"Statement": [
423+
{
424+
"Action": [
425+
"apigatway:PUT"
426+
],
427+
"Effect": "Allow",
428+
"Resource": [
429+
"arn:<partition>:apigateway:<region>::/tags/arn%3Aaws%3Aapigateway%3A<region>%3A%3A%2Frestapis%2Faaeeieije"
430+
]
431+
}
432+
],
433+
"Version": "2012-10-17"
434+
},
435+
"PolicyName": "<policy-name:1>",
436+
"RoleName": "<role-name:1>",
437+
"ResponseMetadata": {
438+
"HTTPHeaders": {},
439+
"HTTPStatusCode": 200
440+
}
441+
},
442+
"get-role-response": {
443+
"Role": {
444+
"Arn": "arn:<partition>:iam::111111111111:role/<role-name:1>",
445+
"AssumeRolePolicyDocument": {
446+
"Statement": [
447+
{
448+
"Action": "sts:AssumeRole",
449+
"Condition": {
450+
"StringEquals": {
451+
"aws:SourceArn": "arn%3Aaws%3Aapigateway%3A<region>%3A%3A%2Frestapis%2Faaeeieije"
452+
}
453+
},
454+
"Effect": "Allow",
455+
"Principal": {
456+
"Service": "lambda.amazonaws.com"
457+
}
458+
}
459+
],
460+
"Version": "2012-10-17"
461+
},
462+
"CreateDate": "datetime",
463+
"MaxSessionDuration": 3600,
464+
"Path": "/",
465+
"RoleId": "<role-id:1>",
466+
"RoleLastUsed": {},
467+
"RoleName": "<role-name:1>"
468+
},
469+
"ResponseMetadata": {
470+
"HTTPHeaders": {},
471+
"HTTPStatusCode": 200
472+
}
473+
}
474+
}
475+
},
476+
"tests/aws/services/iam/test_iam.py::TestIAMPolicyEncoding::test_put_group_policy_encoding": {
477+
"recorded-date": "25-09-2024, 15:10:47",
478+
"recorded-content": {
479+
"get-policy-response": {
480+
"GroupName": "<group-name:1>",
481+
"PolicyDocument": {
482+
"Statement": [
483+
{
484+
"Action": [
485+
"apigatway:PUT"
486+
],
487+
"Effect": "Allow",
488+
"Resource": [
489+
"arn:<partition>:apigateway:<region>::/tags/arn%3Aaws%3Aapigateway%3A<region>%3A%3A%2Frestapis%2Faaeeieije"
490+
]
491+
}
492+
],
493+
"Version": "2012-10-17"
494+
},
495+
"PolicyName": "<policy-name:1>",
496+
"ResponseMetadata": {
497+
"HTTPHeaders": {},
498+
"HTTPStatusCode": 200
499+
}
500+
}
501+
}
416502
}
417503
}

tests/aws/services/iam/test_iam.validation.json

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,6 @@
1111
"tests/aws/services/iam/test_iam.py::TestIAMIntegrations::test_list_roles_with_permission_boundary": {
1212
"last_validated_date": "2023-09-14T15:42:39+00:00"
1313
},
14-
"tests/aws/services/iam/test_iam.py::TestIAMIntegrations::test_put_policy_encoding": {
15-
"last_validated_date": "2024-09-23T12:34:15+00:00"
16-
},
1714
"tests/aws/services/iam/test_iam.py::TestIAMIntegrations::test_role_attach_policy": {
1815
"last_validated_date": "2023-09-14T15:42:42+00:00"
1916
},
@@ -22,5 +19,14 @@
2219
},
2320
"tests/aws/services/iam/test_iam.py::TestIAMIntegrations::test_user_attach_policy": {
2421
"last_validated_date": "2023-09-14T15:42:45+00:00"
22+
},
23+
"tests/aws/services/iam/test_iam.py::TestIAMPolicyEncoding::test_put_group_policy_encoding": {
24+
"last_validated_date": "2024-09-25T15:12:26+00:00"
25+
},
26+
"tests/aws/services/iam/test_iam.py::TestIAMPolicyEncoding::test_put_role_policy_encoding": {
27+
"last_validated_date": "2024-09-25T15:12:24+00:00"
28+
},
29+
"tests/aws/services/iam/test_iam.py::TestIAMPolicyEncoding::test_put_user_policy_encoding": {
30+
"last_validated_date": "2024-09-25T15:12:23+00:00"
2531
}
2632
}

0 commit comments

Comments
 (0)
0