def update_exploits(): try: LOGGER.info('Trying to get %s', VIA4_URL) file = get_file(VIA4_URL) if file: LOGGER.info('File downloaded, updating database.') ExploitFactory.process(file) LOGGER.info('Database updated') else: LOGGER.error('Unable do download file %s', VIA4_URL) except Exception as ex: LOGGER.error(ex)
def update_cwe(): try: LOGGER.info('Updating cws, download file') file = get_file(CWE_MITRE_URL) if file: LOGGER.info('File downloaded for cwe year, parsing...') CWEFactory.process(file) file.close() LOGGER.info('CWE file parsing done.') else: LOGGER.info('Unable to download CWE file') except Exception as ex: LOGGER.error(ex)
def update_cpe(): try: LOGGER.info('Updating cpe, download file') file = get_file(CPE_NVD_URL) if file: LOGGER.info('File downloaded, parsing') CpeFactory.process(file) file.close() LOGGER.info('Cpe update done.') else: LOGGER.info('Unable to download file for cpe') except Exception as ex: LOGGER.error(ex)
def update_exploits(): try: LOGGER.info(F'Trying to get {VIA4_URL}') file = get_file(VIA4_URL) if file: LOGGER.info('File downloaded, updating database.') ExploitFactory.process(file) LOGGER.info('Database updated') else: LOGGER.error(F'Unable do download file {VIA4_URL}') except Exception as ex: LOGGER.error(ex) finally: thread_pool_executor.wait_for_all()
def update_cve(year: int): try: LOGGER.info('Trying to get file for %d year', year) file = get_file(CVE_NVD_URL.format(year)) if file: LOGGER.info('File downloaded for %d year, parsing...', year) factory = CveFactory() factory.process(file) file.close() LOGGER.info('CVS update for %d done, updated: %d, created: %d', year, factory.updated, factory.created) else: LOGGER.info('Unable to download file for %d year', year) except Exception as ex: LOGGER.error(ex)
def update_cve(year: int): try: LOGGER.info(F'Trying to get file for {year} year') file = get_file(CVE_NVD_URL.format(year)) if file: LOGGER.info(F'File downloaded for {year} year, parsing...') CveFactory.process(file) file.close() LOGGER.info(F'Parsing for {year}, done.') else: LOGGER.info(F'Unable to download file for {year} year') except Exception as ex: LOGGER.error(ex) finally: thread_pool_executor.wait_for_all()
def test_call_get_file(self, filename, content_type, verify, result, requests): requests.head.return_value = Mock( headers={'Content-Type': content_type}) with open(get_fixture_location(__file__, filename), mode='r+b', encoding=None) as file: requests.get.return_value = Mock( headers={'Content-Type': content_type}, content=file.read(), status_code=200) self.assertEqual(get_file(UtilsTest.URL, verify).readline(), result) requests.get.assert_called_once_with(UtilsTest.URL, verify=verify)
def test_call_get_file_invalid_response(self, requests): requests.head.return_value = Mock(headers={'Content-Type': 'text'}) requests.get.return_value = Mock(headers={'Content-Type': 'text'}, status_code=404) self.assertIsNone(get_file(UtilsTest.URL))
def test_call_get_file_json(self, requests): requests.head.return_value = Mock(headers={'Content-Type': 'json'}) requests.get.return_value = Mock(headers={'Content-Type': 'json'}, content='response', status_code=200) self.assertEqual(get_file(UtilsTest.URL), 'response')