Skip to content

Commit

Permalink
Add support for excluded hosts.
Browse files Browse the repository at this point in the history
Update tests.
  • Loading branch information
jjnicola committed May 29, 2019
1 parent 6d0c497 commit a019a26
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
8 changes: 6 additions & 2 deletions ospd_openvas/wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -1053,15 +1053,19 @@ def exec_scan(self, scan_id, target):
self.openvas_db.add_single_item(
'internal/%s/globalscanid' % scan_id, [openvas_scan_id])

exclude_hosts = self.get_scan_exclude_hosts(scan_id, target)
if exclude_hosts:
options['exclude_hosts'] = exclude_hosts

# Get unfinished hosts, in case it is a resumed scan. And added
# into exclude_hosts scan preference. Set progress for the finished ones
# to 100%.
finished_hosts = self.get_scan_finished_hosts(scan_id)
exclude_hosts = options.get('exclude_hosts')
if finished_hosts:
if exclude_hosts:
finished_hosts_str = ','.join(finished_hosts)
options['exclude_hosts'] = exlude_hosts + ',' + finished_hosts_str
exclude_hosts = exclude_hosts + ',' + finished_hosts_str
options['exclude_hosts'] = exclude_hosts
else:
options['exclude_hosts'] = ','.join(finished_hosts)

Expand Down
6 changes: 3 additions & 3 deletions tests/testWrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ def test_process_vts(self, mock_nvti, mock_db):
def test_get_openvas_timestamp_scan_host_end(self, mock_nvti, mock_db):
mock_db.get_host_scan_scan_end_time.return_value = '12345'
w = DummyWrapper(mock_nvti, mock_db)
targets = [['192.168.0.1', 'port', 'cred']]
targets = [['192.168.0.1', 'port', 'cred', 'exclude_host']]
w.create_scan('123-456', targets, None, [])
w.get_openvas_timestamp_scan_host('123-456', '192.168.0.1')
for result in w.scan_collection.results_iterator('123-456', False):
Expand All @@ -444,7 +444,7 @@ def test_get_openvas_timestamp_scan_host_start(self, mock_nvti, mock_db):
mock_db.get_host_scan_scan_end_time.return_value = None
mock_db.get_host_scan_scan_end_time.return_value = '54321'
w = DummyWrapper(mock_nvti, mock_db)
targets = [['192.168.0.1', 'port', 'cred']]
targets = [['192.168.0.1', 'port', 'cred', 'exclude_host']]
w.create_scan('123-456', targets, None, [])
w.get_openvas_timestamp_scan_host('123-456', '192.168.0.1')
for result in w.scan_collection.results_iterator('123-456', False):
Expand Down Expand Up @@ -502,7 +502,7 @@ def test_get_openvas_result(self, mock_ospd, mock_nvti, mock_db):
@patch('ospd_openvas.wrapper.OSPDaemon.set_scan_target_progress')
def test_update_progress(self, mock_ospd, mock_nvti, mock_db):
msg = '0/-1'
targets = [['localhost', 'port', 'cred']]
targets = [['localhost', 'port', 'cred', 'exclude_host']]
w = DummyWrapper(mock_nvti, mock_db)
w.create_scan('123-456', targets, None, [])

Expand Down

0 comments on commit a019a26

Please sign in to comment.