def test_init_storage_already_exists(self, clean_init_storage, caplog): analysis_man = AnalysisManager(task=mock_task(), error_queue=queue.Queue()) os.makedirs(os.getcwd() + "/storage/analyses/1234") analysis_man.init_storage() assert "already exists at path" in caplog.text
def test_category_checks_modified_file(self, clean_init_storage, mocker): class mock_sample: sha256 = "123" analysis_man = AnalysisManager(task=mock_task(), error_queue=queue.Queue()) assert analysis_man.init_storage() is True mocker.patch("lib.cuckoo.core.scheduler.Database.view_sample", return_value=mock_sample()) assert analysis_man.category_checks() is False
def test_init_storage_other_error(self, clean_init_storage, mocker, caplog): mocker.patch( "lib.cuckoo.core.scheduler.create_folder", side_effect=CuckooOperationalError("foo"), ) analysis_man = AnalysisManager(task=mock_task(), error_queue=queue.Queue()) # with pytest.raises(CuckooOperationalError) as exc_info: assert analysis_man.init_storage() is False assert "Unable to create analysis folder" in caplog.text
class TestAnalysisManager: def setUp(self): create_structure() self.anal = Dictionary() self.anal["id"] = "test-cuckoo-remove-me" self.a = AnalysisManager(self.anal) def test_init_storage(self): self.a.init_storage() assert os.path.exists(self.a.analysis.results_folder) @raises(CuckooAnalysisError) def test_init_storage_error(self): self.a.analysis.results_folder = os.path.join(os.path.join(CUCKOO_ROOT, "storage", "analyses"), self.anal.id) os.mkdir(self.a.analysis.results_folder) self.a.init_storage() def test_store_file(self): file = tempfile.mkstemp()[1] self.anal["file_path"] = file self.a = AnalysisManager(self.anal) self.a.init_storage() self.a.store_file() bin_path = os.path.join(CUCKOO_ROOT, "storage", "binaries", "d41d8cd98f00b204e9800998ecf8427e") assert_equals(bin_path, self.a.analysis.stored_file_path) assert os.path.exists(bin_path) os.remove(file) os.remove(bin_path) def tearDown(self): shutil.rmtree(self.a.analysis.results_folder)
def test_category_checks_no_store_file(self, clean_init_storage, grab_sample, mocker): class mock_sample: sha256 = "5dd87d3d6b9d8b4016e3c36b189234772661e690c21371f1eb8e018f0f0dec2b" sample_location = grab_sample(sample_hash="5dd87d3d6b9d8b4016e3c36b189234772661e690c21371f1eb8e018f0f0dec2b") mock_task_cat = mock_task() mock_task_cat.target = sample_location analysis_man = AnalysisManager(task=mock_task_cat, error_queue=queue.Queue()) assert analysis_man.init_storage() is True mocker.patch("lib.cuckoo.core.scheduler.Database.view_sample", return_value=mock_sample()) mocker.patch("lib.cuckoo.core.scheduler.AnalysisManager.store_file", return_value=False) assert analysis_man.category_checks() is False
class TestAnalysisManager: def setUp(self): create_structure() self.anal = Dictionary() self.anal["id"] = "test-cuckoo-remove-me" self.a = AnalysisManager(self.anal) def test_init_storage(self): self.a.init_storage() assert os.path.exists(self.a.analysis.results_folder) @raises(CuckooAnalysisError) def test_init_storage_error(self): self.a.analysis.results_folder = os.path.join( os.path.join(CUCKOO_ROOT, "storage", "analyses"), self.anal.id) os.mkdir(self.a.analysis.results_folder) self.a.init_storage() def test_store_file(self): file = tempfile.mkstemp()[1] self.anal["file_path"] = file self.a = AnalysisManager(self.anal) self.a.init_storage() self.a.store_file() bin_path = os.path.join(CUCKOO_ROOT, "storage", "binaries", "d41d8cd98f00b204e9800998ecf8427e") assert_equals(bin_path, self.a.analysis.stored_file_path) assert os.path.exists(bin_path) os.remove(file) os.remove(bin_path) def test_store_file_delete_original(self): file = tempfile.mkstemp()[1] self.anal["file_path"] = file self.a = AnalysisManager(self.anal) self.a.init_storage() self.a.cfg.cuckoo.delete_original = True self.a.store_file() bin_path = os.path.join(CUCKOO_ROOT, "storage", "binaries", "d41d8cd98f00b204e9800998ecf8427e") assert not os.path.exists(file) os.remove(bin_path) def tearDown(self): shutil.rmtree(self.a.analysis.results_folder)
def test_init_storage(self, clean_init_storage): analysis_man = AnalysisManager(task=mock_task(), error_queue=queue.Queue()) analysis_man.init_storage() assert analysis_man.storage.rsplit("/", 1)[-1] == "1234"