class TestProcessor: def setUp(self): self.tmp = tempfile.mkdtemp() self.p = Processor(self.tmp) def test_run_processing(self): res = self.p._run_processing(ProcessingMock) assert "foo" in res assert "bar" in res["foo"] def test_run_signature_alter_results(self): """@note: regression test.""" res = {"foo": "bar"} self.p._run_signature(SignatureMock, res) assert_equals(res["foo"], "bar") def test_signature_disabled(self): res = {"foo": "bar"} assert_equals(None, self.p._run_signature(SignatureDisabledMock, res)) def test_signature_wrong_version(self): res = {"foo": "bar"} assert_equals(None, self.p._run_signature(SignatureWrongVersionMock, res)) def tearDown(self): os.rmdir(self.tmp)
def process_results(self): """Process the analysis results and generate the enabled reports.""" try: logs_path = os.path.join(self.storage, "logs") for csv in os.listdir(logs_path): if not '.raw' in csv: continue csv = os.path.join(logs_path, csv) if os.stat( csv).st_size > self.cfg.processing.analysis_size_limit: log.error( "Analysis file %s is too big to be processed, " "analysis aborted. Process it manually with the " "provided utilities", csv) return False except OSError as e: log.warning("Error accessing analysis logs (task=%d): %s", self.task.id, e) results = Processor(self.task.id).run() Reporter(self.task.id).run(results) # If the target is a file and the user enabled the option, # delete the original copy. if self.task.category == "file" and self.cfg.cuckoo.delete_original: try: os.remove(self.task.target) except OSError as e: log.error( "Unable to delete original file at path \"%s\": " "%s", self.task.target, e) log.info("Task #%d: reports generation completed (path=%s)", self.task.id, self.storage) return True
def main(): parser = argparse.ArgumentParser() parser.add_argument("id", type=str, help="ID of the analysis to process") parser.add_argument("-r", "--report", help="Re-generate report", action="store_true", required=False) parser.add_argument("-f", "--failed", help="Mark the analysis as failed", action="store_true", required=False) args = parser.parse_args() init_modules() if args.failed: results = {"success" : False} else: results = Processor(args.id).run() results["success"] = True if args.report: Reporter(args.id).run(results)
def setUp(self): self.tmp = tempfile.mkdtemp() self.p = Processor(self.tmp)