Skip to content

Commit 9345e0e

Browse files
Add unit test for protected prebuilt-rules (#5242)
1 parent 5662427 commit 9345e0e

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
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.5.3"
3+
version = "1.5.4"
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 & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1112,6 +1112,30 @@ def test_ml_integration_jobs_exist(self):
11121112
f"The following ({len(failures)}) rules are missing a valid `machine_learning_job_id`:\n{err_msg}"
11131113
)
11141114

1115+
def test_preserve_upstream_protected_rule_id_name(self):
1116+
"""
1117+
Ensure upstream referenced rule IDs and rule names remain unchanged
1118+
"""
1119+
protected_rules = {"9a1a2dae-0b5f-4c3d-8305-a268d404c306": "Endpoint Security (Elastic Defend)"}
1120+
1121+
failures: list[str] = []
1122+
for rule_id, rule_name in protected_rules.items():
1123+
try:
1124+
if rule_name != self.rc.id_map[rule_id].name:
1125+
failures.append(
1126+
f"Protected rule_id {rule_id} name modified from '{rule_name}' to '{self.rc.id_map[rule_id].name}' - review upstream impact"
1127+
)
1128+
except KeyError:
1129+
failures.append(
1130+
f"Protected rule: {rule_name} rule_id: {rule_id} missing/modified - review upstream impact"
1131+
)
1132+
1133+
if failures:
1134+
fail_msg = """
1135+
The following protected prebuilt rules have missing/modified rule IDs or names \n
1136+
"""
1137+
self.fail(fail_msg + "\n".join(failures))
1138+
11151139

11161140
class TestRuleTiming(BaseRuleTest):
11171141
"""Test rule timing and timestamps."""

0 commit comments

Comments
 (0)