-
-
Notifications
You must be signed in to change notification settings - Fork 109
/
Copy pathtest_validators_logsource.py
96 lines (85 loc) · 2.38 KB
/
test_validators_logsource.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
from sigma.collection import SigmaCollection
from sigma.correlations import SigmaCorrelationRule
from sigma.rule import SigmaRule
from sigma.validators.core.logsources import FieldnameLogsourceIssue, FieldnameLogsourceValidator
from .test_conversion_correlations import event_count_correlation_rule
def test_fieldnamelogsourcevalidator_valid():
validator = FieldnameLogsourceValidator()
rule = SigmaRule.from_yaml(
"""
title: Test
status: test
logsource:
product: test
category: test
service: test
definition: test
detection:
sel:
field: value
condition: sel
"""
)
assert validator.validate(rule) == []
def test_fieldnamelogsourcevalidator_service_invalid():
validator = FieldnameLogsourceValidator()
rule = SigmaRule.from_yaml(
"""
title: Test
status: test
logsource:
product: test
category: test
services: test
definition: test
detection:
sel:
field: value
condition: sel
"""
)
assert validator.validate(rule) == [FieldnameLogsourceIssue(rule, "services")]
def test_fieldnamelogsourcevalidator_definition_invalid():
validator = FieldnameLogsourceValidator()
rule = SigmaRule.from_yaml(
"""
title: Test
status: test
logsource:
product: test
description: test
detection:
sel:
field: value
condition: sel
"""
)
assert validator.validate(rule) == [FieldnameLogsourceIssue(rule, "description")]
def test_fieldnamelogsourcevalidator_many_invalid():
validator = FieldnameLogsourceValidator()
rule = SigmaRule.from_yaml(
"""
title: Test
status: test
logsource:
editor: test
category: test
description: test
detection:
sel:
field: value
condition: sel
"""
)
assert validator.validate(rule) == [
FieldnameLogsourceIssue(rule, "editor"),
FieldnameLogsourceIssue(rule, "description"),
]
def test_fieldnamelogsourcevalidator_correlation_rule(event_count_correlation_rule):
validator = FieldnameLogsourceValidator()
correlation_rule = [
rule
for rule in event_count_correlation_rule.rules
if isinstance(rule, SigmaCorrelationRule)
][0]
assert validator.validate(correlation_rule) == []