コード例 #1
0
ファイル: test_feedback.py プロジェクト: frank2411/cuckoo_dev
    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")
コード例 #2
0
ファイル: api.py プロジェクト: primmus/cuckoo-1
    def feedback_send(request, body):
        f = CuckooFeedback()

        task_id = body.get("task_id")
        if task_id and task_id.isdigit():
            task_id = int(task_id)

        try:
            feedback_id = f.send_form(task_id=task_id,
                                      name=body.get("name"),
                                      company=body.get("company"),
                                      email=body.get("email"),
                                      message=body.get("message"),
                                      json_report=body.get(
                                          "include_analysis", False),
                                      memdump=body.get("include_memdump",
                                                       False))
        except CuckooFeedbackError as e:
            return json_error_response(str(e))

        return JsonResponse({
            "status": True,
            "feedback_id": feedback_id,
        },
                            safe=False)
コード例 #3
0
 def process_exception(self, request, exception):
     request.exception = exception
     try:
         feedback = CuckooFeedback()
         feedback.send_exception(exception, request)
     except CuckooFeedbackError as e:
         log.warning("Error providing feedback to the backend: %s" % e)
コード例 #4
0
ファイル: test_feedback.py プロジェクト: consen/cuckoo
    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
コード例 #5
0
    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
コード例 #6
0
ファイル: errors.py プロジェクト: LetMeR00t/cuckoo
 def process_exception(self, request, exception):
     request.exception = exception
     try:
         feedback = CuckooFeedback()
         feedback.send_exception(exception, request)
     except CuckooFeedbackError as e:
         log.warning(
             "Error providing feedback to the backend: %s" % e
         )
コード例 #7
0
    def test_exception_no_analysis(self):
        feedback = CuckooFeedback()
        responses.add(responses.POST,
                      feedback.endpoint,
                      json={
                          "status": True,
                          "feedback_id": 1,
                      },
                      status=200)

        assert feedback.send_exception(Exception("Mock Exception"), None) == 1
コード例 #8
0
ファイル: test_feedback.py プロジェクト: LetMeR00t/cuckoo
    def test_exception_no_analysis(self):
        feedback = CuckooFeedback()
        responses.add(
            responses.POST, feedback.endpoint, json={
                "status": True,
                "feedback_id": 1,
            }, status=200
        )

        assert feedback.send_exception(
            Exception("Mock Exception"), None
        ) == 1
コード例 #9
0
    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)

        for error in results["debug"]["errors"]:
            fo.add_error(error)

        fo.gather_export_files(self.analysis_path)
        feedback.send_feedback(fo)
コード例 #10
0
ファイル: test_feedback.py プロジェクト: frank2411/cuckoo_dev
    def test_include_404_report(self, p, q):
        class request(object):
            method = "GET"

            class resolver_match(object):
                kwargs = {
                    "task_id": 1,
                }

        q._get_report.return_value = {}
        p.return_value.report = None
        p.return_value.validate.side_effect = CuckooFeedbackError

        with pytest.raises(CuckooFeedbackError):
            feedback = CuckooFeedback()
            feedback.send_exception(Exception, request)

        p.return_value.include_report_web.assert_called_once()
        p.return_value.include_analysis.assert_not_called()
コード例 #11
0
    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)
コード例 #12
0
ファイル: api.py プロジェクト: LetMeR00t/cuckoo
    def feedback_send(request, body):
        f = CuckooFeedback()

        task_id = body.get("task_id")
        if task_id and task_id.isdigit():
            task_id = int(task_id)

        try:
            feedback_id = f.send_form(
                task_id=task_id,
                name=body.get("name"),
                company=body.get("company"),
                email=body.get("email"),
                message=body.get("message"),
                json_report=body.get("include_analysis", False),
                memdump=body.get("include_memdump", False)
            )
        except CuckooFeedbackError as e:
            return json_error_response(str(e))

        return JsonResponse({
            "status": True,
            "feedback_id": feedback_id,
        }, safe=False)
コード例 #13
0
ファイル: test_feedback.py プロジェクト: frank2411/cuckoo_dev
    def test_exception_middleware(self, rf):
        feedback = CuckooFeedback()
        responses.add(
            responses.POST, feedback.endpoint, json={
                "status": True,
                "feedback_id": 0,
            }, status=200
        )

        try:
            raise Exception("This is an exception!")
        except Exception as e:
            em = ExceptionMiddleware()
            assert em.process_exception(
                rf.get("/analysis/1/summary"), e
            ) is None