def test_scan_is_stopped(self, mock_nvti, mock_db): mock_db.get_single_item.return_value = 'stop_all' mock_db.kb_connect_item.return_value = mock_db mock_db.set_redisctx.return_value = None w = DummyWrapper(mock_nvti, mock_db) ret = w.scan_is_stopped('123-456') self.assertEqual(ret, True)
def test_parse_param(self, mock_subproc, mock_nvti, mock_db): mock_subproc.check_output.return_value = \ 'non_simult_ports = 22'.encode() w = DummyWrapper(mock_nvti, mock_db) w.parse_param() self.assertEqual(mock_subproc.check_output.call_count, 1) self.assertEqual(OSPD_PARAMS, OSPD_PARAMS_OUT)
def test_get_summary_xml(self, mock_nvti, mock_db): w = DummyWrapper(mock_nvti, mock_db) out = '<summary>some summary</summary>' vt = w.VT['1.3.6.1.4.1.25623.1.0.100061'] summary = vt.get('summary') res = w.get_summary_vt_as_xml_str( '1.3.6.1.4.1.25623.1.0.100061', summary) self.assertEqual(res, out)
def test_get_dependencies_xml(self, mock_nvti, mock_db): w = DummyWrapper(mock_nvti, mock_db) out = '<dependencies><dependency vt_id="1.2.3.4"/><dependency vt' \ '_id="4.3.2.1"/></dependencies>' dep = ['1.2.3.4', '4.3.2.1'] res = w.get_dependencies_vt_as_xml_str( '1.3.6.1.4.1.25623.1.0.100061', dep) self.assertEqual(res, out)
def test_get_insight_xml(self, mock_nvti, mock_db): w = DummyWrapper(mock_nvti, mock_db) out = '<insight>some insight</insight>' vt = w.VT['1.3.6.1.4.1.25623.1.0.100061'] insight = vt.get('insight') res = w.get_insight_vt_as_xml_str( '1.3.6.1.4.1.25623.1.0.100061', insight) self.assertEqual(res, out)
def test_get_severities_xml(self, mock_nvti, mock_db): w = DummyWrapper(mock_nvti, mock_db) out = '<severities><severity type="cvss_base_v2">' \ 'AV:N/AC:L/Au:N/C:N/I:N/A:N</severity></severities>' vt =w.VT['1.3.6.1.4.1.25623.1.0.100061'] severities = vt.get('severities') res = w.get_severities_vt_as_xml_str( '1.3.6.1.4.1.25623.1.0.100061', severities) self.assertEqual(res, out)
def test_get_affected_xml(self, mock_nvti, mock_db): w = DummyWrapper(mock_nvti, mock_db) out = '<affected>some affection</affected>' vt = w.VT['1.3.6.1.4.1.25623.1.0.100061'] affected = vt.get('affected') res = w.get_affected_vt_as_xml_str( '1.3.6.1.4.1.25623.1.0.100061', affected=affected) self.assertEqual(res, out)
def test_get_mtime_xml(self, mock_nvti, mock_db): w = DummyWrapper(mock_nvti, mock_db) out = '<modification_time>$Date: 2018-08-10 15:09:25 +0200 ' \ '(Fri, 10 Aug 2018) $</modification_time>' vt = w.VT['1.3.6.1.4.1.25623.1.0.100061'] mtime = vt.get('modification_time') res = w.get_modification_time_vt_as_xml_str( '1.3.6.1.4.1.25623.1.0.100061', mtime) self.assertEqual(res, out)
def test_get_ctime_xml(self, mock_nvti, mock_db): w = DummyWrapper(mock_nvti, mock_db) out = '<creation_time>2009-03-19 11:22:36 +0100 ' \ '(Thu, 19 Mar 2009)</creation_time>' vt = w.VT['1.3.6.1.4.1.25623.1.0.100061'] ctime = vt.get('creation_time') res = w.get_creation_time_vt_as_xml_str( '1.3.6.1.4.1.25623.1.0.100061', ctime) self.assertEqual(res, out)
def test_get_refs_xml(self, mock_nvti, mock_db): w = DummyWrapper(mock_nvti, mock_db) out = '<vt_refs><ref type="url" id="http://www.mantisbt.org/"/>' \ '</vt_refs>' vt = w.VT['1.3.6.1.4.1.25623.1.0.100061'] refs = vt.get('vt_refs') res = w.get_refs_vt_as_xml_str( '1.3.6.1.4.1.25623.1.0.100061', refs) self.assertEqual(res, out)
def test_get_detection_xml(self, mock_nvti, mock_db): w = DummyWrapper(mock_nvti, mock_db) out = '<detection qod_type="remote_banner"/>' vt = w.VT['1.3.6.1.4.1.25623.1.0.100061'] detection_type = vt.get('qod_type') res = w.get_detection_vt_as_xml_str( '1.3.6.1.4.1.25623.1.0.100061', qod_type=detection_type) self.assertEqual(res, out)
def test_get_solution_xml(self, mock_nvti, mock_db): w = DummyWrapper(mock_nvti, mock_db) out = '<solution type="WillNotFix">some solution</solution>' vt =w.VT['1.3.6.1.4.1.25623.1.0.100061'] solution = vt.get('solution') solution_type = vt.get('solution_type') res = w.get_solution_vt_as_xml_str( '1.3.6.1.4.1.25623.1.0.100061', solution, solution_type) self.assertEqual(res, out)
def test_get_params_xml(self, mock_nvti, mock_db): w = DummyWrapper(mock_nvti, mock_db) out = '<vt_params><vt_param type="checkbox" id="Do not randomize the ' \ 'order in which ports are scanned"><name>Do not ran' \ 'domize the order in which ports are scanned</name' \ '><default>no</default></vt_param><vt_param type="ent' \ 'ry" id="Data length : "><name>Data length : </name><' \ '/vt_param></vt_params>' vt = w.VT['1.3.6.1.4.1.25623.1.0.100061'] params = vt.get('vt_params') res = w.get_params_vt_as_xml_str( '1.3.6.1.4.1.25623.1.0.100061', params) self.assertEqual(len(res), len(out))
def test_get_custom_xml(self, mock_nvti, mock_db): out = '<custom><required_ports>Services/www, 80</re' \ 'quired_ports><category>3</category><' \ 'excluded_keys>Settings/disable_cgi_s' \ 'canning</excluded_keys><family>Produ' \ 'ct detection</family><filename>manti' \ 's_detect.nasl</filename><timeout>0</' \ 'timeout></custom>' w = DummyWrapper(mock_nvti, mock_db) vt = w.VT['1.3.6.1.4.1.25623.1.0.100061'] res = w.get_custom_vt_as_xml_str( '1.3.6.1.4.1.25623.1.0.100061', vt.get('custom')) self.assertEqual(len(res), len(out))
def test_build_credentials_ssh_up(self, mock_nvti, mock_db): w = DummyWrapper(mock_nvti, mock_db) cred_out = [ 'auth_port_ssh|||22', 'SSH Authorization[entry]:SSH login name:|||username', 'SSH Authorization[password]:SSH password (unsafe!):|||pass'] cred_dict = { 'ssh': {'type': 'up', 'port': '22', 'username': '******', 'password': '******', } } self.maxDiff=None ret = w.build_credentials_as_prefs(cred_dict) self.assertEqual(ret, cred_out)
def test_process_vts(self, mock_nvti, mock_db): vts = { '1.3.6.1.4.1.25623.1.0.100061': { 'Data length : ': 'new value', 'Do not randomize the order in which ports are ' \ 'scanned': 'new value'}, 'vt_groups': ['family=debian', 'family=general'] } vt_out = ( ['1.3.6.1.4.1.25623.1.0.100061'], [['Mantis Detection[checkbox]:Do not randomize the order i' \ 'n which ports are scanned', 'new value'], ['Mantis Detection[entry]:Data length : ', 'new value']] ) w = DummyWrapper(mock_nvti, mock_db) w.load_vts() ret = w.process_vts(vts) self.assertEqual(len(ret), len(vt_out))
def test_build_credentials(self, mock_nvti, mock_db): w = DummyWrapper(mock_nvti, mock_db) cred_out = [ 'auth_port_ssh|||22', 'SSH Authorization[entry]:SSH login name:|||username', 'SSH Authorization[password]:SSH key passphrase:|||pass', 'SSH Authorization[file]:SSH private key:|||', 'SMB Authorization[entry]:SMB login:|||username', 'SMB Authorization[password]:SMB password :|||pass', 'SNMP Authorization[password]:SNMP Community:some comunity', 'SNMP Authorization[entry]:SNMPv3 Username:username', 'SNMP Authorization[password]:SNMPv3 Password:pass', 'SNMP Authorization[radio]:SNMPv3 Authentication Algorithm:some auth algo', 'SNMP Authorization[password]:SNMPv3 Privacy Password:privacy pass', 'SNMP Authorization[radio]:SNMPv3 Privacy Algorithm:privacy algo', 'ESXi Authorization[entry]:ESXi login name:|||username', 'ESXi Authorization[password]:ESXi login password:|||pass'] cred_dict = { 'ssh': {'type': 'ssh', 'port': '22', 'username': '******', 'password': '******', }, 'smb': {'type': 'smb', 'username': '******', 'password': '******', }, 'esxi': {'type': 'esxi', 'username': '******', 'password': '******', }, 'snmp': {'type': 'snmp', 'username': '******', 'password': '******', 'community': 'some comunity', 'auth_algorithm': 'some auth algo', 'privacy_password': '******', 'privacy_algorithm': 'privacy algo', }, } self.maxDiff=None ret = w.build_credentials_as_prefs(cred_dict) self.assertEqual(len(ret), len(cred_out)) self.assertIn('auth_port_ssh|||22', cred_out)
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) w.create_scan('123-456', '192.168.0.1', '192.168.0.1', None, []) w.get_openvas_timestamp_scan_host('123-456', '192.168.0.1') for result in w.scan_collection.results_iterator('123-456', False): self.assertEqual(result.get('value'), '12345')
def test_redis_nvticache_init(self, mock_subproc, mock_nvti, mock_db): mock_subproc.check_call.return_value = True w = DummyWrapper(mock_nvti, mock_db) w.redis_nvticache_init() self.assertEqual(mock_subproc.check_call.call_count, 1)
def test_scan_is_finished(self, mock_nvti, mock_db): mock_db.get_single_item.return_value = 'finished' w = DummyWrapper(mock_nvti, mock_db) ret = w.scan_is_finished('123-456') self.assertEqual(ret, True)
def test_load_vts(self, mock_nvti, mock_db): w = DummyWrapper(mock_nvti, mock_db) w.load_vts() self.maxDiff = None self.assertEqual(w.vts, w.VT)