Esempio n. 1
0
def initialize_config(tmp_dir):
    config = get_config_for_testing(temp_dir=tmp_dir)

    # Database
    config.set('data_storage', 'main_database', 'tmp_integration_tests')
    config.set('data_storage', 'intercom_database_prefix',
               'tmp_integration_tests')
    config.set('data_storage', 'statistic_database', 'tmp_integration_tests')
    config.set('data_storage', 'view_storage', 'tmp_view_storage')

    # Analysis
    config.add_section('ip_and_uri_finder')
    config.set('ip_and_uri_finder', 'signature_directory',
               'analysis/signatures/ip_and_uri_finder/')
    config.set('default_plugins', 'plugins', 'file_hashes')

    # Unpacker
    config.set('unpack', 'threads', '1')
    config.set('ExpertSettings', 'unpack_throttle_limit', '20')

    # Compare
    config.set('ExpertSettings', 'ssdeep_ignore', '80')
    config.set('ExpertSettings', 'block_delay', '1')
    config.set('ExpertSettings', 'throw_exceptions', 'true')

    return config
Esempio n. 2
0
 def setUp(self):
     config = get_config_for_testing(TMP_DIR)
     self.test_queue = Queue()
     self.interface = InterComBackEndBinding(
         config=config, testing=True, analysis_service=AnalysisServiceMock(), compare_service=ServiceMock(self.test_queue), unpacking_service=ServiceMock(self.test_queue)
     )
     self.interface.WAIT_TIME = 2
     self.db = MongoMgr(config=config)
Esempio n. 3
0
def test_get_radare_endpoint():
    config = get_config_for_testing()

    assert config.get('ExpertSettings', 'nginx') == 'false'
    assert get_radare_endpoint(config) == 'http://localhost:8000'

    config.set('ExpertSettings', 'nginx', 'true')
    assert get_radare_endpoint(config) == 'https://localhost/radare'
Esempio n. 4
0
def binary_service():
    with TemporaryDirectory(prefix='fact_test_') as tmp_dir:
        config = get_config_for_testing(temp_dir=tmp_dir)
        mongo_server = MongoMgr(config=config)
        _init_test_data(config, tmp_dir)
        yield BinaryService(config=config)
        mongo_server.shutdown()
    gc.collect()
Esempio n. 5
0
def test_get_radare_endpoint():
    config = get_config_for_testing()

    assert config.get('ExpertSettings', 'nginx') == 'false'
    assert IORoutes._get_radare_endpoint(config) == 'http://localhost:8000'  # pylint: disable=protected-access

    config.set('ExpertSettings', 'nginx', 'true')
    assert IORoutes._get_radare_endpoint(config) == 'https://localhost/radare'  # pylint: disable=protected-access
    def setUp(self):
        self.config = get_config_for_testing()

        self.enter_patch = unittest.mock.patch(target='web_interface.frontend_main.add_flask_security_to_app', new=add_security_get_mocked)
        self.enter_patch.start()

        self.frontend = frontend_main.WebFrontEnd(config=self.config)

        self.frontend.app.config['TESTING'] = True
        self.test_client = self.frontend.app.test_client()
 def setUp(self):
     routes.FrontEndDbInterface = DbInterfaceMock
     app = Flask(__name__)
     app.config.from_object(__name__)
     app.config['TESTING'] = True
     app.jinja_env.filters['replace_uid_with_hid'] = lambda x: x
     app.jinja_env.filters['nice_unix_time'] = lambda x: x
     config = get_config_for_testing()
     self.plugin_routes = routes.PluginRoutes(app, config)
     self.test_client = app.test_client()
Esempio n. 8
0
    def setUp(self, db_mock=DatabaseMock):  # pylint: disable=arguments-differ
        self.mocked_interface = db_mock()

        self.enter_patch = unittest.mock.patch(target='helperFunctions.database.ConnectTo.__enter__', new=lambda _: self.mocked_interface)
        self.enter_patch.start()

        self.exit_patch = unittest.mock.patch(target='helperFunctions.database.ConnectTo.__exit__', new=fake_exit)
        self.exit_patch.start()

        self.config = get_config_for_testing(TMP_DIR)
        self.frontend = WebFrontEnd(config=self.config)
        self.frontend.app.config['TESTING'] = True
        self.test_client = self.frontend.app.test_client()
Esempio n. 9
0
    def setUp(self):
        self.mocked_interface = DatabaseMock()
        self.enter_patch = mock.patch(target='helperFunctions.database.ConnectTo.__enter__', new=lambda _: self.mocked_interface)
        self.enter_patch.start()
        self.exit_patch = mock.patch(target='helperFunctions.database.ConnectTo.__exit__', new=fake_exit)
        self.exit_patch.start()

        config = get_config_for_testing()
        config.add_section('ip_and_uri_finder')
        config.set('ip_and_uri_finder', 'signature_directory', 'analysis/signatures/ip_and_uri_finder/')
        config.set('default_plugins', 'default', 'file_hashes')
        self.tmp_queue = Queue()
        self.sched = AnalysisScheduler(config=config, pre_analysis=lambda *_: None, post_analysis=self.dummy_callback, db_interface=self.mocked_interface)
 def setUp(self):
     routes.FrontEndDbInterface = DbInterfaceMock
     app = Flask(__name__)
     app.config.from_object(__name__)
     app.config['TESTING'] = True
     config = get_config_for_testing()
     api = Api(app)
     endpoint, methods = routes.FSMetadataRoutesRest.ENDPOINTS[0]
     api.add_resource(routes.FSMetadataRoutesRest,
                      endpoint,
                      methods=methods,
                      resource_class_kwargs={'config': config})
     self.test_client = app.test_client()
Esempio n. 11
0
def test_check_worker_exceptions():
    config = get_config_for_testing()
    config.set('ExpertSettings', 'throw_exceptions', 'true')

    process_list = [ExceptionSafeProcess(target=breaking_process, args=(True, ))]
    process_list[0].start()

    result = check_worker_exceptions(process_list, 'foo', config=config)
    assert not result
    assert len(process_list) == 1
    sleep(1)
    result = check_worker_exceptions(process_list, 'foo', config=config)
    assert result
    assert len(process_list) == 0
Esempio n. 12
0
 def setUp(self):
     self.config = get_config_for_testing()
     self.fw_one = create_test_firmware(device_name='dev_1',
                                        all_files_included_set=True)
     self.fw_one.processed_analysis['file_hashes'] = {
         'ssdeep': get_ssdeep(self.fw_one.binary)
     }
     self.fw_two = create_test_firmware(device_name='dev_2',
                                        bin_path='container/test.7z',
                                        all_files_included_set=True)
     self.fw_two.processed_analysis['file_hashes'] = {
         'ssdeep': get_ssdeep(self.fw_two.binary)
     }
     self.compare_system = Compare(db_interface=MockDbInterface(),
                                   config=self.config)
Esempio n. 13
0
def get_intercom_for_testing():
    with TemporaryDirectory(prefix='fact_test_') as tmp_dir:
        config = get_config_for_testing(tmp_dir)
        test_queue = Queue()
        interface = InterComBackEndBinding(
            config=config,
            testing=True,
            analysis_service=AnalysisServiceMock(),
            compare_service=ServiceMock(test_queue),
            unpacking_service=ServiceMock(test_queue))
        interface.WAIT_TIME = 2
        db = MongoMgr(config=config)
        yield interface
        interface.shutdown()
        test_queue.close()
        db.shutdown()
    gc.collect()
Esempio n. 14
0
def test_check_worker_restart(caplog):
    config = get_config_for_testing()
    config.set('ExpertSettings', 'throw_exceptions', 'false')

    worker = ExceptionSafeProcess(target=breaking_process, args=(True, ))
    process_list = [worker]
    worker.start()

    sleep(1)
    with caplog.at_level(logging.INFO):
        result = check_worker_exceptions(process_list, 'foo', config, worker_function=lambda _: None)
        assert not result
        assert len(process_list) == 1
        assert process_list[0] != worker
        assert 'Exception in foo' in caplog.messages[0]
        assert 'restarting foo' in caplog.messages[-1]
        process_list[0].join()
Esempio n. 15
0
 def setUpClass(cls):
     cls._config = get_config_for_testing(TMP_DIR)
     cls._config.set('data_storage', 'report_threshold', '32')
     cls._config.set('data_storage', 'sanitize_database', 'tmp_sanitize')
     cls.mongo_server = MongoMgr(config=cls._config)
Esempio n. 16
0
 def setUp(self):
     self.config = get_config_for_testing()
     self.mongo_server = MongoMgr(config=self.config)
     self.workload_stat = WorkLoadStatistic(config=self.config,
                                            component='test')
     self.frontend_db_interface = StatisticDbViewer(config=self.config)
Esempio n. 17
0
def test_config():
    return get_config_for_testing()
Esempio n. 18
0
 def setUpClass(cls):
     cls._config = get_config_for_testing(TMP_DIR)
     cls.mongo_server = MongoMgr(config=cls._config)
Esempio n. 19
0
 def setUp(self):
     self.name_prefix = 'FACT_plugin_qemu'
     self.config = get_config_for_testing()
     self.unpacker = qemu_exec.Unpacker(config=self.config)
     qemu_exec.BinaryServiceDbInterface = MockBinaryService
Esempio n. 20
0
def test_config():
    return get_config_for_testing(TemporaryDirectory())
Esempio n. 21
0
 def setUpClass(cls):
     cls.config = get_config_for_testing(TMP_DIR)
     cls.mongo_mgr = MongoMgr(cls.config)
Esempio n. 22
0
 def setUp(self):
     yara_binary_search.YaraBinarySearchScannerDbInterface.__bases__ = (
         MockCommonDbInterface, )
     self.db_interface = yara_binary_search.YaraBinarySearchScannerDbInterface(
         get_config_for_testing())
 def setUp(self):
     self.config = get_config_for_testing()
     routes.FsMetadataDbInterface.__bases__ = (DbInterfaceMock, )
Esempio n. 24
0
 def setUp(self):
     self.config = get_config_for_testing()
     routes.FrontEndDbInterface = DbInterfaceMock
Esempio n. 25
0
 def setUp(self):
     self.config = get_config_for_testing()
     self.repack_service = TarRepack(config=self.config)
Esempio n. 26
0
 def setup(self):
     self.sched.config = get_config_for_testing()
Esempio n. 27
0
 def setUp(self):
     self.app = Flask(__name__)
     self.app.config.from_object(__name__)
     self.api = Api(self.app)
     self.config = get_config_for_testing()
Esempio n. 28
0
 def setUp(self):
     self._config = get_config_for_testing(TMP_DIR)
     self.mongo_server = MongoMgr(config=self._config)
     self.db_interface = MongoInterfaceCommon(config=self._config)
     self.db_interface_backend = BackEndDbInterface(config=self._config)
Esempio n. 29
0
 def setUpClass(cls):
     cls.tmp_dir = TemporaryDirectory(prefix='fact_test_')
     cls.config = get_config_for_testing(temp_dir=cls.tmp_dir)
     cls.config.set('ExpertSettings', 'communication_timeout', '1')
     cls.mongo_server = MongoMgr(config=cls.config)
Esempio n. 30
0
 def setup_class(cls):
     cls.tmp_dir = TemporaryDirectory(prefix='fact_test_')
     cls.config = get_config_for_testing(cls.tmp_dir)
     cls.mongo_mgr = MongoMgr(cls.config)