-
Notifications
You must be signed in to change notification settings - Fork 598
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add in more new rule testing (#3072)
- Loading branch information
Showing
3 changed files
with
88 additions
and
0 deletions.
There are no files selected for viewing
69 changes: 69 additions & 0 deletions
69
test/unit/rules/parameters/test_dynamic_reference_secret.py
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,69 @@ | ||
""" | ||
Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
SPDX-License-Identifier: MIT-0 | ||
""" | ||
|
||
import pytest | ||
|
||
from cfnlint.context import create_context_for_template | ||
from cfnlint.jsonschema import CfnTemplateValidator, ValidationError | ||
from cfnlint.rules.parameters.DynamicReferenceSecret import DynamicReferenceSecret | ||
from cfnlint.template import Template | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
def rule(): | ||
rule = DynamicReferenceSecret() | ||
yield rule | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
def cfn(): | ||
return Template( | ||
"", | ||
{ | ||
"Parameters": { | ||
"MyParameter": { | ||
"Type": "String", | ||
} | ||
}, | ||
"Resources": {}, | ||
}, | ||
regions=["us-east-1"], | ||
) | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
def context(cfn): | ||
return create_context_for_template(cfn) | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"name,instance,expected", | ||
[ | ||
( | ||
"REFing a parameter without a string", | ||
{"Ref": []}, | ||
[], | ||
), | ||
( | ||
"REFing a resource=", | ||
{"Ref": "MyResource"}, | ||
[], | ||
), | ||
( | ||
"REFing a parameter", | ||
{"Ref": "MyParameter"}, | ||
[ | ||
ValidationError( | ||
"Use dynamic references over parameters for secrets", | ||
rule=DynamicReferenceSecret(), | ||
) | ||
], | ||
), | ||
], | ||
) | ||
def test_validate(name, instance, expected, rule, context, cfn): | ||
validator = CfnTemplateValidator(context=context, cfn=cfn) | ||
errs = list(rule.validate(validator, {}, instance, {})) | ||
assert errs == expected, f"Test {name!r} got {errs!r}" |
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