Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix NestedProcessingTransformation #298

Merged
merged 5 commits into from
Nov 10, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion sigma/processing/transformations.py
Original file line number Diff line number Diff line change
Expand Up @@ -1165,9 +1165,10 @@ class NestedProcessingTransformation(Transformation):

def __post_init__(self):
from sigma.processing.pipeline import (
ProcessingPipeline,
ProcessingPipeline, ProcessingItem
) # TODO: move to top-level after restructuring code

self.items = [i if isinstance(i, ProcessingItem) else ProcessingItem.from_dict(i) for i in self.items]
self._nested_pipeline = ProcessingPipeline(items=self.items)

@classmethod
Expand Down
40 changes: 39 additions & 1 deletion tests/test_processing_transformations.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
IncludeFieldCondition,
RuleContainsDetectionItemCondition,
RuleProcessingItemAppliedCondition,
rule_conditions,
)
from sigma.rule import SigmaLogSource, SigmaRule, SigmaDetection, SigmaDetectionItem
from sigma.types import (
Expand All @@ -71,7 +72,6 @@
RuleConditionFalse,
RuleConditionTrue,
TransformationAppend,
inject_test_classes,
)


Expand Down Expand Up @@ -1544,6 +1544,13 @@ def test_regex_transformation_plain_method(dummy_pipeline):
assert detection_item.value[0] == SigmaRegularExpression("\\\\te\\.st.*va.ue")


def test_regex_transformation_empty_string(dummy_pipeline):
detection_item = SigmaDetectionItem("field", [], [SigmaString("")])
transformation = RegexTransformation(method="plain")
transformation.apply_detection_item(detection_item)
assert detection_item.value[0] == SigmaRegularExpression("")


def test_regex_transformation_case_insensitive_bracket_method(dummy_pipeline):
detection_item = SigmaDetectionItem("field", [], [SigmaString("\\tE.sT*val?ue")])
transformation = RegexTransformation(method="ignore_case_brackets")
Expand Down Expand Up @@ -1767,6 +1774,37 @@ def test_nested_pipeline_transformation_from_dict(nested_pipeline_transformation
)


def test_nested_pipeline_transformation_from_yaml(nested_pipeline_transformation, monkeypatch):
monkeypatch.setitem(transformations, "append", TransformationAppend)
monkeypatch.setitem(rule_conditions, "true", RuleConditionTrue)
monkeypatch.setitem(rule_conditions, "false", RuleConditionFalse)
assert (
ProcessingPipeline.from_yaml(
"""
name: Test
priority: 100
transformations:
- type: nest
items:
- id: test
type: append
s: Test
rule_conditions:
- type: "true"
dummy: test-true
- type: "false"
dummy: test-false
rule_cond_op: or
"""
)
== ProcessingPipeline(
name="Test",
priority=100,
items=[ProcessingItem(nested_pipeline_transformation)],
)
)


def test_nested_pipeline_transformation_from_dict_apply(
dummy_pipeline, sigma_rule, nested_pipeline_transformation
):
Expand Down
Loading