def test_monitor_latest_symlink(self): set_cwd(tempfile.mktemp()) cuckoo_create() monitor = open(cwd("monitor", "latest"), "rb").read().strip() os.unlink(cwd("monitor", "latest")) os.symlink(cwd("monitor", monitor), cwd("monitor", "latest")) migrate_cwd()
def test_modified_file(self, p, q): set_cwd(tempfile.mkdtemp()) cuckoo_create() open(cwd("agent", "agent.py"), "wb").write("newer agent") with pytest.raises(SystemExit): migrate_cwd() assert q.error.call_count == 2 assert "One or more files" in q.error.call_args_list[0][0][0] assert q.warning.call_args_list[1][0][1] == "agent/agent.py" p.assert_not_called()
def test_new_directory(self): set_cwd(tempfile.mkdtemp()) cuckoo_create() shutil.rmtree(cwd("yara", "scripts")) shutil.rmtree(cwd("yara", "shellcode")) migrate_cwd() # TODO Move this to its own 2.0.2 -> 2.0.3 migration handler. assert os.path.exists(cwd("yara", "scripts", ".gitignore")) assert os.path.exists(cwd("yara", "index_scripts.yar")) assert os.path.exists(cwd("yara", "shellcode", ".gitignore")) assert os.path.exists(cwd("yara", "index_shellcode.yar"))
def test_using_community(self): def h(filepath): return hashlib.sha1(open(filepath, "rb").read()).hexdigest() set_cwd(tempfile.mkdtemp()) cuckoo_create() filepath = cwd("signatures", "__init__.py") # Old Community version. shutil.copy("tests/files/sig-init-old.py", filepath) assert h(filepath) == "033e19e4fea1989680f4af19b904448347dd9589" migrate_cwd() assert h(filepath) == "5966e9db6bcd3adcd70998f4c51072c7f81b4564"
def test_using_community(self): def h(filepath): return hashlib.sha1(open(filepath, "rb").read()).hexdigest() set_cwd(tempfile.mkdtemp()) cuckoo_create() filepath = cwd("signatures", "__init__.py") # Old Community version. shutil.copy("tests/files/sig-init-old.py", filepath) assert h(filepath) == "033e19e4fea1989680f4af19b904448347dd9589" migrate_cwd() assert h(filepath) == "eaffef3b08fd1069ba2d3c977015b598fa150941"
def test_missing_file(self, p): set_cwd(tempfile.mkdtemp()) cuckoo_create() # We're going to restore a file that has been removed by the user for # one reason or the other, namely, web/local_settings.py. os.unlink(cwd("web", "local_settings.py")) migrate_cwd() p.assert_called_once_with( cwd("..", "data", "web/local_settings.py", private=True), cwd("web/local_settings.py"))
def test_missing_file(self, p): set_cwd(tempfile.mkdtemp()) cuckoo_create() # We're going to restore a file that has been removed by the user for # one reason or the other, namely, web/local_settings.py. os.unlink(cwd("web", "local_settings.py")) migrate_cwd() p.assert_called_once_with( cwd("..", "data", "web/local_settings.py", private=True), cwd("web/local_settings.py") )
def test_new_directory(self): set_cwd(tempfile.mkdtemp()) cuckoo_create() shutil.rmtree(cwd("yara", "scripts")) shutil.rmtree(cwd("yara", "shellcode")) shutil.rmtree(cwd("stuff")) open(cwd("yara", "index_binaries.yar"), "wb").write("hello") migrate_cwd() # TODO Move this to its own 2.0.2 -> 2.0.3 migration handler. assert os.path.exists(cwd("yara", "scripts", ".gitignore")) assert os.path.exists(cwd("yara", "shellcode", ".gitignore")) # TODO Move this to its own 2.0.3 -> 2.0.4 migration handler. assert os.path.exists(cwd("stuff")) assert not os.path.exists(cwd("yara", "index_binaries.yar"))
def test_new_directory(self): set_cwd(tempfile.mkdtemp()) cuckoo_create() shutil.rmtree(cwd("yara", "scripts")) shutil.rmtree(cwd("yara", "shellcode")) shutil.rmtree(cwd("stuff")) open(cwd("yara", "index_binaries.yar"), "wb").write("hello") migrate_cwd() # TODO Move this to its own 2.0.2 -> 2.0.3 migration handler. assert os.path.exists(cwd("yara", "scripts", ".gitignore")) assert os.path.exists(cwd("yara", "shellcode", ".gitignore")) # TODO Move this to its own 2.0.3 -> 2.0.4 migration handler. assert os.path.exists(cwd("stuff")) assert os.path.exists(cwd("yara", "dumpmem")) assert not os.path.exists(cwd("yara", "index_binaries.yar"))
def test_deleted_file(self, p): set_cwd(tempfile.mkdtemp()) cuckoo_create() def our_sha1(buf): class obj(object): def hexdigest(self): return "4989ba7ce0dc38709dd125d6c4fac5852914f0c7" return obj() if buf == "yes!" else hashlib.sha1(buf) p.sha1.side_effect = our_sha1 open(cwd("analyzer/windows/lib/common/errors.py"), "wb").write("yes!") assert os.path.exists(cwd("analyzer/windows/lib/common/errors.py")) migrate_cwd() assert not os.path.exists(cwd("analyzer/windows/lib/common/errors.py"))
def test_create_missing_dirs(self): set_cwd(tempfile.mkdtemp()) cuckoo_create() t1 = submit_task.add_path(__file__) t2 = submit_task.add_path(__file__) task_dirs = ["shots", "logs", "files", "extracted", "buffer", "memory"] shutil.rmtree(cwd(analysis=t1)) os.rmdir(cwd("logs", analysis=t2)) assert not os.path.exists(cwd(analysis=t1)) assert not os.path.exists(cwd("logs", analysis=t2)) migrate_cwd() assert os.path.exists(cwd(analysis=t1)) assert os.path.exists(cwd(analysis=t2)) for task in [t1, t2]: for dir in task_dirs: assert os.path.exists(cwd(dir, analysis=task))
def test_new_directory(self): set_cwd(tempfile.mkdtemp()) cuckoo_create() shutil.rmtree(cwd("yara", "scripts")) shutil.rmtree(cwd("yara", "shellcode")) shutil.rmtree(cwd("stuff")) shutil.rmtree(cwd("whitelist")) open(cwd("yara", "index_binaries.yar"), "wb").write("hello") migrate_cwd() # TODO Move this to its own 2.0.2 -> 2.0.3 migration handler. assert os.path.exists(cwd("yara", "scripts", ".gitignore")) assert os.path.exists(cwd("yara", "shellcode", ".gitignore")) # TODO Move this to its own 2.0.3 -> 2.0.4 migration handler. assert os.path.exists(cwd("stuff")) assert os.path.exists(cwd("whitelist")) assert open(cwd("whitelist", "domain.txt"), "rb").read().strip() == ( "# You can add whitelisted domains here." ) assert not os.path.exists(cwd("yara", "index_binaries.yar"))
def test_new_directory(self): set_cwd(tempfile.mkdtemp()) cuckoo_create() shutil.rmtree(cwd("yara", "scripts")) shutil.rmtree(cwd("yara", "shellcode")) shutil.rmtree(cwd("stuff")) shutil.rmtree(cwd("whitelist")) open(cwd("yara", "index_binaries.yar"), "wb").write("hello") migrate_cwd() # TODO Move this to its own 2.0.2 -> 2.0.3 migration handler. assert os.path.exists(cwd("yara", "scripts", ".gitignore")) assert os.path.exists(cwd("yara", "shellcode", ".gitignore")) # TODO Move this to its own 2.0.3 -> 2.0.4 migration handler. assert os.path.exists(cwd("stuff")) assert os.path.exists(cwd("whitelist")) assert open( cwd("whitelist", "domain.txt"), "rb").read().strip() == ("# You can add whitelisted domains here.") assert os.path.exists(cwd("yara", "dumpmem")) assert not os.path.exists(cwd("yara", "index_binaries.yar"))
def test_outdated_file(self, p, q): set_cwd(tempfile.mkdtemp()) cuckoo_create() # We're going to pretend like web/local_settings.py is outdated by # replacing its sha1 by that of its initial version. our_buf = open(cwd("web", "local_settings.py"), "rb").read() def our_sha1(buf): class obj(object): def hexdigest(self): return "d90bb80df2ed51d393823438f1975c1075523ec8" return obj() if buf == our_buf else hashlib.sha1(buf) q.sha1.side_effect = our_sha1 migrate_cwd() p.assert_called_once_with( cwd("..", "data", "web/local_settings.py", private=True), cwd("web/local_settings.py"))
def test_outdated_file(self, p, q): set_cwd(tempfile.mkdtemp()) cuckoo_create() # We're going to pretend like web/local_settings.py is outdated by # replacing its sha1 by that of its initial version. our_buf = open(cwd("web", "local_settings.py"), "rb").read() def our_sha1(buf): class obj(object): def hexdigest(self): return "d90bb80df2ed51d393823438f1975c1075523ec8" return obj() if buf == our_buf else hashlib.sha1(buf) q.sha1.side_effect = our_sha1 migrate_cwd() p.assert_called_once_with( cwd("..", "data", "web/local_settings.py", private=True), cwd("web/local_settings.py") )
def test_current_community(self): set_cwd(tempfile.mktemp()) shutil.copytree(os.path.expanduser("~/.cuckoo"), cwd()) open(cwd(".cwd"), "wb").write("somethingelse") migrate_cwd()
def test_up_to_date(self, p): set_cwd(tempfile.mkdtemp()) cuckoo_create() migrate_cwd() p.assert_not_called()