Example #1
0
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)
Example #2
0
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)
Example #3
0
 def test001_scan_launch(self):
     with patch("frontend.controllers.frontendtasks.async_call") as mock:
         arg = "whatever"
         module.scan_launch(arg)
     self.assertTrue(mock.called)