Skip to content

Commit 368df94

Browse files
ppcadkmeinerz1
andauthored
Ensure "*_test.json" are not loaded as rules (#805)
* Ensure "*_test.json" are not loaded as rules * Skip loading tests in base processor unit tests as rules * added changelog entry --------- Co-authored-by: kmeinerz1 <kaithomas.meinerz@bwi.de>
1 parent 91e44b2 commit 368df94

File tree

4 files changed

+19
-2
lines changed

4 files changed

+19
-2
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
* add `replacer` processor to replace substrings in fields using a syntax similar to the `dissector`
88

99
### Improvements
10+
11+
* ensured that "_test.json" files are not loaded as rules
12+
1013
### Bugfix
1114

1215
- Fixed logging error in _revoke_callback() by adding error handling

logprep/util/rule_loader.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ def rule_definitions(self) -> List[Dict]:
197197
raise TypeError(f"Expected a string, got {type(self.source)}")
198198
if self.source.endswith(".yaml") or self.source.endswith(".yml"):
199199
rule_definitions = GetterFactory.from_string(self.source).get_yaml()
200-
elif self.source.endswith(".json"):
200+
elif self.source.endswith(".json") and not self.source.endswith("_test.json"):
201201
rule_definitions = GetterFactory.from_string(self.source).get_json()
202202
if not isinstance(rule_definitions, list):
203203
rule_definitions = [rule_definitions]
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[
2+
{
3+
"filter": "message",
4+
"clusterer": {
5+
"source_fields": ["message"],
6+
"pattern": "test (signature) test",
7+
"repl": "<+>\\1</+>"
8+
},
9+
"description": "insert a description text"
10+
}
11+
]

tests/unit/processor/base.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
ProcessingCriticalError,
2525
)
2626
from logprep.processor.base.rule import Rule
27+
from logprep.util.defaults import RULE_FILE_EXTENSIONS
2728
from tests.unit.component.base import BaseComponentTestCase
2829

2930
yaml = YAML(typ="safe", pure=True)
@@ -59,7 +60,9 @@ def set_rules(rules_dirs):
5960
rules = []
6061
for rules_dir in rules_dirs:
6162
rule_paths = [
62-
p for p in Path(rules_dir).glob("**/*") if p.suffix in [".yml", ".json", "yaml"]
63+
path
64+
for path in Path(rules_dir).glob("**/*")
65+
if path.suffix in RULE_FILE_EXTENSIONS and not path.name.endswith("_test.json")
6366
]
6467
for rule_path in rule_paths:
6568
loaded_rules = []

0 commit comments

Comments
 (0)