Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validate null Condition section #3169

Merged
merged 1 commit into from
Apr 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions src/cfnlint/rules/conditions/Configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@ class Configuration(CloudFormationLintRule):
def match(self, cfn):
matches = []

conditions = cfn.template.get("Conditions", {})
if conditions:
if "Conditions" not in cfn.template:
return matches
conditions = cfn.template.get("Conditions", None)
if isinstance(conditions, dict):
for condname, condobj in conditions.items():
if not isinstance(condobj, dict):
message = "Condition {0} has invalid property"
Expand All @@ -52,5 +54,12 @@ def match(self, cfn):
message.format(condname, k),
)
)
else:
matches.append(
RuleMatch(
["Conditions"],
"Condition must be an object",
)
)

return matches
8 changes: 8 additions & 0 deletions test/fixtures/templates/bad/conditions_type.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
AWSTemplateFormatVersion: "2010-09-09"
Conditions:
Resources:
myTopic:
Type: AWS::SNS::Topic
Properties:
DisplayName: mytopic
TopicName: mytopic
4 changes: 4 additions & 0 deletions test/unit/rules/conditions/test_configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ def test_file_positive(self):
"""Test Positive"""
self.helper_file_positive()

def test_file_negative_type(self):
"""Test failure"""
self.helper_file_negative("test/fixtures/templates/bad/conditions_type.yaml", 1)

def test_file_negative(self):
"""Test failure"""
self.helper_file_negative("test/fixtures/templates/bad/conditions.yaml", 4)