mirror of https://github.com/CIRCL/PyCIRCLean
Change the way test dst dirs are handled
* Each test folder now copies files into its own test directory * Change gitignore due to dst dir changes * Make sure logger.tree is called for every directorypull/12/head
parent
0175ee48e5
commit
ac94cf5d6d
|
@ -68,7 +68,11 @@ target/
|
||||||
|
|
||||||
# Project specific
|
# Project specific
|
||||||
tests/dst/*
|
tests/dst/*
|
||||||
|
tests/*_dst
|
||||||
tests/test_logs/*
|
tests/test_logs/*
|
||||||
!tests/**/.keepdir
|
!tests/**/.keepdir
|
||||||
!tests/src_invalid/*
|
!tests/src_invalid/*
|
||||||
!tests/src_valid/*
|
!tests/src_valid/*
|
||||||
|
pdfid.py
|
||||||
|
# Plugins are pdfid stuff
|
||||||
|
plugin_*
|
||||||
|
|
|
@ -477,6 +477,7 @@ class KittenGroomerFileCheck(KittenGroomerBase):
|
||||||
|
|
||||||
def process_dir(self, src_dir, dst_dir):
|
def process_dir(self, src_dir, dst_dir):
|
||||||
"""Main function coordinating file processing."""
|
"""Main function coordinating file processing."""
|
||||||
|
self.logger.tree(src_dir)
|
||||||
for srcpath in self.list_all_files(src_dir):
|
for srcpath in self.list_all_files(src_dir):
|
||||||
dstpath = srcpath.replace(src_dir, dst_dir)
|
dstpath = srcpath.replace(src_dir, dst_dir)
|
||||||
# TODO: Can we clean up the way we handle relative_path?
|
# TODO: Can we clean up the way we handle relative_path?
|
||||||
|
@ -509,12 +510,12 @@ class KittenGroomerFileCheck(KittenGroomerBase):
|
||||||
file.make_dangerous('Archive bomb')
|
file.make_dangerous('Archive bomb')
|
||||||
else:
|
else:
|
||||||
tempdir_path = file.make_tempdir()
|
tempdir_path = file.make_tempdir()
|
||||||
|
# TODO: double check we are properly escaping file.src_path
|
||||||
|
# otherwise we are running unvalidated user input directly in the shell
|
||||||
command_str = '{} -p1 x "{}" -o"{}" -bd -aoa'
|
command_str = '{} -p1 x "{}" -o"{}" -bd -aoa'
|
||||||
unpack_command = command_str.format(SEVENZ_PATH,
|
unpack_command = command_str.format(SEVENZ_PATH,
|
||||||
file.src_path, tempdir_path)
|
file.src_path, tempdir_path)
|
||||||
self._run_process(unpack_command)
|
self._run_process(unpack_command)
|
||||||
# LOG: check that tree is working correctly here
|
|
||||||
self.logger.tree(tempdir_path)
|
|
||||||
self.process_dir(tempdir_path, file.dst_path)
|
self.process_dir(tempdir_path, file.dst_path)
|
||||||
self.safe_rmtree(tempdir_path)
|
self.safe_rmtree(tempdir_path)
|
||||||
self.recursive_archive_depth -= 1
|
self.recursive_archive_depth -= 1
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
import shutil
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
|
@ -20,25 +21,27 @@ skipif_nodeps = pytest.mark.skipif(NODEPS,
|
||||||
class TestIntegration:
|
class TestIntegration:
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def src_valid(self):
|
def src_valid_path(self):
|
||||||
return os.path.join(os.getcwd(), 'tests/src_valid')
|
return os.path.join(os.getcwd(), 'tests/src_valid')
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def src_invalid(self):
|
def src_invalid_path(self):
|
||||||
return os.path.join(os.getcwd(), 'tests/src_invalid')
|
return os.path.join(os.getcwd(), 'tests/src_invalid')
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def dst(self):
|
def dst(self):
|
||||||
return os.path.join(os.getcwd(), 'tests/dst')
|
return os.path.join(os.getcwd(), 'tests/dst')
|
||||||
|
|
||||||
def test_filecheck(self, src_invalid, dst):
|
def test_filecheck_src_invalid(self, src_invalid_path):
|
||||||
groomer = KittenGroomerFileCheck(src_invalid, dst, debug=True)
|
dst_path = self.make_dst_dir_path(src_invalid_path)
|
||||||
|
groomer = KittenGroomerFileCheck(src_invalid_path, dst_path, debug=True)
|
||||||
groomer.run()
|
groomer.run()
|
||||||
test_description = "filecheck_invalid"
|
test_description = "filecheck_invalid"
|
||||||
save_logs(groomer, test_description)
|
save_logs(groomer, test_description)
|
||||||
|
|
||||||
def test_filecheck_2(self, src_valid, dst):
|
def test_filecheck_2(self, src_valid_path):
|
||||||
groomer = KittenGroomerFileCheck(src_valid, dst, debug=True)
|
dst_path = self.make_dst_dir_path(src_valid_path)
|
||||||
|
groomer = KittenGroomerFileCheck(src_valid_path, dst_path, debug=True)
|
||||||
groomer.run()
|
groomer.run()
|
||||||
test_description = "filecheck_valid"
|
test_description = "filecheck_valid"
|
||||||
save_logs(groomer, test_description)
|
save_logs(groomer, test_description)
|
||||||
|
@ -46,8 +49,18 @@ class TestIntegration:
|
||||||
def test_processdir(self):
|
def test_processdir(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
def test_handle_archives(self):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def make_dst_dir_path(self, src_dir_path):
|
||||||
|
dst_path = src_dir_path + '_dst'
|
||||||
|
shutil.rmtree(dst_path, ignore_errors=True)
|
||||||
|
os.makedirs(dst_path, exist_ok=True)
|
||||||
|
return dst_path
|
||||||
|
|
||||||
|
|
||||||
class TestFileHandling:
|
class TestFileHandling:
|
||||||
def test_autorun(self):
|
def test_autorun(self):
|
||||||
# Run on a single autorun file, confirm that it gets flagged as dangerous
|
# Run on a single autorun file, confirm that it gets flagged as dangerous
|
||||||
|
# TODO: build out these and other methods for individual file cases
|
||||||
pass
|
pass
|
||||||
|
|
Loading…
Reference in New Issue