Skip to content

Commit eaf23ca

Browse files
authored
Validate null Condition section (#3169)
1 parent fb55eee commit eaf23ca

File tree

3 files changed

+23
-2
lines changed

3 files changed

+23
-2
lines changed

Diff for: src/cfnlint/rules/conditions/Configuration.py

+11-2
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,10 @@ class Configuration(CloudFormationLintRule):
2626
def match(self, cfn):
2727
matches = []
2828

29-
conditions = cfn.template.get("Conditions", {})
30-
if conditions:
29+
if "Conditions" not in cfn.template:
30+
return matches
31+
conditions = cfn.template.get("Conditions", None)
32+
if isinstance(conditions, dict):
3133
for condname, condobj in conditions.items():
3234
if not isinstance(condobj, dict):
3335
message = "Condition {0} has invalid property"
@@ -52,5 +54,12 @@ def match(self, cfn):
5254
message.format(condname, k),
5355
)
5456
)
57+
else:
58+
matches.append(
59+
RuleMatch(
60+
["Conditions"],
61+
"Condition must be an object",
62+
)
63+
)
5564

5665
return matches

Diff for: test/fixtures/templates/bad/conditions_type.yaml

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
AWSTemplateFormatVersion: "2010-09-09"
2+
Conditions:
3+
Resources:
4+
myTopic:
5+
Type: AWS::SNS::Topic
6+
Properties:
7+
DisplayName: mytopic
8+
TopicName: mytopic

Diff for: test/unit/rules/conditions/test_configuration.py

+4
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ def test_file_positive(self):
2222
"""Test Positive"""
2323
self.helper_file_positive()
2424

25+
def test_file_negative_type(self):
26+
"""Test failure"""
27+
self.helper_file_negative("test/fixtures/templates/bad/conditions_type.yaml", 1)
28+
2529
def test_file_negative(self):
2630
"""Test failure"""
2731
self.helper_file_negative("test/fixtures/templates/bad/conditions.yaml", 4)

0 commit comments

Comments
 (0)