def test_process_log_taskid(p, q): set_cwd(tempfile.mkdtemp()) cuckoo_create() init_console_logging(logging.DEBUG) init_logfile("process-p0.json") def log_something(target, copy_path, task): logger("test message", action="hello.world", status="success") q.side_effect = log_something process_task({ "id": 12345, "category": "url", "target": "http://google.com/", "package": "ie", "options": {}, "custom": None, }) for line in open(cwd("log", "process-p0.json"), "rb"): obj = json.loads(line) if obj["action"] == "hello.world": assert obj["task_id"] == 12345 break else: raise
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", }
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
def test_logger(self, p, q, r): process_task({ "id": 123, "target": "foo", "category": "bar", "package": "baz", "options": { "a": "b", }, "custom": "foobar", }) p.assert_called_once() assert p.call_args[1] == { "action": "task.report", "status": "pending", "target": "foo", "category": "bar", "package": "baz", "options": "a=b", "custom": "foobar", }
def test_process_task(self, mt, mdb): tasks = [] for x in range(1, 10): task = mock.MagicMock() task.id = x tasks.append(task) taskx = mock.MagicMock() taskx.dir_exists.return_value = False tasks.append(taskx) for task in tasks: process_task(task) task.dir_exists.assert_called_once() if task is taskx: # The task dir for this task does not exist. It should # not be processed task.process.assert_not_called() mdb.assert_any_call(task.id, "failed_processing") else: task.process.assert_called_once() mdb.assert_any_call(task.id, "reported")