示例#1
0
 def test_add_files_no_file(self, m_FileExt):
     m_request = MagicMock()
     m_request._params['files'] = None
     expected = "The \"files\" parameter is invalid. Empty list"
     with self.assertRaises(api_files_ext.HTTPInvalidParam) as context:
         api_files_ext.create(m_request)
     self.assertEqual(context.exception.description, expected)
     m_FileExt.assert_not_called()
示例#2
0
 def test_add_files_no_file(self, m_FileExt):
     m_request = MagicMock()
     m_request._params['files'] = None
     expected = "The \"files\" parameter is invalid. Empty list"
     with self.assertRaises(api_files_ext.HTTPInvalidParam) as context:
         api_files_ext.create(m_request)
     self.assertEqual(context.exception.description, expected)
     m_FileExt.assert_not_called()
示例#3
0
 def test_add_files_more_than_one_files(self, m_FileExt):
     m_request = MagicMock()
     m_request._params = {'files': ['file1', 'file2']}
     expected = "The \"files\" parameter is invalid. " \
                "Only one file at a time"
     with self.assertRaises(api_files_ext.HTTPInvalidParam) as context:
         api_files_ext.create(m_request)
     self.assertEqual(context.exception.description, expected)
     m_FileExt.assert_not_called()
示例#4
0
 def test_add_files_more_than_one_files(self, m_FileExt):
     m_request = MagicMock()
     m_request._params = {'files': ['file1', 'file2']}
     expected = "The \"files\" parameter is invalid. " \
                "Only one file at a time"
     with self.assertRaises(api_files_ext.HTTPInvalidParam) as context:
         api_files_ext.create(m_request)
     self.assertEqual(context.exception.description, expected)
     m_FileExt.assert_not_called()
示例#5
0
 def test_create_ok(self, m_File):
     m_file = MagicMock()
     m_request = MagicMock()
     data = b"DATA"
     filename = "filename"
     m_file.filename = filename
     m_file.file = io.BytesIO(data)
     m_request._params = {'files': m_file, 'json': '{"submitter": "cli"}'}
     m_file_obj = MagicMock()
     m_File.get_or_create.return_value = m_file_obj
     api_files_ext.create(m_request)
示例#6
0
 def test_create_ok(self, m_File):
     m_file = MagicMock()
     m_request = MagicMock()
     data = b"DATA"
     filename = "filename"
     m_file.filename = filename
     m_file.file = io.BytesIO(data)
     m_request._params = {'files': m_file,
                          'json': '{"submitter": "cli",'
                          '"submitter_id": "undefined"}'}
     m_file_obj = MagicMock()
     m_File.get_or_create.return_value = m_file_obj
     api_files_ext.create(m_request)
示例#7
0
def quick_scan(request):
    """ Launch a scan for one file
    """
    session = db.session
    ip = request.remote_addr

    # Create file
    fe = files_ctrl.create(request)
    fe = FileExt.load_from_ext_id(fe['result_id'], session)

    # Create a scan
    scan = Scan(compat.timestamp(), ip, files_ext=[fe, ])
    session.add(scan)
    session.commit()

    # launch_asynchronous scan via frontend task
    celery_frontend.scan_launch(str(scan.external_id))

    return scan_schema.dump(scan).data
示例#8
0
def quick_scan(request):
    """ Launch a scan for one file
    """
    session = db.session
    ip = request.remote_addr

    # Create file
    fe = files_ctrl.create(request)
    fe = FileExt.load_from_ext_id(fe['result_id'], session)

    # Create a scan
    scan = Scan(compat.timestamp(), ip, files_ext=[fe, ])
    session.add(scan)
    session.commit()

    # launch_asynchronous scan via frontend task
    celery_frontend.scan_launch(str(scan.external_id))

    return scan_schema.dump(scan).data