Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue #1302 #1303

Merged
merged 1 commit into from
Sep 18, 2023
Merged
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
1 change: 1 addition & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Next Release
- We fixed a text-overflow issue in the Essentials tab of the Vulnerability details template.
- We added clickable links to the Essentials tab of the Vulnerability details template that enable
the user to navigate to the Fixed by packages tab and the Affected packages tab.
- We fixed severity range issue for handling unknown scores.


Version v33.4.0
Expand Down
6 changes: 6 additions & 0 deletions vulnerabilities/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from vulnerabilities.package_managers import PackageVersion
from vulnerabilities.utils import AffectedPackage
from vulnerabilities.utils import get_item
from vulnerabilities.utils import get_severity_range
from vulnerabilities.utils import nearest_patched_package
from vulnerabilities.utils import resolve_version_range
from vulnerabilities.utils import split_markdown_front_matter
Expand Down Expand Up @@ -145,3 +146,8 @@ def test_resolve_version_range_without_ignorable_versions():
"10.0.0",
],
)


def test_get_severity_range():
assert get_severity_range({""}) is None
assert get_severity_range({}) is None
43 changes: 26 additions & 17 deletions vulnerabilities/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -512,20 +512,29 @@ def get_severity_range(severity_list):
'0.1 - 6.9'
>>> get_severity_range({'9.5','critical'})
'9.0 - 10.0'
"""
if len(severity_list) > 1:
score_map = {
"low": [0.1, 3],
"moderate": [4.0, 6.9],
"medium": [4.0, 6.9],
"high": [7.0, 8.9],
"critical": [9.0, 10.0],
}

score_list = []
for score in severity_list:
try:
score_list.append(float(score))
except ValueError:
score_list.extend(score_map[score.lower()])
return f"{min(score_list)} - {max(score_list)}"
>>> get_severity_range({'9.5','critical','unknown'})
'9.0 - 10.0'
>>> get_severity_range({})
"""
if len(severity_list) < 1:
return
score_map = {
"low": [0.1, 3],
"moderate": [4.0, 6.9],
"medium": [4.0, 6.9],
"high": [7.0, 8.9],
"important": [7.0, 8.9],
"critical": [9.0, 10.0],
}

score_list = []
for score in severity_list:
try:
score_list.append(float(score))
except ValueError:
score_range = score_map.get(score.lower()) or []
if score_range:
score_list.extend(score_range)
if not score_list:
return
return f"{min(score_list)} - {max(score_list)}"
Loading