|
36 | 36 | from detection_rules.rule_loader import FILE_PATTERN, RULES_CONFIG |
37 | 37 | from detection_rules.rule_validators import EQLValidator, KQLValidator |
38 | 38 | from detection_rules.schemas import definitions, get_min_supported_stack_version, get_stack_schemas |
39 | | -from detection_rules.utils import INTEGRATION_RULE_DIR, PatchedTemplate, get_path, make_git |
| 39 | +from detection_rules.utils import INTEGRATION_RULE_DIR, PatchedTemplate, get_path, load_etc_dump, make_git |
40 | 40 | from detection_rules.version_lock import loaded_version_lock |
41 | 41 |
|
42 | 42 | from .base import BaseRuleTest |
@@ -1040,6 +1040,29 @@ def test_event_dataset(self): |
1040 | 1040 | if validation_integrations_check and "event.dataset" in rule.contents.data.query: |
1041 | 1041 | raise validation_integrations_check |
1042 | 1042 |
|
| 1043 | + def test_min_stack_version_supported(self): |
| 1044 | + """Test that rules have a min_stack_version that is supported in stack-schema-map.yaml.""" |
| 1045 | + failures = [] |
| 1046 | + # Load supported stack versions from stack-schema-map.yaml |
| 1047 | + stack_map = load_etc_dump(["stack-schema-map.yaml"]) |
| 1048 | + |
| 1049 | + # Get the minimum supported stack version as version object |
| 1050 | + min_supported = min(stack_map.keys(), key=lambda v: Version.parse(v)) |
| 1051 | + # Load all production rules |
| 1052 | + for rule in self.all_rules: |
| 1053 | + min_stack_version = rule.contents.metadata.get("min_stack_version") |
| 1054 | + if not min_stack_version: |
| 1055 | + continue # skip rules without min_stack_version |
| 1056 | + # Compare versions using semantic versioning |
| 1057 | + if Version.parse(min_stack_version) < min_supported: |
| 1058 | + failures.append( |
| 1059 | + f"{self.rule_str(rule)} min_stack_version={min_stack_version} < supported={min_supported}" |
| 1060 | + ) |
| 1061 | + |
| 1062 | + if failures: |
| 1063 | + fail_msg = "The following rules have min_stack_version lower than the minimum supported in stack-schema-map.yaml:\n" |
| 1064 | + self.fail(fail_msg + "\n".join(failures)) |
| 1065 | + |
1043 | 1066 |
|
1044 | 1067 | class TestIntegrationRules(BaseRuleTest): |
1045 | 1068 | """Test integration rules.""" |
|
0 commit comments