Skip to content

Commit c1a6690

Browse files
authored
chore: sync foss changes (#2359)
1 parent b94a290 commit c1a6690

36 files changed

+902
-151
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
from unittest.case import skipIf
2+
3+
from integration.config.service_names import CUSTOM_DOMAIN
4+
from integration.helpers.base_internal_test import BaseInternalTest
5+
from integration.helpers.file_resources import FILE_TO_S3_URI_MAP
6+
from integration.helpers.resource import current_region_not_included
7+
8+
9+
@skipIf(
10+
current_region_not_included([CUSTOM_DOMAIN]),
11+
"CustomDomain is not supported in this testing region",
12+
)
13+
class TestCustomHttpApiDomains(BaseInternalTest):
14+
def test_custom_http_api_domains_regional(self):
15+
self.create_and_verify_stack("combination/http_api_with_custom_domains_regional")
16+
17+
domain_name_list = self.get_stack_resources("AWS::ApiGatewayV2::DomainName")
18+
self.assertEqual(1, len(domain_name_list))
19+
20+
domain_name_id = self.get_physical_id_by_type("AWS::ApiGatewayV2::DomainName")
21+
22+
api_gateway_client = self.client_provider.api_v2_client
23+
result = api_gateway_client.get_domain_name(DomainName=domain_name_id)
24+
25+
self.assertEqual("httpapi.sam-gamma-regional.com", result["DomainName"])
26+
27+
mtls_auth_config = result["MutualTlsAuthentication"]
28+
self.assertEqual(FILE_TO_S3_URI_MAP["MTLSCert.pem"]["uri"], mtls_auth_config["TruststoreUri"])
29+
30+
domain_name_configs = result["DomainNameConfigurations"]
31+
self.assertEqual(1, len(domain_name_configs))
32+
domain_name_config = domain_name_configs[0]
33+
34+
self.assertEqual("REGIONAL", domain_name_config["EndpointType"])
35+
self.assertEqual("TLS_1_2", domain_name_config["SecurityPolicy"])
36+
37+
def test_custom_http_api_domains_regional_ownership_verification(self):
38+
self.create_and_verify_stack("combination/http_api_with_custom_domains_regional_ownership_verification")
39+
40+
domain_name_id = self.get_physical_id_by_type("AWS::ApiGatewayV2::DomainName")
41+
api_gateway_client = self.client_provider.api_v2_client
42+
result = api_gateway_client.get_domain_name(DomainName=domain_name_id)
43+
44+
domain_name_configs = result["DomainNameConfigurations"]
45+
self.assertEqual(1, len(domain_name_configs))
46+
domain_name_config = domain_name_configs[0]
47+
48+
self.assertIsNotNone(domain_name_config.get("OwnershipVerificationCertificateArn"))
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
from unittest.case import skipIf
2+
3+
from integration.config.service_names import CUSTOM_DOMAIN
4+
from integration.helpers.base_internal_test import BaseInternalTest
5+
from integration.helpers.file_resources import FILE_TO_S3_URI_MAP
6+
from integration.helpers.resource import current_region_not_included
7+
8+
9+
@skipIf(
10+
current_region_not_included([CUSTOM_DOMAIN]),
11+
"CustomDomain is not supported in this testing region",
12+
)
13+
class TestCustomRestApiDomains(BaseInternalTest):
14+
def test_custom_rest_api_domains_edge(self):
15+
self.create_and_verify_stack("combination/api_with_custom_domains_edge")
16+
domain_name_list = self.get_stack_resources("AWS::ApiGateway::DomainName")
17+
self.assertEqual(1, len(domain_name_list))
18+
19+
domain_name_id = self.get_physical_id_by_type("AWS::ApiGateway::DomainName")
20+
api_gateway_client = self.client_provider.api_client
21+
result = api_gateway_client.get_domain_name(domainName=domain_name_id)
22+
23+
self.assertEqual("sam-gamma-edge.com", result["domainName"])
24+
25+
end_point_config = result["endpointConfiguration"]
26+
end_point_types = end_point_config["types"]
27+
self.assertEqual(1, len(end_point_types))
28+
self.assertEqual("EDGE", end_point_types[0])
29+
30+
def test_custom_rest_api_domains_regional(self):
31+
self.create_and_verify_stack("combination/api_with_custom_domains_regional")
32+
33+
domain_name_list = self.get_stack_resources("AWS::ApiGateway::DomainName")
34+
self.assertEqual(1, len(domain_name_list))
35+
36+
domain_name_id = self.get_physical_id_by_type("AWS::ApiGateway::DomainName")
37+
38+
api_gateway_client = self.client_provider.api_client
39+
result = api_gateway_client.get_domain_name(domainName=domain_name_id)
40+
41+
self.assertEqual("sam-gamma-regional.com", result["domainName"])
42+
self.assertEqual("TLS_1_2", result["securityPolicy"])
43+
44+
end_point_config = result["endpointConfiguration"]
45+
end_point_types = end_point_config["types"]
46+
self.assertEqual(1, len(end_point_types))
47+
self.assertEqual("REGIONAL", end_point_types[0])
48+
49+
mtls_auth_config = result["mutualTlsAuthentication"]
50+
self.assertEqual(FILE_TO_S3_URI_MAP["MTLSCert.pem"]["uri"], mtls_auth_config["truststoreUri"])
51+
52+
def test_custom_rest_api_domains_regional_ownership_verification(self):
53+
self.create_and_verify_stack("combination/api_with_custom_domains_regional_ownership_verification")
54+
55+
domain_name_id = self.get_physical_id_by_type("AWS::ApiGateway::DomainName")
56+
api_gateway_client = self.client_provider.api_client
57+
result = api_gateway_client.get_domain_name(domainName=domain_name_id)
58+
59+
self.assertIsNotNone(result.get("ownershipVerificationCertificateArn"))

integration/combination/test_function_with_alias.py

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@ def test_updating_version_by_changing_property_value(self):
1818

1919
# Changing CodeUri should create a new version, and leave the existing version in tact
2020
self.set_template_resource_property("MyLambdaFunction", "CodeUri", self.file_to_s3_uri_map["code2.zip"]["uri"])
21-
self.transform_template()
22-
self.deploy_stack()
21+
self.update_stack()
2322

2423
version_ids = self.get_function_version_by_name(function_name)
2524
self.assertEqual(["1", "2"], version_ids)
@@ -43,8 +42,7 @@ def test_alias_deletion_must_retain_version(self):
4342
# Check that the DeletionPolicy on Lambda Version holds good
4443
# Remove alias, update stack, and verify the version still exists by calling Lambda APIs
4544
self.remove_template_resource_property("MyLambdaFunction", "AutoPublishAlias")
46-
self.transform_template()
47-
self.deploy_stack()
45+
self.update_stack()
4846

4947
# Make sure both Lambda version & alias resource does not exist in stack
5048
alias = self.get_stack_resources("AWS::Lambda::Alias")
@@ -71,13 +69,13 @@ def test_function_with_alias_with_intrinsics(self):
7169
# Let's change Key by updating the template parameter, but keep template same
7270
# This should create a new version and leave existing version intact
7371
parameters[1]["ParameterValue"] = "code2.zip"
74-
# self.deploy_stack(parameters)
75-
self.update_stack("combination/function_with_alias_intrinsics", parameters)
72+
73+
self.update_stack(parameters)
7674
version_ids = get_function_versions(function_name, self.client_provider.lambda_client)
75+
self.assertEqual(["1", "2"], version_ids)
7776

78-
self.assertEqual(["1"], version_ids)
7977
alias = self.get_alias(function_name, alias_name)
80-
self.assertEqual("1", alias["FunctionVersion"])
78+
self.assertEqual("2", alias["FunctionVersion"])
8179

8280
def test_alias_in_globals_with_overrides(self):
8381
# It is good enough if we can create a stack. Globals are pre-processed on the SAM template and don't
@@ -111,8 +109,7 @@ def test_alias_with_event_sources_get_correct_permissions(self):
111109

112110
# Remove the alias, deploy the stack, and verify that *all* permission entities transfer to the function
113111
self.remove_template_resource_property("MyAwesomeFunction", "AutoPublishAlias")
114-
self.transform_template()
115-
self.deploy_stack()
112+
self.update_stack()
116113

117114
# Get the policies on both function & alias
118115
# Alias should have *no* policies

integration/combination/test_function_with_deployment_preference.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,7 @@ def test_flip_from_disable_to_enable(self):
4141
pref["Enabled"] = "True"
4242
self.set_template_resource_property("MyLambdaFunction", "DeploymentPreference", pref)
4343

44-
self.transform_template()
45-
self.deploy_stack(self.get_default_test_template_parameters())
44+
self.update_stack(self.get_default_test_template_parameters())
4645

4746
self._verify_no_deployment_then_update_and_verify_deployment(self.get_default_test_template_parameters())
4847

@@ -77,8 +76,7 @@ def _verify_no_deployment_then_update_and_verify_deployment(self, parameters=Non
7776
self.set_template_resource_property(
7877
LAMBDA_FUNCTION_NAME, "CodeUri", self.file_to_s3_uri_map["code2.zip"]["uri"]
7978
)
80-
self.transform_template()
81-
self.deploy_stack(parameters)
79+
self.update_stack(parameters)
8280

8381
for deployment_group in deployment_groups:
8482
deployments = self._get_deployments(application_name, deployment_group)
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
from integration.helpers.base_test import BaseTest
2+
from integration.helpers.common_api import get_policy_statements
3+
4+
5+
class TestFunctionWithPolicyTemplates(BaseTest):
6+
def test_with_policy_templates(self):
7+
self.create_and_verify_stack("combination/function_with_policy_templates")
8+
role_name = self.get_physical_id_by_type("AWS::IAM::Role")
9+
10+
# There should be three policies created. Each policy has the name <resource-logicalid>Policy<index>
11+
12+
# Verify the contents of first policy
13+
sqs_poller_policy = get_policy_statements(role_name, "MyFunctionRolePolicy0", self.client_provider.iam_client)
14+
self.assertEqual(len(sqs_poller_policy), 1, "Only one statement must be in SQS Poller policy")
15+
16+
sqs_policy_statement = sqs_poller_policy[0]
17+
self.assertTrue(type(sqs_policy_statement["Resource"]) != list)
18+
19+
queue_url = self.get_physical_id_by_type("AWS::SQS::Queue")
20+
parts = queue_url.split("/")
21+
expected_queue_name = parts[-1]
22+
actual_queue_arn = sqs_policy_statement["Resource"]
23+
self.assertTrue(
24+
actual_queue_arn.endswith(expected_queue_name),
25+
"Queue Arn " + actual_queue_arn + " must end with suffix " + expected_queue_name,
26+
)
27+
28+
# Verify the contents of second policy
29+
lambda_invoke_policy = get_policy_statements(
30+
role_name, "MyFunctionRolePolicy1", self.client_provider.iam_client
31+
)
32+
self.assertEqual(len(lambda_invoke_policy), 1, "One policies statements should be present")
33+
34+
lambda_policy_statement = lambda_invoke_policy[0]
35+
self.assertTrue(type(lambda_policy_statement["Resource"]) != list)
36+
37+
# NOTE: The resource ARN has "*" suffix to allow for any Lambda function version as well
38+
expected_function_suffix = "function:somename*"
39+
actual_function_arn = lambda_policy_statement["Resource"]
40+
self.assertTrue(
41+
actual_function_arn.endswith(expected_function_suffix),
42+
"Function ARN " + actual_function_arn + " must end with suffix " + expected_function_suffix,
43+
)
44+
45+
# Verify the contents of third policy
46+
cloud_watch_put_metric_policy = get_policy_statements(
47+
role_name, "MyFunctionRolePolicy2", self.client_provider.iam_client
48+
)
49+
self.assertEqual(
50+
len(cloud_watch_put_metric_policy), 1, "Only one statement must be in CloudWatchPutMetricPolicy"
51+
)
52+
53+
cloud_watch_put_metric_statement = cloud_watch_put_metric_policy[0]
54+
self.assertEqual(cloud_watch_put_metric_statement.get("Resource"), "*")
55+
56+
def test_all_policy_templates(self):
57+
# template too large, upload it to s3
58+
self.create_and_verify_stack("combination/all_policy_templates", s3_uploader=self.s3_uploader)
59+
60+
iam_roles = self.get_stack_resources("AWS::IAM::Role")
61+
actual_num_polices = 0
62+
63+
for iam_role in iam_roles:
64+
role_name = iam_role.get("PhysicalResourceId")
65+
result = self.client_provider.iam_client.list_role_policies(RoleName=role_name)
66+
policy_names = result.get("PolicyNames")
67+
actual_num_polices += len(policy_names)
68+
69+
expected_num_polices = 69
70+
self.assertEqual(actual_num_polices, expected_num_polices)

integration/combination/test_function_with_signing_profile.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from integration.config.service_names import CODE_SIGN
66

77

8-
class TestDependsOn(BaseTest):
8+
class TestFunctionWithSigningProfile(BaseTest):
99
@skipIf(current_region_does_not_support([CODE_SIGN]), "CodeSign is not supported in this testing region")
1010
def test_function_with_signing_profile(self):
1111
self.create_and_verify_stack("combination/function_with_signing_profile")

integration/combination/test_http_api_with_auth.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def test_function_with_user_pool_event(self):
5555
self.assertEqual(oauth_2_auth["IdentitySource"][0], "$request.querystring.param")
5656

5757
# Test updating stack
58-
self.update_stack("combination/http_api_with_auth_updated")
58+
self.update_stack(file_path="combination/http_api_with_auth_updated")
5959

6060
http_api_list_updated = self.get_stack_resources("AWS::ApiGatewayV2::Api")
6161
self.assertEqual(len(http_api_list_updated), 1)

integration/combination/test_http_api_with_disable_execute_api_endpoint.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
from parameterized import parameterized
44

55
from integration.helpers.base_test import BaseTest
6-
from integration.helpers.resource import current_region_does_not_support
6+
from integration.helpers.resource import current_region_not_included
77
from integration.config.service_names import CUSTOM_DOMAIN
88

99

10-
@skipIf(current_region_does_not_support([CUSTOM_DOMAIN]), "CustomDomain is not supported in this testing region")
10+
@skipIf(current_region_not_included([CUSTOM_DOMAIN]), "CustomDomain is not supported in this testing region")
1111
class TestHttpApiWithDisableExecuteApiEndpoint(BaseTest):
1212
@parameterized.expand(
1313
[

0 commit comments

Comments
 (0)