-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CloudFormation's non-standard YAML parser converts Boolean literal `false` to string value `"false"` (which is actually truthy). Work around by doing our own parsing for Boolean properties. Fixes #10.
- Loading branch information
Showing
6 changed files
with
113 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -98,8 +98,8 @@ def test_create_all_options(self): | |
"RequestType": "Create", | ||
"ResourceProperties": { | ||
"Domain": "example.com.", | ||
"EnableSend": True, | ||
"EnableReceive": True, | ||
"EnableSend": "true", | ||
"EnableReceive": "true", | ||
"MailFromSubdomain": "bounce", | ||
"CustomDMARC": '"v=DMARC1; p=quarantine; rua=mailto:[email protected];"', | ||
"TTL": "300", | ||
|
@@ -166,8 +166,8 @@ def test_update_receive_only(self): | |
"RequestType": "Update", | ||
"ResourceProperties": { | ||
"Domain": "example.com.", | ||
"EnableSend": False, | ||
"EnableReceive": True, | ||
"EnableSend": "false", | ||
"EnableReceive": "true", | ||
"CustomDMARC": None, | ||
}, | ||
"StackId": self.mock_stack_id} | ||
|
@@ -208,8 +208,8 @@ def test_delete(self): | |
"PhysicalResourceId": "arn:aws:ses:mock-region:111111111111:identity/example.com", | ||
"ResourceProperties": { | ||
"Domain": "example.com.", | ||
"EnableSend": True, | ||
"EnableReceive": True, | ||
"EnableSend": "true", | ||
"EnableReceive": "true", | ||
}, | ||
"StackId": self.mock_stack_id} | ||
self.ses_stubber.add_response( | ||
|
@@ -244,8 +244,8 @@ def test_v0_3_physical_id_change(self): | |
"PhysicalResourceId": "example.com", # old format: just the domain | ||
"ResourceProperties": { | ||
"Domain": "example.com.", | ||
"EnableSend": True, | ||
"EnableReceive": True, | ||
"EnableSend": "true", | ||
"EnableReceive": "true", | ||
}, | ||
"StackId": self.mock_stack_id} | ||
# self.ses_stubber.nothing: *no* SES ops should occur | ||
|
@@ -280,3 +280,17 @@ def test_boto_error(self): | |
'ERROR:root:Error updating SES: An error occurred (InvalidParameterValue) when' | ||
' calling the VerifyDomainIdentity operation: Invalid domain name bad domain name.', | ||
cm.output[0]) | ||
|
||
def test_invalid_boolean_property(self): | ||
event = { | ||
"RequestType": "Create", | ||
"ResourceProperties": { | ||
"Domain": "example.com", | ||
"EnableSend": "yes", | ||
}, | ||
"StackId": self.mock_stack_id} | ||
handle_domain_identity_request(event, self.mock_context) | ||
self.assertSentResponse( | ||
event, status="FAILED", | ||
reason="The 'EnableSend' property must be 'true' or 'false', not 'yes'.", | ||
physical_resource_id=MOCK_ANY) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
from unittest import TestCase | ||
|
||
from aws_cfn_ses_domain.utils import to_bool | ||
|
||
|
||
class TestToBool(TestCase): | ||
TRUE_VALUES = ( | ||
'true', 'True', 'TRUE', 'tRuE', | ||
1, '1', | ||
True, | ||
) | ||
|
||
FALSE_VALUES = ( | ||
'false', 'False', 'FALSE', 'fAlSe', | ||
0, '0', | ||
None, 'None', | ||
'null', # JSON's None as a string | ||
'', # empty string | ||
False, | ||
) | ||
|
||
INVALID_VALUES = ( | ||
'yes', 'no', 't', 'f', ' ', | ||
100, -1, 0.5, | ||
) | ||
|
||
def test_true(self): | ||
for value in self.TRUE_VALUES: | ||
with self.subTest(value=value): | ||
self.assertIs(to_bool(value), True) | ||
|
||
def test_false(self): | ||
for value in self.FALSE_VALUES: | ||
with self.subTest(value=value): | ||
self.assertIs(to_bool(value), False) | ||
|
||
def test_invalid(self): | ||
for value in self.INVALID_VALUES: | ||
with self.subTest(value=value): | ||
with self.assertRaises(ValueError): | ||
to_bool(value) |