Ejemplo n.º 1
0
def test_write_results_csv_exploits_to_cve_success() -> None:
    """
    Test how we can save exploits info to csv
    :return: None
    """
    with open(
        TestDefaultFilemanagerValues.TEST_DATA_RESULTS_JSON_PATH.joinpath(
            TestDefaultFilemanagerValues.TEST_EXPLOITS_JSON_FILE
        ),
        mode="r",
    ) as vulners_results:
        vulners_by_vulnerabilities = load(vulners_results)
    with open(
        TestDefaultFilemanagerValues.TEST_DATA_RESULTS_JSON_PATH.joinpath(
            "results.json"
        ),
        mode="r",
    ) as hosts_results:
        hosts = load(hosts_results)
        hosts = {host.get("ip"): host for host in hosts}
    filemanager = GrinderFileManager()
    filemanager.write_results_csv_exploits_to_cve(
        results_to_write=vulners_by_vulnerabilities,
        hosts_results=hosts,
        dest_dir=str(TestDefaultFilemanagerValues.TEST_RESULTS_PATH),
        csv_dir=str(Path("filemanager").joinpath("csv")),
        csv_file=TestDefaultFilemanagerValues.TEST_EXPLOITS_CSV_FILE,
    )
Ejemplo n.º 2
0
def test_write_results_csv_exploits_to_cve_error() -> None:
    """
    Test how we can handle errors when operating
    with exploits and CVEs in file cases
    :return: None
    """
    filemanager = GrinderFileManager()
    with raises(GrinderFileManagerOpenError):
        filemanager.write_results_csv_exploits_to_cve(
            hosts_results={"test": "test"},
            results_to_write=["test", "test"],
            dest_dir=str(TestDefaultFilemanagerValues.TEST_RESULTS_PATH),
            csv_dir=str(Path("filemanager").joinpath("csv")),
            csv_file="malformed_exploits.csv")