From a7d24bf57d94cef5631f3a21f2715f1daf3d84b5 Mon Sep 17 00:00:00 2001 From: Kevin DeJong Date: Fri, 9 Aug 2024 09:19:23 -0700 Subject: [PATCH] Add Value to path in E6101 as we descend --- src/cfnlint/rules/outputs/Value.py | 9 +++++-- test/unit/rules/outputs/test_value.py | 37 ++++++++++++++++++++++++++- 2 files changed, 43 insertions(+), 3 deletions(-) diff --git a/src/cfnlint/rules/outputs/Value.py b/src/cfnlint/rules/outputs/Value.py index 4d86d9fb87..7d6ec9739f 100644 --- a/src/cfnlint/rules/outputs/Value.py +++ b/src/cfnlint/rules/outputs/Value.py @@ -28,7 +28,8 @@ def __init__(self): ) def validate(self, validator: Validator, _: Any, instance: Any, schema: Any): - value = instance.get("Value") + key = "Value" + value = instance.get(key) if not value: return @@ -42,6 +43,10 @@ def validate(self, validator: Validator, _: Any, instance: Any, schema: Any): conditions=validator.context.conditions.evolve( conditions, ), + path=validator.context.path.descend( + path=key, + cfn_path=key, + ), ), schema={ "type": ["array", "string"], @@ -52,5 +57,5 @@ def validate(self, validator: Validator, _: Any, instance: Any, schema: Any): ) for err in self._iter_errors(validator, value): - err.path.appendleft("Value") + err.path.appendleft(key) yield err diff --git a/test/unit/rules/outputs/test_value.py b/test/unit/rules/outputs/test_value.py index e2739cfec9..ec1b481d45 100644 --- a/test/unit/rules/outputs/test_value.py +++ b/test/unit/rules/outputs/test_value.py @@ -7,11 +7,14 @@ import pytest +from cfnlint.context import Path from cfnlint.jsonschema import CfnTemplateValidator, ValidationError from cfnlint.rules.functions.Cidr import Cidr +from cfnlint.rules.functions.ImportValue import ImportValue from cfnlint.rules.functions.Join import Join from cfnlint.rules.functions.Ref import Ref from cfnlint.rules.functions.RefResolved import RefResolved +from cfnlint.rules.outputs.ImportValue import ImportValue as OutputsImportValue from cfnlint.rules.outputs.Value import Value # pylint: disable=E0401 @@ -54,19 +57,34 @@ def template(): @pytest.fixture -def validator(cfn): +def path(): + return Path( + path=deque(["Outputs", "Test"]), + value_path=deque(), + cfn_path=deque(["Outputs", "*"]), + ) + + +@pytest.fixture +def validator(cfn, context): ref = Ref() ref.child_rules["W1030"] = RefResolved() + + importvalue = ImportValue() + importvalue.child_rules["W6001"] = OutputsImportValue() + yield CfnTemplateValidator(schema={}).extend( validators={ "fn_join": Join().fn_join, "ref": ref.ref, "fn_cidr": Cidr().fn_cidr, + "fn_importvalue": importvalue.fn_importvalue, } )( schema={}, cfn=cfn, + context=context, ) @@ -143,6 +161,23 @@ def validator(cfn): ) ], ), + ( + { + "Value": {"Fn::ImportValue": "test-stack-value"}, + }, + [ + ValidationError( + ( + "The output value {'Fn::ImportValue': 'test-stack-value'} " + "is an import from another output" + ), + validator="fn_importvalue", + schema_path=deque(["fn_importvalue"]), + path=deque(["Value", "Fn::ImportValue"]), + rule=OutputsImportValue(), + ) + ], + ), ( { "Condition": "isAdditionalVpc",