def test_append_error(self): feedback = CuckooFeedbackObject(message="test") feedback.add_error("test") obj = feedback.to_dict() assert obj["message"] == "test" assert obj["errors"] == ["test"]
def test_send_data(self, p, q): q._get_report.return_value = self.report( "tests/files/sample_analysis_storage" ) p.post.return_value.json.return_value = { "status": True, "feedback_id": 1, } feedback = CuckooFeedback() cf = CuckooFeedbackObject( "message", "*****@*****.**", "name", "company", True ) cf.include_report_web(1) cf.include_analysis() assert feedback.send_feedback(cf) == 1 p.post.assert_called_once_with( feedback.endpoint, data={ "feedback": mock.ANY, }, files={ "file": mock.ANY, }, headers=mock.ANY ) # Ensure that the second entry for each file is an open file handle. files = p.post.call_args[1]["files"] z = zipfile.ZipFile(files["file"]) assert "Starting analyzer" in z.read("analysis.log") assert len(z.read("cuckoo.log")) == 15274
def test_invalid_configuration(self): # Explicitly want a clean CWD here. set_cwd(tempfile.mkdtemp()) cuckoo_create() cf = CuckooFeedback() with pytest.raises(CuckooFeedbackError) as e: cf.send_feedback(CuckooFeedbackObject( name=None, email="*****@*****.**", company="foo" )) e.match("Could not validate") with pytest.raises(CuckooFeedbackError) as e: cf.send_feedback(CuckooFeedbackObject( name="foo", email=None, company="foo" )) e.match("Could not validate") with pytest.raises(CuckooFeedbackError) as e: cf.send_feedback(CuckooFeedbackObject( name="foo", email="a@b,com", company="foo" )) e.match("Could not validate") with pytest.raises(CuckooFeedbackError) as e: cf.send_feedback(CuckooFeedbackObject( name="foo", email="*****@*****.**", company=None )) e.match("Could not validate")
def test_include_analysis_files(self): set_cwd(tempfile.mkdtemp()) fake_task = cwd(analysis=1) shutil.copytree("tests/files/sample_analysis_storage", fake_task) feedback = CuckooFeedbackObject(task_id=1, include_files=True) assert len(feedback.get_files()["file"].getvalue()) == 71487 shutil.rmtree(fake_task)
def test_include_report(self, p): p._get_report.return_value = self.report( "tests/files/sample_analysis_storage") feedback = CuckooFeedbackObject() feedback.include_report_web(1) assert feedback.report.target["file"]["name"] == "binary" assert feedback.report.target["file"]["size"] == 91010
def test_include_report(self, p): p._get_report.return_value = self.report( "tests/files/sample_analysis_storage" ) feedback = CuckooFeedbackObject() feedback.include_report_web(1) assert feedback.report.target["file"]["name"] == "binary" assert feedback.report.target["file"]["size"] == 91010
def test_include_analysis(self, p): p._get_report.return_value = self.report( "tests/files/sample_analysis_storage") feedback = CuckooFeedbackObject() feedback.include_report_web(1) feedback.include_analysis(memdump=False) assert len(feedback.to_files()) == 1
def run(self, results): # Nothing to see here. if not results.get("debug", {}).get("errors"): return feedback = CuckooFeedback() if not feedback.enabled(): return fo = CuckooFeedbackObject( message="One or more errors occurred during an analysis", automated=True, task_id=self.task["id"], include_files=True) for error in results["debug"]["errors"]: fo.add_error(error) feedback.send_feedback(fo)
def test_send_data(self, p, q, c): set_cwd(tempfile.mkdtemp()) fake_task = cwd(analysis=1) shutil.copytree("tests/files/sample_analysis_storage", fake_task) q.get_report.return_value = self.report( "tests/files/sample_analysis_storage") p.post.return_value.json.return_value = { "status": True, "feedback_id": 1, } c.from_confdir.return_value = {} feedback = CuckooFeedback() cf = CuckooFeedbackObject("message", "*****@*****.**", "name", "company", True, include_files=True, task_id=1) cf.include_report_web(1) assert feedback.send_feedback(cf) == 1 p.post.assert_called_once_with(feedback.endpoint, data={ "feedback": mock.ANY, }, files={ "file": mock.ANY, }, headers=mock.ANY) # Ensure that the second entry for each file is an open file handle. files = p.post.call_args[1]["files"] z = zipfile.ZipFile(files["file"]) assert "Starting analyzer" in z.read("analysis.log") assert len(z.read("cuckoo.log")) == 15274 shutil.rmtree(fake_task)
def test_send_data(self, p, q): q._get_report.return_value = self.report( "tests/files/sample_analysis_storage") p.post.return_value.json.return_value = { "status": True, "feedback_id": 1, } feedback = CuckooFeedback() cf = CuckooFeedbackObject("message", "*****@*****.**", "name", "company", True) cf.include_report_web(1) cf.include_analysis() assert feedback.send_feedback(cf) == 1 p.post.assert_called_once_with(feedback.endpoint, data={ "feedback": mock.ANY, }, files={ "file": mock.ANY, }, headers=mock.ANY) # Ensure that the second entry for each file is an open file handle. files = p.post.call_args[1]["files"] z = zipfile.ZipFile(files["file"]) assert "Starting analyzer" in z.read("analysis.log") assert len(z.read("cuckoo.log")) == 15274
def test_include_analysis(self, p): p._get_report.return_value = self.report( "tests/files/sample_analysis_storage" ) feedback = CuckooFeedbackObject() feedback.include_report_web(1) feedback.include_analysis(memdump=False) assert len(feedback.to_files()) == 1
def check_configs(): """Checks if config files exist. @raise CuckooStartupError: if config files do not exist. """ configs = ( "auxiliary", "cuckoo", "memory", "processing", "reporting", "routing", ) for filename in configs: if not os.path.exists(cwd("conf", "%s.conf" % filename)): raise CuckooStartupError( "Config file does not exist at path: %s" % cwd("conf", "%s.conf" % filename) ) check_specific_config(filename) # Also check the specific machinery handler for this instance. machinery = config("cuckoo:cuckoo:machinery") if machinery not in Config.configuration: raise CuckooStartupError( "An unknown machinery has been chosen (machinery=%s)!" % machinery ) check_specific_config(machinery) # If Cuckoo Feedback is enabled, ensure its configuration is valid. feedback_enabled = ( config("cuckoo:feedback:enabled") or config("reporting:feedback:enabled") ) if feedback_enabled: try: CuckooFeedbackObject( name=config("cuckoo:feedback:name"), email=config("cuckoo:feedback:email"), company=config("cuckoo:feedback:company"), message="startup" ).validate() except CuckooFeedbackError as e: raise CuckooStartupError( "You have filled out the Cuckoo Feedback configuration, but " "there's an error in it: %s" % e ) return True