Skip to content

Commit 6cf6665

Browse files
committed
Add additional unit test
1 parent 9229c52 commit 6cf6665

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

detection_rules/rule_validators.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -711,7 +711,6 @@ def validate_query_text_with_schema(
711711
def validate_rule_type_configurations(self, data: EQLRuleData, meta: RuleMeta) -> tuple[list[str | None], bool]:
712712
"""Validate EQL rule type configurations."""
713713
if data.timestamp_field or data.event_category_override or data.tiebreaker_field:
714-
# get a list of rule type configuration fields
715714
# Get a list of rule type configuration fields
716715
fields = ["timestamp_field", "event_category_override", "tiebreaker_field"]
717716
set_fields = list(filter(None, (data.get(field) for field in fields))) # type: ignore[reportUnknownVariableType]

tests/test_python_library.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,30 @@ def test_sequence_across_integrations_invalid_crowdstrike_subquery_azure_field(s
238238
with self.assertRaisesRegex(ValueError, r"Error in both stack and integrations checks"):
239239
rc.load_dict(bad_rule)
240240

241+
def test_sequence_mixed_dataset_and_datasetless_subquery_invalid_field(self) -> None:
242+
"""First subquery has dataset; second is datasetless with an invalid vendor field; with no metadata integration
243+
for the datasetless subquery, integration validation so overall validation should fail.
244+
"""
245+
rc = RuleCollection()
246+
query = """
247+
sequence with maxspan=30m
248+
[any where event.dataset == "azure.auditlogs"] by azure.auditlogs.properties.initiated_by.user.userPrincipalName
249+
[any where foo.invalid_field == "badfield"] by host.id
250+
"""
251+
bad_rule = {
252+
# No integrations in metadata: datasetless subquery should not be validated against any integration
253+
"metadata": mk_metadata([], comments="Mixed dataset and datasetless invalid field"),
254+
"rule": mk_rule(
255+
name="EQL sequence mixed dataset and datasetless invalid",
256+
rule_id="5f6071aa-5678-4f8d-9f72-1d8e5f3e5f17",
257+
description="Second datasetless subquery contains an invalid field; expect failure.",
258+
risk_score=33,
259+
query=query,
260+
),
261+
}
262+
with self.assertRaisesRegex(ValueError, r"Error in both stack and integrations checks"):
263+
rc.load_dict(bad_rule)
264+
241265
def test_sequence_datasetless_subquery_with_metadata_integration_valid(self) -> None:
242266
"""Datasetless azure subquery uses azure.* fields with metadata including azure; should validate and pass."""
243267
rc = RuleCollection()

0 commit comments

Comments
 (0)