-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Store CVSS severity in combined deb information
- Loading branch information
Showing
7 changed files
with
154 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# SPDX-License-Identifier: MIT | ||
|
||
from __future__ import annotations | ||
|
||
import enum | ||
|
||
|
||
@enum.verify(enum.UNIQUE) | ||
class CvssSeverity(enum.Enum): | ||
NONE = 0 | ||
LOW = 1 | ||
MEDIUM = 2 | ||
HIGH = 3 | ||
CRITICAL = 4 | ||
|
||
@classmethod | ||
def from_score(cls, score: int) -> Self: | ||
if score < 0 or score > 10: | ||
raise ValueError | ||
if score >= 9: | ||
return cls.CRITICAL | ||
if score >= 7: | ||
return cls.HIGH | ||
if score >= 4: | ||
return cls.MEDIUM | ||
if score > 0: | ||
return cls.LOW | ||
return cls.NONE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# SPDX-License-Identifier: MIT | ||
|
||
import pytest | ||
|
||
from glvd.data.cvss import CvssSeverity | ||
|
||
|
||
class TestCvssSeverity: | ||
@pytest.mark.parametrize('score,value', [ | ||
(0, CvssSeverity.NONE), | ||
(1, CvssSeverity.LOW), | ||
(4, CvssSeverity.MEDIUM), | ||
(7, CvssSeverity.HIGH), | ||
(9, CvssSeverity.CRITICAL), | ||
(10, CvssSeverity.CRITICAL), | ||
]) | ||
def test_from_score(self, score, value): | ||
a = CvssSeverity.from_score(score) | ||
assert a is value | ||
|
||
@pytest.mark.parametrize('score', [-0.1,10.1]) | ||
def test_from_score_fail(self, score): | ||
with pytest.raises(ValueError): | ||
CvssSeverity.from_score(score) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters