Esempio n. 1
0
def test_load_data_from_file_error() -> None:
    """
    Check how we handle errors in case
    when file can't be loaded or parsed
    :return: None
    """
    filemanager = GrinderFileManager()
    with raises(GrinderFileManagerOpenError):
        filemanager.load_data_from_file(
            load_dir="totally", load_json_dir="wrong", load_file="path.json"
        )
Esempio n. 2
0
def test_load_data_from_malformed_file_error() -> None:
    """
    Check case when JSON is malformed but needed
    to be loaded
    :return: None
    """
    filemanager = GrinderFileManager()
    with raises(GrinderFileManagerJsonDecoderError):
        filemanager.load_data_from_file(
            load_dir=str(TestDefaultFilemanagerValues.TEST_DATA_PATH),
            load_json_dir="test_queries",
            load_file=TestDefaultFilemanagerValues.TEST_MALFORMED_FILE,
        )
Esempio n. 3
0
def test_load_data_from_file_success() -> None:
    """
    Originally this function is used to load results
    file, but in case of functionality we can check
    that this function can load any other
    json file (because results - is just dumped
    dicts)
    :return: None
    """
    filemanager = GrinderFileManager()
    queries = filemanager.load_data_from_file(
        load_dir=str(TestDefaultFilemanagerValues.TEST_DATA_PATH),
        load_json_dir="test_queries",
        load_file=TestDefaultFilemanagerValues.TEST_QUERIES_FILE,
    )
    for query_obj in queries:
        assert sorted(query_obj.keys()) == sorted(
            [
                "vendor",
                "product",
                "shodan_queries",
                "censys_queries",
                "scripts",
                "vendor_confidence",
            ]
        )
        assert (
            isinstance(query_obj.get("vendor"), str) and query_obj.get("vendor") != ""
        )
        assert (
            isinstance(query_obj.get("product"), str) and query_obj.get("product") != ""
        )
        assert (
            isinstance(query_obj.get("shodan_queries"), list)
            and query_obj.get("shodan_queries") != []
        )
        for query in query_obj.get("shodan_queries"):
            assert sorted(query.keys()) == sorted(["query", "query_confidence"])
        assert (
            isinstance(query_obj.get("censys_queries"), list)
            and query_obj.get("censys_queries") != []
        )
        for query in query_obj.get("censys_queries"):
            assert sorted(query.keys()) == sorted(["query", "query_confidence"])
        assert sorted(query_obj.get("scripts").keys()) == sorted(
            ["py_script", "nse_script"]
        )
        assert (
            isinstance(query_obj.get("vendor_confidence"), str)
            and query_obj.get("vendor_confidence") != ""
        )