|
14 | 14 |
|
15 | 15 | import eql |
16 | 16 | import kql |
| 17 | +import yaml |
17 | 18 | from marshmallow import ValidationError |
18 | 19 | from semver import Version |
19 | 20 |
|
@@ -1040,6 +1041,35 @@ def test_event_dataset(self): |
1040 | 1041 | if validation_integrations_check and "event.dataset" in rule.contents.data.query: |
1041 | 1042 | raise validation_integrations_check |
1042 | 1043 |
|
| 1044 | + def test_min_stack_version_supported(self): |
| 1045 | + failures = [] |
| 1046 | + # Load supported stack versions from stack-schema-map.yaml |
| 1047 | + stack_map_path = Path("detection_rules/etc/stack-schema-map.yaml") |
| 1048 | + with Path.open(stack_map_path) as f: |
| 1049 | + stack_map = yaml.safe_load(f) |
| 1050 | + |
| 1051 | + # Get the minimum supported stack version (as string) |
| 1052 | + supported_versions = [v for v in stack_map if not v.startswith("#") and isinstance(v, str)] |
| 1053 | + min_supported = min(supported_versions, key=lambda v: tuple(map(int, v.split(".")))) |
| 1054 | + # Load all production rules |
| 1055 | + for rule in self.all_rules: |
| 1056 | + min_stack_version = rule.contents.metadata.get("min_stack_version") |
| 1057 | + if not min_stack_version: |
| 1058 | + continue # skip rules without min_stack_version |
| 1059 | + # Compare versions as tuples of ints |
| 1060 | + def version_tuple(v): |
| 1061 | + return tuple(map(int, v.split("."))) |
| 1062 | + |
| 1063 | + if version_tuple(min_stack_version) < version_tuple(min_supported): |
| 1064 | + failures.append( |
| 1065 | + f"{self.rule_str(rule)}" |
| 1066 | + f"min_stack_version={min_stack_version} < supported={min_supported}" |
| 1067 | + ) |
| 1068 | + |
| 1069 | + if failures: |
| 1070 | + fail_msg = "The following rules have min_stack_version lower than the minimum supported in stack-schema-map.yaml:\n" |
| 1071 | + self.fail(fail_msg + "\n".join(failures)) |
| 1072 | + |
1043 | 1073 |
|
1044 | 1074 | class TestIntegrationRules(BaseRuleTest): |
1045 | 1075 | """Test integration rules.""" |
|
0 commit comments