Skip to content

Commit

Permalink
optimize tags tests
Browse files Browse the repository at this point in the history
  • Loading branch information
frack113 committed Nov 4, 2023
1 parent 5be220e commit 7bf29dd
Showing 1 changed file with 31 additions and 61 deletions.
92 changes: 31 additions & 61 deletions tests/test_validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -755,68 +755,38 @@ def test_validator_duplicate_tags():


@pytest.mark.parametrize(
"cve_tags,cve_issue_tags",
"opt_validator_class,opt_tags,opt_issue_tags,opt_issue_class",
[
(["cve.2023.11.04", "cve.2023.007"], ["cve.2023.11.04"]),
(["cve.2023.007", "cve.2022.963"], []),
],
)
def test_validator_cve_tag(cve_tags, cve_issue_tags):
validator = CVETagValidator()
rule = SigmaRule.from_yaml(
"""
title: Test
status: test
logsource:
category: test
detection:
sel:
field: value
condition: sel
"""
)
rule.tags = [SigmaRuleTag.from_str(tag) for tag in cve_tags]
assert validator.validate(rule) == [
InvalidCVETagIssue([rule], SigmaRuleTag.from_str(tag)) for tag in cve_issue_tags
]


@pytest.mark.parametrize(
"detection_tags,detection_issue_tags",
[
(["detection.new_threats", "cve.2023.007"], ["detection.new_threats"]),
(["detection.emerging_threats", "cve.2022.963"], []),
],
)
def test_validator_detection_tag(detection_tags, detection_issue_tags):
validator = DetectionTagValidator()
rule = SigmaRule.from_yaml(
"""
title: Test
status: test
logsource:
category: test
detection:
sel:
field: value
condition: sel
"""
)
rule.tags = [SigmaRuleTag.from_str(tag) for tag in detection_tags]
assert validator.validate(rule) == [
InvalidDetectionTagIssue([rule], SigmaRuleTag.from_str(tag)) for tag in detection_issue_tags
]


@pytest.mark.parametrize(
"car_tags,car_issue_tags",
[
(["car.2016-04-005", "car.2023-011-11"], ["car.2023-011-11"]),
(["car.2016-04-005", "car.2023-11-011"], []),
(
CVETagValidator,
["cve.2023.11.04", "cve.2023.007"],
["cve.2023.11.04"],
InvalidCVETagIssue,
),
(CVETagValidator, ["cve.2023.007", "cve.2022.963"], [], InvalidCVETagIssue),
(
DetectionTagValidator,
["detection.new_threats", "cve.2023.007"],
["detection.new_threats"],
InvalidDetectionTagIssue,
),
(
DetectionTagValidator,
["detection.emerging_threats", "cve.2022.963"],
[],
InvalidDetectionTagIssue,
),
(
CARTagValidator,
["car.2016-04-005", "car.2023-011-11"],
["car.2023-011-11"],
InvalidCARTagIssue,
),
(CARTagValidator, ["car.2016-04-005", "car.2023-11-011"], [], InvalidCARTagIssue),
],
)
def test_validator_car_tag(car_tags, car_issue_tags):
validator = CARTagValidator()
def test_validator_optional_tag(opt_validator_class, opt_tags, opt_issue_tags, opt_issue_class):
validator = opt_validator_class()
rule = SigmaRule.from_yaml(
"""
title: Test
Expand All @@ -829,9 +799,9 @@ def test_validator_car_tag(car_tags, car_issue_tags):
condition: sel
"""
)
rule.tags = [SigmaRuleTag.from_str(tag) for tag in car_tags]
rule.tags = [SigmaRuleTag.from_str(tag) for tag in opt_tags]
assert validator.validate(rule) == [
InvalidCARTagIssue([rule], SigmaRuleTag.from_str(tag)) for tag in car_issue_tags
opt_issue_class([rule], SigmaRuleTag.from_str(tag)) for tag in opt_issue_tags
]


Expand Down

0 comments on commit 7bf29dd

Please sign in to comment.