Skip to content

Commit

Permalink
fix: Raise correct exception when Domain BasePath contains non-str it…
Browse files Browse the repository at this point in the history
…ems (#2756)
  • Loading branch information
aahung authored Dec 20, 2022
1 parent 19fd6d8 commit 8066335
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
8 changes: 7 additions & 1 deletion samtranslator/model/api/api_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,12 @@
ApiGatewayApiKey,
)
from samtranslator.model.route53 import Route53RecordSetGroup
from samtranslator.model.exceptions import InvalidDocumentException, InvalidResourceException, InvalidTemplateException
from samtranslator.model.exceptions import (
ExpectedType,
InvalidDocumentException,
InvalidResourceException,
InvalidTemplateException,
)
from samtranslator.model.s3_utils.uri_parser import parse_s3_uri
from samtranslator.region_configuration import RegionConfiguration
from samtranslator.schema.common import PassThrough
Expand Down Expand Up @@ -524,6 +529,7 @@ def _construct_api_domain(
basepath_mapping.Stage = ref(rest_api.logical_id + ".Stage")
basepath_resource_list.extend([basepath_mapping])
else:
sam_expect(basepaths, self.logical_id, "Domain.BasePath").to_be_a_list_of(ExpectedType.STRING)
for basepath in basepaths:
# Remove possible leading and trailing '/' because a base path may only
# contain letters, numbers, and one of "$-_.+!*'()"
Expand Down
11 changes: 11 additions & 0 deletions tests/translator/input/error_api_with_custom_domains_invalid.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,14 @@ Resources:
OpenApiVersion: 3.0.1
StageName: Prod
Domain: !Ref MyDomainName # this should be a map after solution

MyApiWithIncorrectBasePathItemType:
Type: AWS::Serverless::Api
Properties:
OpenApiVersion: 3.0.1
StageName: Prod
Domain:
DomainName: api-example.com
CertificateArn: my-api-cert-arn
BasePath:
- 3 # this should not be a number
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 4. Resource with id [MyApi] is invalid. EndpointConfiguration for Custom Domains must be one of ['EDGE', 'REGIONAL', 'PRIVATE']. Resource with id [MyApiInvalidDomainType] is invalid. Property 'Domain' should be a map. Resource with id [MyApiMissingCertificateArn] is invalid. Property 'Domain.CertificateArn' is required. Resource with id [ServerlessRestApi] is invalid. Property 'Domain.DomainName' is required."
"errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 5. Resource with id [MyApi] is invalid. EndpointConfiguration for Custom Domains must be one of ['EDGE', 'REGIONAL', 'PRIVATE']. Resource with id [MyApiInvalidDomainType] is invalid. Property 'Domain' should be a map. Resource with id [MyApiMissingCertificateArn] is invalid. Property 'Domain.CertificateArn' is required. Resource with id [MyApiWithIncorrectBasePathItemType] is invalid. Property 'Domain.BasePath[0]' should be a string. Resource with id [ServerlessRestApi] is invalid. Property 'Domain.DomainName' is required."
}

0 comments on commit 8066335

Please sign in to comment.