def test_analyze_invalid_schema(config, input):
    """Test analyze pass through"""
    manager = LocalEngineManager(config)

    result = manager.analyze(input)
    if result["binary_hash"] is not None:
        result = EngineResponseSchema.validate(result)
    assert not result["success"]
Ejemplo n.º 2
0
def local_engine_manager(config):
    """Creates local engine manager for integration tests"""
    manager = LocalEngineManager(config)

    manager.engine.mock_engine_output(
        "405f03534be8b45185695f68deb47d4daf04dcd6df9d351ca6831d3721b1efc4",
        IOC_HASH)
    return manager
    def _init_components(self):
        """
        Initialize the components of the toolkit, injecting their dependencies as they're created.

        Returns:
            dict: A dict containing all the references to the top-level components.

        """
        try:
            state_manager = StateManager(self.config)
        except:
            log.error(
                "Failed to create State Manager. Check your configuration")
            log.debug(traceback.format_exc())
            state_manager = None

        cbc_api = self.cbc_api
        if cbc_api is None:
            cbc_api = CBCloudAPI(
                url=self.config.get("carbonblackcloud.url"),
                org_key=self.config.get("carbonblackcloud.org_key"),
                token=self.config.get("carbonblackcloud.api_token"),
                ssl_verify=self.config.get("carbonblackcloud.ssl_verify"))

        deduplicate = DeduplicationComponent(self.config, state_manager)
        ingest = IngestionComponent(self.config, cbc_api, state_manager)

        results_engine = EngineResults(self.config.get("engine.name"),
                                       state_manager, cbc_api)
        if self.config.get("engine.type") == "local":
            try:
                engine_manager = LocalEngineManager(self.config)
            except:
                log.error(
                    "Failed to create Local Engine Manager. Check your configuration"
                )
                log.debug(traceback.format_exc())
                engine_manager = None
        else:
            engine_manager = None

        return {
            "deduplicate":
            deduplicate,
            "ingest":
            ingest,
            "engine_manager":
            engine_manager,
            "results_engine":
            results_engine,
            "state_manager":
            state_manager,
            "success":
            True if state_manager is not None and engine_manager is not None
            else False
        }
def test_analyze(config):
    """Test analyze pass through"""
    manager = LocalEngineManager(config)

    assert EngineResponseSchema.validate(manager.analyze(VALID_BINARY_METADATA))
def test_create_engine(config):
    """Test successful creation of MockLocalEngine"""
    manager = LocalEngineManager(config)

    assert isinstance(manager.create_engine(), MockLocalEngine)
def test_failed_init(engine_config, exception):
    """Test raised exceptions on init of LocalEngineManager"""
    config = Config.load(engine_config)
    with pytest.raises(exception):
        LocalEngineManager(config)
Ejemplo n.º 7
0
def engine(config):
    """Yara Engine"""
    manager = LocalEngineManager(config)
    return manager.engine
Ejemplo n.º 8
0
def test_invalid_config(config_text, exception):
    """Test invalid initialization"""
    with pytest.raises(exception):
        LocalEngineManager(Config.load(config_text))