Skip to content

Commit

Permalink
Merge pull request #281 from frack113/remove_optional_validator
Browse files Browse the repository at this point in the history
Remove optional fields validator
  • Loading branch information
thomaspatzke authored Oct 10, 2024
2 parents b84ca95 + c53549a commit 4aec9da
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 339 deletions.
99 changes: 0 additions & 99 deletions sigma/validators/core/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,54 +113,6 @@ def validate(self, rule: SigmaRule) -> List[SigmaValidationIssue]:
]


@dataclass
class StatusExistenceIssue(SigmaValidationIssue):
description: ClassVar[str] = "Rule has no status"
severity: ClassVar[SigmaValidationIssueSeverity] = SigmaValidationIssueSeverity.MEDIUM


class StatusExistenceValidator(SigmaRuleValidator):
"""Checks if rule has a status."""

def validate(self, rule: SigmaRule) -> List[SigmaValidationIssue]:
if rule.status is None:
return [StatusExistenceIssue([rule])]
else:
return []


@dataclass
class StatusUnsupportedIssue(SigmaValidationIssue):
description: ClassVar[str] = "Rule has UNSUPPORTED status"
severity: ClassVar[SigmaValidationIssueSeverity] = SigmaValidationIssueSeverity.MEDIUM


class StatusUnsupportedValidator(SigmaRuleValidator):
"""Checks if rule has a status UNSUPPORTED."""

def validate(self, rule: SigmaRule) -> List[SigmaValidationIssue]:
if rule.status and rule.status.name == "UNSUPPORTED":
return [StatusUnsupportedIssue([rule])]
else:
return []


@dataclass
class DateExistenceIssue(SigmaValidationIssue):
description: ClassVar[str] = "Rule has no date"
severity: ClassVar[SigmaValidationIssueSeverity] = SigmaValidationIssueSeverity.MEDIUM


class DateExistenceValidator(SigmaRuleValidator):
"""Checks if rule has a data."""

def validate(self, rule: SigmaRule) -> List[SigmaValidationIssue]:
if rule.date is None:
return [DateExistenceIssue([rule])]
else:
return []


@dataclass
class DuplicateFilenameIssue(SigmaValidationIssue):
description: ClassVar[str] = "Rule filename used by multiple rules"
Expand Down Expand Up @@ -238,54 +190,3 @@ def validate(self, rule: SigmaRule) -> List[SigmaValidationIssue]:
if k in self.known_custom_attributes:
return [CustomAttributesIssue(rule, k)]
return []


@dataclass
class DescriptionExistenceIssue(SigmaValidationIssue):
description: ClassVar[str] = "Rule has no description"
severity: ClassVar[SigmaValidationIssueSeverity] = SigmaValidationIssueSeverity.MEDIUM


class DescriptionExistenceValidator(SigmaRuleValidator):
"""Checks if rule has a description."""

def validate(self, rule: SigmaRule) -> List[SigmaValidationIssue]:
if rule.description is None:
return [DescriptionExistenceIssue([rule])]
else:
return []


@dataclass
class DescriptionLengthIssue(SigmaValidationIssue):
description: ClassVar[str] = "Rule has a too short description"
severity: ClassVar[SigmaValidationIssueSeverity] = SigmaValidationIssueSeverity.MEDIUM


@dataclass(frozen=True)
class DescriptionLengthValidator(SigmaRuleValidator):
"""Checks if rule has a description."""

min_length: int = 16

def validate(self, rule: SigmaRule) -> List[SigmaValidationIssue]:
if rule.description is not None and len(rule.description) < self.min_length:
return [DescriptionLengthIssue([rule])]
else:
return []


@dataclass
class LevelExistenceIssue(SigmaValidationIssue):
description: ClassVar[str] = "Rule has no level"
severity: ClassVar[SigmaValidationIssueSeverity] = SigmaValidationIssueSeverity.MEDIUM


class LevelExistenceValidator(SigmaRuleValidator):
"""Checks if rule has a level."""

def validate(self, rule: SigmaRule) -> List[SigmaValidationIssue]:
if rule.level is None:
return [LevelExistenceIssue([rule])]
else:
return []
11 changes: 0 additions & 11 deletions tests/test_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
from tests.test_validators import rule_with_id, rule_without_id, rules_with_id_collision
from sigma.collection import SigmaCollection
from sigma.validators.core.metadata import (
DescriptionLengthValidator,
IdentifierExistenceValidator,
IdentifierUniquenessValidator,
IdentifierExistenceIssue,
Expand Down Expand Up @@ -81,17 +80,11 @@ def test_sigmavalidator_from_dict(validators):
"number_as_string",
],
},
"config": {
"description_length": {
"min_length": 100,
},
},
},
validators,
)
assert DanglingDetectionValidator in (v.__class__ for v in validator.validators)
assert TLPv1TagValidator not in (v.__class__ for v in validator.validators)
assert DescriptionLengthValidator(min_length=100) in validator.validators
assert len(validator.validators) >= 10
assert validator.exclusions == {
UUID("c702c6c7-1393-40e5-93f8-91469f3445ad"): {DanglingDetectionValidator},
Expand All @@ -114,15 +107,11 @@ def test_sigmavalidator_from_yaml(validators):
bf39335e-e666-4eaf-9416-47f1955b5fb3:
- attacktag
- number_as_string
config:
description_length:
min_length: 100
""",
validators,
)
assert DanglingDetectionValidator in (v.__class__ for v in validator.validators)
assert TLPv1TagValidator not in (v.__class__ for v in validator.validators)
assert DescriptionLengthValidator(min_length=100) in validator.validators
assert len(validator.validators) >= 10
assert validator.exclusions == {
UUID("c702c6c7-1393-40e5-93f8-91469f3445ad"): {DanglingDetectionValidator},
Expand Down
Loading

0 comments on commit 4aec9da

Please sign in to comment.