Cloudformation: Fix - validate template yml fixes
This change fixes: * Replace call to non-existent exception yaml.ParserError * Catches yaml scanner error for valid json with tabs * Supply yaml loader to ensure yaml loading throws exception validly for json with tabs and doesn't try to load the json incorrectly
This commit is contained in:
parent
73813460b6
commit
0f062f68ff
@ -365,8 +365,8 @@ class CloudFormationResponse(BaseResponse):
|
||||
except (ValueError, KeyError):
|
||||
pass
|
||||
try:
|
||||
description = yaml.load(template_body)["Description"]
|
||||
except (yaml.ParserError, KeyError):
|
||||
description = yaml.load(template_body, Loader=yaml.Loader)["Description"]
|
||||
except (yaml.parser.ParserError, yaml.scanner.ScannerError, KeyError):
|
||||
pass
|
||||
template = self.response_template(VALIDATE_STACK_RESPONSE_TEMPLATE)
|
||||
return template.render(description=description)
|
||||
|
@ -40,6 +40,16 @@ json_template = {
|
||||
},
|
||||
}
|
||||
|
||||
json_valid_template_with_tabs = """
|
||||
{
|
||||
\t"AWSTemplateFormatVersion": "2010-09-09",
|
||||
\t"Description": "Stack 2",
|
||||
\t"Resources": {
|
||||
\t\t"Queue": {"Type": "AWS::SQS::Queue", "Properties": {"VisibilityTimeout": 60}}
|
||||
\t}
|
||||
}
|
||||
"""
|
||||
|
||||
# One resource is required
|
||||
json_bad_template = {"AWSTemplateFormatVersion": "2010-09-09", "Description": "Stack 1"}
|
||||
|
||||
@ -56,6 +66,15 @@ def test_boto3_json_validate_successful():
|
||||
assert response["ResponseMetadata"]["HTTPStatusCode"] == 200
|
||||
|
||||
|
||||
@mock_cloudformation
|
||||
def test_boto3_json_with_tabs_validate_successful():
|
||||
cf_conn = boto3.client("cloudformation", region_name="us-east-1")
|
||||
response = cf_conn.validate_template(TemplateBody=json_valid_template_with_tabs)
|
||||
assert response["Description"] == "Stack 2"
|
||||
assert response["Parameters"] == []
|
||||
assert response["ResponseMetadata"]["HTTPStatusCode"] == 200
|
||||
|
||||
|
||||
@mock_cloudformation
|
||||
def test_boto3_json_invalid_missing_resource():
|
||||
cf_conn = boto3.client("cloudformation", region_name="us-east-1")
|
||||
|
Loading…
Reference in New Issue
Block a user