From 051a2b5de54b1b931811610084465991fbfd8464 Mon Sep 17 00:00:00 2001 From: cecinestpasunepipe <110607403+cecinestpasunepipe@users.noreply.github.com> Date: Mon, 7 Aug 2023 17:23:46 +0200 Subject: [PATCH] Allow Default/None-OS to access plugins (#346) (DIS-2138) --- dissect/target/plugin.py | 3 ++- tests/conftest.py | 6 ++++++ tests/test_plugin.py | 14 ++++++++++++-- 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/dissect/target/plugin.py b/dissect/target/plugin.py index 7db7e31a0..bc9e18bb1 100644 --- a/dissect/target/plugin.py +++ b/dissect/target/plugin.py @@ -832,7 +832,8 @@ def plugin_function_index(target: Target) -> tuple[dict[str, Any], set[str]]: def all_plugins(): # Filter out plugins based on the target os - os_type = type(target._os) if target._os else None + os_type = type(target._os) if target._os and target._os.os != "default" else None + yield from plugins(os_type) yield from os_plugins() yield from child_plugins() # Doesn't export anything but added for completeness. diff --git a/tests/conftest.py b/tests/conftest.py index cb419072f..0cb1ae439 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -90,6 +90,12 @@ def hive_hku(): yield hive +@pytest.fixture +def target_default(): + mock_target = next(make_mock_target()) + yield mock_target + + @pytest.fixture def target_win(hive_hklm, fs_win): mock_target = next(make_mock_target()) diff --git a/tests/test_plugin.py b/tests/test_plugin.py index da7395600..f7874115e 100644 --- a/tests/test_plugin.py +++ b/tests/test_plugin.py @@ -10,6 +10,7 @@ get_external_module_paths, save_plugin_import_failure, ) +from dissect.target.target import Target def test_save_plugin_import_failure(): @@ -106,15 +107,24 @@ def f6(self): assert len(found) == assert_num_found -def test_find_plugin_function_windows(target_win): +def test_find_plugin_function_windows(target_win: Target) -> None: found, _ = find_plugin_functions(target_win, "services") assert len(found) == 1 assert found[0].name == "os.windows.services.services" -def test_find_plugin_function_unix(target_unix): +def test_find_plugin_function_unix(target_unix: Target) -> None: found, _ = find_plugin_functions(target_unix, "services") assert len(found) == 1 assert found[0].name == "os.unix.services.services" + + +def test_find_plugin_function_default(target_default: Target) -> None: + found, _ = find_plugin_functions(target_default, "services") + + assert len(found) == 2 + names = [item.name for item in found] + assert "os.unix.services.services" in names + assert "os.windows.services.services" in names