Skip to content
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
4 changes: 3 additions & 1 deletion src/cfnlint/data/schemas/other/template/configuration.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@
"Metadata": {},
"Outputs": {},
"Parameters": {},
"Resources": {},
"Resources": {
"minProperties": 1
},
"Rules": {
"type": "object"
},
Expand Down
8 changes: 6 additions & 2 deletions test/fixtures/templates/good/decode/parsing.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@
"Parameters": {
"VPN": {
"Type": "String",
"AllowedPattern": "^\\\/"
"AllowedPattern": "^\\/"
}
},
"Resources": {}
"Resources": {
"Bucket": {
"Type": "AWS::S3::Bucket"
}
}
}
8 changes: 7 additions & 1 deletion test/fixtures/templates/integration/metdata.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,10 @@ Parameters:
Description: VPC To Create Stack In
Type: String

Resources: {}
Resources:
LambdaPermission:
Type: AWS::Lambda::Permission
Properties:
FunctionName: !Sub "arn:${AWS::Partition}:lambda:${AWS::Region}:${AWS::AccountId}:function:placeholder"
Action: lambda:InvokeFunction
Principal: events.amazonaws.com
37 changes: 36 additions & 1 deletion test/unit/rules/jsonschema/test_json_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,11 @@ def test_extra(self):
["Foo"],
validator="additionalProperties",
),
self.build_result(
"expected minimum property count: 1, found: 0",
["Resources"],
validator="minProperties",
),
]
self.cfn = Template(
"",
Expand All @@ -128,6 +133,15 @@ def test_extra(self):
self.validate(expected)

def test_config(self):
# sections only whitelists the named section, the Resources
# lower bound still applies
expected = [
self.build_result(
"expected minimum property count: 1, found: 0",
["Resources"],
validator="minProperties",
),
]
self.rule.config["sections"] = "Foo"
self.cfn = Template(
"",
Expand All @@ -139,7 +153,28 @@ def test_config(self):
),
["us-east-1"],
)
self.validate([])
self.validate(expected)

def test_empty_resources(self):
"""An empty Resources section is rejected by CloudFormation
and must fail E1001 just like a missing Resources section"""
expected = [
self.build_result(
"expected minimum property count: 1, found: 0",
["Resources"],
validator="minProperties",
),
]
self.cfn = Template(
"",
build_dict(
{
build_str("Resources"): build_dict({}),
},
),
["us-east-1"],
)
self.validate(expected)


def build_node(instance: str | dict, loc: str, type=str_node):
Expand Down
6 changes: 3 additions & 3 deletions test/unit/rules/templates/test_base_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,16 @@ def test_file_negative(self):

def test_file_base(self):
"""Test failure"""
self.helper_file_negative("test/fixtures/templates/bad/templates/base.yaml", 1)
self.helper_file_negative("test/fixtures/templates/bad/templates/base.yaml", 2)

def test_file_base_date(self):
"""Test failure"""
self.helper_file_negative(
"test/fixtures/templates/bad/templates/base_date.yaml", 1
"test/fixtures/templates/bad/templates/base_date.yaml", 2
)

def test_file_base_null(self):
"""Test failure"""
self.helper_file_negative(
"test/fixtures/templates/bad/templates/base_null.yaml", 2
"test/fixtures/templates/bad/templates/base_null.yaml", 3
)
Loading