diff --git a/pyproject.toml b/pyproject.toml index 59d862709..e5f76f87c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -48,9 +48,7 @@ testpaths = [ "src/plugins/**/test", ] markers = [ - "AnalysisPluginClass: Set the Class of the analysis_plugin fixture", - "plugin_init_kwargs: Keyword arguments to pass to AnalysisPluginClass", - "plugin_start_worker: Whether or not to start actual workers", + "AnalysisPluginTestConfig: Configure the analysis_plugin fixture", "cfg_defaults: Overwrite defaults for the testing config", "WebInterfaceUnitTestConfig: Configure the web_interface fixture", ] diff --git a/src/conftest.py b/src/conftest.py index 9639dc32d..c2a2c9643 100644 --- a/src/conftest.py +++ b/src/conftest.py @@ -1,12 +1,15 @@ from __future__ import annotations +import dataclasses import grp import logging import os from configparser import ConfigParser from tempfile import TemporaryDirectory +from typing import Type import pytest +from pydantic.dataclasses import dataclass import config from analysis.PluginBase import AnalysisBasePlugin @@ -160,17 +163,27 @@ def patch_cfg(cfg_tuple): mpatch.undo() +@dataclass(config=dict(arbitrary_types_allowed=True)) +class AnalysisPluginTestConfig: + """A class configuring the :py:func:`analysis_plugin` fixture.""" + + #: The class of the plugin to be tested. It will most probably be called ``AnalysisPlugin``. + plugin_class: Type[AnalysisBasePlugin] = AnalysisBasePlugin + #: Whether or not to start the workers (see ``AnalysisPlugin.start_worker``) + start_processes: bool = False + #: Keyword arguments to be given to the ``plugin_class`` constructor. + init_kwargs: dict = dataclasses.field(default_factory=dict) + + @pytest.fixture def analysis_plugin(request, monkeypatch, patch_cfg): """Returns an instance of an AnalysisPlugin. - The following pytest markers affect this fixture: + This fixture can be configured by the supplying an instance of ``AnalysisPluginTestConfig`` as marker of the same + name. - * AnalysisPluginClass: The plugin class type. Must be a class derived from ``AnalysisBasePlugin``. - The marker has to be set with ``@pytest.mark.with_args`` to work around pytest - `link weirdness `. - * plugin_start_worker: If set the AnalysisPluginClass.start_worker method will NOT be overwritten. - If not set the method is overwritten by a stub that does nothing. - * plugin_init_kwargs: Additional keyword arguments that shall be passed to the ``AnalysisPluginClass`` constructor + .. seealso:: + + The documentation of :py:class:`AnalysisPluginTestConfig` If this fixture does not fit your needs (which normally should not be necessary) you can define a fixture like this: @@ -187,13 +200,18 @@ def my_fancy_plugin(analysis_plugin) .. Note:: - If you use the ``plugin_start_worker`` marker and want to modify plugin configuration like for example TIMEOUT - you have to put the following in your test: + If you want to set ``AnalysisPluginTestConfig.start_processes = True`` and want to modify plugin configuration + like for example TIMEOUT you have to put the following in your test: .. code-block:: - @pytest.mark.AnalysisPluginClass.with_args(MyFancyPlugin) - # Don't use `plugin_start_worker` + @pytest.mark.AnalysisPluginTestConfig( + AnalysisPluginTestConfig( + plugin_class=MyFancyPlugin, + # Actually don't start the processes in the fixture + start_processes = False, + ), + ) def my_fancy_test(analysis_plugin, monkeypatch): # Undo the patching of MyFancyPlugin.start_worker monkeypatch.undo() @@ -208,25 +226,16 @@ def my_fancy_test(analysis_plugin, monkeypatch): # create a new instance. # # See also: The note in the doc comment. + test_config = merge_markers(request, 'AnalysisPluginTestConfig', AnalysisPluginTestConfig) - plugin_class_marker = request.node.get_closest_marker('AnalysisPluginClass') - assert plugin_class_marker, '@pytest.mark.AnalysisPluginClass has to be defined' - PluginClass = plugin_class_marker.args[0] - assert issubclass( - PluginClass, AnalysisBasePlugin - ), f'{PluginClass.__name__} is not a subclass of {AnalysisBasePlugin.__name__}' + PluginClass = test_config.plugin_class - # We don't want to actually start workers when testing, except for some special cases - plugin_start_worker_marker = request.node.get_closest_marker('plugin_start_worker') - if not plugin_start_worker_marker: + if not test_config.start_processes: monkeypatch.setattr(PluginClass, 'start_worker', lambda _: None) - plugin_init_kwargs_marker = request.node.get_closest_marker('plugin_init_kwargs') - kwargs = plugin_init_kwargs_marker.kwargs if plugin_init_kwargs_marker else {} - plugin_instance = PluginClass( view_updater=CommonDatabaseMock(), - **kwargs, + **test_config.init_kwargs, ) yield plugin_instance diff --git a/src/plugins/analysis/binwalk/test/test_plugin_binwalk.py b/src/plugins/analysis/binwalk/test/test_plugin_binwalk.py index 1ad90e745..888773bd0 100644 --- a/src/plugins/analysis/binwalk/test/test_plugin_binwalk.py +++ b/src/plugins/analysis/binwalk/test/test_plugin_binwalk.py @@ -19,7 +19,7 @@ ''' -@pytest.mark.AnalysisPluginClass.with_args(AnalysisPlugin) +@pytest.mark.AnalysisPluginTestConfig(dict(plugin_class=AnalysisPlugin)) class TestPluginBinwalk: def test_signature_analysis(self, analysis_plugin): test_file = FileObject(file_path=f'{get_test_data_dir()}/container/test.zip') diff --git a/src/plugins/analysis/checksec/test/test_plugin_checksec.py b/src/plugins/analysis/checksec/test/test_plugin_checksec.py index d1b3b1e58..a3002cbd3 100644 --- a/src/plugins/analysis/checksec/test/test_plugin_checksec.py +++ b/src/plugins/analysis/checksec/test/test_plugin_checksec.py @@ -33,7 +33,7 @@ FILE_PATH_EXE_STRIPPED = PLUGIN_DIR / 'test/data/Hallo_stripped' -@pytest.mark.AnalysisPluginClass.with_args(AnalysisPlugin) +@pytest.mark.AnalysisPluginTestConfig(dict(plugin_class=AnalysisPlugin)) def test_check_mitigations(analysis_plugin): test_file = FileObject(file_path=str(FILE_PATH_EXE)) test_file.processed_analysis['file_type'] = {'full': 'ELF 64-bit LSB shared object, x86-64, dynamically linked'} diff --git a/src/plugins/analysis/crypto_hints/test/test_crypto_hints.py b/src/plugins/analysis/crypto_hints/test/test_crypto_hints.py index d6936f01d..f521b7415 100644 --- a/src/plugins/analysis/crypto_hints/test/test_crypto_hints.py +++ b/src/plugins/analysis/crypto_hints/test/test_crypto_hints.py @@ -9,7 +9,7 @@ TEST_DATA_DIR = Path(__file__).parent / 'data' -@pytest.mark.AnalysisPluginClass.with_args(AnalysisPlugin) +@pytest.mark.AnalysisPluginTestConfig(dict(plugin_class=AnalysisPlugin)) def test_additional_rules(analysis_plugin): test_file = FileObject(file_path=str(TEST_DATA_DIR / 'additional_rules_test_file')) processed_file = analysis_plugin.process_object(test_file) @@ -25,7 +25,7 @@ def test_additional_rules(analysis_plugin): assert rule in result -@pytest.mark.AnalysisPluginClass.with_args(AnalysisPlugin) +@pytest.mark.AnalysisPluginTestConfig(dict(plugin_class=AnalysisPlugin)) def test_basic_scan_feature(analysis_plugin): test_file = FileObject(file_path=str(TEST_DATA_DIR / 'CRC32_table')) processed_file = analysis_plugin.process_object(test_file) diff --git a/src/plugins/analysis/crypto_material/test/test_plugin_crypto_material.py b/src/plugins/analysis/crypto_material/test/test_plugin_crypto_material.py index 4dbbae2ed..9f7af39a2 100644 --- a/src/plugins/analysis/crypto_material/test/test_plugin_crypto_material.py +++ b/src/plugins/analysis/crypto_material/test/test_plugin_crypto_material.py @@ -24,7 +24,7 @@ def _rule_match(analysis_plugin, filename, expected_rule_name, expected_number_o ), f'Expected rule {expected_rule_name} missing' -@pytest.mark.AnalysisPluginClass.with_args(AnalysisPlugin) +@pytest.mark.AnalysisPluginTestConfig(dict(plugin_class=AnalysisPlugin)) class TestCryptoMaterial: # pylint:disable=no-self-use def test_gnupg(self, analysis_plugin): diff --git a/src/plugins/analysis/cve_lookup/test/test_cve_lookup.py b/src/plugins/analysis/cve_lookup/test/test_cve_lookup.py index aedce118b..a34f7cf25 100644 --- a/src/plugins/analysis/cve_lookup/test/test_cve_lookup.py +++ b/src/plugins/analysis/cve_lookup/test/test_cve_lookup.py @@ -214,7 +214,7 @@ def test_search_cve_summary(monkeypatch): assert MATCHED_SUMMARY == actual_match -@pytest.mark.AnalysisPluginClass.with_args(AnalysisPlugin) +@pytest.mark.AnalysisPluginTestConfig(dict(plugin_class=AnalysisPlugin)) class TestCveLookup: def test_process_object(self, analysis_plugin): TEST_FW.processed_analysis['software_components'] = SOFTWARE_COMPONENTS_ANALYSIS_RESULT diff --git a/src/plugins/analysis/cwe_checker/test/test_cwe_checker.py b/src/plugins/analysis/cwe_checker/test/test_cwe_checker.py index a0e3deb0b..17be8fb5b 100644 --- a/src/plugins/analysis/cwe_checker/test/test_cwe_checker.py +++ b/src/plugins/analysis/cwe_checker/test/test_cwe_checker.py @@ -5,7 +5,7 @@ from ..code.cwe_checker import AnalysisPlugin -@pytest.mark.AnalysisPluginClass.with_args(AnalysisPlugin) +@pytest.mark.AnalysisPluginTestConfig(dict(plugin_class=AnalysisPlugin)) class TestCweCheckerFunctions: def test_parse_cwe_checker_output(self, analysis_plugin): test_data = """[ diff --git a/src/plugins/analysis/device_tree/test/test_device_tree.py b/src/plugins/analysis/device_tree/test/test_device_tree.py index 047d866fe..cb8cbf9c8 100644 --- a/src/plugins/analysis/device_tree/test/test_device_tree.py +++ b/src/plugins/analysis/device_tree/test/test_device_tree.py @@ -15,7 +15,7 @@ TEST_BROKEN = TEST_DATA / 'broken.dtb' -@pytest.mark.AnalysisPluginClass.with_args(AnalysisPlugin) +@pytest.mark.AnalysisPluginTestConfig(dict(plugin_class=AnalysisPlugin)) def test_process_object(analysis_plugin): test_object = FileObject() test_object.processed_analysis['file_type'] = {'mime': 'linux/device-tree'} diff --git a/src/plugins/analysis/elf_analysis/test/test_plugin_elf_analysis.py b/src/plugins/analysis/elf_analysis/test/test_plugin_elf_analysis.py index 9a4874fb8..650c03e7c 100644 --- a/src/plugins/analysis/elf_analysis/test/test_plugin_elf_analysis.py +++ b/src/plugins/analysis/elf_analysis/test/test_plugin_elf_analysis.py @@ -44,7 +44,7 @@ def stub_object(): return test_object -@pytest.mark.AnalysisPluginClass.with_args(AnalysisPlugin) +@pytest.mark.AnalysisPluginTestConfig(dict(plugin_class=AnalysisPlugin)) class TestElfAnalysis: @pytest.mark.parametrize( 'tag, tag_color', diff --git a/src/plugins/analysis/file_system_metadata/test/test_plugin_file_system_metadata.py b/src/plugins/analysis/file_system_metadata/test/test_plugin_file_system_metadata.py index c10a51723..dfc61b4d4 100644 --- a/src/plugins/analysis/file_system_metadata/test/test_plugin_file_system_metadata.py +++ b/src/plugins/analysis/file_system_metadata/test/test_plugin_file_system_metadata.py @@ -59,7 +59,7 @@ def file_system_metadata_plugin(analysis_plugin): yield analysis_plugin -@pytest.mark.AnalysisPluginClass.with_args(AnalysisPlugin) +@pytest.mark.AnalysisPluginTestConfig(dict(plugin_class=AnalysisPlugin)) class TestFileSystemMetadata: test_file_tar = TEST_DATA_DIR / 'test.tar' test_file_fs = TEST_DATA_DIR / 'squashfs.img' diff --git a/src/plugins/analysis/file_type/test/test_plugin_file_type.py b/src/plugins/analysis/file_type/test/test_plugin_file_type.py index 81704f819..f8211129a 100644 --- a/src/plugins/analysis/file_type/test/test_plugin_file_type.py +++ b/src/plugins/analysis/file_type/test/test_plugin_file_type.py @@ -6,7 +6,7 @@ from ..code.file_type import AnalysisPlugin -@pytest.mark.AnalysisPluginClass.with_args(AnalysisPlugin) +@pytest.mark.AnalysisPluginTestConfig(dict(plugin_class=AnalysisPlugin)) def test_detect_type_of_file(analysis_plugin): test_file = FileObject(file_path=f'{get_test_data_dir()}/container/test.zip') test_file = analysis_plugin.process_object(test_file) diff --git a/src/plugins/analysis/hardware_analysis/test/test_hardware_analysis.py b/src/plugins/analysis/hardware_analysis/test/test_hardware_analysis.py index b8452d364..676cf9c21 100644 --- a/src/plugins/analysis/hardware_analysis/test/test_hardware_analysis.py +++ b/src/plugins/analysis/hardware_analysis/test/test_hardware_analysis.py @@ -10,7 +10,7 @@ TEST_DATA = Path(get_test_data_dir()) -@pytest.mark.AnalysisPluginClass.with_args(AnalysisPlugin) +@pytest.mark.AnalysisPluginTestConfig(dict(plugin_class=AnalysisPlugin)) class TestHardwareAnalysis: def test_cpu_architecture_found(self, analysis_plugin): test_object = FileObject() diff --git a/src/plugins/analysis/hash/test/test_plugin_hash.py b/src/plugins/analysis/hash/test/test_plugin_hash.py index 7163ad643..89a55012b 100644 --- a/src/plugins/analysis/hash/test/test_plugin_hash.py +++ b/src/plugins/analysis/hash/test/test_plugin_hash.py @@ -17,7 +17,7 @@ } }, ) -@pytest.mark.AnalysisPluginClass.with_args(AnalysisPlugin) +@pytest.mark.AnalysisPluginTestConfig(dict(plugin_class=AnalysisPlugin)) class TestAnalysisPluginHash: def test_all_hashes(self, analysis_plugin): result = analysis_plugin.process_object(MockFileObject()).processed_analysis[analysis_plugin.NAME] diff --git a/src/plugins/analysis/hashlookup/test/test_hashlookup.py b/src/plugins/analysis/hashlookup/test/test_hashlookup.py index 57324fb9d..19862e16f 100644 --- a/src/plugins/analysis/hashlookup/test/test_hashlookup.py +++ b/src/plugins/analysis/hashlookup/test/test_hashlookup.py @@ -15,7 +15,7 @@ def file_object(monkeypatch): return test_file -@pytest.mark.AnalysisPluginClass.with_args(AnalysisPlugin) +@pytest.mark.AnalysisPluginTestConfig(dict(plugin_class=AnalysisPlugin)) class TestHashlookup: def test_process_object_unknown_hash(self, analysis_plugin, file_object): file_object.processed_analysis['file_hashes'] = {'sha256': file_object.sha256} diff --git a/src/plugins/analysis/information_leaks/test/test_plugin_information_leaks.py b/src/plugins/analysis/information_leaks/test/test_plugin_information_leaks.py index 79ad021da..b7a5dfa75 100644 --- a/src/plugins/analysis/information_leaks/test/test_plugin_information_leaks.py +++ b/src/plugins/analysis/information_leaks/test/test_plugin_information_leaks.py @@ -9,7 +9,7 @@ TEST_DATA_DIR = Path(__file__).parent / 'data' -@pytest.mark.AnalysisPluginClass.with_args(AnalysisPlugin) +@pytest.mark.AnalysisPluginTestConfig(dict(plugin_class=AnalysisPlugin)) class TestAnalysisPluginInformationLeaks: def test_find_path(self, analysis_plugin): fo = MockFileObject() diff --git a/src/plugins/analysis/init_systems/test/test_plugin_init_system.py b/src/plugins/analysis/init_systems/test/test_plugin_init_system.py index 7019b509c..afb85f0b5 100644 --- a/src/plugins/analysis/init_systems/test/test_plugin_init_system.py +++ b/src/plugins/analysis/init_systems/test/test_plugin_init_system.py @@ -20,7 +20,7 @@ def _get_fo(path): return fo -@pytest.mark.AnalysisPluginClass.with_args(AnalysisPlugin) +@pytest.mark.AnalysisPluginTestConfig(dict(plugin_class=AnalysisPlugin)) class TestAnalysisPluginInit: test_file_not_text = FileObject(file_path=f'{_test_init_dir}etc/systemd/system/foobar') test_file_not_text.processed_analysis['file_type'] = {'mime': 'application/zip'} diff --git a/src/plugins/analysis/input_vectors/test/test_input_vectors.py b/src/plugins/analysis/input_vectors/test/test_input_vectors.py index 2008ff6ba..71f7795ea 100644 --- a/src/plugins/analysis/input_vectors/test/test_input_vectors.py +++ b/src/plugins/analysis/input_vectors/test/test_input_vectors.py @@ -9,7 +9,7 @@ TEST_FILE_DIR = Path(__file__).parent / 'data' -@pytest.mark.AnalysisPluginClass.with_args(AnalysisPlugin) +@pytest.mark.AnalysisPluginTestConfig(dict(plugin_class=AnalysisPlugin)) class TestAnalysisPluginInputVectors: def test_process_object_inputs(self, analysis_plugin): result = self.assert_process_object(analysis_plugin, 'test_fgets.elf') diff --git a/src/plugins/analysis/interesting_uris/test/test_interesting_uris.py b/src/plugins/analysis/interesting_uris/test/test_interesting_uris.py index b6c5ca0bd..03eafa030 100644 --- a/src/plugins/analysis/interesting_uris/test/test_interesting_uris.py +++ b/src/plugins/analysis/interesting_uris/test/test_interesting_uris.py @@ -32,7 +32,7 @@ def test_white_ip_and_uris(input_list, whitelist, expected_output): assert sorted(AnalysisPlugin.whitelist_ip_and_uris(whitelist, input_list)) == expected_output -@pytest.mark.AnalysisPluginClass.with_args(AnalysisPlugin) +@pytest.mark.AnalysisPluginTestConfig(dict(plugin_class=AnalysisPlugin)) class TestAnalysisPluginInterestingUris: def test_process_object(self, analysis_plugin): fo = create_test_file_object() diff --git a/src/plugins/analysis/ip_and_uri_finder/test/test_ip_and_uri_finder.py b/src/plugins/analysis/ip_and_uri_finder/test/test_ip_and_uri_finder.py index fde21680d..7ceacd898 100644 --- a/src/plugins/analysis/ip_and_uri_finder/test/test_ip_and_uri_finder.py +++ b/src/plugins/analysis/ip_and_uri_finder/test/test_ip_and_uri_finder.py @@ -50,7 +50,7 @@ def ip_and_uri_finder_plugin(analysis_plugin): yield analysis_plugin -@pytest.mark.AnalysisPluginClass.with_args(AnalysisPlugin) +@pytest.mark.AnalysisPluginTestConfig(dict(plugin_class=AnalysisPlugin)) class TestAnalysisPluginIpAndUriFinder: def test_process_object_ips(self, ip_and_uri_finder_plugin): with tempfile.NamedTemporaryFile() as tmp: diff --git a/src/plugins/analysis/ipc/test/test_ipc_analyzer.py b/src/plugins/analysis/ipc/test/test_ipc_analyzer.py index a698a1997..68f8cd1f5 100644 --- a/src/plugins/analysis/ipc/test/test_ipc_analyzer.py +++ b/src/plugins/analysis/ipc/test/test_ipc_analyzer.py @@ -32,7 +32,7 @@ } -@pytest.mark.AnalysisPluginClass.with_args(AnalysisPlugin) +@pytest.mark.AnalysisPluginTestConfig(dict(plugin_class=AnalysisPlugin)) @pytest.mark.parametrize( 'test_file, expected_result, expected_summary', [ diff --git a/src/plugins/analysis/kernel_config/test/test_kernel_config.py b/src/plugins/analysis/kernel_config/test/test_kernel_config.py index 49d663b77..ff70d30fd 100644 --- a/src/plugins/analysis/kernel_config/test/test_kernel_config.py +++ b/src/plugins/analysis/kernel_config/test/test_kernel_config.py @@ -24,7 +24,7 @@ TEST_DATA_DIR = Path(__file__).parent / 'data' -@pytest.mark.AnalysisPluginClass.with_args(AnalysisPlugin) +@pytest.mark.AnalysisPluginTestConfig(dict(plugin_class=AnalysisPlugin)) class ExtractIKConfigTest: def test_probably_kernel_config_true(self, analysis_plugin): test_file = FileObject(file_path=str(TEST_DATA_DIR / 'configs/CONFIG')) diff --git a/src/plugins/analysis/known_vulnerabilities/test/test_known_vulnerabilities.py b/src/plugins/analysis/known_vulnerabilities/test/test_known_vulnerabilities.py index ace0ffdc6..12aadc932 100644 --- a/src/plugins/analysis/known_vulnerabilities/test/test_known_vulnerabilities.py +++ b/src/plugins/analysis/known_vulnerabilities/test/test_known_vulnerabilities.py @@ -11,7 +11,7 @@ TEST_DATA_DIR = os.path.join(get_dir_of_file(__file__), 'data') -@pytest.mark.AnalysisPluginClass.with_args(AnalysisPlugin) +@pytest.mark.AnalysisPluginTestConfig(dict(plugin_class=AnalysisPlugin)) class TestAnalysisPluginsKnownVulnerabilities: _software_components_result = json.loads((Path(TEST_DATA_DIR) / 'sc.json').read_text()) diff --git a/src/plugins/analysis/linter/test/test_source_code_analysis.py b/src/plugins/analysis/linter/test/test_source_code_analysis.py index 22441daa2..93d7cff7c 100644 --- a/src/plugins/analysis/linter/test/test_source_code_analysis.py +++ b/src/plugins/analysis/linter/test/test_source_code_analysis.py @@ -16,7 +16,7 @@ def test_object(): return create_test_file_object() -@pytest.mark.AnalysisPluginClass.with_args(AnalysisPlugin) +@pytest.mark.AnalysisPluginTestConfig(dict(plugin_class=AnalysisPlugin)) class TestSourceCodeAnalysis: def test_process_object_not_supported(self, analysis_plugin, test_object, monkeypatch): monkeypatch.setattr( diff --git a/src/plugins/analysis/qemu_exec/test/test_plugin_qemu_exec.py b/src/plugins/analysis/qemu_exec/test/test_plugin_qemu_exec.py index da97a07f4..2a0fb3615 100644 --- a/src/plugins/analysis/qemu_exec/test/test_plugin_qemu_exec.py +++ b/src/plugins/analysis/qemu_exec/test/test_plugin_qemu_exec.py @@ -10,6 +10,7 @@ from requests.exceptions import ConnectionError as RequestConnectionError from requests.exceptions import ReadTimeout +from conftest import AnalysisPluginTestConfig from test.common_helper import TEST_FW, create_test_firmware, get_test_data_dir from test.mock import mock_patch @@ -83,8 +84,12 @@ def execute_docker_error(monkeypatch): monkeypatch.setattr('docker.client.from_env', DockerClientMock) -@pytest.mark.AnalysisPluginClass.with_args(AnalysisPlugin) -@pytest.mark.plugin_init_kwargs(unpacker=MockUnpacker()) +@pytest.mark.AnalysisPluginTestConfig( + AnalysisPluginTestConfig( + plugin_class=AnalysisPlugin, + init_kwargs={'unpacker': MockUnpacker()}, + ), +) class TestPluginQemuExec: def test_has_relevant_type(self, analysis_plugin): assert analysis_plugin._has_relevant_type(None) is False diff --git a/src/plugins/analysis/software_components/test/test_plugin_software_components.py b/src/plugins/analysis/software_components/test/test_plugin_software_components.py index 778f00184..316f9f7ba 100644 --- a/src/plugins/analysis/software_components/test/test_plugin_software_components.py +++ b/src/plugins/analysis/software_components/test/test_plugin_software_components.py @@ -10,7 +10,7 @@ TEST_DATA_DIR = os.path.join(get_dir_of_file(__file__), 'data') -@pytest.mark.AnalysisPluginClass.with_args(AnalysisPlugin) +@pytest.mark.AnalysisPluginTestConfig(dict(plugin_class=AnalysisPlugin)) class TestAnalysisPluginsSoftwareComponents: def test_process_object(self, analysis_plugin): test_file = FileObject(file_path=os.path.join(TEST_DATA_DIR, 'yara_test_file')) diff --git a/src/plugins/analysis/string_evaluation/test/test_plugin.py b/src/plugins/analysis/string_evaluation/test/test_plugin.py index 72ac3c4e4..e5afa30f0 100644 --- a/src/plugins/analysis/string_evaluation/test/test_plugin.py +++ b/src/plugins/analysis/string_evaluation/test/test_plugin.py @@ -5,7 +5,7 @@ from ..code.string_eval import AnalysisPlugin -@pytest.mark.AnalysisPluginClass.with_args(AnalysisPlugin) +@pytest.mark.AnalysisPluginTestConfig(dict(plugin_class=AnalysisPlugin)) def test_find_strings(analysis_plugin): fo = create_test_file_object() fo.processed_analysis['printable_strings'] = dict( diff --git a/src/plugins/analysis/strings/test/test_plugin_strings.py b/src/plugins/analysis/strings/test/test_plugin_strings.py index ca9da002f..04343429e 100644 --- a/src/plugins/analysis/strings/test/test_plugin_strings.py +++ b/src/plugins/analysis/strings/test/test_plugin_strings.py @@ -18,7 +18,7 @@ } }, ) -@pytest.mark.AnalysisPluginClass.with_args(AnalysisPlugin) +@pytest.mark.AnalysisPluginTestConfig(dict(plugin_class=AnalysisPlugin)) class TestAnalysisPlugInPrintableStrings: strings = ['first string', 'second<>_$tring!', 'third:?-+012345/\\string'] offsets = [(3, strings[0]), (21, strings[1]), (61, strings[2])] diff --git a/src/plugins/analysis/tlsh/test/test_plugin_tlsh.py b/src/plugins/analysis/tlsh/test/test_plugin_tlsh.py index 08f470901..9ed06a5c3 100644 --- a/src/plugins/analysis/tlsh/test/test_plugin_tlsh.py +++ b/src/plugins/analysis/tlsh/test/test_plugin_tlsh.py @@ -27,7 +27,7 @@ def tlsh_plugin(analysis_plugin, monkeypatch): yield analysis_plugin -@pytest.mark.AnalysisPluginClass.with_args(AnalysisPlugin) +@pytest.mark.AnalysisPluginTestConfig(dict(plugin_class=AnalysisPlugin)) class TestTlsh: def test_one_matching_file(self, tlsh_plugin, test_object): diff --git a/src/plugins/analysis/users_and_passwords/test/test_plugin_password_file_analyzer.py b/src/plugins/analysis/users_and_passwords/test/test_plugin_password_file_analyzer.py index 417f1151a..5da8e1ca7 100644 --- a/src/plugins/analysis/users_and_passwords/test/test_plugin_password_file_analyzer.py +++ b/src/plugins/analysis/users_and_passwords/test/test_plugin_password_file_analyzer.py @@ -9,7 +9,7 @@ TEST_DATA_DIR = Path(__file__).parent / 'data' -@pytest.mark.AnalysisPluginClass.with_args(AnalysisPlugin) +@pytest.mark.AnalysisPluginTestConfig(dict(plugin_class=AnalysisPlugin)) class TestAnalysisPluginPasswordFileAnalyzer: def test_process_object_shadow_file(self, analysis_plugin): test_file = FileObject(file_path=str(TEST_DATA_DIR / 'passwd_test')) diff --git a/src/test/unit/analysis/test_plugin_base.py b/src/test/unit/analysis/test_plugin_base.py index 2dd257dec..82c505f4a 100644 --- a/src/test/unit/analysis/test_plugin_base.py +++ b/src/test/unit/analysis/test_plugin_base.py @@ -5,6 +5,7 @@ import pytest from analysis.PluginBase import AnalysisBasePlugin, PluginInitException +from conftest import AnalysisPluginTestConfig from helperFunctions.fileSystem import get_src_dir from objects.file import FileObject from plugins.analysis.dummy.code.dummy import AnalysisPlugin as DummyPlugin @@ -22,8 +23,12 @@ }, } ) -@pytest.mark.AnalysisPluginClass.with_args(DummyPlugin) -@pytest.mark.plugin_start_worker +@pytest.mark.AnalysisPluginTestConfig( + AnalysisPluginTestConfig( + plugin_class=DummyPlugin, + start_processes=True, + ), +) class TestPluginBaseCore: def test_object_processing_no_children(self, analysis_plugin): root_object = FileObject(binary=b'root_file') @@ -48,7 +53,7 @@ def test_object_processing_one_child(self, analysis_plugin): assert child_object.uid in root_object.files_included, 'child object not in processed file' -@pytest.mark.AnalysisPluginClass.with_args(DummyPlugin) +@pytest.mark.AnalysisPluginTestConfig(dict(plugin_class=DummyPlugin)) class TestPluginBaseAddJob: def test_analysis_depth_not_reached_yet(self, analysis_plugin): fo = FileObject(binary=b'test', scheduled_analysis=[]) @@ -69,7 +74,7 @@ def test_analysis_depth_not_reached_yet(self, analysis_plugin): analysis_plugin.RECURSIVE = True assert analysis_plugin._analysis_depth_not_reached_yet(fo) - @pytest.mark.plugin_start_worker + @pytest.mark.AnalysisPluginTestConfig(dict(start_processes=True)) def test__add_job__recursive_is_set(self, analysis_plugin): fo = FileObject(binary=b'test', scheduled_analysis=[]) fo.depth = 1 @@ -126,7 +131,7 @@ def test_init_result_dict(self): self.p_base.shutdown() -@pytest.mark.AnalysisPluginClass.with_args(DummyPlugin) +@pytest.mark.AnalysisPluginTestConfig(dict(plugin_class=DummyPlugin)) def test_timeout(analysis_plugin, monkeypatch): # See the note in the docs of analysis_pluing fixture for why this is necessary monkeypatch.undo() diff --git a/src/test/unit/analysis/test_yara_plugin_base.py b/src/test/unit/analysis/test_yara_plugin_base.py index 7225ae096..0d68faec0 100644 --- a/src/test/unit/analysis/test_yara_plugin_base.py +++ b/src/test/unit/analysis/test_yara_plugin_base.py @@ -18,7 +18,7 @@ class YaraPlugin(YaraBasePlugin): FILE = '/foo/bar/Yara_Base_Plugin/code/test.py' -@pytest.mark.AnalysisPluginClass.with_args(YaraPlugin) +@pytest.mark.AnalysisPluginTestConfig(dict(plugin_class=YaraPlugin)) class TestAnalysisYaraBasePlugin: def test_get_signature_paths(self, analysis_plugin): intended_signature_path = os.path.join(get_src_dir(), 'analysis/signatures', analysis_plugin.NAME)