def report_openvas_scan_status(self, scan_db: ScanDB, scan_id: str, current_host: str): """ Get all status entries from redis kb. Arguments: scan_id: Scan ID to identify the current scan. current_host: Host to be updated. """ res = scan_db.get_scan_status() while res: self.update_progress(scan_id, current_host, res) res = scan_db.get_scan_status()
def report_openvas_timestamp_scan_host( self, scan_db: ScanDB, scan_id: str, host: str ): """ Get start and end timestamp of a host scan from redis kb. """ timestamp = scan_db.get_host_scan_end_time() if timestamp: self.add_scan_log( scan_id, host=host, name='HOST_END', value=timestamp ) return timestamp = scan_db.get_host_scan_start_time() if timestamp: self.add_scan_log( scan_id, host=host, name='HOST_START', value=timestamp ) return
class ScanDBTestCase(TestCase): @patch('ospd_openvas.db.redis.Redis') def setUp(self, mock_redis): # pylint: disable=arguments-differ self.ctx = mock_redis.return_value self.db = ScanDB(10, self.ctx) def test_get_result(self, mock_openvas_db): mock_openvas_db.pop_list_items.return_value = [ 'some result', ] ret = self.db.get_result() self.assertEqual( ret, [ 'some result', ], ) mock_openvas_db.pop_list_items.assert_called_with( self.ctx, 'internal/results') def test_get_status(self, mock_openvas_db): mock_openvas_db.get_single_item.return_value = 'some status' ret = self.db.get_status('foo') self.assertEqual(ret, 'some status') mock_openvas_db.get_single_item.assert_called_with( self.ctx, 'internal/foo') def test_select(self, mock_openvas_db): ret = self.db.select(11) self.assertIs(ret, self.db) self.assertEqual(self.db.index, 11) mock_openvas_db.select_database.assert_called_with(self.ctx, 11) def test_flush(self, mock_openvas_db): self.db.flush() self.ctx.flushdb.assert_called_with()
def setUp(self, mock_redis): # pylint: disable=arguments-differ self.ctx = mock_redis.return_value self.db = ScanDB(10, self.ctx)
class ScanDBTestCase(TestCase): @patch('ospd_openvas.db.redis.Redis') def setUp(self, mock_redis): # pylint: disable=arguments-differ self.ctx = mock_redis.return_value self.db = ScanDB(10, self.ctx) def test_get_result(self, mock_openvas_db): mock_openvas_db.get_last_list_item.return_value = 'some result' ret = self.db.get_result() self.assertEqual(ret, 'some result') mock_openvas_db.get_last_list_item.assert_called_with( self.ctx, 'internal/results') def test_get_status(self, mock_openvas_db): mock_openvas_db.get_single_item.return_value = 'some status' ret = self.db.get_status('foo') self.assertEqual(ret, 'some status') mock_openvas_db.get_single_item.assert_called_with( self.ctx, 'internal/foo') def test_select(self, mock_openvas_db): ret = self.db.select(11) self.assertIs(ret, self.db) self.assertEqual(self.db.index, 11) mock_openvas_db.select_database.assert_called_with(self.ctx, 11) def test_get_scan_id(self, mock_openvas_db): mock_openvas_db.get_single_item.return_value = 'foo' ret = self.db.get_scan_id() self.assertEqual(ret, 'foo') mock_openvas_db.get_single_item.assert_called_with( self.ctx, 'internal/scan_id') def test_get_scan_status(self, mock_openvas_db): mock_openvas_db.get_last_list_item.return_value = 'foo' ret = self.db.get_scan_status() self.assertEqual(ret, 'foo') mock_openvas_db.get_last_list_item.assert_called_with( self.ctx, 'internal/status') def test_get_host_scan_start_time(self, mock_openvas_db): mock_openvas_db.get_last_list_item.return_value = 'some start time' ret = self.db.get_host_scan_start_time() self.assertEqual(ret, 'some start time') mock_openvas_db.get_last_list_item.assert_called_with( self.ctx, 'internal/start_time') def test_get_host_scan_end_time(self, mock_openvas_db): mock_openvas_db.get_last_list_item.return_value = 'some end time' ret = self.db.get_host_scan_end_time() self.assertEqual(ret, 'some end time') mock_openvas_db.get_last_list_item.assert_called_with( self.ctx, 'internal/end_time') def test_get_host_ip(self, mock_openvas_db): mock_openvas_db.get_single_item.return_value = '192.168.0.1' ret = self.db.get_host_ip() self.assertEqual(ret, '192.168.0.1') mock_openvas_db.get_single_item.assert_called_with( self.ctx, 'internal/ip') def test_host_is_finished_false(self, mock_openvas_db): mock_openvas_db.get_single_item.return_value = 'foo' ret = self.db.host_is_finished('bar') self.assertFalse(ret) mock_openvas_db.get_single_item.assert_called_with( self.ctx, 'internal/bar') def test_host_is_finished_true(self, mock_openvas_db): mock_openvas_db.get_single_item.return_value = 'finished' ret = self.db.host_is_finished('bar') self.assertTrue(ret) mock_openvas_db.get_single_item.assert_called_with( self.ctx, 'internal/bar') def test_flush(self, mock_openvas_db): self.db.flush() self.ctx.flushdb.assert_called_with()