def test_store_file_wrong_path(self, caplog): mock_task_wrong_path = mock_task() mock_task_wrong_path.target += "foobar" analysis_man = AnalysisManager(task=mock_task_wrong_path, error_queue=queue.Queue()) analysis_man.store_file(sha256="e3be3b") is False assert "analysis aborted" in caplog.text
def test_store_file_symlink_err(self, symlink, caplog): with open("binary", "wb") as f: f.write(b"\x00") analysis_man = AnalysisManager(task=mock_task(), error_queue=queue.Queue()) analysis_man.store_file(sha256="e3be3b") assert "Unable to create symlink/copy" 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)
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_store_file_symlink(self, symlink): analysis_man = AnalysisManager(task=mock_task(), error_queue=queue.Queue()) assert analysis_man.store_file(sha256="e3be3b") is True
def test_store_file_no_dir(self, caplog): analysis_man = AnalysisManager(task=mock_task(), error_queue=queue.Queue()) assert analysis_man.store_file(sha256="e3be3b") is False assert "Unable to store file" in caplog.text
def test_store_file(self, create_store_file_dir): analysis_man = AnalysisManager(task=mock_task(), error_queue=queue.Queue()) assert analysis_man.store_file(sha256="e3") is True