Skip to content

Commit

Permalink
Merge pull request #192 from janowagner/extended-severities
Browse files Browse the repository at this point in the history
Create extended severities object
  • Loading branch information
timopollmeier authored Oct 15, 2020
2 parents c2292d6 + f4ab2e6 commit 83c525c
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

### Changed
- Get all results from main kb. [#285](https://github.com/greenbone/ospd-openvas/pull/285)
- Extend severities with origin and date. [#192](https://github.com/greenbone/ospd-openvas/pull/192)

### Removed
- Remove methods handling the nvticache name. [#318](https://github.com/greenbone/ospd-openvas/pull/318)
Expand Down
11 changes: 8 additions & 3 deletions ospd_openvas/daemon.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
# Copyright (C) 2014-2020 Greenbone Networks GmbH
# Copyright (C) 2019-2020 Greenbone Networks GmbH
#
# SPDX-License-Identifier: AGPL-3.0-or-later
#
Expand Down Expand Up @@ -621,13 +621,18 @@ def get_severities_vt_as_xml_str(vt_id: str, severities: Dict) -> str:
_severity = SubElement(_severities, 'severity')
if 'severity_base_vector' in severities:
try:
_severity.text = severities.get('severity_base_vector')
_value = SubElement(_severity, 'value')
_value.text = severities.get('severity_base_vector')
except ValueError as e:
logger.warning(
"Not possible to parse severity tag for vt %s: %s", vt_id, e
)
if 'severity_origin' in severities:
_severity.set('origin', severities.get('severity_origin'))
_origin = SubElement(_severity, 'origin')
_origin.text = severities.get('severity_origin')
if 'severity_date' in severities:
_date = SubElement(_severity, 'date')
_date.text = severities.get('severity_date')
if 'severity_type' in severities:
_severity.set('type', severities.get('severity_type'))

Expand Down
2 changes: 2 additions & 0 deletions tests/dummydaemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ class DummyDaemon(OSPDopenvas):
'severities': {
'severity_base_vector': 'AV:N/AC:L/Au:N/C:N/I:N/A:N',
'severity_type': 'cvss_base_v2',
'severity_date': '1237458156',
'severity_origin': 'Greenbone',
},
'solution': 'some solution',
'solution_type': 'WillNotFix',
Expand Down
19 changes: 14 additions & 5 deletions tests/test_daemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,9 @@ def test_get_severities_xml(self):
out = (
'<severities>'
'<severity type="cvss_base_v2">'
'AV:N/AC:L/Au:N/C:N/I:N/A:N'
'<value>AV:N/AC:L/Au:N/C:N/I:N/A:N</value>'
'<origin>Greenbone</origin>'
'<date>1237458156</date>'
'</severity>'
'</severities>'
)
Expand Down Expand Up @@ -687,7 +689,9 @@ def test_feed_is_outdated_none(
@patch('ospd_openvas.daemon.Path.exists')
@patch('ospd_openvas.daemon.Path.open')
def test_feed_is_outdated_true(
self, mock_path_open: MagicMock, mock_path_exists: MagicMock,
self,
mock_path_open: MagicMock,
mock_path_exists: MagicMock,
):
read_data = 'PLUGIN_SET = "1235";'

Expand All @@ -710,7 +714,9 @@ def test_feed_is_outdated_true(
@patch('ospd_openvas.daemon.Path.exists')
@patch('ospd_openvas.daemon.Path.open')
def test_feed_is_outdated_false(
self, mock_path_open: MagicMock, mock_path_exists: MagicMock,
self,
mock_path_open: MagicMock,
mock_path_exists: MagicMock,
):
mock_path_exists.return_value = True

Expand Down Expand Up @@ -808,7 +814,8 @@ def test_get_openvas_result_dead_hosts(self, MockDBClass):

w.report_openvas_results(MockDBClass, '123-456')
w.scan_collection.set_amount_dead_hosts.assert_called_with(
'123-456', total_dead=4,
'123-456',
total_dead=4,
)

@patch('ospd_openvas.daemon.BaseDB')
Expand All @@ -831,7 +838,9 @@ def test_get_openvas_result_host_start(
w.report_openvas_results(MockDBClass, '123-456')

mock_add_scan_log_to_list.assert_called_with(
host='192.168.10.124', name='HOST_START', value='today 1',
host='192.168.10.124',
name='HOST_START',
value='today 1',
)

@patch('ospd_openvas.daemon.BaseDB')
Expand Down

0 comments on commit 83c525c

Please sign in to comment.