• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

ninoseki / abuse_whois / 4020719131

pending completion
4020719131

push

github

GitHub
Merge pull request #42 from ninoseki/sigma

300 of 421 new or added lines in 19 files covered. (71.26%)

7 existing lines in 4 files now uncovered.

608 of 791 relevant lines covered (76.86%)

1.54 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

60.87
/abuse_whois/pysigma/validator.py
1
import datetime
2✔
2
import uuid
2✔
3
from dataclasses import dataclass, field
2✔
4
from typing import Any
2✔
5

6
from .exceptions import RuleLoadError, UnsupportedFeature
2✔
7
from .factories import RuleFactory
2✔
8

9
MANDATORY_FIELDS = [
2✔
10
    "title",
11
    "detection",
12
]
13
OPTIONAL_FIELDS = [
2✔
14
    "author",
15
    "description",
16
    "falsepositives",
17
    "fields",
18
    "id",
19
    "level",
20
    "logsource",
21
    "references",
22
    "related",
23
    "status",
24
    "tags",
25
]
26

27

28
def validate_date(date_text: str):
2✔
NEW
29
    try:
×
NEW
30
        if date_text != datetime.datetime.strptime(date_text, "%Y/%m/%d").strftime(
×
31
            "%Y/%m/%d"
32
        ):
NEW
33
            raise ValueError
×
NEW
34
        return True
×
NEW
35
    except ValueError:
×
NEW
36
        return False
×
37

38

39
def validate_uuid(value: str):
2✔
40
    # Checks if uuid complies with version 4 uuid
NEW
41
    try:
×
NEW
42
        uuid.UUID(str(value), version=4)
×
NEW
43
        return True
×
NEW
44
    except ValueError:
×
NEW
45
        return False
×
46

47

48
@dataclass
2✔
49
class SigmaReturn:
2✔
50
    msg: str
2✔
51
    key: str
2✔
52
    description: str | None = field(default=None)
2✔
53

54

55
class SigmaValidator:
2✔
56
    def __init__(self, data: dict[Any, Any]):
2✔
57
        self.data = data
2✔
58
        self.file_errors: list[SigmaReturn] = []
2✔
59
        self.sigma_rules = None
2✔
60

61
        self.validate_errors()
2✔
62

63
    def validate_errors(self):
2✔
64
        errors: list[SigmaReturn] = []
2✔
65
        for key in MANDATORY_FIELDS:
2✔
66
            if key not in self.data:
2✔
NEW
67
                errors.append(SigmaReturn("Missing field ", key))
×
68

69
        # Test signature load
70
        try:
2✔
71
            RuleFactory.from_data(self.data)
2✔
NEW
72
        except ValueError as e:
×
NEW
73
            errors.append(SigmaReturn("Signature Load error", e))
×
NEW
74
        except RuleLoadError as e:
×
NEW
75
            errors.append(SigmaReturn("Signature Load error", e))
×
NEW
76
        except UnsupportedFeature as e:
×
NEW
77
            errors.append(SigmaReturn("Unsupported feature ", e))
×
78

79
        self.file_errors = errors
2✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc