Skip to content

Commit 4df4eac

Browse files
PR review comments
1 parent 10a735b commit 4df4eac

File tree

1 file changed

+5
-8
lines changed

1 file changed

+5
-8
lines changed

tests/test_all_rules.py

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

1515
import eql
1616
import kql
17-
import yaml
1817
from marshmallow import ValidationError
1918
from semver import Version
2019

@@ -37,7 +36,7 @@
3736
from detection_rules.rule_loader import FILE_PATTERN, RULES_CONFIG
3837
from detection_rules.rule_validators import EQLValidator, KQLValidator
3938
from detection_rules.schemas import definitions, get_min_supported_stack_version, get_stack_schemas
40-
from detection_rules.utils import ETC_DIR, INTEGRATION_RULE_DIR, PatchedTemplate, get_path, make_git
39+
from detection_rules.utils import load_etc_dump, INTEGRATION_RULE_DIR, PatchedTemplate, get_path, make_git
4140
from detection_rules.version_lock import loaded_version_lock
4241

4342
from .base import BaseRuleTest
@@ -1044,19 +1043,17 @@ def test_event_dataset(self):
10441043
def test_min_stack_version_supported(self):
10451044
failures = []
10461045
# Load supported stack versions from stack-schema-map.yaml
1047-
stack_map_path = Path(f"{ETC_DIR}/stack-schema-map.yaml")
1048-
with Path.open(stack_map_path) as f:
1049-
stack_map = yaml.safe_load(f)
1046+
stack_map = load_etc_dump(["stack-schema-map.yaml"])
10501047

1051-
# Get the minimum supported stack version (as string)
1052-
min_supported = min([v for v in stack_map if not v.startswith("#") and isinstance(v, str)])
1048+
# Get the minimum supported stack version as version object
1049+
min_supported = min(stack_map.keys(), key=lambda v: Version.parse(v))
10531050
# Load all production rules
10541051
for rule in self.all_rules:
10551052
min_stack_version = rule.contents.metadata.get("min_stack_version")
10561053
if not min_stack_version:
10571054
continue # skip rules without min_stack_version
10581055
# Compare versions using semantic versioning
1059-
if Version.parse(min_stack_version) < Version.parse(min_supported):
1056+
if Version.parse(min_stack_version) < min_supported:
10601057
failures.append(
10611058
f"{self.rule_str(rule)} min_stack_version={min_stack_version} < supported={min_supported}"
10621059
)

0 commit comments

Comments
 (0)