def test_integration_ingest(cbapi_mock, deduplication_component,
                            ingestion_component, state_manager):
    """Test input to ingestion"""
    input = read_json(
        '["31132832bc0f3ce4a15601dc190c98b9a40a9aba1d87dae59b217610175bdfde", \
                        "405f03534be8b45185695f68deb47d4daf04dcd6df9d351ca6831d3721b1efc4", \
                        "0995f71c34f613207bc39ed4fcc1bbbee396a543fa1739656f7ddf70419309fc", \
                        "e02d9989cbe295518350ed3f5a04a713ece692406a9ee354785c2a4078466dcd"]'
    )
    assert isinstance(input, list)

    unique_list = deduplication_component.deduplicate(input)
    assert HASH_ALREADY_DONE not in unique_list

    ingestion_component.fetch_metadata(unique_list)
    db = state_manager._persistor.db
    assert "31132832bc0f3ce4a15601dc190c98b9a40a9aba1d87dae59b217610175bdfde" not in db
    assert db[
        "405f03534be8b45185695f68deb47d4daf04dcd6df9d351ca6831d3721b1efc4"][
            "checkpoint_name"] == "INGESTED"
    assert db[
        "0995f71c34f613207bc39ed4fcc1bbbee396a543fa1739656f7ddf70419309fc"][
            "checkpoint_name"] == "INGESTED"
    assert db[
        "e02d9989cbe295518350ed3f5a04a713ece692406a9ee354785c2a4078466dcd"][
            "checkpoint_name"] == "DONE"
Esempio n. 2
0
    def _analyze_command(self, args, components):
        """
        Implements the "analyze" command to analyze a list of hashes.

        Args:
            args (Namespace): The command-line arguments as parsed.
            components (dict): Dict containing all the component references as returned from _init_components.

        """
        if args.file is not None:
            hash_group = cli_input.read_csv(args.file)
        else:
            hash_group = cli_input.read_json(args.list)

        before = len(hash_group)
        log.info("Checking for previously executed binaries")
        hash_group = components["deduplicate"].deduplicate(hash_group)
        if before > len(hash_group):
            log.info(f"Found {before - len(hash_group)} binaries that have already been analyzed")

        metadata_list = components["ingest"].fetch_metadata(hash_group)
        self._process_metadata(components, metadata_list)
Esempio n. 3
0
 def test_json_exceptions(self, error, input_file_path: str, msg: str):
     """Unit testing read_json exceptions"""
     with pytest.raises(error) as context:
         with open(attach_path(input_file_path), 'r') as input_file:
             str(read_json(input_file.read()))
     assert str(context.value) == msg
Esempio n. 4
0
 def test_json(self, input_file_path: str, answer_file_path: List[Dict]):
     """Unit testing read_json function"""
     with open(attach_path(input_file_path), 'r') as input_file:
         with open(attach_path(answer_file_path), 'r') as answer_file:
             assert str(read_json(input_file.read().strip())) == answer_file.read().strip()