Skip to content

Commit 4c3f5f8

Browse files
Merge release-v1.48.0 into main
2 parents 6b0afc5 + a1dead3 commit 4c3f5f8

File tree

77 files changed

+4508
-563
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

77 files changed

+4508
-563
lines changed

INTEGRATION_TESTS.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,14 @@ If you haven't done so already, run the following command in a terminal at the r
3434
make init
3535
```
3636

37+
### Setting up a companion stack
38+
39+
To run the tests, a companion stack first needs to be created. This stack houses some resources that are required by the tests, such as an S3 bucket.
40+
41+
```
42+
make prepare-companion-stack
43+
```
44+
3745
### Running all the tests
3846

3947
From the root of the repository, run:

Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ lint:
2727
# Linter performs static analysis to catch latent bugs
2828
pylint --rcfile .pylintrc samtranslator
2929

30+
prepare-companion-stack:
31+
pytest -v --no-cov integration/setup -m setup
32+
3033
# Command to run everytime you make changes to verify everything works
3134
dev: test
3235

@@ -43,5 +46,6 @@ TARGETS
4346
integ-test Run the Integration tests.
4447
dev Run all development tests after a change.
4548
pr Perform all checks before submitting a Pull Request.
49+
prepare-companion-stack Create or update the companion stack for running integration tests.
4650

4751
endef

integration/combination/test_api_settings.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
import hashlib
2+
from unittest.case import skipIf
3+
4+
from integration.helpers.resource import current_region_does_not_support
5+
from integration.config.service_names import REST_API
26

37
try:
48
from pathlib import Path
@@ -10,6 +14,7 @@
1014
from integration.helpers.base_test import BaseTest
1115

1216

17+
@skipIf(current_region_does_not_support([REST_API]), "Rest API is not supported in this testing region")
1318
class TestApiSettings(BaseTest):
1419
def test_method_settings(self):
1520
self.create_and_verify_stack("combination/api_with_method_settings")

integration/combination/test_api_with_cors.py

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
1+
from integration.helpers.base_test import BaseTest
12
import requests
3+
from unittest.case import skipIf
24

35
from integration.helpers.base_test import BaseTest
6+
from integration.helpers.resource import current_region_does_not_support
7+
from integration.config.service_names import REST_API
48
from integration.helpers.deployer.utils.retry import retry
59
from parameterized import parameterized
610

7-
from integration.helpers.exception import StatusCodeError
8-
911
ALL_METHODS = "DELETE,GET,HEAD,OPTIONS,PATCH,POST,PUT"
1012

1113

14+
@skipIf(current_region_does_not_support([REST_API]), "Rest API is not supported in this testing region")
1215
class TestApiWithCors(BaseTest):
1316
@parameterized.expand(
1417
[
@@ -26,8 +29,8 @@ def test_cors(self, file_name):
2629
allow_headers = "headers"
2730
max_age = "600"
2831

29-
self.verify_options_request(base_url + "/apione", allow_methods, allow_origin, allow_headers, max_age)
30-
self.verify_options_request(base_url + "/apitwo", allow_methods, allow_origin, allow_headers, max_age)
32+
self.verify_cors_options_request(base_url + "/apione", allow_methods, allow_origin, allow_headers, max_age)
33+
self.verify_cors_options_request(base_url + "/apitwo", allow_methods, allow_origin, allow_headers, max_age)
3134

3235
def test_cors_with_shorthand_notation(self):
3336
self.create_and_verify_stack("combination/api_with_cors_shorthand")
@@ -38,8 +41,8 @@ def test_cors_with_shorthand_notation(self):
3841
allow_headers = None # This should be absent from response
3942
max_age = None # This should be absent from response
4043

41-
self.verify_options_request(base_url + "/apione", ALL_METHODS, allow_origin, allow_headers, max_age)
42-
self.verify_options_request(base_url + "/apitwo", "OPTIONS,POST", allow_origin, allow_headers, max_age)
44+
self.verify_cors_options_request(base_url + "/apione", ALL_METHODS, allow_origin, allow_headers, max_age)
45+
self.verify_cors_options_request(base_url + "/apitwo", "OPTIONS,POST", allow_origin, allow_headers, max_age)
4346

4447
def test_cors_with_only_methods(self):
4548
self.create_and_verify_stack("combination/api_with_cors_only_methods")
@@ -51,8 +54,8 @@ def test_cors_with_only_methods(self):
5154
allow_headers = None # This should be absent from response
5255
max_age = None # This should be absent from response
5356

54-
self.verify_options_request(base_url + "/apione", allow_methods, allow_origin, allow_headers, max_age)
55-
self.verify_options_request(base_url + "/apitwo", allow_methods, allow_origin, allow_headers, max_age)
57+
self.verify_cors_options_request(base_url + "/apione", allow_methods, allow_origin, allow_headers, max_age)
58+
self.verify_cors_options_request(base_url + "/apitwo", allow_methods, allow_origin, allow_headers, max_age)
5659

5760
def test_cors_with_only_headers(self):
5861
self.create_and_verify_stack("combination/api_with_cors_only_headers")
@@ -63,8 +66,8 @@ def test_cors_with_only_headers(self):
6366
allow_headers = "headers"
6467
max_age = None # This should be absent from response
6568

66-
self.verify_options_request(base_url + "/apione", ALL_METHODS, allow_origin, allow_headers, max_age)
67-
self.verify_options_request(base_url + "/apitwo", "OPTIONS,POST", allow_origin, allow_headers, max_age)
69+
self.verify_cors_options_request(base_url + "/apione", ALL_METHODS, allow_origin, allow_headers, max_age)
70+
self.verify_cors_options_request(base_url + "/apitwo", "OPTIONS,POST", allow_origin, allow_headers, max_age)
6871

6972
def test_cors_with_only_max_age(self):
7073
self.create_and_verify_stack("combination/api_with_cors_only_max_age")
@@ -75,17 +78,12 @@ def test_cors_with_only_max_age(self):
7578
allow_headers = None
7679
max_age = "600"
7780

78-
self.verify_options_request(base_url + "/apione", ALL_METHODS, allow_origin, allow_headers, max_age)
79-
self.verify_options_request(base_url + "/apitwo", "OPTIONS,POST", allow_origin, allow_headers, max_age)
81+
self.verify_cors_options_request(base_url + "/apione", ALL_METHODS, allow_origin, allow_headers, max_age)
82+
self.verify_cors_options_request(base_url + "/apitwo", "OPTIONS,POST", allow_origin, allow_headers, max_age)
8083

81-
@retry(StatusCodeError, 3)
82-
def verify_options_request(self, url, allow_methods, allow_origin, allow_headers, max_age):
83-
response = requests.options(url)
84-
status = response.status_code
85-
if status != 200:
86-
raise StatusCodeError("Request to {} failed with status: {}, expected status: 200".format(url, status))
84+
def verify_cors_options_request(self, url, allow_methods, allow_origin, allow_headers, max_age):
85+
response = self.verify_options_request(url, 200)
8786

88-
self.assertEqual(status, 200, "Options request must be successful and return HTTP 200")
8987
headers = response.headers
9088
self.assertEqual(
9189
headers.get("Access-Control-Allow-Methods"), allow_methods, "Allow-Methods header must have proper value"
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
from parameterized import parameterized
2+
3+
from integration.helpers.base_test import BaseTest
4+
5+
6+
class TestApiWithFailOnWarnings(BaseTest):
7+
@parameterized.expand(
8+
[
9+
("combination/api_with_fail_on_warnings", True),
10+
("combination/api_with_fail_on_warnings", False),
11+
]
12+
)
13+
def test_end_point_configuration(self, file_name, disable_value):
14+
parameters = [
15+
{
16+
"ParameterKey": "FailOnWarningsValue",
17+
"ParameterValue": "true" if disable_value else "false",
18+
"UsePreviousValue": False,
19+
"ResolvedValue": "string",
20+
}
21+
]
22+
23+
self.create_and_verify_stack(file_name, parameters)
24+
25+
rest_api_id = self.get_physical_id_by_type("AWS::ApiGateway::RestApi")
26+
apigw_client = self.client_provider.api_client
27+
28+
api_result = apigw_client.get_rest_api(restApiId=rest_api_id)
29+
self.assertEqual(api_result["ResponseMetadata"]["HTTPStatusCode"], 200)

integration/combination/test_api_with_gateway_responses.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
1+
import logging
12
from unittest.case import skipIf
23

4+
from tenacity import stop_after_attempt, retry_if_exception_type, after_log, wait_exponential, retry, wait_random
5+
36
from integration.helpers.base_test import BaseTest
4-
from integration.helpers.deployer.utils.retry import retry
57
from integration.helpers.resource import current_region_does_not_support
68
from integration.config.service_names import GATEWAY_RESPONSES
79

10+
LOG = logging.getLogger(__name__)
11+
812

913
@skipIf(
1014
current_region_does_not_support([GATEWAY_RESPONSES]), "GatewayResponses is not supported in this testing region"
@@ -33,7 +37,13 @@ def test_gateway_responses(self):
3337
base_url = stack_outputs["ApiUrl"]
3438
self._verify_request_response_and_cors(base_url + "iam", 403)
3539

36-
@retry(AssertionError, exc_raise=AssertionError, exc_raise_msg="Unable to verify GatewayResponse request.")
40+
@retry(
41+
stop=stop_after_attempt(5),
42+
wait=wait_exponential(multiplier=1, min=4, max=10) + wait_random(0, 1),
43+
retry=retry_if_exception_type(AssertionError),
44+
after=after_log(LOG, logging.WARNING),
45+
reraise=True,
46+
)
3747
def _verify_request_response_and_cors(self, url, expected_response):
3848
response = self.verify_get_request_response(url, expected_response)
3949
access_control_allow_origin = response.headers.get("Access-Control-Allow-Origin", "")

integration/combination/test_api_with_resource_policies.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
import json
2+
from unittest.case import skipIf
23

34
from integration.helpers.base_test import BaseTest
5+
from integration.helpers.resource import current_region_does_not_support
6+
from integration.config.service_names import REST_API
47

58

9+
@skipIf(current_region_does_not_support([REST_API]), "Rest API is not supported in this testing region")
610
class TestApiWithResourcePolicies(BaseTest):
711
def test_api_resource_policies(self):
812
self.create_and_verify_stack("combination/api_with_resource_policies")

integration/combination/test_custom_http_api_domains_test.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
from integration.config.service_names import CUSTOM_DOMAIN
44
from integration.helpers.base_internal_test import BaseInternalTest
5-
from integration.helpers.file_resources import FILE_TO_S3_URI_MAP
65
from integration.helpers.resource import current_region_not_included
76

87

@@ -25,7 +24,7 @@ def test_custom_http_api_domains_regional(self):
2524
self.assertEqual("httpapi.sam-gamma-regional.com", result["DomainName"])
2625

2726
mtls_auth_config = result["MutualTlsAuthentication"]
28-
self.assertEqual(FILE_TO_S3_URI_MAP["MTLSCert.pem"]["uri"], mtls_auth_config["TruststoreUri"])
27+
self.assertEqual(self.file_to_s3_uri_map["MTLSCert.pem"]["uri"], mtls_auth_config["TruststoreUri"])
2928

3029
domain_name_configs = result["DomainNameConfigurations"]
3130
self.assertEqual(1, len(domain_name_configs))

integration/combination/test_custom_rest_api_domains.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
from integration.config.service_names import CUSTOM_DOMAIN
44
from integration.helpers.base_internal_test import BaseInternalTest
5-
from integration.helpers.file_resources import FILE_TO_S3_URI_MAP
65
from integration.helpers.resource import current_region_not_included
76

87

@@ -47,7 +46,7 @@ def test_custom_rest_api_domains_regional(self):
4746
self.assertEqual("REGIONAL", end_point_types[0])
4847

4948
mtls_auth_config = result["mutualTlsAuthentication"]
50-
self.assertEqual(FILE_TO_S3_URI_MAP["MTLSCert.pem"]["uri"], mtls_auth_config["truststoreUri"])
49+
self.assertEqual(self.file_to_s3_uri_map["MTLSCert.pem"]["uri"], mtls_auth_config["truststoreUri"])
5150

5251
def test_custom_rest_api_domains_regional_ownership_verification(self):
5352
self.create_and_verify_stack("combination/api_with_custom_domains_regional_ownership_verification")

integration/combination/test_function_with_alias.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
import json
2+
from unittest.case import skipIf
23

34
from botocore.exceptions import ClientError
45
from integration.helpers.base_test import BaseTest, LOG
56
from integration.helpers.common_api import get_function_versions
7+
from integration.helpers.resource import current_region_does_not_support
8+
from integration.config.service_names import REST_API
69

710

811
class TestFunctionWithAlias(BaseTest):
@@ -82,6 +85,7 @@ def test_alias_in_globals_with_overrides(self):
8285
# add any extra runtime behavior that needs to be verified
8386
self.create_and_verify_stack("combination/function_with_alias_globals")
8487

88+
@skipIf(current_region_does_not_support([REST_API]), "Rest API is not supported in this testing region")
8589
def test_alias_with_event_sources_get_correct_permissions(self):
8690
# There are two parts to testing Event Source integrations:
8791
# 1. Check if all event sources get wired to the alias

0 commit comments

Comments
 (0)