|
5 | 5 |
|
6 | 6 | from checkov.common.checks_infra.checks_parser import GraphCheckParser |
7 | 7 | from checkov.common.checks_infra.resources_types import resources_types as raw_resources_types |
| 8 | +from checkov.common.graph.checks_infra.enums import SolverType |
8 | 9 |
|
9 | 10 | EXAMPLES_DIR = Path(__file__).parent / "examples" |
10 | 11 |
|
@@ -91,3 +92,49 @@ def test_parse_taggable_resource_list(): |
91 | 92 | providers = ["azure"] |
92 | 93 | check = parser._parse_raw_check(raw_check, [], providers) |
93 | 94 | assert check.resource_types == raw_resources_types.get("azure_taggable") |
| 95 | + |
| 96 | + |
| 97 | +def test_validate_check_config_list_definition(caplog: LogCaptureFixture): |
| 98 | + """A definition that is a list should pass validation.""" |
| 99 | + # given |
| 100 | + file_path = EXAMPLES_DIR / "valid_check_list_definition.yaml" |
| 101 | + check_yaml = yaml.safe_load(file_path.read_text()) |
| 102 | + |
| 103 | + # when |
| 104 | + valid = GraphCheckParser().validate_check_config(file_path=str(file_path), raw_check=check_yaml) |
| 105 | + |
| 106 | + # then |
| 107 | + assert valid |
| 108 | + assert len(caplog.messages) == 0 |
| 109 | + |
| 110 | + |
| 111 | +def test_parse_raw_check_list_definition(): |
| 112 | + """A list-type definition should be treated as an implicit AND of its elements.""" |
| 113 | + parser = GraphCheckParser() |
| 114 | + raw_check = { |
| 115 | + "metadata": {"id": "TEST_LIST", "name": "Test List Def", "category": "GENERAL_SECURITY"}, |
| 116 | + "definition": [ |
| 117 | + { |
| 118 | + "cond_type": "attribute", |
| 119 | + "resource_types": ["aws_s3_bucket"], |
| 120 | + "attribute": "versioning.enabled", |
| 121 | + "operator": "equals", |
| 122 | + "value": "true", |
| 123 | + }, |
| 124 | + { |
| 125 | + "cond_type": "attribute", |
| 126 | + "resource_types": ["aws_s3_bucket"], |
| 127 | + "attribute": "server_side_encryption_configuration", |
| 128 | + "operator": "exists", |
| 129 | + }, |
| 130 | + ], |
| 131 | + } |
| 132 | + |
| 133 | + check = parser.parse_raw_check(raw_check) |
| 134 | + |
| 135 | + assert check.id == "TEST_LIST" |
| 136 | + assert check.type == SolverType.COMPLEX |
| 137 | + assert check.operator == "and" |
| 138 | + assert len(check.sub_checks) == 2 |
| 139 | + assert check.sub_checks[0].attribute == "versioning.enabled" |
| 140 | + assert check.sub_checks[1].attribute == "server_side_encryption_configuration" |
0 commit comments