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')
def test_setup_cpe_entry_with_colons(): result = sr.setup_cpe_table([ 'cpe:2.3:a:net::netmask_project:net::netmask:*:*:*:*:*:perl:*:*', 'cpe:2.3:a:lemonldap-ng:lemonldap\\:\\::1.0.3:*:*:*:*:*:*:*' ]) expected_result = [ ('cpe:2.3:a:net::netmask_project:net::netmask:*:*:*:*:*:perl:*:*', 'a', 'net::netmask_project', 'net::netmask', 'ANY', 'ANY', 'ANY', 'ANY', 'ANY', 'perl', 'ANY', 'ANY'), ('cpe:2.3:a:lemonldap-ng:lemonldap\\:\\::1.0.3:*:*:*:*:*:*:*', 'a', 'lemonldap\\-ng', 'lemonldap\\:\\:', '1\\.0\\.3', 'ANY', 'ANY', 'ANY', 'ANY', 'ANY', 'ANY', 'ANY') ] for entry in result: assert len(entry) == 12 for actual, expected in zip(result, expected_result): assert actual == expected
def test_setup_cpe_table(): result = sr.setup_cpe_table(CPE_LIST) for entry in result: assert len(entry) == 12 for actual, expected in zip(result, CPE_TABLE): assert actual == expected
def test_setup_cpe_table(): result = sr.setup_cpe_table(CPE_LIST) assert CPE_TABLE == result