Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jjnicola committed Sep 10, 2020
1 parent fc83900 commit 968b4b1
Showing 1 changed file with 35 additions and 16 deletions.
51 changes: 35 additions & 16 deletions tests/test_preferencehandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,19 +200,20 @@ def test_build_alive_test_opt_empty(self):
p = PreferenceHandler('1234-1234', None, w.scan_collection, None)
ret = p.build_alive_test_opt_as_prefs(target_options_dict)

self.assertEqual(ret, [])
self.assertEqual(ret, {})

def test_build_alive_test_opt(self):
w = DummyDaemon()

alive_test_out = [
"1.3.6.1.4.1.25623.1.0.100315:1:checkbox:Do a TCP ping|||no",
"1.3.6.1.4.1.25623.1.0.100315:2:checkbox:TCP ping tries also TCP-SYN ping|||no",
"1.3.6.1.4.1.25623.1.0.100315:7:checkbox:TCP ping tries only TCP-SYN ping|||no",
"1.3.6.1.4.1.25623.1.0.100315:3:checkbox:Do an ICMP ping|||yes",
"1.3.6.1.4.1.25623.1.0.100315:4:checkbox:Use ARP|||no",
"1.3.6.1.4.1.25623.1.0.100315:5:checkbox:Mark unrechable Hosts as dead (not scanning)|||yes",
]
alive_test_out = {
"1.3.6.1.4.1.25623.1.0.100315:1:checkbox:Do a TCP ping": "no",
"1.3.6.1.4.1.25623.1.0.100315:2:checkbox:TCP ping tries also TCP-SYN ping": "no",
"1.3.6.1.4.1.25623.1.0.100315:7:checkbox:TCP ping tries only TCP-SYN ping": "no",
"1.3.6.1.4.1.25623.1.0.100315:3:checkbox:Do an ICMP ping": "yes",
"1.3.6.1.4.1.25623.1.0.100315:4:checkbox:Use ARP": "no",
"1.3.6.1.4.1.25623.1.0.100315:5:checkbox:Mark unrechable Hosts as dead (not scanning)": "yes",
}

target_options_dict = {'alive_test': '2'}
p = PreferenceHandler('1234-1234', None, w.scan_collection, None)
ret = p.build_alive_test_opt_as_prefs(target_options_dict)
Expand Down Expand Up @@ -242,7 +243,8 @@ def test_set_target(self, mock_kb):
p.prepare_target_for_openvas()

p.kbdb.add_scan_preferences.assert_called_with(
p._openvas_scan_id, ['TARGET|||192.168.0.1'],
p._openvas_scan_id,
['TARGET|||192.168.0.1'],
)

@patch('ospd_openvas.db.KbDB')
Expand All @@ -257,7 +259,8 @@ def test_set_ports(self, mock_kb):
p.prepare_ports_for_openvas()

p.kbdb.add_scan_preferences.assert_called_with(
p._openvas_scan_id, ['port_range|||80,443'],
p._openvas_scan_id,
['port_range|||80,443'],
)

@patch('ospd_openvas.db.KbDB')
Expand All @@ -270,7 +273,8 @@ def test_set_main_kbindex(self, mock_kb):
p.prepare_main_kbindex_for_openvas()

p.kbdb.add_scan_preferences.assert_called_with(
p._openvas_scan_id, ['ov_maindbid|||2'],
p._openvas_scan_id,
['ov_maindbid|||2'],
)

@patch('ospd_openvas.db.KbDB')
Expand Down Expand Up @@ -363,7 +367,8 @@ def test_set_host_options(self, mock_kb):
p.prepare_host_options_for_openvas()

p.kbdb.add_scan_preferences.assert_called_with(
p._openvas_scan_id, ['exclude_hosts|||192.168.0.1'],
p._openvas_scan_id,
['exclude_hosts|||192.168.0.1'],
)

@patch('ospd_openvas.db.KbDB')
Expand Down Expand Up @@ -422,7 +427,10 @@ def test_set_reverse_lookup_opt(self, mock_kb):

p.kbdb.add_scan_preferences.assert_called_with(
p._openvas_scan_id,
['reverse_lookup_only|||yes', 'reverse_lookup_unify|||no',],
[
'reverse_lookup_only|||yes',
'reverse_lookup_unify|||no',
],
)

@patch('ospd_openvas.db.KbDB')
Expand Down Expand Up @@ -537,18 +545,29 @@ def test_set_alive_pinghost(self, mock_kb):
"1.3.6.1.4.1.25623.1.0.100315:5:checkbox:Mark unrechable Hosts as dead (not scanning)|||yes",
]

alive_test_preferences = {
"1.3.6.1.4.1.25623.1.0.100315:1:checkbox:Do a TCP ping": "no",
"1.3.6.1.4.1.25623.1.0.100315:2:checkbox:TCP ping tries also TCP-SYN ping": "no",
"1.3.6.1.4.1.25623.1.0.100315:7:checkbox:TCP ping tries only TCP-SYN ping": "no",
"1.3.6.1.4.1.25623.1.0.100315:3:checkbox:Do an ICMP ping": "yes",
"1.3.6.1.4.1.25623.1.0.100315:4:checkbox:Use ARP": "no",
"1.3.6.1.4.1.25623.1.0.100315:5:checkbox:Mark unrechable Hosts as dead (not scanning)": "yes",
}

t_opt = {'alive_test': 2}
w.scan_collection.get_target_options = MagicMock(return_value=t_opt)

ov_setting = {'some_setting': 1}

with patch.object(Openvas, 'get_settings', return_value=ov_setting):
p = PreferenceHandler('1234-1234', mock_kb, w.scan_collection, None)

p._nvts_params = {}
p._openvas_scan_id = '456-789'
p.kbdb.add_scan_preferences = MagicMock()
p.prepare_alive_test_option_for_openvas()
p.prepare_nvt_preferences()

p.kbdb.add_scan_preferences.assert_called_with(
p._openvas_scan_id, alive_test_out,
p._openvas_scan_id,
alive_test_out,
)

0 comments on commit 968b4b1

Please sign in to comment.