Skip to content

Commit 700de74

Browse files
authored
Merge pull request #3907 from aws/tmp/1775691083/main
Merge main to develop
2 parents 75dc369 + 6dfc469 commit 700de74

File tree

207 files changed

+22581
-500
lines changed

Some content is hidden

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

207 files changed

+22581
-500
lines changed

integration/combination/test_custom_http_api_domains_test.py

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

33
from integration.config.service_names import CUSTOM_DOMAIN
4-
from integration.helpers.base_internal_test import CUSTOM_DOMAIN_TOP_LEVEL, BaseInternalTest
4+
from integration.helpers.base_internal_test import (
5+
CUSTOM_DOMAIN_TOP_LEVEL,
6+
FEATURE_TOGGLE_CUSTOM_DOMAIN_TOP_LEVEL,
7+
BaseInternalTest,
8+
)
59
from integration.helpers.base_test import nonblocking
610
from integration.helpers.resource import current_region_not_included
711

@@ -24,7 +28,9 @@ def test_custom_http_api_domains_regional(self):
2428
result = api_gateway_client.get_domain_name(DomainName=domain_name_id)
2529

2630
if "FeatureToggle" in self.pipeline_prefix:
27-
self.assertEqual("httpapi.ftl.sam-gamma-regional.com", result["DomainName"])
31+
self.assertEqual(
32+
f"httpapi-sam-gamma-regional.{FEATURE_TOGGLE_CUSTOM_DOMAIN_TOP_LEVEL}", result["DomainName"]
33+
)
2834
else:
2935
self.assertEqual(f"httpapi-sam-gamma-regional.{CUSTOM_DOMAIN_TOP_LEVEL}", result["DomainName"])
3036

integration/combination/test_custom_rest_api_domains.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
from unittest.case import skipIf
22

33
from integration.config.service_names import CUSTOM_DOMAIN
4-
from integration.helpers.base_internal_test import CUSTOM_DOMAIN_TOP_LEVEL, BaseInternalTest
4+
from integration.helpers.base_internal_test import (
5+
CUSTOM_DOMAIN_TOP_LEVEL,
6+
FEATURE_TOGGLE_CUSTOM_DOMAIN_TOP_LEVEL,
7+
BaseInternalTest,
8+
)
59
from integration.helpers.base_test import nonblocking
610
from integration.helpers.resource import current_region_not_included
711

@@ -23,7 +27,7 @@ def test_custom_rest_api_domains_edge(self):
2327
result = api_gateway_client.get_domain_name(domainName=domain_name_id)
2428

2529
if "FeatureToggle" in self.pipeline_prefix:
26-
self.assertEqual("ftl.sam-gamma-edge.com", result["domainName"])
30+
self.assertEqual(f"sam-gamma-edge.{FEATURE_TOGGLE_CUSTOM_DOMAIN_TOP_LEVEL}", result["domainName"])
2731
else:
2832
self.assertEqual(f"sam-gamma-edge.{CUSTOM_DOMAIN_TOP_LEVEL}", result["domainName"])
2933

@@ -44,7 +48,7 @@ def test_custom_rest_api_domains_regional(self):
4448
result = api_gateway_client.get_domain_name(domainName=domain_name_id)
4549

4650
if "FeatureToggle" in self.pipeline_prefix:
47-
self.assertEqual("ftl.sam-gamma-regional.com", result["domainName"])
51+
self.assertEqual(f"sam-gamma-regional.{FEATURE_TOGGLE_CUSTOM_DOMAIN_TOP_LEVEL}", result["domainName"])
4852
else:
4953
self.assertEqual(f"sam-gamma-regional.{CUSTOM_DOMAIN_TOP_LEVEL}", result["domainName"])
5054

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
from unittest.case import skipIf
2+
3+
from integration.config.service_names import WEBSOCKET_API
4+
from integration.helpers.base_test import BaseTest
5+
from integration.helpers.resource import current_region_does_not_support
6+
7+
8+
@skipIf(current_region_does_not_support([WEBSOCKET_API]), "WebSocketApi is not supported in this region")
9+
class TestWebSocketApiBasic(BaseTest):
10+
11+
def test_websocket_api_basic(self):
12+
"""
13+
Creates a Basic WebSocket API
14+
"""
15+
# Validates list of generated resources is same as expected
16+
self.create_and_verify_stack("combination/websocket_api_basic")
17+
18+
stages = self.get_api_v2_stack_stages()
19+
20+
self.assertEqual(len(stages), 1)
21+
self.assertEqual(stages[0]["StageName"], "default")
22+
23+
api_id = self.get_stack_outputs()["ApiId"]
24+
api_2_client = self.client_provider.api_v2_client
25+
26+
routes = api_2_client.get_routes(ApiId=api_id)["Items"]
27+
self.assertEqual(len(routes), 1)
28+
self.assertEqual(routes[0]["RouteKey"], "$default")
29+
30+
integrations = api_2_client.get_integrations(ApiId=api_id)["Items"]
31+
self.assertEqual(len(integrations), 1)
32+
33+
def test_websocket_api_basic_config(self):
34+
"""
35+
Checks API config parameters that are strings
36+
"""
37+
self.create_and_verify_stack("combination/websocket_api_basic_config")
38+
websocket_api_list = self.get_stack_resources("AWS::ApiGatewayV2::Api")
39+
self.assertEqual(len(websocket_api_list), 1)
40+
41+
websocket_resource = websocket_api_list[0]
42+
websocket_api_id = websocket_resource["PhysicalResourceId"]
43+
api_v2_client = self.client_provider.api_v2_client
44+
api_configuration = api_v2_client.get_api(ApiId=websocket_api_id)
45+
properties_to_check = {
46+
"ApiKeySelectionExpression": "$request.header.x-api-key",
47+
"Description": "Toy API",
48+
"DisableExecuteApiEndpoint": False,
49+
"Name": "MyApiName",
50+
"ProtocolType": "WEBSOCKET",
51+
"RouteSelectionExpression": "$request.body.action",
52+
}
53+
for key, value in properties_to_check.items():
54+
self.assertEqual(api_configuration[key], value)
55+
# assert custom tags are present
56+
# CFN and SAM tags also exist, so we can't check equality of the full list
57+
self.assertEqual(api_configuration["Tags"].get("t1"), "v1")
58+
self.assertEqual(api_configuration["Tags"].get("t2"), "v2")
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
from unittest.case import skipIf
2+
3+
from integration.config.service_names import CUSTOM_DOMAIN, WEBSOCKET_API
4+
from integration.helpers.base_internal_test import (
5+
CUSTOM_DOMAIN_TOP_LEVEL,
6+
FEATURE_TOGGLE_CUSTOM_DOMAIN_TOP_LEVEL,
7+
BaseInternalTest,
8+
)
9+
from integration.helpers.base_test import nonblocking
10+
from integration.helpers.resource import current_region_does_not_support, current_region_not_included
11+
12+
13+
# Custom domain tests require pre-created infrastructure (hosted zones, certificates)
14+
# that only exists in us-east-1.
15+
@skipIf(
16+
current_region_does_not_support([WEBSOCKET_API]) or current_region_not_included([CUSTOM_DOMAIN]),
17+
"WebSocketApi is not supported or CustomDomain infrastructure is not available in this testing region",
18+
)
19+
@nonblocking
20+
class TestWebSocketApiCustomDomains(BaseInternalTest):
21+
def test_websocket_custom_api_domains_regional(self):
22+
self.create_and_verify_stack("combination/websocket_api_custom_domains_regional")
23+
24+
domain_name_list = self.get_stack_resources("AWS::ApiGatewayV2::DomainName")
25+
self.assertEqual(1, len(domain_name_list))
26+
27+
domain_name_id = self.get_physical_id_by_type("AWS::ApiGatewayV2::DomainName")
28+
29+
api_gateway_client = self.client_provider.api_v2_client
30+
result = api_gateway_client.get_domain_name(DomainName=domain_name_id)
31+
32+
if "FeatureToggle" in self.pipeline_prefix:
33+
self.assertEqual(
34+
f"websocket-sam-gamma-regional.{FEATURE_TOGGLE_CUSTOM_DOMAIN_TOP_LEVEL}", result["DomainName"]
35+
)
36+
else:
37+
self.assertEqual(f"websocket-sam-gamma-regional.{CUSTOM_DOMAIN_TOP_LEVEL}", result["DomainName"])
38+
39+
domain_name_configs = result["DomainNameConfigurations"]
40+
self.assertEqual(1, len(domain_name_configs))
41+
domain_name_config = domain_name_configs[0]
42+
43+
self.assertEqual("REGIONAL", domain_name_config["EndpointType"])
44+
self.assertEqual("TLS_1_2", domain_name_config["SecurityPolicy"])
45+
46+
domain_name_configs = result["DomainNameConfigurations"]
47+
self.assertEqual(1, len(domain_name_configs))
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
from unittest.case import skipIf
2+
3+
from integration.config.service_names import WEBSOCKET_API
4+
from integration.helpers.base_test import BaseTest
5+
from integration.helpers.resource import current_region_does_not_support
6+
7+
8+
@skipIf(current_region_does_not_support([WEBSOCKET_API]), "WebSocketApi is not supported in this region")
9+
class TestWebSocketApiMultiple(BaseTest):
10+
11+
def test_websocket_multi_api(self):
12+
self.create_and_verify_stack("combination/websocket_api_multiple_api")
13+
14+
def test_websocket_multi_route(self):
15+
self.create_and_verify_stack("combination/websocket_api_multiple_routes")
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
from unittest.case import skipIf
2+
3+
from integration.config.service_names import WEBSOCKET_API
4+
from integration.helpers.base_test import BaseTest
5+
from integration.helpers.resource import current_region_does_not_support
6+
7+
8+
@skipIf(current_region_does_not_support([WEBSOCKET_API]), "WebSocketApi is not supported in this region")
9+
class TestWebSocketApiRouteConfig(BaseTest):
10+
11+
def test_websocket_api_route_config(self):
12+
"""
13+
Checks API config parameters that are strings
14+
"""
15+
self.create_and_verify_stack("combination/websocket_api_route_config")
16+
websocket_route_list = self.get_stack_resources("AWS::ApiGatewayV2::Route")
17+
self.assertEqual(len(websocket_route_list), 1)
18+
websocket_route_integ_list = self.get_stack_resources("AWS::ApiGatewayV2::Integration")
19+
self.assertEqual(len(websocket_route_integ_list), 1)
20+
websocket_route_perm_list = self.get_stack_resources("AWS::Lambda::Permission")
21+
self.assertEqual(len(websocket_route_perm_list), 1)
22+
api_id = self.get_stack_outputs()["ApiId"]
23+
api_2_client = self.client_provider.api_v2_client
24+
routes = api_2_client.get_routes(ApiId=api_id)["Items"]
25+
self.assertEqual(len(routes), 1)
26+
route = routes[0]
27+
self.assertEqual(route["RouteKey"], "$connect")
28+
self.assertEqual(route["ModelSelectionExpression"], "$request.body.modelType")
29+
self.assertEqual(route["OperationName"], "connect")
30+
self.assertIsNotNone(route["RequestParameters"].get("route.request.querystring.p1"))
31+
self.assertEqual(route["RouteResponseSelectionExpression"], "$default")
32+
integrations = api_2_client.get_integrations(ApiId=api_id)
33+
self.assertEqual(len(integrations["Items"]), 1)
34+
integration = integrations["Items"][0]
35+
self.assertEqual(integration["TimeoutInMillis"], 15000)
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
from unittest.case import skipIf
2+
3+
from integration.config.service_names import WEBSOCKET_API
4+
from integration.helpers.base_test import BaseTest
5+
from integration.helpers.resource import current_region_does_not_support
6+
7+
8+
@skipIf(current_region_does_not_support([WEBSOCKET_API]), "WebSocketApi is not supported in this region")
9+
class TestWebSocketApiRouteSettings(BaseTest):
10+
def test_websocket_api_route_settings(self):
11+
"""
12+
Verifies that RouteSettings with specific route keys deploys successfully.
13+
This test ensures Stage has DependsOn for routes.
14+
"""
15+
self.create_and_verify_stack("combination/websocket_api_route_settings")
16+
17+
stages = self.get_api_v2_stack_stages()
18+
self.assertEqual(len(stages), 1)
19+
stage = stages[0]
20+
self.assertIsNotNone(stage.get("RouteSettings"))
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
from unittest.case import skipIf
2+
3+
from integration.config.service_names import WEBSOCKET_API
4+
from integration.helpers.base_test import BaseTest
5+
from integration.helpers.resource import current_region_does_not_support
6+
7+
8+
@skipIf(current_region_does_not_support([WEBSOCKET_API]), "WebSocketApi is not supported in this region")
9+
class TestWebSocketApiStageConfig(BaseTest):
10+
11+
def test_websocket_api_stage_config(self):
12+
"""
13+
Checks API config parameters that are strings
14+
"""
15+
self.create_and_verify_stack("combination/websocket_api_stage_config")
16+
stages = self.get_api_v2_stack_stages()
17+
self.assertEqual(len(stages), 1)
18+
stage = stages[0]
19+
self.assertEqual(stage["StageName"], "Prod")
20+
self.assertEqual(stage["StageVariables"], {"var1": "val1", "var2": "val2"})
21+
self.assertIsNotNone(stage["Tags"].get("t1"))
22+
self.assertIsNotNone(stage["Tags"].get("t2"))
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
from unittest.case import skipIf
2+
3+
from integration.config.service_names import WEBSOCKET_API
4+
from integration.helpers.base_test import BaseTest
5+
from integration.helpers.resource import current_region_does_not_support
6+
7+
8+
@skipIf(current_region_does_not_support([WEBSOCKET_API]), "WebSocketApi is not supported in this region")
9+
class TestWebSocketApiWithAuth(BaseTest):
10+
11+
def test_websocket_api_with_iam_auth(self):
12+
"""
13+
Creates a WebSocket API with an IAM authorizer
14+
"""
15+
self.create_and_verify_stack("combination/websocket_api_with_iam_auth")
16+
17+
websocket_api_list = self.get_stack_resources("AWS::ApiGatewayV2::Api")
18+
self.assertEqual(len(websocket_api_list), 1)
19+
20+
stages = self.get_api_v2_stack_stages()
21+
22+
self.assertEqual(len(stages), 1)
23+
self.assertEqual(stages[0]["StageName"], "default")
24+
25+
websocket_resource = websocket_api_list[0]
26+
websocket_api_id = websocket_resource["PhysicalResourceId"]
27+
api_v2_client = self.client_provider.api_v2_client
28+
routes_list = api_v2_client.get_routes(ApiId=websocket_api_id)["Items"]
29+
route = routes_list[0]
30+
self.assertEqual(route["AuthorizationType"], "AWS_IAM")
31+
32+
def test_none_auth(self):
33+
self.create_and_verify_stack("combination/websocket_api_with_none_auth")
34+
35+
websocket_api_list = self.get_stack_resources("AWS::ApiGatewayV2::Api")
36+
self.assertEqual(len(websocket_api_list), 1)
37+
38+
websocket_resource = websocket_api_list[0]
39+
websocket_api_id = websocket_resource["PhysicalResourceId"]
40+
api_v2_client = self.client_provider.api_v2_client
41+
routes_list = api_v2_client.get_routes(ApiId=websocket_api_id)["Items"]
42+
route = routes_list[0]
43+
self.assertEqual(route["AuthorizationType"], "NONE")
44+
45+
def test_websocket_api_with_lambda_auth_config(self):
46+
"""
47+
Creates a WebSocket API with a Lambda authorizer
48+
"""
49+
self.create_and_verify_stack("combination/websocket_api_with_lambda_auth")
50+
51+
websocket_api_list = self.get_stack_resources("AWS::ApiGatewayV2::Api")
52+
self.assertEqual(len(websocket_api_list), 1)
53+
54+
websocket_resource = websocket_api_list[0]
55+
websocket_api_id = websocket_resource["PhysicalResourceId"]
56+
api_v2_client = self.client_provider.api_v2_client
57+
58+
route_list = api_v2_client.get_routes(ApiId=websocket_api_id)["Items"]
59+
self.assertEqual(len(route_list), 1)
60+
route = route_list[0]
61+
self.assertEqual(route["AuthorizationType"], "CUSTOM")
62+
self.assertIsNotNone(route["AuthorizerId"])
63+
64+
authorizer_list = api_v2_client.get_authorizers(ApiId=websocket_api_id)["Items"]
65+
self.assertEqual(len(authorizer_list), 1)
66+
lambda_auth = authorizer_list[0]
67+
# Not sure this is returning properly either
68+
self.assertEqual(lambda_auth["AuthorizerType"], "REQUEST")
69+
# Verify authorizer URI contains expected components
70+
authorizer_uri = lambda_auth["AuthorizerUri"]
71+
self.assertIn("lambda:path/2015-03-31/functions", authorizer_uri)
72+
self.assertIn("MyAuthFn", authorizer_uri)
73+
self.assertIn("/invocations", authorizer_uri)
74+
75+
# Same authorizer coming from the route and from the authorizers
76+
self.assertEqual(route["AuthorizerId"], lambda_auth["AuthorizerId"])
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
from unittest.case import skipIf
2+
3+
from parameterized import parameterized
4+
5+
from integration.config.service_names import WEBSOCKET_API
6+
from integration.helpers.base_test import BaseTest
7+
from integration.helpers.resource import current_region_does_not_support
8+
9+
10+
@skipIf(current_region_does_not_support([WEBSOCKET_API]), "WebSocketApi is not supported in this region")
11+
class TestWebSocketApiWithDisableExecuteApiEndpoint(BaseTest):
12+
@parameterized.expand([True, False])
13+
def test_disable_execute_api_endpoint_true(self, is_disable):
14+
parameters = [
15+
{
16+
"ParameterKey": "DisableExecuteApiEndpointValue",
17+
"ParameterValue": "true" if is_disable else "false",
18+
"UsePreviousValue": False,
19+
"ResolvedValue": "string",
20+
}
21+
]
22+
23+
self.create_and_verify_stack("combination/websocket_api_with_disable_execute_api_endpoint", parameters)
24+
api_2_client = self.client_provider.api_v2_client
25+
api_id = self.get_stack_outputs()["ApiId"]
26+
api_result = api_2_client.get_api(ApiId=api_id)
27+
self.assertEqual(api_result["DisableExecuteApiEndpoint"], is_disable)

0 commit comments

Comments
 (0)