|
3 | 3 | SPDX-License-Identifier: MIT-0
|
4 | 4 | """
|
5 | 5 |
|
| 6 | +from collections import deque |
| 7 | + |
6 | 8 | import pytest
|
7 | 9 |
|
8 |
| -from cfnlint.context import create_context_for_template |
| 10 | +from cfnlint.context import Path, create_context_for_template |
9 | 11 | from cfnlint.jsonschema import CfnTemplateValidator, ValidationError
|
10 | 12 | from cfnlint.rules.parameters.DynamicReferenceSecret import DynamicReferenceSecret
|
11 | 13 | from cfnlint.template import Template
|
@@ -39,31 +41,40 @@ def context(cfn):
|
39 | 41 |
|
40 | 42 |
|
41 | 43 | @pytest.mark.parametrize(
|
42 |
| - "name,instance,expected", |
| 44 | + "name,instance,path,expected", |
43 | 45 | [
|
44 | 46 | (
|
45 | 47 | "REFing a parameter without a string",
|
46 | 48 | {"Ref": []},
|
| 49 | + deque([]), |
47 | 50 | [],
|
48 | 51 | ),
|
49 | 52 | (
|
50 | 53 | "REFing a resource=",
|
51 | 54 | {"Ref": "MyResource"},
|
| 55 | + deque([]), |
52 | 56 | [],
|
53 | 57 | ),
|
54 | 58 | (
|
55 | 59 | "REFing a parameter",
|
56 | 60 | {"Ref": "MyParameter"},
|
| 61 | + deque([]), |
57 | 62 | [
|
58 | 63 | ValidationError(
|
59 | 64 | "Use dynamic references over parameters for secrets",
|
60 | 65 | rule=DynamicReferenceSecret(),
|
61 | 66 | )
|
62 | 67 | ],
|
63 | 68 | ),
|
| 69 | + ( |
| 70 | + "REFing a parameter in a sub", |
| 71 | + {"Ref": "MyParameter"}, |
| 72 | + deque(["Fn::Sub"]), |
| 73 | + [], |
| 74 | + ), |
64 | 75 | ],
|
65 | 76 | )
|
66 |
| -def test_validate(name, instance, expected, rule, context, cfn): |
67 |
| - validator = CfnTemplateValidator(context=context, cfn=cfn) |
| 77 | +def test_validate(name, instance, path, expected, rule, context, cfn): |
| 78 | + validator = CfnTemplateValidator(context=context.evolve(path=Path(path)), cfn=cfn) |
68 | 79 | errs = list(rule.validate(validator, {}, instance, {}))
|
69 | 80 | assert errs == expected, f"Test {name!r} got {errs!r}"
|
0 commit comments