Skip to content

Commit 5df3e23

Browse files
shashank-elastictradebot-elastic
authored andcommitted
Add test_min_stack_version_supported testcase (#5077)
(cherry picked from commit a6dfd2c)
1 parent 1142b04 commit 5df3e23

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "detection_rules"
3-
version = "1.3.31"
3+
version = "1.3.32"
44
description = "Detection Rules is the home for rules used by Elastic Security. This repository is used for the development, maintenance, testing, validation, and release of rules for Elastic Security’s Detection Engine."
55
readme = "README.md"
66
requires-python = ">=3.12"

tests/test_all_rules.py

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
from detection_rules.rule_loader import FILE_PATTERN, RULES_CONFIG
3737
from detection_rules.rule_validators import EQLValidator, KQLValidator
3838
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
4040
from detection_rules.version_lock import loaded_version_lock
4141

4242
from .base import BaseRuleTest
@@ -1040,6 +1040,29 @@ def test_event_dataset(self):
10401040
if validation_integrations_check and "event.dataset" in rule.contents.data.query:
10411041
raise validation_integrations_check
10421042

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

10441067
class TestIntegrationRules(BaseRuleTest):
10451068
"""Test integration rules."""

0 commit comments

Comments
 (0)