@@ -81,6 +81,12 @@ def test_prepare(self, set_lock, init_logging, config, pipeserver):
8181
8282
8383class TestAnalyzerChoosePackage (unittest .TestCase ):
84+ def setUp (self ):
85+ patch_process = patch ("analyzer.Process" )
86+ self .mock_process = patch_process .start ()
87+ self .mock_process .return_value = MagicMock ()
88+ self .addCleanup (patch_process .stop )
89+
8490 def test_choose_package_shellcode (self ):
8591 test = analyzer .Analyzer ()
8692 test .config = MagicMock ()
@@ -621,6 +627,34 @@ def test_choose_package_zip_compound(self):
621627 self .assertEqual ("modules.packages.zip_compound" , pkg_name )
622628 self .assertEqual (pkg_class .__class__ .__name__ , "ZipCompound" )
623629
630+ def _assert_autodetected_package (self , file_name , expected_pkg_module , expected_pkg_class_name , file_type = "ASCII text" ):
631+ """Helper: auto-detect a package from a file in test_data and assert the result."""
632+ file_path = os .path .join (os .path .dirname (__file__ ), "test_data" , file_name )
633+ test = analyzer .Analyzer ()
634+ test .config = MagicMock ()
635+ test .options = MagicMock ()
636+ test .config .package = ""
637+ test .config .category = "file"
638+ test .config .file_name = file_name
639+ test .config .file_type = file_type
640+ test .config .exports = ""
641+ test .target = file_path
642+ pkg_name , pkg_class = test .choose_package ()
643+ self .assertEqual (f"modules.packages.{ expected_pkg_module } " , pkg_name )
644+ self .assertEqual (expected_pkg_class_name , pkg_class .__class__ .__name__ )
645+
646+ def test_choose_package_from_eml_file (self ):
647+ """Auto-detect eml package by reading test_email.eml from test_data."""
648+ self ._assert_autodetected_package ("test_email.eml" , "eml" , "EML" )
649+
650+ def test_choose_package_from_python_py_file (self ):
651+ """Auto-detect python package from test_python_file1.py via file extension."""
652+ self ._assert_autodetected_package ("test_python_file1.py" , "python" , "Python" )
653+
654+ def test_choose_package_from_python_data_file (self ):
655+ """Auto-detect python package from test_python_file2.data via #!/usr/bin/env python in content."""
656+ self ._assert_autodetected_package ("test_python_file2.data" , "python" , "Python" )
657+
624658
625659class TestAnalyzerMonitoring (unittest .TestCase ):
626660 def setUp (self ):
0 commit comments