Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions vulnerabilities/severity_systems.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ def compute(self, scoring_elements: str) -> str:
Return a normalized numeric score as a string for this scoring system
given a ``scoring_elements`` string value.
"""
return NotImplementedError
raise NotImplementedError

def get(self, scoring_elements: str):
return NotImplementedError
raise NotImplementedError

def __str__(self):
return f"{self.identifier}"
Expand Down Expand Up @@ -227,7 +227,7 @@ def get(self, scoring_elements: str) -> dict:
@dataclasses.dataclass(order=True)
class EPSSScoringSystem(ScoringSystem):
def compute(self, scoring_elements: str):
return NotImplementedError
raise NotImplementedError


EPSS = EPSSScoringSystem(
Expand Down
32 changes: 32 additions & 0 deletions vulnerabilities/tests/test_get_serverity.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,13 @@
from cvss.exceptions import CVSS2MalformedError
from cvss.exceptions import CVSS3MalformedError

from vulnerabilities.severity_systems import CVSS31_QUALITY
from vulnerabilities.severity_systems import CVSSV2
from vulnerabilities.severity_systems import CVSSV3
from vulnerabilities.severity_systems import EPSS
from vulnerabilities.severity_systems import GENERIC
from vulnerabilities.severity_systems import REDHAT_BUGZILLA
from vulnerabilities.severity_systems import SSVC
from vulnerabilities.templatetags.show_cvss import cvss_printer


Expand Down Expand Up @@ -98,3 +103,30 @@ def test_cvss_printer():
"<p class='has-text-grey mb-2'>medium</p>"
"<p class='has-text-grey mb-2'>low</p>"
)


@pytest.mark.parametrize(
"scoring_system, scoring_elements",
[
(GENERIC, "HIGH"),
(REDHAT_BUGZILLA, "important"),
(CVSS31_QUALITY, "HIGH"),
(EPSS, "0.95"),
],
)
def test_unimplemented_scoring_system_raises_not_implemented_error(
scoring_system, scoring_elements
):
with pytest.raises(NotImplementedError):
scoring_system.get(scoring_elements)

with pytest.raises(NotImplementedError):
scoring_system.compute(scoring_elements)


def test_ssvc_scoring_system_compute_raises_and_get_returns_vector():
vector = "SSVCv2/E:A/A:Y/T:T/P:M/2024-01-01T00:00:00Z/"
assert SSVC.get(vector) == {"version": "ssvc", "vectorString": vector}

with pytest.raises(NotImplementedError):
SSVC.compute(vector)