Beispiel #1
0
    def test_process(self, mp, ms, mr):
        id, sample = self.add_task()
        task = Task()
        task.load_from_db(id)

        mp.return_value = {"x":"x"}

        task.process()
        mp.assert_called_once()
        ms.assert_called_once()
        mr.assert_called_once()
Beispiel #2
0
    def test_process_nodelete(self, mp, ms, mr):
        set_cwd(tempfile.mkdtemp())
        cuckoo_create(cfg={
            "cuckoo": {
                "cuckoo": {
                    "delete_original": False,
                    "delete_bin_copy": False,
                },
            },
        })

        id, sample = self.add_task()
        task = Task()
        task.load_from_db(id)
        task.create_dirs()
        copied_binary = cwd("storage", "binaries", File(sample).get_sha256())

        task.process()
        assert os.path.exists(copied_binary)
        assert os.path.exists(sample)
Beispiel #3
0
    def test_process_dodelete(self, mp, ms, mr):
        set_cwd(tempfile.mkdtemp())
        cuckoo_create(cfg={
            "cuckoo": {
                "cuckoo": {
                    "delete_original": True,
                    "delete_bin_copy": True,
                },
            },
        })

        id, sample = self.add_task()
        task = Task()
        task.load_from_db(id)
        task.create_dirs()

        assert os.path.exists(task.target)
        assert os.path.exists(task.targets[0].copied_binary)
        task.process()
        assert not os.path.exists(sample)
        assert not os.path.exists(task.targets[0].copied_binary)
Beispiel #4
0
    def test_logger(self, p, q):
        task = Task()
        task.process = mock.MagicMock()
        id = submit_task.add_path(__file__,
                                  options={"a": "b"},
                                  custom="foobar",
                                  package="baz")
        task.load_from_db(id)
        process_task(task)

        p.assert_called_once()
        assert p.call_args[1] == {
            "action": "task.report",
            "status": "pending",
            "target": __file__,
            "category": "file",
            "package": "baz",
            "options": "a=b",
            "custom": "foobar",
        }
Beispiel #5
0
def test_process_log_taskid():
    set_cwd(tempfile.mkdtemp())
    cuckoo_create()
    db.connect()

    init_console_logging(logging.DEBUG)
    init_logfile("process-p0.json")

    task = Task()
    id = submit_task.add_url("http://google.com/", package="ie")
    task.load_from_db(id)
    task.process = mock.MagicMock()
    process_task(task)

    for line in open(cwd("log", "process-p0.json"), "rb"):
        obj = json.loads(line)
        if obj["action"] == "task.report":
            assert obj["task_id"] == task.id
            break
    else:
        raise