def launch(scanid, db): """ Launch a scan. The request should be performed using a POST request method. """ try: validate_id(scanid) scan = Scan.load_from_ext_id(scanid, db) probes = None # handle scan parameter / cached results: "force" if 'force' in request.json and request.json.get('force'): scan.force = True db.commit() # V1 retro compatibility scan.mimetype_filtering = False scan.file_resubmit = False # handle scan parameter / probelist: "probes" if 'probes' in request.json: probes = request.json.get('probes').split(',') msg = "scanid: %s Force %s MimeF %s" msg += "Resub %s Probes %s" log.debug(msg, scanid, scan.force, scan.mimetype_filtering, scan.resubmit_files, probes) scan_ctrl.check_probe(scan, probes, db) # launch_asynchronous scan via frontend task celery_frontend.scan_launch(scanid) response.content_type = "application/json; charset=UTF-8" return scan_schema.dumps(scan).data except Exception as e: log.exception(e) process_error(e)
def test003_check_probe_None(self): scan, session = MagicMock(), MagicMock() scan.status = IrmaScanStatus.ready probelist = None all_probelist = ['probe1', 'probe2', 'probe3'] scan.set_probelist.return_value = None self.celery_brain.probe_list.return_value = all_probelist module.check_probe(scan, probelist, session) self.assertTrue(scan.set_probelist.called) scan.set_probelist.assert_called_once_with(all_probelist)
def test004_check_probe_unknown_probe(self): scan, session = MagicMock(), MagicMock() scan.status = IrmaScanStatus.ready probelist = ['probe1', 'probe2', 'probe6'] all_probelist = ['probe1', 'probe2', 'probe3'] scan.set_probelist.return_value = None self.celery_brain.probe_list.return_value = all_probelist with self.assertRaises(IrmaValueError) as context: module.check_probe(scan, probelist, session) self.assertFalse(scan.set_probelist.called) self.assertEquals(str(context.exception), "probe probe6 unknown")