Skip to content

Commit 2cfe620

Browse files
Add test_min_stack_version_supported testcase
1 parent 392e025 commit 2cfe620

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

tests/test_all_rules.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
import eql
1616
import kql
17+
import yaml
1718
from marshmallow import ValidationError
1819
from semver import Version
1920

@@ -1040,6 +1041,35 @@ def test_event_dataset(self):
10401041
if validation_integrations_check and "event.dataset" in rule.contents.data.query:
10411042
raise validation_integrations_check
10421043

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+
10431073

10441074
class TestIntegrationRules(BaseRuleTest):
10451075
"""Test integration rules."""

0 commit comments

Comments
 (0)