def test_unpack_analyse_and_compare(self): test_fw_1 = Firmware( file_path='{}/container/test.zip'.format(get_test_data_dir())) test_fw_1.release_date = '2017-01-01' test_fw_2 = Firmware( file_path='{}/regression_one'.format(get_test_data_dir())) test_fw_2.release_date = '2017-01-01' self._unpack_scheduler.add_task(test_fw_1) self._unpack_scheduler.add_task(test_fw_2) self.analysis_finished_event.wait(timeout=20) compare_id = normalize_compare_id(';'.join( [fw.uid for fw in [test_fw_1, test_fw_2]])) self.assertIsNone( self._compare_scheduler.add_task((compare_id, False)), 'adding compare task creates error') self.compare_finished_event.wait(timeout=10) with ConnectTo(CompareDbInterface, self._config) as sc: result = sc.get_compare_result(compare_id) self.assertEqual(result['plugins']['Software'], self._expected_result()['Software']) self.assertCountEqual( result['plugins']['File_Coverage']['files_in_common'], self._expected_result()['File_Coverage']['files_in_common'])
def test_unpack_analyse_and_compare(self): test_fw_1 = Firmware( file_path='{}/container/test.zip'.format(get_test_data_dir())) test_fw_1.release_date = '2017-01-01' test_fw_2 = Firmware( file_path='{}/container/test.7z'.format(get_test_data_dir())) test_fw_2.release_date = '2017-01-01' self._unpack_scheduler.add_task(test_fw_1) self._unpack_scheduler.add_task(test_fw_2) self.analysis_finished_event.wait(timeout=10) compare_id = unify_string_list(';'.join( [fw.uid for fw in [test_fw_1, test_fw_2]])) self.assertIsNone( self._compare_scheduler.add_task((compare_id, False)), 'adding compare task creates error') self.compare_finished_event.wait(timeout=10) with ConnectTo(CompareDbInterface, self._config) as sc: result = sc.get_compare_result(compare_id) self.assertFalse(isinstance(result, str), 'compare result should exist') self.assertEqual(result['plugins']['Software'], self._expected_result()['Software']) self.assertCountEqual( result['plugins']['File_Coverage']['exclusive_files'], self._expected_result()['File_Coverage']['exclusive_files'])
def test_run_analysis_with_tag(self): test_fw = Firmware(file_path='{}/container/with_key.7z'.format(get_test_data_dir())) test_fw.release_date = '2017-01-01' test_fw.scheduled_analysis = ['crypto_material'] self._unpack_scheduler.add_task(test_fw) assert self.analysis_finished_event.wait(timeout=20) processed_fo = self.backend_interface.get_object(self.uid_of_key_file, analysis_filter=['crypto_material']) assert processed_fo.processed_analysis['crypto_material']['tags'], 'no tags set in analysis' processed_fw = self.backend_interface.get_object(test_fw.uid, analysis_filter=['crypto_material']) assert processed_fw.analysis_tags, 'tags not propagated properly' assert processed_fw.analysis_tags['crypto_material']['private_key_inside']
def _convert_to_firmware(self, entry: dict, analysis_filter: List[str] = None) -> Firmware: firmware = Firmware() firmware.uid = entry['_id'] firmware.size = entry['size'] firmware.file_name = entry['file_name'] firmware.device_name = entry['device_name'] firmware.device_class = entry['device_class'] firmware.release_date = convert_time_to_str(entry['release_date']) firmware.vendor = entry['vendor'] firmware.version = entry['version'] firmware.processed_analysis = self.retrieve_analysis(entry['processed_analysis'], analysis_filter=analysis_filter) firmware.files_included = set(entry['files_included']) firmware.virtual_file_path = entry['virtual_file_path'] firmware.tags = entry['tags'] if 'tags' in entry else dict() firmware.analysis_tags = self._collect_analysis_tags_from_children(firmware.uid) try: # for backwards compatibility firmware.set_part_name(entry['device_part']) except KeyError: firmware.set_part_name('complete') if 'comments' in entry: # for backwards compatibility firmware.comments = entry['comments'] return firmware
def add_test_file(scheduler, path_in_test_dir): firmware = Firmware( file_path=str(Path(get_test_data_dir(), path_in_test_dir))) firmware.release_date = '1990-01-16' scheduler.add_task(firmware)