From 3e67a9f05a552edf2ed20cd4f0c72d92a09055f0 Mon Sep 17 00:00:00 2001 From: Dom Whewell Date: Sat, 9 Nov 2024 09:53:12 +0000 Subject: [PATCH] Added test to check the detected file type --- bbot/modules/jadx.py | 2 +- .../module_tests/test_module_jadx.py | 17 +++++++++++------ 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/bbot/modules/jadx.py b/bbot/modules/jadx.py index 5a773c8f8..829542f99 100644 --- a/bbot/modules/jadx.py +++ b/bbot/modules/jadx.py @@ -67,7 +67,7 @@ async def setup(self): async def filter_event(self, event): if "file" in event.tags: if not event.data["magic_description"].lower() in self.allowed_file_types: - return False, f"Jadx is not able to decompile this file type: {event.data['magic_description']}" + return False, f"Jadx is not able to decompile this file type" else: return False, "Event is not a file" return True diff --git a/bbot/test/test_step_2/module_tests/test_module_jadx.py b/bbot/test/test_step_2/module_tests/test_module_jadx.py index f949580d2..9eb3c1537 100644 --- a/bbot/test/test_step_2/module_tests/test_module_jadx.py +++ b/bbot/test/test_step_2/module_tests/test_module_jadx.py @@ -1,5 +1,6 @@ from pathlib import Path -from .base import ModuleTestBase, tempapkfile +from bbot.core.helpers.libmagic import get_magic_info +from bbot.test.test_step_2.module_tests.base import ModuleTestBase, tempapkfile class TestJadx(ModuleTestBase): @@ -37,14 +38,18 @@ async def setup_after_prep(self, module_test): module_test.httpx_mock.add_response( url="https://d.apkpure.com/b/XAPK/com.bbot.test?version=latest", content=self.apk_file, + headers={ + "Content-Type": "application/vnd.android.package-archive", + "Content-Disposition": "attachment; filename=com.bbot.test.xapk", + }, ) def check(self, module_test, events): - extract_event = [ - e - for e in events - if e.type == "FILESYSTEM" and "com_bbot_test_xapk" in e.data["path"] and "folder" in e.tags - ] + filesystem_events = [e for e in events if e.type == "FILESYSTEM"] + apk_event = [e for e in filesystem_events if "file" in e.tags] + extension, mime_type, description, confidence = get_magic_info(apk_event[0].data["path"]) + assert description == "Android application package", f"Downloaded file was detected as {description}" + extract_event = [e for e in filesystem_events if "folder" in e.tags] assert 1 == len(extract_event), "Failed to extract apk" extract_path = Path(extract_event[0].data["path"]) assert extract_path.is_dir(), "Destination apk doesn't exist"