From 746993e2a26f681b3cb057c80594c06bcde56a02 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Stucke?= Date: Tue, 10 Sep 2024 15:29:29 +0200 Subject: [PATCH] chore: fix 'compare' typos --- CONTRIBUTING.md | 2 +- pyproject.toml | 4 +- src/{compare => comparison}/__init__.py | 0 .../compare.py => comparison/comparison.py} | 26 ++--- .../comparison_base_plugin.py} | 14 +-- src/helperFunctions/data_conversion.py | 26 ++--- src/helperFunctions/plugin.py | 8 +- src/intercom/back_end_binding.py | 10 +- src/intercom/front_end_binding.py | 4 +- .../{compare => comparison}/__init__.py | 0 .../file_coverage/__init__.py | 0 .../file_coverage/code/__init__.py | 0 .../file_coverage/code/file_coverage.py | 42 ++++---- .../file_coverage/test/__init__.py | 0 .../test/test_plugin_file_coverage.py | 14 +-- .../file_coverage/view/file_coverage.html | 0 .../file_header/__init__.py | 0 .../file_header/code/__init__.py | 0 .../file_header/code/file_header.py | 6 +- .../file_header/test/__init__.py | 0 .../file_header/test/test_file_header.py | 10 +- .../file_header/view/file_header.html | 0 .../software/__init__.py | 0 .../software/code/__init__.py | 0 .../software/code/software.py | 14 +-- .../software/test/__init__.py | 0 .../software/test/test_plugin_software.py | 8 +- src/scheduler/comparison_scheduler.py | 12 +-- src/start_fact_backend.py | 12 +-- src/statistic/work_load.py | 6 +- src/storage/db_interface_comparison.py | 26 ++--- src/test/acceptance/conftest.py | 2 +- src/test/acceptance/rest/test_rest_compare.py | 14 +-- src/test/acceptance/test_compare_firmwares.py | 22 ++-- src/test/acceptance/test_io_routes.py | 16 +-- src/test/acceptance/test_search.py | 8 +- src/test/common_helper.py | 7 +- .../intercom/test_backend_scheduler.py | 2 +- .../intercom/test_task_communication.py | 8 +- .../test_unpack_analyse_and_compare.py | 12 +-- .../storage/test_db_interface_comparison.py | 46 ++++---- .../web_interface/rest/test_rest_binary.py | 2 +- .../web_interface/rest/test_rest_compare.py | 12 +-- .../unit/{compare => comparison}/__init__.py | 0 .../comparison_plugin_test_class.py} | 4 +- .../test_comparison.py} | 30 +++--- .../test_plugin_base.py | 22 ++-- src/test/unit/conftest.py | 4 +- .../helperFunctions/test_data_conversion.py | 14 +-- .../{test_compare.py => test_comparison.py} | 32 +++--- ...est_compare.py => test_rest_comparison.py} | 24 ++--- .../unit/web_interface/test_ajax_routes.py | 6 +- .../web_interface/test_app_ajax_routes.py | 12 +-- .../unit/web_interface/test_app_compare.py | 10 +- .../test_app_comparison_basket.py | 22 ++-- .../web_interface/test_comparison_routes.py | 34 +++--- src/web_interface/components/ajax_routes.py | 28 ++--- .../components/analysis_routes.py | 2 +- ...compare_routes.py => comparison_routes.py} | 100 +++++++++--------- src/web_interface/components/io_routes.py | 10 +- src/web_interface/components/plugin_routes.py | 2 +- src/web_interface/frontend_main.py | 4 +- src/web_interface/rest/rest_base.py | 4 +- .../{rest_compare.py => rest_comparison.py} | 57 +++++----- src/web_interface/static/js/start_compare.js | 8 +- src/web_interface/templates/about.html | 2 +- src/web_interface/templates/base.html | 4 +- src/web_interface/templates/compare/wait.html | 6 +- ...re_browse.html => browse_comparisons.html} | 2 +- .../templates/show_analysis.html | 10 +- 70 files changed, 425 insertions(+), 423 deletions(-) rename src/{compare => comparison}/__init__.py (100%) rename src/{compare/compare.py => comparison/comparison.py} (84%) rename src/{compare/PluginBase.py => comparison/comparison_base_plugin.py} (81%) rename src/plugins/{compare => comparison}/__init__.py (100%) rename src/plugins/{compare => comparison}/file_coverage/__init__.py (100%) rename src/plugins/{compare => comparison}/file_coverage/code/__init__.py (100%) rename src/plugins/{compare => comparison}/file_coverage/code/file_coverage.py (85%) rename src/plugins/{compare => comparison}/file_coverage/test/__init__.py (100%) rename src/plugins/{compare => comparison}/file_coverage/test/test_plugin_file_coverage.py (89%) rename src/plugins/{compare => comparison}/file_coverage/view/file_coverage.html (100%) rename src/plugins/{compare => comparison}/file_header/__init__.py (100%) rename src/plugins/{compare => comparison}/file_header/code/__init__.py (100%) rename src/plugins/{compare => comparison}/file_header/code/file_header.py (95%) rename src/plugins/{compare => comparison}/file_header/test/__init__.py (100%) rename src/plugins/{compare => comparison}/file_header/test/test_file_header.py (77%) rename src/plugins/{compare => comparison}/file_header/view/file_header.html (100%) rename src/plugins/{compare => comparison}/software/__init__.py (100%) rename src/plugins/{compare => comparison}/software/code/__init__.py (100%) rename src/plugins/{compare => comparison}/software/code/software.py (85%) rename src/plugins/{compare => comparison}/software/test/__init__.py (100%) rename src/plugins/{compare => comparison}/software/test/test_plugin_software.py (92%) rename src/test/unit/{compare => comparison}/__init__.py (100%) rename src/test/unit/{compare/compare_plugin_test_class.py => comparison/comparison_plugin_test_class.py} (95%) rename src/test/unit/{compare/test_compare.py => comparison/test_comparison.py} (78%) rename src/test/unit/{compare => comparison}/test_plugin_base.py (74%) rename src/test/unit/scheduler/{test_compare.py => test_comparison.py} (63%) rename src/test/unit/web_interface/rest/{test_rest_compare.py => test_rest_comparison.py} (70%) rename src/web_interface/components/{compare_routes.py => comparison_routes.py} (71%) rename src/web_interface/rest/{rest_compare.py => rest_comparison.py} (59%) rename src/web_interface/templates/database/{compare_browse.html => browse_comparisons.html} (96%) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index ea3791e72..9dd101fe4 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,6 +1,6 @@ # Contribute There are many ways to contribute to FACT. -For instance, you can write an unpacking, compare or analysis plug-in. +For instance, you can write an unpacking, comparison or analysis plug-in. You can develop your plug-in in your own repository under your favorite license. It can be added to a local FACT installation as git submodule. Have a look at [FACT’s Developer’s Manual](https://github.com/fkie-cad/FACT_core/wiki) for more details. diff --git a/pyproject.toml b/pyproject.toml index d5da98fee..44e3bb53b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -79,8 +79,8 @@ fixable = ["ALL"] "conftest.py" = ["ARG002"] [tool.ruff.lint.isort] -known-first-party = ["analysis", "compare", "helperFunctions", "install", "intercom", "objects", "plugins", "scheduler", - "statistic", "storage", "test", "unpacker", "version", "web_interface", "config"] +known-first-party = ["analysis", "comparison", "helperFunctions", "install", "intercom", "objects", "plugins", + "scheduler", "statistic", "storage", "test", "unpacker", "version", "web_interface", "config"] known-third-party = ["docker"] [tool.ruff.lint.pylint] diff --git a/src/compare/__init__.py b/src/comparison/__init__.py similarity index 100% rename from src/compare/__init__.py rename to src/comparison/__init__.py diff --git a/src/compare/compare.py b/src/comparison/comparison.py similarity index 84% rename from src/compare/compare.py rename to src/comparison/comparison.py index 9a5777849..925504bce 100644 --- a/src/compare/compare.py +++ b/src/comparison/comparison.py @@ -3,28 +3,28 @@ import logging from typing import TYPE_CHECKING -from helperFunctions.plugin import discover_compare_plugins +from helperFunctions.plugin import discover_comparison_plugins from helperFunctions.virtual_file_path import get_paths_for_all_parents from objects.firmware import Firmware from storage.binary_service import BinaryService if TYPE_CHECKING: - from compare.PluginBase import CompareBasePlugin + from comparison.comparison_base_plugin import ComparisonBasePlugin from objects.file import FileObject from storage.db_interface_comparison import ComparisonDbInterface -class Compare: +class Comparison: """ This Module compares firmware images """ - compare_plugins = {} # noqa: RUF012 + comparison_plugins = {} # noqa: RUF012 def __init__(self, db_interface: ComparisonDbInterface | None = None): self.db_interface = db_interface self._setup_plugins() - logging.info(f'Comparison plugins available: {", ".join(self.compare_plugins)}') + logging.info(f'Comparison plugins available: {", ".join(self.comparison_plugins)}') def compare(self, uid_list): logging.info(f'Comparison in progress: {uid_list}') @@ -41,7 +41,7 @@ def compare(self, uid_list): def compare_objects(self, fo_list): return { 'general': self._create_general_section_dict(fo_list), - 'plugins': self._execute_compare_plugins(fo_list), + 'plugins': self._execute_comparison_plugins(fo_list), } def _create_general_section_dict(self, object_list): @@ -78,24 +78,26 @@ def _get_vfp_data(self, object_list: list[FileObject]) -> dict[str, list[str]]: # --- plug-in system --- def _setup_plugins(self): - self.compare_plugins = {} + self.comparison_plugins = {} self._init_plugins() def _init_plugins(self): - for plugin in discover_compare_plugins(): + for plugin in discover_comparison_plugins(): try: - self.compare_plugins[plugin.ComparePlugin.NAME] = plugin.ComparePlugin(db_interface=self.db_interface) + self.comparison_plugins[plugin.ComparisonPlugin.NAME] = plugin.ComparisonPlugin( + db_interface=self.db_interface + ) except Exception: logging.error(f'Could not import comparison plugin {plugin.AnalysisPlugin.NAME}', exc_info=True) - def _execute_compare_plugins(self, fo_list: list[FileObject]) -> dict[str, dict]: + def _execute_comparison_plugins(self, fo_list: list[FileObject]) -> dict[str, dict]: comparison_results = {} - for plugin in schedule_comparison_plugins(self.compare_plugins): + for plugin in schedule_comparison_plugins(self.comparison_plugins): comparison_results[plugin.NAME] = plugin.compare(fo_list, comparison_results) return comparison_results -def schedule_comparison_plugins(plugin_dict: dict[str, CompareBasePlugin]) -> list[CompareBasePlugin]: +def schedule_comparison_plugins(plugin_dict: dict[str, ComparisonBasePlugin]) -> list[ComparisonBasePlugin]: # we use a reverse topological sort for scheduling the plugins while considering their dependencies # see also: https://en.wikipedia.org/wiki/Topological_sorting#Depth-first_search visited = set() diff --git a/src/compare/PluginBase.py b/src/comparison/comparison_base_plugin.py similarity index 81% rename from src/compare/PluginBase.py rename to src/comparison/comparison_base_plugin.py index 7a93ada54..fd050dbd2 100644 --- a/src/compare/PluginBase.py +++ b/src/comparison/comparison_base_plugin.py @@ -1,4 +1,4 @@ -from __future__ import annotations # noqa: N999 +from __future__ import annotations from abc import abstractmethod from typing import TYPE_CHECKING @@ -9,9 +9,9 @@ from objects.file import FileObject -class CompareBasePlugin(BasePlugin): +class ComparisonBasePlugin(BasePlugin): """ - This is the compare plug-in base class. All compare plug-ins should be derived from this class. + This is the comparison plugin base class. All comparison plugins should be derived from this class. """ # must be set by the plugin: @@ -26,7 +26,7 @@ def __init__(self, config=None, db_interface=None, view_updater=None): self.database = db_interface @abstractmethod - def compare_function(self, fo_list: list[FileObject], dependency_results: dict[str, dict]) -> dict[str, dict]: + def compare_objects(self, fo_list: list[FileObject], dependency_results: dict[str, dict]) -> dict[str, dict]: """ This function must be implemented by the plugin. `fo_list` is a list with file_objects including analysis and all summaries. @@ -38,7 +38,7 @@ def compare_function(self, fo_list: list[FileObject], dependency_results: dict[s def compare(self, fo_list: list[FileObject], dependency_results: dict[str, dict]) -> dict[str, dict]: """ - This function is called by the compare module. + This function is called by the comparison module. """ missing_comparison_deps = self._get_missing_comparison_deps(dependency_results) if missing_comparison_deps: @@ -49,8 +49,8 @@ def compare(self, fo_list: list[FileObject], dependency_results: dict[str, dict] } missing_analysis_deps = self._get_missing_analysis_deps(fo_list) if missing_analysis_deps: - return {'Compare Skipped': {'all': f"Required analyses not present: {', '.join(missing_analysis_deps)}"}} - return self.compare_function(fo_list, dependency_results) + return {'Comparison Skipped': {'all': f"Required analyses not present: {', '.join(missing_analysis_deps)}"}} + return self.compare_objects(fo_list, dependency_results) def _get_missing_comparison_deps(self, dependency_results: dict[str, dict]) -> list[str]: return [ diff --git a/src/helperFunctions/data_conversion.py b/src/helperFunctions/data_conversion.py index 8b46e8c81..0d2c739be 100644 --- a/src/helperFunctions/data_conversion.py +++ b/src/helperFunctions/data_conversion.py @@ -35,36 +35,36 @@ def make_unicode_string(code: Any) -> str: return code.__str__() -def convert_uid_list_to_compare_id(uid_list: Iterable[str]) -> str: +def convert_uid_list_to_comparison_id(uid_list: Iterable[str]) -> str: """ - Convert a list of UIDs to a compare ID (which is a unique string consisting of UIDs separated by semi-colons, used + Convert a list of UIDs to a comparison ID (which is a unique string consisting of UIDs separated by semicolons, used to identify a FACT `Firmware` or `FileObject` comparison). :param uid_list: A list of `FileObject` or `Firmware` UIDs. - :return: The compare ID. + :return: The comparison ID. """ return ';'.join(sorted(uid_list)) -def convert_compare_id_to_list(compare_id: str) -> list[str]: +def convert_comparison_id_to_list(comparison_id: str) -> list[str]: """ - Convert a compare ID back to a list of UIDs. + Convert a comparison ID back to a list of UIDs. - :param compare_id: The compare ID. + :param comparison_id: The comparison ID. :return: The according UID list. """ - return compare_id.split(';') + return comparison_id.split(';') -def normalize_compare_id(compare_id: str) -> str: +def normalize_comparison_id(comparison_id: str) -> str: """ - Sort the UIDs in a compare ID (so that it is unique) and return it. + Sort the UIDs in a comparison ID (so that it is unique) and return it. - :param compare_id: The compare ID. - :return: The according unique compare ID with reordered UIDs. + :param comparison_id: The comparison ID. + :return: The according unique comparison ID with reordered UIDs. """ - uids = convert_compare_id_to_list(compare_id) - return convert_uid_list_to_compare_id(uids) + uids = convert_comparison_id_to_list(comparison_id) + return convert_uid_list_to_comparison_id(uids) def get_value_of_first_key(input_dict: dict[_KT, _VT]) -> _VT | None: diff --git a/src/helperFunctions/plugin.py b/src/helperFunctions/plugin.py index ab3cbe00e..5d365ed4e 100644 --- a/src/helperFunctions/plugin.py +++ b/src/helperFunctions/plugin.py @@ -14,13 +14,13 @@ def discover_analysis_plugins() -> list: return _import_plugins('analysis') -def discover_compare_plugins() -> list: - """Returns a list of modules where each module is a compare plugin.""" - return _import_plugins('compare') +def discover_comparison_plugins() -> list: + """Returns a list of modules where each module is a comparison plugin.""" + return _import_plugins('comparison') def _import_plugins(plugin_type): - assert plugin_type in ['analysis', 'compare'] + assert plugin_type in ['analysis', 'comparison'] plugins = [] src_dir = get_src_dir() diff --git a/src/intercom/back_end_binding.py b/src/intercom/back_end_binding.py index 655598371..baf7468e2 100644 --- a/src/intercom/back_end_binding.py +++ b/src/intercom/back_end_binding.py @@ -31,13 +31,13 @@ class InterComBackEndBinding: def __init__( self, analysis_service=None, - compare_service=None, + comparison_service=None, unpacking_service=None, unpacking_locks=None, testing=False, # noqa: ARG002 ): self.analysis_service = analysis_service - self.compare_service = compare_service + self.comparison_service = comparison_service self.unpacking_service = unpacking_service self.unpacking_locks = unpacking_locks self.poll_delay = config.backend.intercom_poll_delay @@ -49,7 +49,7 @@ def start(self): InterComBackEndAnalysisPlugInsPublisher(analysis_service=self.analysis_service) self._start_listener(InterComBackEndAnalysisTask, self.unpacking_service.add_task) self._start_listener(InterComBackEndReAnalyzeTask, self.unpacking_service.add_task) - self._start_listener(InterComBackEndCompareTask, self.compare_service.add_task) + self._start_listener(InterComBackEndComparisonTask, self.comparison_service.add_task) self._start_listener(InterComBackEndRawDownloadTask) self._start_listener(InterComBackEndFileDiffTask) self._start_listener(InterComBackEndTarRepackTask) @@ -131,8 +131,8 @@ class InterComBackEndSingleFileTask(InterComBackEndReAnalyzeTask): CONNECTION_TYPE = 'single_file_task' -class InterComBackEndCompareTask(InterComListener): - CONNECTION_TYPE = 'compare_task' +class InterComBackEndComparisonTask(InterComListener): + CONNECTION_TYPE = 'comparison_task' class InterComBackEndRawDownloadTask(InterComListenerAndResponder): diff --git a/src/intercom/front_end_binding.py b/src/intercom/front_end_binding.py index 218fce113..3b87b0278 100644 --- a/src/intercom/front_end_binding.py +++ b/src/intercom/front_end_binding.py @@ -25,8 +25,8 @@ def add_re_analyze_task(self, fw, unpack=True): def add_single_file_task(self, fw): self._add_to_redis_queue('single_file_task', fw, fw.uid) - def add_compare_task(self, compare_id, force=False): - self._add_to_redis_queue('compare_task', (compare_id, force), compare_id) + def add_comparison_task(self, comparison_id, force=False): + self._add_to_redis_queue('comparison_task', (comparison_id, force), comparison_id) def delete_file(self, uid_list: set[str]): self._add_to_redis_queue('file_delete_task', uid_list) diff --git a/src/plugins/compare/__init__.py b/src/plugins/comparison/__init__.py similarity index 100% rename from src/plugins/compare/__init__.py rename to src/plugins/comparison/__init__.py diff --git a/src/plugins/compare/file_coverage/__init__.py b/src/plugins/comparison/file_coverage/__init__.py similarity index 100% rename from src/plugins/compare/file_coverage/__init__.py rename to src/plugins/comparison/file_coverage/__init__.py diff --git a/src/plugins/compare/file_coverage/code/__init__.py b/src/plugins/comparison/file_coverage/code/__init__.py similarity index 100% rename from src/plugins/compare/file_coverage/code/__init__.py rename to src/plugins/comparison/file_coverage/code/__init__.py diff --git a/src/plugins/compare/file_coverage/code/file_coverage.py b/src/plugins/comparison/file_coverage/code/file_coverage.py similarity index 85% rename from src/plugins/compare/file_coverage/code/file_coverage.py rename to src/plugins/comparison/file_coverage/code/file_coverage.py index 2579460e2..3a7e9fe88 100644 --- a/src/plugins/compare/file_coverage/code/file_coverage.py +++ b/src/plugins/comparison/file_coverage/code/file_coverage.py @@ -7,16 +7,16 @@ import ssdeep import config -from compare.PluginBase import CompareBasePlugin +from comparison.comparison_base_plugin import ComparisonBasePlugin from helperFunctions.compare_sets import iter_element_and_rest, remove_duplicates_from_list -from helperFunctions.data_conversion import convert_uid_list_to_compare_id +from helperFunctions.data_conversion import convert_uid_list_to_comparison_id from objects.firmware import Firmware if TYPE_CHECKING: from objects.file import FileObject -class ComparePlugin(CompareBasePlugin): +class ComparisonPlugin(ComparisonBasePlugin): """ Compares file coverage """ @@ -29,27 +29,27 @@ def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.ssdeep_ignore_threshold = config.backend.ssdeep_ignore - def compare_function(self, fo_list, dependency_results: dict[str, dict]): # noqa: ARG002 - compare_result = { + def compare_objects(self, fo_list, dependency_results: dict[str, dict]): # noqa: ARG002 + comparison_result = { 'files_in_common': self._get_intersection_of_files(fo_list), 'exclusive_files': self._get_exclusive_files(fo_list), } - self._handle_partially_common_files(compare_result, fo_list) + self._handle_partially_common_files(comparison_result, fo_list) - for result in compare_result.values(): + for result in comparison_result.values(): if isinstance(result, dict): result['collapse'] = False - similar_files, similarity = self._get_similar_files(fo_list, compare_result['exclusive_files']) - compare_result['similar_files'] = self.combine_similarity_results(similar_files, fo_list, similarity) + similar_files, similarity = self._get_similar_files(fo_list, comparison_result['exclusive_files']) + comparison_result['similar_files'] = self.combine_similarity_results(similar_files, fo_list, similarity) if len(fo_list) == 2 and all(isinstance(fo, Firmware) for fo in fo_list): # noqa: PLR2004 - compare_result['changed_text_files'] = self._find_changed_text_files( - fo_list, compare_result['files_in_common']['all'] + comparison_result['changed_text_files'] = self._find_changed_text_files( + fo_list, comparison_result['files_in_common']['all'] ) - return compare_result + return comparison_result def _get_exclusive_files(self, fo_list: list[FileObject]) -> dict[str, list[str]]: result = {} @@ -68,16 +68,16 @@ def _get_intersection_of_files(self, fo_list: list[FileObject]) -> dict[str, lis def _get_included_file_sets(fo_list: list[FileObject]) -> list[set[str]]: return [set(file_object.list_of_all_included_files) for file_object in fo_list] - def _handle_partially_common_files(self, compare_result, fo_list): + def _handle_partially_common_files(self, comparison_result, fo_list): if len(fo_list) > 2: # noqa: PLR2004 - compare_result['files_in_more_than_one_but_not_in_all'] = self._get_files_in_more_than_one_but_not_in_all( - fo_list, compare_result - ) - not_in_all = compare_result['files_in_more_than_one_but_not_in_all'] + comparison_result[ + 'files_in_more_than_one_but_not_in_all' + ] = self._get_files_in_more_than_one_but_not_in_all(fo_list, comparison_result) + not_in_all = comparison_result['files_in_more_than_one_but_not_in_all'] else: not_in_all = {} - compare_result['non_zero_files_in_common'] = self._get_non_zero_common_files( - compare_result['files_in_common'], not_in_all + comparison_result['non_zero_files_in_common'] = self._get_non_zero_common_files( + comparison_result['files_in_common'], not_in_all ) @staticmethod @@ -104,7 +104,7 @@ def _get_similar_files( for file_one in exclusive_files[parent_one.uid]: for similar_file_pair, value in self._find_similar_file_for(file_one, parent_one.uid, parent_two): similar_files.append(similar_file_pair) - similarity[convert_uid_list_to_compare_id(similar_file_pair)] = value + similarity[convert_uid_list_to_comparison_id(similar_file_pair)] = value similarity_sets = generate_similarity_sets(remove_duplicates_from_list(similar_files)) return similarity_sets, similarity @@ -134,7 +134,7 @@ def combine_similarity_results(self, similar_files: list[list[str]], fo_list: li def _get_similarity_value(group_of_similar_files: list[str], similarity_dict: dict[str, str]) -> str: similarities_list = [] for id_tuple in combinations(group_of_similar_files, 2): - similar_file_pair_id = convert_uid_list_to_compare_id(id_tuple) + similar_file_pair_id = convert_uid_list_to_comparison_id(id_tuple) if similar_file_pair_id in similarity_dict: similarities_list.append(similarity_dict[similar_file_pair_id]) if not similarities_list: diff --git a/src/plugins/compare/file_coverage/test/__init__.py b/src/plugins/comparison/file_coverage/test/__init__.py similarity index 100% rename from src/plugins/compare/file_coverage/test/__init__.py rename to src/plugins/comparison/file_coverage/test/__init__.py diff --git a/src/plugins/compare/file_coverage/test/test_plugin_file_coverage.py b/src/plugins/comparison/file_coverage/test/test_plugin_file_coverage.py similarity index 89% rename from src/plugins/compare/file_coverage/test/test_plugin_file_coverage.py rename to src/plugins/comparison/file_coverage/test/test_plugin_file_coverage.py index 984f58013..dc89798a1 100644 --- a/src/plugins/compare/file_coverage/test/test_plugin_file_coverage.py +++ b/src/plugins/comparison/file_coverage/test/test_plugin_file_coverage.py @@ -1,8 +1,8 @@ import pytest -from plugins.compare.file_coverage.code.file_coverage import ComparePlugin, generate_similarity_sets +from plugins.comparison.file_coverage.code.file_coverage import ComparisonPlugin, generate_similarity_sets from test.common_helper import CommonDatabaseMock -from test.unit.compare.compare_plugin_test_class import ComparePluginTest +from test.unit.comparison.comparison_plugin_test_class import ComparisonPluginTest class DbMock: @@ -20,17 +20,17 @@ def get_vfp_of_included_text_files(self, root_uid, blacklist=None): return {} -class TestComparePluginFileCoverage(ComparePluginTest): +class TestComparisonPluginFileCoverage(ComparisonPluginTest): # This name must be changed according to the name of plug-in to test PLUGIN_NAME = 'File_Coverage' - PLUGIN_CLASS = ComparePlugin + PLUGIN_CLASS = ComparisonPlugin def setup_plugin(self): """ This function must be overwritten by the test instance. In most cases it is sufficient to copy this function. """ - return ComparePlugin(db_interface=DbMock(), view_updater=CommonDatabaseMock()) + return ComparisonPlugin(db_interface=DbMock(), view_updater=CommonDatabaseMock()) def test_get_intersection_of_files(self): self.fw_one.list_of_all_included_files.append('foo') @@ -65,7 +65,7 @@ def test_get_files_in_more_than_one_but_not_in_all(self): def test_run_compare_plugin(self): self.fw_one.list_of_all_included_files.append('foo') self.fw_two.list_of_all_included_files.append('foo') - result = self.c_plugin.compare_function([self.fw_one, self.fw_two], {}) + result = self.c_plugin.compare_objects([self.fw_one, self.fw_two], {}) assert len(result.keys()) == 5 # noqa: PLR2004 def test_find_changed_text_files(self): @@ -95,7 +95,7 @@ def test_find_changed_text_files(self): ], ) def test_get_similarity_value(similar_files, similarity_dict, expected_output): - assert ComparePlugin._get_similarity_value(similar_files, similarity_dict) == expected_output + assert ComparisonPlugin._get_similarity_value(similar_files, similarity_dict) == expected_output @pytest.mark.parametrize( diff --git a/src/plugins/compare/file_coverage/view/file_coverage.html b/src/plugins/comparison/file_coverage/view/file_coverage.html similarity index 100% rename from src/plugins/compare/file_coverage/view/file_coverage.html rename to src/plugins/comparison/file_coverage/view/file_coverage.html diff --git a/src/plugins/compare/file_header/__init__.py b/src/plugins/comparison/file_header/__init__.py similarity index 100% rename from src/plugins/compare/file_header/__init__.py rename to src/plugins/comparison/file_header/__init__.py diff --git a/src/plugins/compare/file_header/code/__init__.py b/src/plugins/comparison/file_header/code/__init__.py similarity index 100% rename from src/plugins/compare/file_header/code/__init__.py rename to src/plugins/comparison/file_header/code/__init__.py diff --git a/src/plugins/compare/file_header/code/file_header.py b/src/plugins/comparison/file_header/code/file_header.py similarity index 95% rename from src/plugins/compare/file_header/code/file_header.py rename to src/plugins/comparison/file_header/code/file_header.py index 2ae268c16..8860ad0ae 100644 --- a/src/plugins/compare/file_header/code/file_header.py +++ b/src/plugins/comparison/file_header/code/file_header.py @@ -4,7 +4,7 @@ from markupsafe import Markup -from compare.PluginBase import CompareBasePlugin +from comparison.comparison_base_plugin import ComparisonBasePlugin ASCII_RANGE = (32, 127) BYTES_TO_SHOW = 512 @@ -17,7 +17,7 @@ class Mask: RED = 'fb5151' -class ComparePlugin(CompareBasePlugin): +class ComparisonPlugin(ComparisonBasePlugin): """ Shows a "binwalk -Ww"-ish comparison of the FOs headers in highlighted hexadecimal """ @@ -26,7 +26,7 @@ class ComparePlugin(CompareBasePlugin): DEPENDENCIES = [] # noqa: RUF012 FILE = __file__ - def compare_function(self, fo_list, dependency_results: dict[str, dict]): # noqa: ARG002 + def compare_objects(self, fo_list, dependency_results: dict[str, dict]): # noqa: ARG002 binaries = [fo.binary for fo in fo_list] lower_bound = min(*(len(binary) for binary in binaries), BYTES_TO_SHOW) diff --git a/src/plugins/compare/file_header/test/__init__.py b/src/plugins/comparison/file_header/test/__init__.py similarity index 100% rename from src/plugins/compare/file_header/test/__init__.py rename to src/plugins/comparison/file_header/test/__init__.py diff --git a/src/plugins/compare/file_header/test/test_file_header.py b/src/plugins/comparison/file_header/test/test_file_header.py similarity index 77% rename from src/plugins/compare/file_header/test/test_file_header.py rename to src/plugins/comparison/file_header/test/test_file_header.py index 90fd7bee7..38fa40f81 100644 --- a/src/plugins/compare/file_header/test/test_file_header.py +++ b/src/plugins/comparison/file_header/test/test_file_header.py @@ -1,16 +1,16 @@ from markupsafe import Markup -from test.unit.compare.compare_plugin_test_class import ComparePluginTest +from test.unit.comparison.comparison_plugin_test_class import ComparisonPluginTest -from ..code.file_header import ComparePlugin, replace_none_ascii_with_dots +from ..code.file_header import ComparisonPlugin, replace_none_ascii_with_dots -class TestComparePluginFileHeader(ComparePluginTest): +class TestComparisonPluginFileHeader(ComparisonPluginTest): PLUGIN_NAME = 'File_Header' - PLUGIN_CLASS = ComparePlugin + PLUGIN_CLASS = ComparisonPlugin def test_compare(self): - result = self.c_plugin.compare_function([self.fw_one, self.fw_two, self.fw_three], {}) + result = self.c_plugin.compare_objects([self.fw_one, self.fw_two, self.fw_three], {}) assert all(key in result for key in ['hexdiff', 'ascii', 'offsets']), 'not all result keys given' assert all( diff --git a/src/plugins/compare/file_header/view/file_header.html b/src/plugins/comparison/file_header/view/file_header.html similarity index 100% rename from src/plugins/compare/file_header/view/file_header.html rename to src/plugins/comparison/file_header/view/file_header.html diff --git a/src/plugins/compare/software/__init__.py b/src/plugins/comparison/software/__init__.py similarity index 100% rename from src/plugins/compare/software/__init__.py rename to src/plugins/comparison/software/__init__.py diff --git a/src/plugins/compare/software/code/__init__.py b/src/plugins/comparison/software/code/__init__.py similarity index 100% rename from src/plugins/compare/software/code/__init__.py rename to src/plugins/comparison/software/code/__init__.py diff --git a/src/plugins/compare/software/code/software.py b/src/plugins/comparison/software/code/software.py similarity index 85% rename from src/plugins/compare/software/code/software.py rename to src/plugins/comparison/software/code/software.py index c71130f84..f1fdcd61b 100644 --- a/src/plugins/compare/software/code/software.py +++ b/src/plugins/comparison/software/code/software.py @@ -2,14 +2,14 @@ from typing import TYPE_CHECKING -from compare.PluginBase import CompareBasePlugin +from comparison.comparison_base_plugin import ComparisonBasePlugin from helperFunctions.compare_sets import iter_element_and_rest if TYPE_CHECKING: from objects.file import FileObject -class ComparePlugin(CompareBasePlugin): +class ComparisonPlugin(ComparisonBasePlugin): """ Compares Software """ @@ -18,16 +18,16 @@ class ComparePlugin(CompareBasePlugin): DEPENDENCIES = ['software_components'] # noqa: RUF012 FILE = __file__ - def compare_function(self, fo_list, dependency_results: dict[str, dict]): # noqa: ARG002 - compare_result = { + def compare_objects(self, fo_list, dependency_results: dict[str, dict]): # noqa: ARG002 + comparison_result = { 'software_in_common': self._get_intersection_of_software(fo_list), 'exclusive_software': self._get_exclusive_software(fo_list), } if len(fo_list) > 2: # noqa: PLR2004 - compare_result[ + comparison_result[ 'software_in_more_than_one_but_not_in_all' - ] = self._get_software_in_more_than_one_but_not_in_all(fo_list, compare_result) - return compare_result + ] = self._get_software_in_more_than_one_but_not_in_all(fo_list, comparison_result) + return comparison_result def _get_exclusive_software(self, fo_list: list[FileObject]) -> dict: result = {'collapse': True} diff --git a/src/plugins/compare/software/test/__init__.py b/src/plugins/comparison/software/test/__init__.py similarity index 100% rename from src/plugins/compare/software/test/__init__.py rename to src/plugins/comparison/software/test/__init__.py diff --git a/src/plugins/compare/software/test/test_plugin_software.py b/src/plugins/comparison/software/test/test_plugin_software.py similarity index 92% rename from src/plugins/compare/software/test/test_plugin_software.py rename to src/plugins/comparison/software/test/test_plugin_software.py index d98ed1dd9..9d90e24ee 100644 --- a/src/plugins/compare/software/test/test_plugin_software.py +++ b/src/plugins/comparison/software/test/test_plugin_software.py @@ -1,12 +1,12 @@ -from test.unit.compare.compare_plugin_test_class import ComparePluginTest +from test.unit.comparison.comparison_plugin_test_class import ComparisonPluginTest -from ..code.software import ComparePlugin +from ..code.software import ComparisonPlugin -class TestComparePluginSoftware(ComparePluginTest): +class TestComparePluginSoftware(ComparisonPluginTest): # This name must be changed according to the name of plug-in to test PLUGIN_NAME = 'Software' - PLUGIN_CLASS = ComparePlugin + PLUGIN_CLASS = ComparisonPlugin def test_get_intersection_of_software(self): self.fw_one.processed_analysis['software_components'] = {'summary': {'software a': self.fw_one.uid}} diff --git a/src/scheduler/comparison_scheduler.py b/src/scheduler/comparison_scheduler.py index 374e9781b..783b17b51 100644 --- a/src/scheduler/comparison_scheduler.py +++ b/src/scheduler/comparison_scheduler.py @@ -6,8 +6,8 @@ from queue import Empty import config -from compare.compare import Compare -from helperFunctions.data_conversion import convert_compare_id_to_list +from comparison.comparison import Comparison +from helperFunctions.data_conversion import convert_comparison_id_to_list from helperFunctions.process import check_worker_exceptions, new_worker_was_started, start_single_worker from storage.db_interface_admin import AdminDbInterface from storage.db_interface_comparison import ComparisonDbInterface @@ -24,7 +24,7 @@ def __init__(self, db_interface=None, admin_db_interface=None, callback=None): self.stop_condition = Value('i', 1) self.in_queue = Queue() self.callback = callback - self.comparison_module = Compare(db_interface=self.db_interface) + self.comparison_module = Comparison(db_interface=self.db_interface) self.worker = None def start(self): @@ -52,10 +52,10 @@ def _comparison_scheduler_worker(self, worker_id: int): logging.debug(f'Started comparison worker {worker_id} (pid={os.getpid()})') comparisons_done = set() while self.stop_condition.value == 0: - self._compare_single_run(comparisons_done) + self._comparison_worker(comparisons_done) logging.debug(f'Stopped comparison worker {worker_id}') - def _compare_single_run(self, comparisons_done): + def _comparison_worker(self, comparisons_done): try: comparison_id, redo = self.in_queue.get(timeout=config.backend.block_delay) except Empty: @@ -71,7 +71,7 @@ def _compare_single_run(self, comparisons_done): def _process_comparison(self, comparison_id: str): try: self.db_interface.add_comparison_result( - self.comparison_module.compare(convert_compare_id_to_list(comparison_id)) + self.comparison_module.compare(convert_comparison_id_to_list(comparison_id)) ) except Exception: logging.error(f'Fatal error in comparison process for {comparison_id}', exc_info=True) diff --git a/src/start_fact_backend.py b/src/start_fact_backend.py index f6893f7b8..43ae23d39 100755 --- a/src/start_fact_backend.py +++ b/src/start_fact_backend.py @@ -62,10 +62,10 @@ def __init__(self): analysis_workload=self.analysis_service.get_combined_analysis_workload, unpacking_locks=self.unpacking_lock_manager, ) - self.compare_service = ComparisonScheduler() + self.comparison_service = ComparisonScheduler() self.intercom = InterComBackEndBinding( analysis_service=self.analysis_service, - compare_service=self.compare_service, + comparison_service=self.comparison_service, unpacking_service=self.unpacking_service, unpacking_locks=self.unpacking_lock_manager, ) @@ -73,13 +73,13 @@ def __init__(self): def start(self): self.analysis_service.start() self.unpacking_service.start() - self.compare_service.start() + self.comparison_service.start() self.intercom.start() def shutdown(self): super().shutdown() self.intercom.shutdown() - self.compare_service.shutdown() + self.comparison_service.shutdown() self.unpacking_service.shutdown() self.analysis_service.shutdown() self.unpacking_lock_manager.shutdown() @@ -108,7 +108,7 @@ def _exception_occurred(self): return any( ( self.unpacking_service.check_exceptions(), - self.compare_service.check_exceptions(), + self.comparison_service.check_exceptions(), self.analysis_service.check_exceptions(), ) ) @@ -132,7 +132,7 @@ def _check_ulimit(): | unpacking_lock_manager | 2 | - | 2 | | analysis_service | 200 | 294 | 494 | | unpacking_service | 2 | 20 | 22 | - | compare_service | 3 | 4 | 7 | + | comparison_service | 3 | 4 | 7 | | intercom | - | 24 | 24 | | total | | | 556 | diff --git a/src/statistic/work_load.py b/src/statistic/work_load.py index e82c3a2bd..7134bb4d8 100644 --- a/src/statistic/work_load.py +++ b/src/statistic/work_load.py @@ -25,7 +25,7 @@ def shutdown(self): logging.debug(f'{self.component}: shutting down -> set offline message') self.db.update_statistic(self.component, {'status': 'offline', 'last_update': time()}) - def update(self, unpacking_workload=None, analysis_workload=None, compare_workload=None): + def update(self, unpacking_workload=None, analysis_workload=None, comparison_workload=None): stats = { 'name': self.component, 'status': 'online', @@ -37,8 +37,8 @@ def update(self, unpacking_workload=None, analysis_workload=None, compare_worklo stats['unpacking'] = unpacking_workload if analysis_workload: stats['analysis'] = analysis_workload - if compare_workload: - stats['compare'] = compare_workload + if comparison_workload: + stats['compare'] = comparison_workload self.db.update_statistic(self.component, stats) def _get_system_information(self): diff --git a/src/storage/db_interface_comparison.py b/src/storage/db_interface_comparison.py index 4cfe69a9f..e0031b835 100644 --- a/src/storage/db_interface_comparison.py +++ b/src/storage/db_interface_comparison.py @@ -7,9 +7,9 @@ from sqlalchemy.dialects.postgresql import JSONB from helperFunctions.data_conversion import ( - convert_compare_id_to_list, - convert_uid_list_to_compare_id, - normalize_compare_id, + convert_comparison_id_to_list, + convert_uid_list_to_comparison_id, + normalize_comparison_id, ) from storage.db_interface_base import ReadWriteDbInterface from storage.db_interface_common import DbInterfaceCommon @@ -33,15 +33,15 @@ def add_comparison_result(self, comparison_result: dict): self.update_comparison(comparison_id, comparison_result) else: self.insert_comparison(comparison_id, comparison_result) - logging.info(f'compare result added to db: {comparison_id}') + logging.info(f'Comparison result added to db: {comparison_id}') def comparison_exists(self, comparison_id: str) -> bool: with self.get_read_only_session() as session: query = select(ComparisonEntry.comparison_id).filter(ComparisonEntry.comparison_id == comparison_id) return bool(session.execute(query).scalar()) - def objects_exist(self, compare_id: str) -> bool: - uid_list = convert_compare_id_to_list(compare_id) + def objects_exist(self, comparison_id: str) -> bool: + uid_list = convert_comparison_id_to_list(comparison_id) with self.get_read_only_session() as session: query = select(func.count(FileObjectEntry.uid)).filter(FileObjectEntry.uid.in_(uid_list)) return session.execute(query).scalar() == len(uid_list) @@ -49,16 +49,16 @@ def objects_exist(self, compare_id: str) -> bool: @staticmethod def _calculate_comp_id(comparison_result): uid_set = {uid for c_dict in comparison_result['general'].values() for uid in c_dict} - return convert_uid_list_to_compare_id(uid_set) + return convert_uid_list_to_comparison_id(uid_set) def get_comparison_result(self, comparison_id: str) -> dict | None: - comparison_id = normalize_compare_id(comparison_id) + comparison_id = normalize_comparison_id(comparison_id) if not self.comparison_exists(comparison_id): - logging.debug(f'Compare result not found in db: {comparison_id}') + logging.debug(f'Comparison result not found in db: {comparison_id}') return None with self.get_read_only_session() as session: comparison_entry = session.get(ComparisonEntry, comparison_id) - logging.debug(f'got compare result from db: {comparison_id}') + logging.debug(f'Got comparison result from db: {comparison_id}') return self._entry_to_dict(comparison_entry, comparison_id) @staticmethod @@ -111,11 +111,11 @@ def get_entropy(self, uid: str) -> float: return 0.0 return analysis.result['entropy'] - def get_exclusive_files(self, compare_id: str, root_uid: str) -> list[str]: - if compare_id is None or root_uid is None: + def get_exclusive_files(self, comparison_id: str, root_uid: str) -> list[str]: + if comparison_id is None or root_uid is None: return [] try: - result = self.get_comparison_result(compare_id) + result = self.get_comparison_result(comparison_id) exclusive_files = result['plugins']['File_Coverage']['exclusive_files'][root_uid] except (KeyError, FactComparisonException): exclusive_files = [] diff --git a/src/test/acceptance/conftest.py b/src/test/acceptance/conftest.py index f4c97fa35..c2ae0d481 100644 --- a/src/test/acceptance/conftest.py +++ b/src/test/acceptance/conftest.py @@ -30,7 +30,7 @@ def test_client(web_frontend): def intercom_backend_binding(_unpacking_lock_manager, analysis_scheduler, comparison_scheduler, unpacking_scheduler): _intercom_backend_binding = InterComBackEndBinding( analysis_service=analysis_scheduler, - compare_service=comparison_scheduler, + comparison_service=comparison_scheduler, unpacking_service=unpacking_scheduler, unpacking_locks=_unpacking_lock_manager, ) diff --git a/src/test/acceptance/rest/test_rest_compare.py b/src/test/acceptance/rest/test_rest_compare.py index b78434d62..b2b17608e 100644 --- a/src/test/acceptance/rest/test_rest_compare.py +++ b/src/test/acceptance/rest/test_rest_compare.py @@ -33,15 +33,15 @@ def _rest_search(self, test_client, fw): rv = test_client.get(f'/rest/firmware?query={query}', follow_redirects=True) assert fw.uid.encode() in rv.data, 'test firmware not found in REST search' - def _rest_start_compare(self, test_client): + def _rest_start_comparison(self, test_client): data = {'uid_list': [test_fw_a.uid, test_fw_c.uid]} rv = test_client.put('/rest/compare', json=data, follow_redirects=True) - assert b'Compare started' in rv.data, 'could not start REST compare' + assert b'Comparison started' in rv.data, 'could not start REST comparison' - def _rest_get_compare(self, test_client): + def _rest_get_comparison(self, test_client): rv = test_client.get(f'/rest/compare/{test_fw_a.uid};{test_fw_c.uid}', follow_redirects=True) - assert b'Compare not found in database.' not in rv.data, 'compare not found in database' - assert b'"files_in_common": {"' in rv.data, 'REST compare not successful' + assert b'Comparison not found in database.' not in rv.data, 'comparison not found in database' + assert b'"files_in_common": {"' in rv.data, 'REST comparison not successful' # two firmware container with 3 included files each times three plugins @pytest.mark.SchedulerTestConfig(items_to_analyze=4 * 2 * 3) @@ -52,6 +52,6 @@ def test_run_from_upload_to_show_analysis(self, test_client, analysis_finished_e assert analysis_finished_event.wait(timeout=20) self._rest_search(test_client, test_fw_a) self._rest_search(test_client, test_fw_c) - self._rest_start_compare(test_client) + self._rest_start_comparison(test_client) assert comparison_finished_event.wait(timeout=20) - self._rest_get_compare(test_client) + self._rest_get_comparison(test_client) diff --git a/src/test/acceptance/test_compare_firmwares.py b/src/test/acceptance/test_compare_firmwares.py index ade9fd47a..00647ff23 100644 --- a/src/test/acceptance/test_compare_firmwares.py +++ b/src/test/acceptance/test_compare_firmwares.py @@ -16,9 +16,9 @@ def _add_firmwares_to_compare(self, test_client): rv = test_client.get(f'/comparison/add/{test_fw_c.uid}', follow_redirects=True) assert 'Remove All' in rv.data.decode() - def _start_compare(self, test_client): + def _start_comparison(self, test_client): rv = test_client.get('/compare', follow_redirects=True) - assert b'Your compare task is in progress.' in rv.data, 'compare wait page not displayed correctly' + assert b'Your comparison task is in progress.' in rv.data, 'comparison wait page not displayed correctly' def _show_comparison_results(self, test_client): rv = test_client.get(f'/compare/{test_fw_a.uid};{test_fw_c.uid}') @@ -30,15 +30,15 @@ def _show_home_page(self, test_client): rv = test_client.get('/') assert b'Latest Comparisons' in rv.data, 'latest comparisons not displayed on "home"' - def _show_compare_browse(self, test_client): - rv = test_client.get('/database/browse_compare') - assert test_fw_a.name.encode() in rv.data, 'no compare result shown in browse' + def _show_comparison_browse(self, test_client): + rv = test_client.get('/database/browse_comparisons') + assert test_fw_a.name.encode() in rv.data, 'no comparison result shown in browse' - def _show_analysis_without_compare_list(self, test_client): + def _show_analysis_without_comparison_list(self, test_client): rv = test_client.get(f'/analysis/{test_fw_a.uid}') assert b'Show list of known comparisons' not in rv.data - def _show_analysis_with_compare_list(self, test_client): + def _show_analysis_with_comparison_list(self, test_client): rv = test_client.get(f'/analysis/{test_fw_a.uid}') assert b'Show list of known comparisons' in rv.data @@ -49,11 +49,11 @@ def test_compare_firmwares(self, test_client, analysis_finished_event, compariso for firmware in [test_fw_a, test_fw_c]: upload_test_firmware(test_client, firmware) assert analysis_finished_event.wait(timeout=20) - self._show_analysis_without_compare_list(test_client) + self._show_analysis_without_comparison_list(test_client) self._add_firmwares_to_compare(test_client) - self._start_compare(test_client) + self._start_comparison(test_client) assert comparison_finished_event.wait(timeout=20) self._show_comparison_results(test_client) self._show_home_page(test_client) - self._show_compare_browse(test_client) - self._show_analysis_with_compare_list(test_client) + self._show_comparison_browse(test_client) + self._show_analysis_with_comparison_list(test_client) diff --git a/src/test/acceptance/test_io_routes.py b/src/test/acceptance/test_io_routes.py index 823b6f637..2f715475d 100644 --- a/src/test/acceptance/test_io_routes.py +++ b/src/test/acceptance/test_io_routes.py @@ -4,7 +4,7 @@ from storage.db_interface_comparison import ComparisonDbInterface from test.common_helper import create_test_firmware -COMPARE_RESULT = { +COMPARISON_RESULT = { 'general': {'a': {'id1': '', 'id2': ''}, 'b': {'id1': '', 'id2': ''}}, 'plugins': {'Ida_Diff_Highlighting': {'idb_binary': 'The IDA database'}}, } @@ -35,23 +35,23 @@ def test_radare_button(self, test_client, backend_db): assert b'Failed to establish a new connection' in response.data, 'connection shall fail' def test_ida_download(self, backend_db, test_client): - compare_interface = ComparisonDbInterface() + comparison_interface = ComparisonDbInterface() backend_db.add_object(self.test_fw) - COMPARE_RESULT['general'] = {'a': {self.test_fw.uid: 'x'}, 'b': {self.test_fw.uid: 'y'}} + COMPARISON_RESULT['general'] = {'a': {self.test_fw.uid: 'x'}, 'b': {self.test_fw.uid: 'y'}} - compare_interface.add_comparison_result(COMPARE_RESULT) - cid = compare_interface._calculate_comp_id(COMPARE_RESULT) + comparison_interface.add_comparison_result(COMPARISON_RESULT) + cid = comparison_interface._calculate_comp_id(COMPARISON_RESULT) response = test_client.get(f'/ida-download/{cid}') assert b'IDA database' in response.data, 'mocked ida database not in result' def test_ida_download_bad_uid(self, test_client): - compare_interface = ComparisonDbInterface() + comparison_interface = ComparisonDbInterface() - compare_interface.add_comparison_result(COMPARE_RESULT) - cid = compare_interface._calculate_comp_id(COMPARE_RESULT) + comparison_interface.add_comparison_result(COMPARISON_RESULT) + cid = comparison_interface._calculate_comp_id(COMPARISON_RESULT) response = test_client.get(f'/ida-download/{cid}') assert b'not found' in response.data, 'endpoint should dismiss result' diff --git a/src/test/acceptance/test_search.py b/src/test/acceptance/test_search.py index 95202c73b..446c4d55f 100644 --- a/src/test/acceptance/test_search.py +++ b/src/test/acceptance/test_search.py @@ -26,9 +26,9 @@ def _show_browse_db(self, test_client): rv = test_client.get('/database/browse') assert test_fw.uid.encode() in rv.data, 'test firmware not found in browse database' - def _show_browse_compare(self, test_client): - rv = test_client.get('/database/browse_compare') - assert '200' in rv.status, 'compare browsing site offline' + def _show_browse_comparisons(self, test_client): + rv = test_client.get('/database/browse_comparisons') + assert '200' in rv.status, 'comparison browsing site offline' def _show_search_post(self, test_client): data = { @@ -59,7 +59,7 @@ def _search_date(self, test_client): def test_search(self, test_client): self._show_browse_db(test_client) - self._show_browse_compare(test_client) + self._show_browse_comparisons(test_client) self._show_search_get(test_client) self._show_search_post(test_client) self._show_quick_search(test_client) diff --git a/src/test/common_helper.py b/src/test/common_helper.py index 22f2be87d..506c7eae4 100644 --- a/src/test/common_helper.py +++ b/src/test/common_helper.py @@ -186,9 +186,6 @@ def get_hid(self, uid, root_uid=None): # noqa: ARG002 def get_device_class_list(self): return ['test class'] - def page_compare_results(self): - return [] - def get_vendor_list(self): return ['test vendor'] @@ -253,8 +250,8 @@ def get_comparison_result(comparison_id): return None @staticmethod - def objects_exist(compare_id): - if compare_id in ['existing_id', 'uid1;uid2', COMPARISON_ID]: + def objects_exist(comparison_id): + if comparison_id in ['existing_id', 'uid1;uid2', COMPARISON_ID]: return True return False diff --git a/src/test/integration/intercom/test_backend_scheduler.py b/src/test/integration/intercom/test_backend_scheduler.py index 561fa8e3d..dba3a7511 100644 --- a/src/test/integration/intercom/test_backend_scheduler.py +++ b/src/test/integration/intercom/test_backend_scheduler.py @@ -51,7 +51,7 @@ def get_intercom_for_testing(): interface = InterComBackEndBinding( testing=True, analysis_service=AnalysisServiceMock(), - compare_service=ServiceMock(test_queue), + comparison_service=ServiceMock(test_queue), unpacking_service=ServiceMock(test_queue), ) interface.WAIT_TIME = 2 diff --git a/src/test/integration/intercom/test_task_communication.py b/src/test/integration/intercom/test_task_communication.py index d6564f4ab..eec95d9e2 100644 --- a/src/test/integration/intercom/test_task_communication.py +++ b/src/test/integration/intercom/test_task_communication.py @@ -11,7 +11,7 @@ InterComBackEndAnalysisPlugInsPublisher, InterComBackEndAnalysisTask, InterComBackEndBinarySearchTask, - InterComBackEndCompareTask, + InterComBackEndComparisonTask, InterComBackEndFileDiffTask, InterComBackEndLogsTask, InterComBackEndPeekBinaryTask, @@ -85,9 +85,9 @@ def test_re_analyze_task(self, intercom_frontend): task = task_listener.get_next_task() assert task.uid == test_fw.uid, 'uid not correct' - def test_compare_task(self, intercom_frontend): - task = InterComBackEndCompareTask() - intercom_frontend.add_compare_task('valid_id', force=False) + def test_comparison_task(self, intercom_frontend): + task = InterComBackEndComparisonTask() + intercom_frontend.add_comparison_task('valid_id', force=False) result = task.get_next_task() assert result == ('valid_id', False) diff --git a/src/test/integration/scheduler/test_unpack_analyse_and_compare.py b/src/test/integration/scheduler/test_unpack_analyse_and_compare.py index 5988dec9e..1d8897b8f 100644 --- a/src/test/integration/scheduler/test_unpack_analyse_and_compare.py +++ b/src/test/integration/scheduler/test_unpack_analyse_and_compare.py @@ -1,13 +1,13 @@ import pytest -from helperFunctions.data_conversion import normalize_compare_id +from helperFunctions.data_conversion import normalize_comparison_id from objects.firmware import Firmware from storage.db_interface_backend import BackendDbInterface from test.common_helper import get_test_data_dir _expected_result = { 'File_Coverage': {'files_in_common': {'all': [], 'collapse': False}}, - 'Software': {'Compare Skipped': {'all': 'Required analyses not present: software_components'}}, + 'Software': {'Comparison Skipped': {'all': 'Required analyses not present: software_components'}}, } @@ -19,7 +19,7 @@ class TestFileAddition: pipeline=True, backend_db_class=BackendDbInterface, ) - def test_unpack_analyse_and_compare( # noqa: PLR0913 + def test_unpack_analyse_and_comparison( # noqa: PLR0913 self, backend_db, unpacking_scheduler, @@ -41,13 +41,13 @@ def test_unpack_analyse_and_compare( # noqa: PLR0913 assert analysis_finished_event.wait(timeout=20) - compare_id = normalize_compare_id(';'.join([fw.uid for fw in [test_fw_1, test_fw_2]])) + comparison_id = normalize_comparison_id(';'.join([fw.uid for fw in [test_fw_1, test_fw_2]])) - assert comparison_scheduler.add_task((compare_id, False)) is None, 'adding comparison task creates error' + assert comparison_scheduler.add_task((comparison_id, False)) is None, 'adding comparison task creates error' assert comparison_finished_event.wait(timeout=10) - result = comparison_db.get_comparison_result(compare_id) + result = comparison_db.get_comparison_result(comparison_id) assert result is not None, 'comparison result not found in DB' assert result['plugins']['Software'] == _expected_result['Software'] diff --git a/src/test/integration/storage/test_db_interface_comparison.py b/src/test/integration/storage/test_db_interface_comparison.py index d9ee37ab5..69d4a6d1a 100644 --- a/src/test/integration/storage/test_db_interface_comparison.py +++ b/src/test/integration/storage/test_db_interface_comparison.py @@ -15,27 +15,27 @@ def test_comparison_exists(comparison_db, backend_db): def test_add_and_get_comparison_result(comparison_db, backend_db): - fw_one, _, _, compare_id = _add_comparison(comparison_db, backend_db) - retrieved = comparison_db.get_comparison_result(compare_id) + fw_one, _, _, comparison_id = _add_comparison(comparison_db, backend_db) + retrieved = comparison_db.get_comparison_result(comparison_id) assert retrieved['general']['virtual_file_path'][fw_one.uid] == 'dev_one_name', 'content of retrieval not correct' def test_get_not_existing_result(comparison_db, backend_db): - fw_one, fw_two, _, compare_id = _create_comparison() + fw_one, fw_two, _, comparison_id = _create_comparison() backend_db.insert_multiple_objects(fw_one, fw_two) - result = comparison_db.get_comparison_result(compare_id) + result = comparison_db.get_comparison_result(comparison_id) assert result is None def test_calculate_comparison_id(comparison_db): - _, _, compare_dict, compare_id = _create_comparison() - comp_id = comparison_db._calculate_comp_id(compare_dict) - assert comp_id == compare_id + _, _, comparison_dict, comparison_id = _create_comparison() + comp_id = comparison_db._calculate_comp_id(comparison_dict) + assert comp_id == comparison_id def test_comp_id_incomplete_entries(comparison_db): - compare_dict = {'general': {'stat_1': {'a': None}, 'stat_2': {'b': None}}} - comp_id = comparison_db._calculate_comp_id(compare_dict) + comparison_dict = {'general': {'stat_1': {'a': None}, 'stat_2': {'b': None}}} + comp_id = comparison_db._calculate_comp_id(comparison_dict) assert comp_id == 'a;b' @@ -64,25 +64,25 @@ def test_delete_fw_cascades_to_comp(backend_db, comparison_db, admin_db): def test_get_latest_removed_firmware(comparison_db, backend_db, admin_db): - fw_one, fw_two, compare_dict, _ = _create_comparison() + fw_one, fw_two, comparison_dict, _ = _create_comparison() backend_db.insert_multiple_objects(fw_one, fw_two) - comparison_db.add_comparison_result(compare_dict) + comparison_db.add_comparison_result(comparison_dict) result = comparison_db.page_comparison_results(limit=10) - assert result != [], 'A compare result should be available' + assert result != [], 'A comparison result should be available' admin_db.delete_firmware(fw_two.uid) result = comparison_db.page_comparison_results(limit=10) - assert result == [], 'No compare result should be available' + assert result == [], 'No comparison result should be available' def test_get_total_number_of_results(comparison_db, backend_db): _add_comparison(comparison_db, backend_db) number = comparison_db.get_total_number_of_results() - assert number == 1, 'no compare result found in database' + assert number == 1, 'no comparison result found in database' @pytest.mark.parametrize( @@ -94,10 +94,10 @@ def test_get_total_number_of_results(comparison_db, backend_db): ], ) def test_get_exclusive_files(comparison_db, backend_db, root_uid, expected_result): - fw_one, fw_two, compare_dict, comp_id = _create_comparison() - compare_dict['plugins'] = {'File_Coverage': {'exclusive_files': {'the_root_uid': ['uid1', 'uid2']}}} + fw_one, fw_two, comparison_dict, comp_id = _create_comparison() + comparison_dict['plugins'] = {'File_Coverage': {'exclusive_files': {'the_root_uid': ['uid1', 'uid2']}}} backend_db.insert_multiple_objects(fw_one, fw_two) - comparison_db.add_comparison_result(compare_dict) + comparison_db.add_comparison_result(comparison_dict) exclusive_files = comparison_db.get_exclusive_files(comp_id, root_uid) assert exclusive_files == expected_result @@ -116,19 +116,19 @@ def _create_comparison(uid1='uid1', uid2='uid2'): fw_two = create_test_firmware() fw_two.set_binary(b'another firmware') fw_two.uid = uid2 - compare_dict = { + comparison_dict = { 'general': { 'hid': {fw_one.uid: 'foo', fw_two.uid: 'bar'}, 'virtual_file_path': {fw_one.uid: 'dev_one_name', fw_two.uid: 'dev_two_name'}, }, 'plugins': {}, } - compare_id = f'{fw_one.uid};{fw_two.uid}' - return fw_one, fw_two, compare_dict, compare_id + comparison_id = f'{fw_one.uid};{fw_two.uid}' + return fw_one, fw_two, comparison_dict, comparison_id def _add_comparison(comparison_db, backend_db, uid1='uid1', uid2='uid2'): - fw_one, fw_two, compare_dict, comparison_id = _create_comparison(uid1=uid1, uid2=uid2) + fw_one, fw_two, comparison_dict, comparison_id = _create_comparison(uid1=uid1, uid2=uid2) backend_db.insert_multiple_objects(fw_one, fw_two) - comparison_db.add_comparison_result(compare_dict) - return fw_one, fw_two, compare_dict, comparison_id + comparison_db.add_comparison_result(comparison_dict) + return fw_one, fw_two, comparison_dict, comparison_id diff --git a/src/test/integration/web_interface/rest/test_rest_binary.py b/src/test/integration/web_interface/rest/test_rest_binary.py index 08d0d4806..dca198b45 100644 --- a/src/test/integration/web_interface/rest/test_rest_binary.py +++ b/src/test/integration/web_interface/rest/test_rest_binary.py @@ -23,7 +23,7 @@ def teardown_method(self): def test_rest_download_valid(self, backend_config): backend_binding = InterComBackEndBinding( analysis_service=test_backend_scheduler.AnalysisServiceMock(), - compare_service=test_backend_scheduler.ServiceMock(self.test_queue), + comparison_service=test_backend_scheduler.ServiceMock(self.test_queue), unpacking_service=test_backend_scheduler.ServiceMock(self.test_queue), ) backend_binding.start() diff --git a/src/test/integration/web_interface/rest/test_rest_compare.py b/src/test/integration/web_interface/rest/test_rest_compare.py index 6e5550b00..f6a4550a0 100644 --- a/src/test/integration/web_interface/rest/test_rest_compare.py +++ b/src/test/integration/web_interface/rest/test_rest_compare.py @@ -7,8 +7,8 @@ @pytest.mark.usefixtures('database_interfaces') -class TestRestStartCompare(RestTestBase): - def test_rest_start_compare_valid(self, backend_db): +class TestRestStartComparison(RestTestBase): + def test_rest_start_comparison_valid(self, backend_db): test_firmware_1 = create_test_firmware( device_class='test class', device_name='test device', vendor='test vendor' ) @@ -20,13 +20,13 @@ def test_rest_start_compare_valid(self, backend_db): data = {'uid_list': [test_firmware_1.uid, test_firmware_2.uid], 'redo': True} rv = self.test_client.put('/rest/compare', json=data, follow_redirects=True) - assert b'Compare started.' in rv.data + assert b'Comparison started.' in rv.data - def test_rest_start_compare_invalid_uid(self): + def test_rest_start_comparison_invalid_uid(self): rv = self.test_client.put('/rest/compare', json={'uid_list': ['123', '456']}, follow_redirects=True) assert b'not found in the database' in rv.data - def test_rest_start_compare_invalid_data(self, backend_db): + def test_rest_start_comparison_invalid_data(self, backend_db): test_firmware = create_test_firmware(device_class='test class', device_name='test device', vendor='test vendor') backend_db.add_object(test_firmware) @@ -46,7 +46,7 @@ def test_rest_get_compare_valid_not_in_db(self, backend_db): backend_db.add_object(test_firmware_2) rv = self.test_client.get(f'/rest/compare/{test_firmware_1.uid};{test_firmware_2.uid}', follow_redirects=True) - assert b'Compare not found in database.' in rv.data + assert b'Comparison not found in database.' in rv.data def test_rest_get_compare_invalid_uid(self): rv = self.test_client.get(f'/rest/compare/{TEST_UID};{TEST_UID}', follow_redirects=True) diff --git a/src/test/unit/compare/__init__.py b/src/test/unit/comparison/__init__.py similarity index 100% rename from src/test/unit/compare/__init__.py rename to src/test/unit/comparison/__init__.py diff --git a/src/test/unit/compare/compare_plugin_test_class.py b/src/test/unit/comparison/comparison_plugin_test_class.py similarity index 95% rename from src/test/unit/compare/compare_plugin_test_class.py rename to src/test/unit/comparison/comparison_plugin_test_class.py index 9a242b91f..3510a4c53 100644 --- a/src/test/unit/compare/compare_plugin_test_class.py +++ b/src/test/unit/comparison/comparison_plugin_test_class.py @@ -4,7 +4,7 @@ from test.common_helper import CommonDatabaseMock, create_test_firmware -class ComparePluginTest: +class ComparisonPluginTest: # This name must be changed according to the name of plug-in to test PLUGIN_NAME = 'base' PLUGIN_CLASS = None @@ -13,7 +13,7 @@ def setup_method(self): self.config = self.generate_config() self.config.add_section('expert-settings') self.config.set('expert-settings', 'ssdeep-ignore', '80') - self.compare_plugins = {} + self.comparison_plugins = {} self.c_plugin = self.setup_plugin() self.setup_test_fw() diff --git a/src/test/unit/compare/test_compare.py b/src/test/unit/comparison/test_comparison.py similarity index 78% rename from src/test/unit/compare/test_compare.py rename to src/test/unit/comparison/test_comparison.py index f514f11a1..027162b92 100644 --- a/src/test/unit/compare/test_compare.py +++ b/src/test/unit/comparison/test_comparison.py @@ -2,14 +2,14 @@ import pytest -from compare.compare import Compare, schedule_comparison_plugins -from compare.PluginBase import CompareBasePlugin +from comparison.comparison import Comparison, schedule_comparison_plugins +from comparison.comparison_base_plugin import ComparisonBasePlugin from test.common_helper import create_test_file_object, create_test_firmware @pytest.fixture(autouse=True) -def _no_compare_views(monkeypatch): - monkeypatch.setattr(CompareBasePlugin, '_sync_view', value=lambda *_: None) +def _no_comparison_views(monkeypatch): + monkeypatch.setattr(ComparisonBasePlugin, '_sync_view', value=lambda *_: None) class MockDbInterface: @@ -39,16 +39,16 @@ def get_vfps_for_uid_list(self, uid_list, root_uid=None): @pytest.fixture -def compare_system(): - return Compare(db_interface=MockDbInterface()) +def comparison_system(): + return Comparison(db_interface=MockDbInterface()) fw_one = create_test_firmware(device_name='dev_1', all_files_included_set=True) fw_two = create_test_firmware(device_name='dev_2', bin_path='container/test.7z', all_files_included_set=True) -def test_compare_objects(compare_system): - result = compare_system.compare_objects([fw_one, fw_two]) +def test_compare_objects(comparison_system): + result = comparison_system.compare_objects([fw_one, fw_two]) assert isinstance(result, dict), 'Result is not a dict' assert 'general' in result, 'general part is missing' assert isinstance(result['general'], dict), 'general part is not a dict' @@ -56,13 +56,13 @@ def test_compare_objects(compare_system): assert isinstance(result['plugins'], dict), 'plugins part is not a dict' -def test_compare_error_none_existing_fo(compare_system): +def test_compare_error_non_existing_fo(comparison_system): with pytest.raises(AttributeError): - compare_system.compare(['error']) + comparison_system.compare(['error']) -def test_create_general_section_dict(compare_system): - result = compare_system._create_general_section_dict([fw_one, fw_two]) +def test_create_general_section_dict(comparison_system): + result = comparison_system._create_general_section_dict([fw_one, fw_two]) assert isinstance(result, dict), 'result is not a dict' assert result['device_name'][fw_one.uid] == 'dev_1' assert result['device_name'][fw_two.uid] == 'dev_2' @@ -74,9 +74,9 @@ def test_create_general_section_dict(compare_system): assert result['virtual_file_path'][fw_one.uid] == [fw_one.file_name] -def test_plugin_system(compare_system): - assert len(compare_system.compare_plugins) > 0, 'no compare plugin found' - assert 'File_Coverage' in compare_system.compare_plugins, 'File Coverage module not found' +def test_plugin_system(comparison_system): + assert len(comparison_system.comparison_plugins) > 0, 'no comparison plugin found' + assert 'File_Coverage' in comparison_system.comparison_plugins, 'File Coverage module not found' class MockPlugin: diff --git a/src/test/unit/compare/test_plugin_base.py b/src/test/unit/comparison/test_plugin_base.py similarity index 74% rename from src/test/unit/compare/test_plugin_base.py rename to src/test/unit/comparison/test_plugin_base.py index 38d97cd9c..ba7029efa 100644 --- a/src/test/unit/compare/test_plugin_base.py +++ b/src/test/unit/comparison/test_plugin_base.py @@ -1,6 +1,6 @@ import pytest -from compare.PluginBase import CompareBasePlugin as ComparePlugin +from comparison.comparison_base_plugin import ComparisonBasePlugin as ComparisonPlugin from test.common_helper import CommonDatabaseMock, create_test_firmware fw_one = create_test_firmware(device_name='dev_1', all_files_included_set=True) @@ -9,8 +9,8 @@ @pytest.fixture -def compare_plugin(): - return ComparePlugin(view_updater=CommonDatabaseMock()) +def comparison_plugin(): + return ComparisonPlugin(view_updater=CommonDatabaseMock()) @pytest.mark.backend_config_overwrite( @@ -19,16 +19,16 @@ def compare_plugin(): } ) class TestPluginBase: - def test_compare_missing_dep(self, compare_plugin): - compare_plugin.DEPENDENCIES = ['test_ana'] + def test_comparison_missing_dep(self, comparison_plugin): + comparison_plugin.DEPENDENCIES = ['test_ana'] fw_one.processed_analysis['test_ana'] = {} - result = compare_plugin.compare([fw_one, fw_two], {}) + result = comparison_plugin.compare([fw_one, fw_two], {}) assert result == { - 'Compare Skipped': {'all': 'Required analyses not present: test_ana'} + 'Comparison Skipped': {'all': 'Required analyses not present: test_ana'} }, 'missing dep result not correct' - def test_compare(self, compare_plugin): - result = compare_plugin.compare([fw_one, fw_two], {}) + def test_compare(self, comparison_plugin): + result = comparison_plugin.compare([fw_one, fw_two], {}) assert result == {'dummy': {'all': 'dummy-content', 'collapse': False}}, 'result not correct' @@ -47,13 +47,13 @@ def __init__(self, processed_analysis_list): ], ) def test_get_missing_analysis_deps(fo_list, dependencies, expected_output): - plugin = ComparePlugin() + plugin = ComparisonPlugin() plugin.DEPENDENCIES = dependencies assert plugin._get_missing_analysis_deps(fo_list) == expected_output def test_missing_comparison_deps(): - plugin = ComparePlugin() + plugin = ComparisonPlugin() plugin.COMPARISON_DEPS = ['a', 'b', 'c'] dependency_results = { 'a': {'foo': 'bar'}, diff --git a/src/test/unit/conftest.py b/src/test/unit/conftest.py index c0a1ad470..3fff80443 100644 --- a/src/test/unit/conftest.py +++ b/src/test/unit/conftest.py @@ -58,8 +58,8 @@ def get_binary_search_result(uid): return {'test_rule': ['test_uid']}, b'some yara rule' return None, None - def add_compare_task(self, compare_id, force=False): - self.task_list.append((compare_id, force)) + def add_comparison_task(self, comparison_id, force=False): + self.task_list.append((comparison_id, force)) def add_analysis_task(self, task): self.task_list.append(task) diff --git a/src/test/unit/helperFunctions/test_data_conversion.py b/src/test/unit/helperFunctions/test_data_conversion.py index df538353a..cef37558f 100644 --- a/src/test/unit/helperFunctions/test_data_conversion.py +++ b/src/test/unit/helperFunctions/test_data_conversion.py @@ -3,14 +3,14 @@ import pytest from helperFunctions.data_conversion import ( - convert_compare_id_to_list, + convert_comparison_id_to_list, convert_str_to_bool, convert_time_to_str, get_value_of_first_key, make_bytes, make_unicode_string, none_to_none, - normalize_compare_id, + normalize_comparison_id, ) @@ -44,11 +44,11 @@ def test_make_unicode_string(input_data, expected): assert result == expected -def test_normalize_compare_id(): +def test_normalize_comparison_id(): ids_a = 'a;b' ids_b = 'b;a' - assert normalize_compare_id(ids_a) == 'a;b', 'compare id not correct' - assert normalize_compare_id(ids_a) == normalize_compare_id(ids_b), 'compare ids not the same' + assert normalize_comparison_id(ids_a) == 'a;b', 'comparison ID not correct' + assert normalize_comparison_id(ids_a) == normalize_comparison_id(ids_b), 'comparison IDs not the same' @pytest.mark.parametrize( @@ -58,8 +58,8 @@ def test_normalize_compare_id(): ('a;b;c', ['a', 'b', 'c']), ], ) -def test_convert_compare_id_to_list(input_data, expected): - assert convert_compare_id_to_list(input_data) == expected +def test_convert_comparison_id_to_list(input_data, expected): + assert convert_comparison_id_to_list(input_data) == expected @pytest.mark.parametrize(('input_data', 'expected'), [({'b': 'b', 'c': 'c', 'a': 'a'}, 'a'), ({}, None)]) diff --git a/src/test/unit/scheduler/test_compare.py b/src/test/unit/scheduler/test_comparison.py similarity index 63% rename from src/test/unit/scheduler/test_compare.py rename to src/test/unit/scheduler/test_comparison.py index c6018d05d..e0180e171 100644 --- a/src/test/unit/scheduler/test_compare.py +++ b/src/test/unit/scheduler/test_comparison.py @@ -2,13 +2,13 @@ import pytest -from compare.PluginBase import CompareBasePlugin +from comparison.comparison_base_plugin import ComparisonBasePlugin from test.common_helper import CommonDatabaseMock, create_test_file_object @pytest.fixture(autouse=True) -def no_compare_views(monkeypatch): # noqa: PT004 - monkeypatch.setattr(CompareBasePlugin, '_sync_view', value=lambda s, p: None) # noqa: ARG005 +def no_comparison_views(monkeypatch): # noqa: PT004 + monkeypatch.setattr(ComparisonBasePlugin, '_sync_view', value=lambda s, p: None) # noqa: ARG005 class MockDbInterface(CommonDatabaseMock): @@ -31,8 +31,8 @@ def get_vfp_of_included_text_files(self, root_uid, blacklist=None): }, ) @pytest.mark.SchedulerTestConfig(start_processes=False, comparison_db_class=MockDbInterface) -class TestSchedulerCompare: - def test_start_compare(self, comparison_scheduler): +class TestSchedulerComparison: + def test_start_comparison(self, comparison_scheduler): comparison_scheduler.add_task(('existing_id', True)) uid, redo = comparison_scheduler.in_queue.get(timeout=2) assert uid == 'existing_id', 'retrieved id not correct' @@ -43,21 +43,23 @@ def test_start(self, comparison_scheduler): sleep(2) comparison_scheduler.shutdown() - def test_compare_single_run(self, comparison_scheduler): - compares_done = set() + def test_run_single_comparison(self, comparison_scheduler): + comparisons_done = set() comparison_scheduler.in_queue.put((comparison_scheduler.db_interface.test_object.uid, False)) - comparison_scheduler._compare_single_run(compares_done) - assert len(compares_done) == 1, 'compares done not set correct' - assert comparison_scheduler.db_interface.test_object.uid in compares_done, 'correct uid not in compares done' + comparison_scheduler._comparison_worker(comparisons_done) + assert len(comparisons_done) == 1, 'comparisons done not set correct' + assert ( + comparison_scheduler.db_interface.test_object.uid in comparisons_done + ), 'correct uid not in comparisons done' def test_decide_whether_to_process(self, comparison_scheduler): - compares_done = set('a') + comparisons_done = set('a') assert comparison_scheduler._comparison_should_start( - 'b', False, compares_done - ), 'non-existing compare should always be done' + 'b', False, comparisons_done + ), 'non-existing comparison should always be done' assert comparison_scheduler._comparison_should_start( - 'a', True, compares_done + 'a', True, comparisons_done ), 'redo is true so result should be true' assert not comparison_scheduler._comparison_should_start( - 'a', False, compares_done + 'a', False, comparisons_done ), 'already done and redo no -> should be false' diff --git a/src/test/unit/web_interface/rest/test_rest_compare.py b/src/test/unit/web_interface/rest/test_rest_comparison.py similarity index 70% rename from src/test/unit/web_interface/rest/test_rest_compare.py rename to src/test/unit/web_interface/rest/test_rest_comparison.py index 9d2dacede..0f72b2106 100644 --- a/src/test/unit/web_interface/rest/test_rest_compare.py +++ b/src/test/unit/web_interface/rest/test_rest_comparison.py @@ -19,21 +19,21 @@ def test_empty_data(test_client): assert 'The method is not allowed for the requested URL' in result['message'] -def test_get_unknown_compare(test_client): - compare_id = f'{UID_1};{UID_2}' - result = test_client.get(f'/rest/compare/{compare_id}').json - assert 'Compare not found in database' in result['error_message'] +def test_get_unknown_comparison(test_client): + comparison_id = f'{UID_1};{UID_2}' + result = test_client.get(f'/rest/compare/{comparison_id}').json + assert 'Comparison not found in database' in result['error_message'] -def test_get_invalid_compare_id(test_client): - compare_id = f'invalid_uid;{UID_2}' - result = test_client.get(f'/rest/compare/{compare_id}').json +def test_get_invalid_comparison_id(test_client): + comparison_id = f'invalid_uid;{UID_2}' + result = test_client.get(f'/rest/compare/{comparison_id}').json assert 'contains invalid chars' in result['error_message'] -def test_get_invalid_compare_id_2(test_client): - compare_id = f'deadbeef_1;{UID_2}' - result = test_client.get(f'/rest/compare/{compare_id}').json +def test_get_invalid_comparison_id_2(test_client): + comparison_id = f'deadbeef_1;{UID_2}' + result = test_client.get(f'/rest/compare/{comparison_id}').json assert 'contains invalid UIDs' in result['error_message'] @@ -54,11 +54,11 @@ def test_put_pre_existing(test_client): data = {'uid_list': [TEST_FW.uid, TEST_FW_2.uid], 'redo': False} result = test_client.put('/rest/compare', json=data).json assert result['status'] == 1 - assert 'Compare already exists' in result['error_message'] + assert 'Comparison already exists' in result['error_message'] def test_put_success(test_client): data = {'uid_list': [TEST_FW.uid, TEST_FW_2.uid], 'redo': True} result = test_client.put('/rest/compare', json=data).json assert result['status'] == 0 - assert 'Compare started' in result['message'] + assert 'Comparison started' in result['message'] diff --git a/src/test/unit/web_interface/test_ajax_routes.py b/src/test/unit/web_interface/test_ajax_routes.py index dccda3e53..f857a7ec1 100644 --- a/src/test/unit/web_interface/test_ajax_routes.py +++ b/src/test/unit/web_interface/test_ajax_routes.py @@ -4,7 +4,7 @@ @pytest.mark.parametrize( - ('candidate', 'compare_id', 'expected_result'), + ('candidate', 'comparison_id', 'expected_result'), [ ('all', 'uid1;uid2', 'uid1'), ('uid1', 'uid1;uid2', 'uid1'), @@ -12,5 +12,5 @@ ('all', 'uid1', 'uid1'), ], ) -def test_get_root_uid(candidate, compare_id, expected_result): - assert AjaxRoutes._get_root_uid(candidate, compare_id) == expected_result +def test_get_root_uid(candidate, comparison_id, expected_result): + assert AjaxRoutes._get_root_uid(candidate, comparison_id) == expected_result diff --git a/src/test/unit/web_interface/test_app_ajax_routes.py b/src/test/unit/web_interface/test_app_ajax_routes.py index c7aa0c73d..54c1fd099 100644 --- a/src/test/unit/web_interface/test_app_ajax_routes.py +++ b/src/test/unit/web_interface/test_app_ajax_routes.py @@ -1,6 +1,6 @@ import pytest -from helperFunctions.data_conversion import normalize_compare_id +from helperFunctions.data_conversion import normalize_comparison_id from test.common_helper import TEST_FW, TEST_FW_2, TEST_TEXT_FILE, CommonDatabaseMock from test.mock import mock_patch @@ -8,14 +8,14 @@ class DbMock(CommonDatabaseMock): @staticmethod def get_comparison_result(comparison_id): - if comparison_id == normalize_compare_id(';'.join([TEST_FW.uid, TEST_FW_2.uid])): + if comparison_id == normalize_comparison_id(';'.join([TEST_FW.uid, TEST_FW_2.uid])): return { - 'this_is': 'a_compare_result', + 'this_is': 'a_comparison_result', 'general': {'hid': {TEST_FW.uid: 'foo', TEST_TEXT_FILE.uid: 'bar'}}, 'plugins': {'File_Coverage': {'some_feature': {TEST_FW.uid: [TEST_TEXT_FILE.uid]}}}, } - if comparison_id == normalize_compare_id(';'.join([TEST_FW.uid, TEST_TEXT_FILE.uid])): - return {'this_is': 'a_compare_result'} + if comparison_id == normalize_comparison_id(';'.join([TEST_FW.uid, TEST_TEXT_FILE.uid])): + return {'this_is': 'a_comparison_result'} return 'generic error' @staticmethod @@ -49,7 +49,7 @@ def test_ajax_get_summary__summary_not_found(self, test_client): result = test_client.get(f'/ajax_get_summary/{TEST_FW.uid}/not_found').data assert b'No summary found' in result - def test_ajax_get_common_files_for_compare(self, test_client): + def test_ajax_get_common_files_for_comparison(self, test_client): url = f'/compare/ajax_common_files/{TEST_FW.uid};{TEST_FW_2.uid}/some_feature___{TEST_FW.uid}/' result = test_client.get(url).data.decode() assert TEST_FW.uid in result diff --git a/src/test/unit/web_interface/test_app_compare.py b/src/test/unit/web_interface/test_app_compare.py index 899dd13df..abd26f327 100644 --- a/src/test/unit/web_interface/test_app_compare.py +++ b/src/test/unit/web_interface/test_app_compare.py @@ -19,22 +19,22 @@ def test_add_firmwares_to_compare__multiple(test_client): assert 'Remove All' in rv.data.decode() -def test_start_compare(test_client, intercom_task_list): +def test_start_comparison(test_client, intercom_task_list): with test_client as tc: with tc.session_transaction() as test_session: test_session['uids_for_comparison'] = {'uid1': None, 'uid2': None} rv = test_client.get('/compare', follow_redirects=True) - assert b'Your compare task is in progress' in rv.data + assert b'Your comparison task is in progress' in rv.data assert len(intercom_task_list) == 1, 'task not added' assert intercom_task_list[0] == ('uid1;uid2', None), 'task not correct' -def test_start_compare__force(test_client, intercom_task_list): +def test_start_comparison__force(test_client, intercom_task_list): with test_client as tc: with tc.session_transaction() as test_session: test_session['uids_for_comparison'] = {'uid1': None, 'uid2': None} rv = test_client.get('/compare?force_recompare=true', follow_redirects=True) - assert b'Your compare task is in progress' in rv.data + assert b'Your comparison task is in progress' in rv.data assert len(intercom_task_list) == 1, 'task not added' assert intercom_task_list[0] == ('uid1;uid2', True), 'task not correct' @@ -44,6 +44,6 @@ def test_start_compare__list_empty(test_client): assert b'No UIDs found for comparison' in rv.data -def test_show_compare_result(test_client): +def test_show_comparison_result(test_client): rv = test_client.get(f'/compare/{COMPARISON_ID}', follow_redirects=True) assert b'General information' in rv.data diff --git a/src/test/unit/web_interface/test_app_comparison_basket.py b/src/test/unit/web_interface/test_app_comparison_basket.py index b6c76473a..f9509bf72 100644 --- a/src/test/unit/web_interface/test_app_comparison_basket.py +++ b/src/test/unit/web_interface/test_app_comparison_basket.py @@ -1,43 +1,43 @@ from flask import session from test.common_helper import TEST_FW, TEST_FW_2 -from web_interface.components.compare_routes import CompareRoutes, get_comparison_uid_dict_from_session +from web_interface.components.comparison_routes import ComparisonRoutes, get_comparison_uid_dict_from_session def test_get_comparison_uid_list_dict_session(web_frontend): with web_frontend.app.test_request_context(): assert 'uids_for_comparison' not in session - compare_list = get_comparison_uid_dict_from_session() + comparison_list = get_comparison_uid_dict_from_session() assert 'uids_for_comparison' in session assert isinstance(session['uids_for_comparison'], dict) - assert isinstance(compare_list, dict) + assert isinstance(comparison_list, dict) -def test_add_to_compare_basket(web_frontend): +def test_add_to_comparison_basket(web_frontend): with web_frontend.app.test_request_context(): assert 'uids_for_comparison' not in session - CompareRoutes.add_to_compare_basket(web_frontend, 'test') + ComparisonRoutes.add_to_comparison_basket(web_frontend, 'test') assert 'uids_for_comparison' in session assert isinstance(session['uids_for_comparison'], dict) assert 'test' in session['uids_for_comparison'] -def test_remove_from_compare_basket(web_frontend): +def test_remove_from_comparison_basket(web_frontend): with web_frontend.app.test_request_context(): - CompareRoutes.add_to_compare_basket(web_frontend, TEST_FW.uid) - CompareRoutes.add_to_compare_basket(web_frontend, TEST_FW_2.uid) + ComparisonRoutes.add_to_comparison_basket(web_frontend, TEST_FW.uid) + ComparisonRoutes.add_to_comparison_basket(web_frontend, TEST_FW_2.uid) assert 'uids_for_comparison' in session assert TEST_FW.uid in session['uids_for_comparison'] assert TEST_FW_2.uid in session['uids_for_comparison'] - CompareRoutes.remove_from_compare_basket(web_frontend, 'some_uid', TEST_FW.uid) + ComparisonRoutes.remove_from_comparison_basket(web_frontend, 'some_uid', TEST_FW.uid) assert TEST_FW.uid not in session['uids_for_comparison'] assert TEST_FW_2.uid in session['uids_for_comparison'] -def test_remove_all_from_compare_basket(web_frontend): +def test_remove_all_from_comparison_basket(web_frontend): with web_frontend.app.test_request_context(): session['uids_for_comparison'] = [TEST_FW.uid, TEST_FW_2.uid] session.modified = True @@ -45,6 +45,6 @@ def test_remove_all_from_compare_basket(web_frontend): assert TEST_FW.uid in session['uids_for_comparison'] assert TEST_FW_2.uid in session['uids_for_comparison'] - CompareRoutes.remove_all_from_compare_basket(web_frontend, 'some_uid') + ComparisonRoutes.remove_all_from_comparison_basket(web_frontend, 'some_uid') assert TEST_FW.uid not in session['uids_for_comparison'] assert TEST_FW_2.uid not in session['uids_for_comparison'] diff --git a/src/test/unit/web_interface/test_comparison_routes.py b/src/test/unit/web_interface/test_comparison_routes.py index 733af25d5..6b5765b48 100644 --- a/src/test/unit/web_interface/test_comparison_routes.py +++ b/src/test/unit/web_interface/test_comparison_routes.py @@ -1,10 +1,10 @@ import pytest from test.common_helper import CommonDatabaseMock -from web_interface.components.compare_routes import ( - CompareRoutes, - _add_plugin_views_to_compare_view, - _get_compare_view, +from web_interface.components.comparison_routes import ( + ComparisonRoutes, + _add_plugin_views_to_comparison_view, + _get_comparison_view, _insert_plugin_into_view_at_index, ) @@ -18,36 +18,36 @@ def get_view(name): @pytest.mark.WebInterfaceUnitTestConfig(database_mock_class=TemplateDbMock) -def test_get_compare_plugin_views(web_frontend): - compare_result = {'plugins': {}} - result = CompareRoutes._get_compare_plugin_views(web_frontend, compare_result) +def test_get_comparison_plugin_views(web_frontend): + comparison_result = {'plugins': {}} + result = ComparisonRoutes._get_comparison_plugin_views(web_frontend, comparison_result) assert result == ([], []) - compare_result = {'plugins': {'plugin_1': None, 'plugin_2': None}} - plugin_views, plugins_without_view = CompareRoutes._get_compare_plugin_views(web_frontend, compare_result) + comparison_result = {'plugins': {'plugin_1': None, 'plugin_2': None}} + plugin_views, plugins_without_view = ComparisonRoutes._get_comparison_plugin_views(web_frontend, comparison_result) assert plugin_views == [('plugin_1', b'')] assert plugins_without_view == ['plugin_2'] -def test_get_compare_view(): - result = _get_compare_view([]) +def test_get_comparison_view(): + result = _get_comparison_view([]) assert '>General information<' in result assert '--- plugin results ---' in result def test_add_views_missing_key(): plugin_views = [('plugin_1', b''), ('plugin_2', b'')] - compare_view = 'xxxxxyyyyy' - result = _add_plugin_views_to_compare_view(compare_view, plugin_views) - assert result == compare_view + comparison_view = 'xxxxxyyyyy' + result = _add_plugin_views_to_comparison_view(comparison_view, plugin_views) + assert result == comparison_view def test_add_plugin_views(): plugin_views = [('plugin_1', b''), ('plugin_2', b'')] key = '{# individual plugin views #}' - compare_view = f'xxxxx{key}yyyyy' - key_index = compare_view.find(key) - result = _add_plugin_views_to_compare_view(compare_view, plugin_views) + comparison_view = f'xxxxx{key}yyyyy' + key_index = comparison_view.find(key) + result = _add_plugin_views_to_comparison_view(comparison_view, plugin_views) for plugin, view in plugin_views: assert f"elif plugin == '{plugin}'" in result diff --git a/src/web_interface/components/ajax_routes.py b/src/web_interface/components/ajax_routes.py index e9a7ca607..b2a0ca521 100644 --- a/src/web_interface/components/ajax_routes.py +++ b/src/web_interface/components/ajax_routes.py @@ -20,17 +20,17 @@ class AjaxRoutes(ComponentBase): @roles_accepted(*PRIVILEGES['view_analysis']) @AppRoute('/ajax_tree//', GET) - @AppRoute('/compare/ajax_tree///', GET) - def ajax_get_tree_children(self, uid, root_uid=None, compare_id=None): - root_uid, compare_id = none_to_none(root_uid), none_to_none(compare_id) - exclusive_files = self._get_exclusive_files(compare_id, root_uid) + @AppRoute('/compare/ajax_tree///', GET) + def ajax_get_tree_children(self, uid, root_uid=None, comparison_id=None): + root_uid, comparison_id = none_to_none(root_uid), none_to_none(comparison_id) + exclusive_files = self._get_exclusive_files(comparison_id, root_uid) tree = self._generate_file_tree(root_uid, uid, exclusive_files) children = [convert_to_jstree_node(child_node) for child_node in tree.get_list_of_child_nodes()] return jsonify(children) - def _get_exclusive_files(self, compare_id, root_uid): - if compare_id: - return self.db.comparison.get_exclusive_files(compare_id, root_uid) + def _get_exclusive_files(self, comparison_id, root_uid): + if comparison_id: + return self.db.comparison.get_exclusive_files(comparison_id, root_uid) return None def _generate_file_tree(self, root_uid: str | None, uid: str, whitelist: list[str]) -> FileTreeNode: @@ -59,19 +59,19 @@ def ajax_get_tree_root(self, uid, root_uid): return jsonify(root) @roles_accepted(*PRIVILEGES['compare']) - @AppRoute('/compare/ajax_common_files///', GET) - def ajax_get_common_files_for_compare(self, compare_id, feature_id): - result = self.db.comparison.get_comparison_result(compare_id) + @AppRoute('/compare/ajax_common_files///', GET) + def ajax_get_common_files_for_comparison(self, comparison_id, feature_id): + result = self.db.comparison.get_comparison_result(comparison_id) feature, matching_uid = feature_id.split('___') uid_list = result['plugins']['File_Coverage'][feature][matching_uid] - return self._get_nice_uid_list_html(uid_list, root_uid=self._get_root_uid(matching_uid, compare_id)) + return self._get_nice_uid_list_html(uid_list, root_uid=self._get_root_uid(matching_uid, comparison_id)) @staticmethod - def _get_root_uid(candidate, compare_id): - # feature_id contains an UID in individual case, in all case simply take first uid from compare + def _get_root_uid(candidate, comparison_id): + # feature_id contains an UID in individual case, in all case simply take first uid from comparison if candidate != 'all': return candidate - return compare_id.split(';')[0] + return comparison_id.split(';')[0] def _get_nice_uid_list_html(self, input_data, root_uid): included_files = self.db.frontend.get_data_for_nice_list(input_data, None) diff --git a/src/web_interface/components/analysis_routes.py b/src/web_interface/components/analysis_routes.py index bd253f1a3..a4531721f 100644 --- a/src/web_interface/components/analysis_routes.py +++ b/src/web_interface/components/analysis_routes.py @@ -17,7 +17,7 @@ from helperFunctions.task_conversion import check_for_errors, convert_analysis_task_to_fw_obj, create_re_analyze_task from helperFunctions.web_interface import get_template_as_string from objects.firmware import Firmware -from web_interface.components.compare_routes import get_comparison_uid_dict_from_session +from web_interface.components.comparison_routes import get_comparison_uid_dict_from_session from web_interface.components.component_base import GET, POST, AppRoute, ComponentBase from web_interface.components.dependency_graph import ( create_data_graph_edges, diff --git a/src/web_interface/components/compare_routes.py b/src/web_interface/components/comparison_routes.py similarity index 71% rename from src/web_interface/components/compare_routes.py rename to src/web_interface/components/comparison_routes.py index 7231c2f3f..0784cd1b0 100644 --- a/src/web_interface/components/compare_routes.py +++ b/src/web_interface/components/comparison_routes.py @@ -7,9 +7,9 @@ from flask import redirect, render_template, render_template_string, request, session, url_for from helperFunctions.data_conversion import ( - convert_compare_id_to_list, - convert_uid_list_to_compare_id, - normalize_compare_id, + convert_comparison_id_to_list, + convert_uid_list_to_comparison_id, + normalize_comparison_id, ) from helperFunctions.database import get_shared_session from helperFunctions.web_interface import get_template_as_string @@ -25,27 +25,27 @@ class FileDiffData(NamedTuple): fw_hid: str -class CompareRoutes(ComponentBase): +class ComparisonRoutes(ComponentBase): def __init__(self, **kwargs): super().__init__(**kwargs) @roles_accepted(*PRIVILEGES['compare']) - @AppRoute('/compare/', GET) - def show_compare_result(self, compare_id): - compare_id = normalize_compare_id(compare_id) + @AppRoute('/compare/', GET) + def show_comparison_result(self, comparison_id): + comparison_id = normalize_comparison_id(comparison_id) with get_shared_session(self.db.comparison) as comparison_db: - if not comparison_db.objects_exist(compare_id): + if not comparison_db.objects_exist(comparison_id): return render_template('compare/error.html', error='Not all UIDs found in the DB') - result = comparison_db.get_comparison_result(compare_id) + result = comparison_db.get_comparison_result(comparison_id) if not result: - return render_template('compare/wait.html', compare_id=compare_id) - download_link = self._create_ida_download_if_existing(result, compare_id) - uid_list = convert_compare_id_to_list(compare_id) - plugin_views, plugins_without_view = self._get_compare_plugin_views(result) - compare_view = _get_compare_view(plugin_views) - self._fill_in_empty_fields(result, compare_id) + return render_template('compare/wait.html', comparison_id=comparison_id) + download_link = self._create_ida_download_if_existing(result, comparison_id) + uid_list = convert_comparison_id_to_list(comparison_id) + plugin_views, plugins_without_view = self._get_comparison_plugin_views(result) + comparison_view = _get_comparison_view(plugin_views) + self._fill_in_empty_fields(result, comparison_id) return render_template_string( - compare_view, + comparison_view, result=result, uid_list=uid_list, download_link=download_link, @@ -53,17 +53,17 @@ def show_compare_result(self, compare_id): ) @staticmethod - def _fill_in_empty_fields(result, compare_id): - compare_uids = compare_id.split(';') + def _fill_in_empty_fields(result, comparison_id): + comparison_uids = comparison_id.split(';') for key in result['general']: - for uid in compare_uids: + for uid in comparison_uids: if uid not in result['general'][key]: result['general'][key][uid] = '' - def _get_compare_plugin_views(self, compare_result): + def _get_comparison_plugin_views(self, comparison_result): views, plugins_without_view = [], [] with suppress(KeyError): - used_plugins = list(compare_result['plugins'].keys()) + used_plugins = list(comparison_result['plugins'].keys()) with get_shared_session(self.db.template) as template_db: for plugin in used_plugins: view = template_db.get_view(plugin) @@ -80,7 +80,7 @@ def start_compare(self): if len(uid_dict) < 2: # noqa: PLR2004 return render_template('compare/error.html', error='No UIDs found for comparison') - comparison_id = convert_uid_list_to_compare_id(list(uid_dict)) + comparison_id = convert_uid_list_to_comparison_id(list(uid_dict)) session['uids_for_comparison'] = None redo = True if request.args.get('force_recompare') else None @@ -89,24 +89,24 @@ def start_compare(self): return render_template('compare/error.html', error='Not all UIDs found in the DB') if not redo and comparison_db.comparison_exists(comparison_id): - return redirect(url_for('show_compare_result', compare_id=comparison_id)) + return redirect(url_for('show_comparison_result', comparison_id=comparison_id)) - self.intercom.add_compare_task(comparison_id, force=redo) - return render_template('compare/wait.html', compare_id=comparison_id) + self.intercom.add_comparison_task(comparison_id, force=redo) + return render_template('compare/wait.html', comparison_id=comparison_id) @staticmethod - def _create_ida_download_if_existing(result, compare_id): + def _create_ida_download_if_existing(result, comparison_id): if isinstance(result, dict) and result.get('plugins', {}).get('Ida_Diff_Highlighting', {}).get('idb_binary'): - return f'/ida-download/{compare_id}' + return f'/ida-download/{comparison_id}' return None @roles_accepted(*PRIVILEGES['compare']) - @AppRoute('/database/browse_compare', GET) + @AppRoute('/database/browse_comparisons', GET) def browse_comparisons(self): with get_shared_session(self.db.comparison) as comparison_db: page, per_page = extract_pagination_from_request(request)[0:2] try: - compare_list = comparison_db.page_comparison_results(skip=per_page * (page - 1), limit=per_page) + comparison_list = comparison_db.page_comparison_results(skip=per_page * (page - 1), limit=per_page) except Exception as exception: error_message = f'Could not query database: {type(exception)}' logging.error(error_message, exc_info=True) @@ -116,8 +116,8 @@ def browse_comparisons(self): pagination = get_pagination(page=page, per_page=per_page, total=total) return render_template( - 'database/compare_browse.html', - compare_list=compare_list, + 'database/browse_comparisons.html', + comparison_list=comparison_list, page=page, per_page=per_page, pagination=pagination, @@ -126,28 +126,28 @@ def browse_comparisons(self): @roles_accepted(*PRIVILEGES['submit_analysis']) @AppRoute('/comparison/add/', GET) @AppRoute('/comparison/add//', GET) - def add_to_compare_basket(self, uid, root_uid=None): - compare_uid_list = get_comparison_uid_dict_from_session() - compare_uid_list[uid] = root_uid + def add_to_comparison_basket(self, uid, root_uid=None): + comparison_uid_list = get_comparison_uid_dict_from_session() + comparison_uid_list[uid] = root_uid session.modified = True return redirect(url_for('show_analysis', uid=uid, root_uid=root_uid)) @roles_accepted(*PRIVILEGES['submit_analysis']) - @AppRoute('/comparison/remove//', GET) - @AppRoute('/comparison/remove///', GET) - def remove_from_compare_basket(self, analysis_uid, compare_uid, root_uid=None): - compare_uid_list = get_comparison_uid_dict_from_session() - if compare_uid in compare_uid_list: - session['uids_for_comparison'].pop(compare_uid) + @AppRoute('/comparison/remove//', GET) + @AppRoute('/comparison/remove///', GET) + def remove_from_comparison_basket(self, analysis_uid, comparison_uid, root_uid=None): + comparison_uid_list = get_comparison_uid_dict_from_session() + if comparison_uid in comparison_uid_list: + session['uids_for_comparison'].pop(comparison_uid) session.modified = True return redirect(url_for('show_analysis', uid=analysis_uid, root_uid=root_uid)) @roles_accepted(*PRIVILEGES['submit_analysis']) @AppRoute('/comparison/remove_all/', GET) @AppRoute('/comparison/remove_all//', GET) - def remove_all_from_compare_basket(self, analysis_uid, root_uid=None): - compare_uid_list = get_comparison_uid_dict_from_session() - compare_uid_list.clear() + def remove_all_from_comparison_basket(self, analysis_uid, root_uid=None): + comparison_uid_list = get_comparison_uid_dict_from_session() + comparison_uid_list.clear() session.modified = True return redirect(url_for('show_analysis', uid=analysis_uid, root_uid=root_uid)) @@ -205,14 +205,14 @@ def _get_data_for_file_diff(self, uid: str, root_uid: str | None) -> FileDiffDat return FileDiffData(uid, mime, fw_hid) -def _get_compare_view(plugin_views): - compare_view = get_template_as_string('compare/compare.html') - return _add_plugin_views_to_compare_view(compare_view, plugin_views) +def _get_comparison_view(plugin_views): + comparison_view = get_template_as_string('compare/compare.html') + return _add_plugin_views_to_comparison_view(comparison_view, plugin_views) -def _add_plugin_views_to_compare_view(compare_view, plugin_views): +def _add_plugin_views_to_comparison_view(comparison_view, plugin_views): key = '{# individual plugin views #}' - insertion_index = compare_view.find(key) + insertion_index = comparison_view.find(key) if insertion_index == -1: logging.error('compare view insertion point not found in compare template') else: @@ -220,8 +220,8 @@ def _add_plugin_views_to_compare_view(compare_view, plugin_views): for plugin, view in plugin_views: if_case = f"{{% elif plugin == '{plugin}' %}}" view = f'{if_case}\n{view.decode()}' # noqa: PLW2901 - compare_view = _insert_plugin_into_view_at_index(view, compare_view, insertion_index) - return compare_view + comparison_view = _insert_plugin_into_view_at_index(view, comparison_view, insertion_index) + return comparison_view def _insert_plugin_into_view_at_index(plugin, view, index): diff --git a/src/web_interface/components/io_routes.py b/src/web_interface/components/io_routes.py index 7666994a5..3a16e4a6b 100644 --- a/src/web_interface/components/io_routes.py +++ b/src/web_interface/components/io_routes.py @@ -85,15 +85,15 @@ def _get_file_download_mime(self, binary: bytes, uid: str) -> str: return mime or magic.from_buffer(binary, mime=True) @roles_accepted(*PRIVILEGES['download']) - @AppRoute('/ida-download/', GET) - def download_ida_file(self, compare_id): + @AppRoute('/ida-download/', GET) + def download_ida_file(self, comparison_id): # FixMe: IDA comparison plugin must not add binary strings to the result (not JSON compatible) - result = self.db.comparison.get_comparison_result(compare_id) + result = self.db.comparison.get_comparison_result(comparison_id) if result is None: - return render_template('error.html', message=f'Comparison with ID {compare_id} not found') + return render_template('error.html', message=f'Comparison with ID {comparison_id} not found') binary = result['plugins']['Ida_Diff_Highlighting']['idb_binary'] response = make_response(binary) - response.headers['Content-Disposition'] = f'attachment; filename={compare_id[:8]}.idb' + response.headers['Content-Disposition'] = f'attachment; filename={comparison_id[:8]}.idb' return response @roles_accepted(*PRIVILEGES['download']) diff --git a/src/web_interface/components/plugin_routes.py b/src/web_interface/components/plugin_routes.py index 408a74cf6..643c65bbc 100644 --- a/src/web_interface/components/plugin_routes.py +++ b/src/web_interface/components/plugin_routes.py @@ -5,7 +5,7 @@ from web_interface.components.component_base import ComponentBase ROUTES_MODULE_NAME = 'routes' -PLUGIN_CATEGORIES = ['analysis', 'compare'] +PLUGIN_CATEGORIES = ['analysis', 'comparison'] PLUGIN_DIR = f'{get_src_dir()}/plugins' diff --git a/src/web_interface/frontend_main.py b/src/web_interface/frontend_main.py index 906ee01bc..72795321a 100644 --- a/src/web_interface/frontend_main.py +++ b/src/web_interface/frontend_main.py @@ -8,7 +8,7 @@ from web_interface.app import create_app from web_interface.components.ajax_routes import AjaxRoutes from web_interface.components.analysis_routes import AnalysisRoutes -from web_interface.components.compare_routes import CompareRoutes +from web_interface.components.comparison_routes import ComparisonRoutes from web_interface.components.database_routes import DatabaseRoutes from web_interface.components.io_routes import IORoutes from web_interface.components.jinja_filter import FilterClass @@ -38,7 +38,7 @@ def _setup_app(self): AjaxRoutes(**base_args) AnalysisRoutes(**base_args) - CompareRoutes(**base_args) + ComparisonRoutes(**base_args) DatabaseRoutes(**base_args) IORoutes(**base_args) MiscellaneousRoutes(**base_args) diff --git a/src/web_interface/rest/rest_base.py b/src/web_interface/rest/rest_base.py index 82a371ccf..663d8c155 100644 --- a/src/web_interface/rest/rest_base.py +++ b/src/web_interface/rest/rest_base.py @@ -7,7 +7,7 @@ from web_interface.rest.rest_analysis import api as analysis_api from web_interface.rest.rest_binary import api as binary_api from web_interface.rest.rest_binary_search import api as binary_search_api -from web_interface.rest.rest_compare import api as compare_api +from web_interface.rest.rest_comparison import api as comparison_api from web_interface.rest.rest_file_object import api as file_object_api from web_interface.rest.rest_firmware import api as firmware_api from web_interface.rest.rest_missing_analyses import api as missing_analyses_api @@ -31,7 +31,7 @@ def __init__(self, app=None, db=None, intercom=None, status=None): analysis_api, binary_api, binary_search_api, - compare_api, + comparison_api, file_object_api, firmware_api, missing_analyses_api, diff --git a/src/web_interface/rest/rest_compare.py b/src/web_interface/rest/rest_comparison.py similarity index 59% rename from src/web_interface/rest/rest_compare.py rename to src/web_interface/rest/rest_comparison.py index 616fc3912..55897f3e5 100644 --- a/src/web_interface/rest/rest_compare.py +++ b/src/web_interface/rest/rest_comparison.py @@ -1,7 +1,7 @@ from flask import request from flask_restx import Namespace, fields -from helperFunctions.data_conversion import convert_compare_id_to_list, normalize_compare_id +from helperFunctions.data_conversion import convert_comparison_id_to_list, normalize_comparison_id from helperFunctions.database import get_shared_session from helperFunctions.uid import is_uid from web_interface.rest.helper import error_message, success_message @@ -30,24 +30,24 @@ class RestComparePut(RestResourceBase): def put(self): """ Start a comparison - For this sake a list of uids of the files, which should be compared, is needed - The `uid_list` must contain uids of already analysed FileObjects or Firmware objects + For this sake a list of UIDs of the files, which should be compared, is needed + The `uid_list` must contain UIDs of already analysed FileObjects or Firmware objects """ data = self.validate_payload_data(compare_model) - compare_id = normalize_compare_id(';'.join(data['uid_list'])) + comparison_id = normalize_comparison_id(';'.join(data['uid_list'])) with get_shared_session(self.db.comparison) as comparison_db: - if comparison_db.comparison_exists(compare_id) and not data['redo']: + if comparison_db.comparison_exists(comparison_id) and not data['redo']: return error_message( - 'Compare already exists. Use "redo" to force re-compare.', + 'Comparison already exists. Use "redo" to force re-compare.', self.URL, request_data=request.json, return_code=200, ) - if not comparison_db.objects_exist(compare_id): + if not comparison_db.objects_exist(comparison_id): missing_uids = ', '.join( - uid for uid in convert_compare_id_to_list(compare_id) if not comparison_db.exists(uid) + uid for uid in convert_comparison_id_to_list(comparison_id) if not comparison_db.exists(uid) ) return error_message( f'Some objects are not found in the database: {missing_uids}', @@ -56,9 +56,9 @@ def put(self): return_code=404, ) - self.intercom.add_compare_task(compare_id, force=data['redo']) + self.intercom.add_comparison_task(comparison_id, force=data['redo']) return success_message( - {'message': 'Compare started. Please use GET to get the results.'}, + {'message': 'Comparison started. Please use GET to get the results.'}, self.URL, request_data=request.json, return_code=202, @@ -66,48 +66,49 @@ def put(self): @api.route( - '/', doc={'description': 'Retrieve comparison results', 'params': {'compare_id': 'Firmware UID'}} + '/', + doc={'description': 'Retrieve comparison results', 'params': {'comparison_id': 'Firmware UID'}}, ) class RestCompareGet(RestResourceBase): URL = '/rest/compare' @roles_accepted(*PRIVILEGES['compare']) @api.doc(responses={200: 'Success', 400: 'Unknown comparison ID'}) - def get(self, compare_id): + def get(self, comparison_id): """ - Request results from a comparisons - The result can be requested by providing a semicolon separated list of uids as compare_id + Request results from a comparison + The result can be requested by providing a semicolon separated list of UIDs as comparison_id The response will contain a json_document with the comparison result, along with the fields status, timestamp, request_resource and request as metadata """ try: - self._validate_compare_id(compare_id) - compare_id = normalize_compare_id(compare_id) + self._validate_comparison_id(comparison_id) + comparison_id = normalize_comparison_id(comparison_id) except (TypeError, ValueError) as error: return error_message( - f'Compare ID must be of the form uid1;uid2(;uid3..): {error}', + f'Comparison ID must be of the form uid1;uid2(;uid3..): {error}', self.URL, - request_data={'compare_id': compare_id}, + request_data={'comparison_id': comparison_id}, ) result = None with get_shared_session(self.db.comparison) as comparison_db: - if comparison_db.comparison_exists(compare_id): - result = comparison_db.get_comparison_result(compare_id) + if comparison_db.comparison_exists(comparison_id): + result = comparison_db.get_comparison_result(comparison_id) if result: - return success_message(result, self.URL, request_data={'compare_id': compare_id}, return_code=202) + return success_message(result, self.URL, request_data={'comparison_id': comparison_id}, return_code=202) return error_message( - 'Compare not found in database. Please use /rest/start_compare to start the compare.', + 'Comparison not found in database. Please use PUT /rest/compare to start the comparison.', self.URL, - request_data={'compare_id': compare_id}, + request_data={'comparison_id': comparison_id}, return_code=404, ) @staticmethod - def _validate_compare_id(compare_id: str): + def _validate_comparison_id(comparison_id: str): valid_chars = '0123456789abcdef_;' - if not all(char in valid_chars for char in compare_id): - raise ValueError(f'Compare ID {compare_id} contains invalid chars') - uids = convert_compare_id_to_list(compare_id) + if not all(char in valid_chars for char in comparison_id): + raise ValueError(f'Comparison ID {comparison_id} contains invalid chars') + uids = convert_comparison_id_to_list(comparison_id) if not all(is_uid(uid) for uid in uids): - raise TypeError(f'Compare ID {compare_id} contains invalid UIDs') + raise TypeError(f'Comparison ID {comparison_id} contains invalid UIDs') diff --git a/src/web_interface/static/js/start_compare.js b/src/web_interface/static/js/start_compare.js index 60ef3b497..913dbc8f9 100644 --- a/src/web_interface/static/js/start_compare.js +++ b/src/web_interface/static/js/start_compare.js @@ -1,13 +1,13 @@ -function start_compare(){ +function start_comparison(){ var checkbox = document.getElementById('recompare_checkbox'); var link = '/compare'; if (checkbox.checked) link += '?force_recompare=true'; location.href = link; } -document.getElementById("start_compare_button").onclick = start_compare; +document.getElementById("start_comparison_button").onclick = start_comparison; -function start_text_file_compare(){ +function start_text_file_comparison(){ var link = '/comparison/text_files'; location.href = link; } -document.getElementById("start_text_file_compare_button").onclick = start_text_file_compare; \ No newline at end of file +document.getElementById("start_text_file_comparison_button").onclick = start_text_file_comparison; diff --git a/src/web_interface/templates/about.html b/src/web_interface/templates/about.html index 841373d7e..6fd742898 100644 --- a/src/web_interface/templates/about.html +++ b/src/web_interface/templates/about.html @@ -521,7 +521,7 @@

FAF 1.2 (2017-02-01)

  • Advanced Search database map added
  • -
  • Latest compares and comments shown on start page
  • +
  • Latest comparisons and comments shown on start page
  • Delete comment feature added
  • Linux Mint 18.1 support added
  • Bug fixes
  • diff --git a/src/web_interface/templates/base.html b/src/web_interface/templates/base.html index 376ea85c3..1a5682a11 100644 --- a/src/web_interface/templates/base.html +++ b/src/web_interface/templates/base.html @@ -146,8 +146,8 @@