Skip to content

Commit

Permalink
Fix: qod-type is in advisory not meta-data
Browse files Browse the repository at this point in the history
Instead of asking meta-data and always fallback to package use the
defined value within advisory.
  • Loading branch information
nichtsfrei committed Oct 11, 2022
1 parent c77098b commit fd1d529
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
2 changes: 1 addition & 1 deletion ospd_openvas/notus.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ def __to_ospd(
'Checks if a vulnerable package version is present on the target'
' host.'
)
result['qod_type'] = meta_data.get('qod_type', 'package')
result['qod_type'] = advisory.get('qod_type', 'package')
severity = advisory.get('severity', {})
cvss = severity.get("cvss_v3", None)
if not cvss:
Expand Down
31 changes: 30 additions & 1 deletion tests/test_notus.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,36 @@ def test_notus_reload(self, mock_openvasdb):
do_not_load_into_redis.reload_cache()
self.assertEqual(mock_openvasdb.set_single_item.call_count, 0)

def test_notus_qod_type(self):
path_mock = mock.MagicMock()
adv_path = mock.MagicMock()
adv_path.name = "hi"
adv_path.stem = "family"
path_mock.glob.return_value = [adv_path]
adv_path.read_bytes.return_value = b'''
{
"family": "family",
"advisories": [
{
"oid": "12",
"qod_type": "package_unreliable",
"severity": {
"origin": "NVD",
"date": 1505784960,
"cvss_v2": "AV:N/AC:M/Au:N/C:C/I:C/A:C",
"cvss_v3": null
}
}
]
}'''
cache_fake = CacheFake()
notus = Notus(path_mock, cache_fake)
notus._verifier = lambda _: True # pylint: disable=protected-access
notus.reload_cache()
nm = notus.get_nvt_metadata("12")
assert nm
self.assertEqual("package_unreliable", nm.get("qod_type", ""))

def test_notus_cvss_v2_v3_none(self):
path_mock = mock.MagicMock()
adv_path = mock.MagicMock()
Expand All @@ -107,7 +137,6 @@ def test_notus_cvss_v2_v3_none(self):
adv_path.read_bytes.return_value = b'''
{
"family": "family",
"qod_type": "remote_app",
"advisories": [
{
"oid": "12",
Expand Down

0 comments on commit fd1d529

Please sign in to comment.