def setup():
    with suppress(OSError):
        remove('cve_cpe.db')
    sr.QUERIES.update(TEST_QUERIES)
    cpe_base = sr.setup_cpe_table(dp.extract_cpe(PATH_TO_TEST + EXTRACT_CPE_XML))
    cve_base, summary_base = dp.extract_cve(PATH_TO_TEST + EXTRACT_CVE_JSON)
    cve_base = sr.setup_cve_feeds_table(cve_list=cve_base)
    summary_base = sr.setup_cve_summary_table(summary_list=summary_base)

    with DatabaseInterface(PATH_TO_TEST + 'test_update.db') as db:
        db.execute_query(query=QUERIES['create_cpe_table'].format('cpe_table'))
        db.insert_rows(query=QUERIES['insert_cpe'].format('cpe_table'), input_data=cpe_base)
        db.execute_query(query=QUERIES['create_cve_table'].format('cve_table'))
        db.execute_query(query=QUERIES['create_summary_table'].format('summary_table'))
        db.insert_rows(query=QUERIES['insert_cve'].format('cve_table'), input_data=cve_base)
        db.insert_rows(query=QUERIES['insert_summary'].format('summary_table'), input_data=summary_base)

        db.execute_query(query=TEST_QUERIES['test_create_update'].format('outdated'))
        db.execute_query(query=TEST_QUERIES['test_create_update'].format('new'))
        db.insert_rows(query=TEST_QUERIES['test_insert_cve_id'].format('outdated'), input_data=[('CVE-2018-0001', 2018), ('CVE-2018-0002', 2018)])
        db.insert_rows(query=TEST_QUERIES['test_insert_cve_id'].format('new'), input_data=[('CVE-2018-0002', 2018), ('CVE-2018-0003', 2018)])

    yield

    with suppress(OSError):
        remove(PATH_TO_TEST + 'test_update.db')
        remove(PATH_TO_TEST + 'test_import.db')
        remove(PATH_TO_TEST + 'test_output.db')
示例#2
0
def get_cve_update_content(cve_extraction_path: str) -> Tuple[list, list]:
    dp.download_cve(update=True,
                    download_path=cve_extraction_path,
                    years=list())
    if not glob(cve_extraction_path + 'nvdcve*.json')[0]:
        raise Exception('Error: Glob has found none of the specified files!')
    return dp.extract_cve(cve_file=glob(cve_extraction_path +
                                        'nvdcve*.json')[0])
示例#3
0
def get_cve_import_content(cve_extraction_path: str,
                           year_selection: list) -> Tuple[list, list]:
    cve_list, summary_list = list(), list()
    dp.download_cve(update=False,
                    download_path=cve_extraction_path,
                    years=year_selection)
    for file in glob(cve_extraction_path + 'nvdcve*.json'):
        cve_data, summary_data = dp.extract_cve(cve_file=file)
        cve_list.extend(cve_data)
        summary_list.extend(summary_data)

    return cve_list, summary_list