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
|
||||
tests/dst/*
|
||||
tests/*_dst
|
||||
tests/test_logs/*
|
||||
!tests/**/.keepdir
|
||||
!tests/src_invalid/*
|
||||
!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):
|
||||
"""Main function coordinating file processing."""
|
||||
self.logger.tree(src_dir)
|
||||
for srcpath in self.list_all_files(src_dir):
|
||||
dstpath = srcpath.replace(src_dir, dst_dir)
|
||||
# TODO: Can we clean up the way we handle relative_path?
|
||||
|
@ -509,12 +510,12 @@ class KittenGroomerFileCheck(KittenGroomerBase):
|
|||
file.make_dangerous('Archive bomb')
|
||||
else:
|
||||
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'
|
||||
unpack_command = command_str.format(SEVENZ_PATH,
|
||||
file.src_path, tempdir_path)
|
||||
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.safe_rmtree(tempdir_path)
|
||||
self.recursive_archive_depth -= 1
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
import os
|
||||
import shutil
|
||||
|
||||
import pytest
|
||||
|
||||
|
@ -20,25 +21,27 @@ skipif_nodeps = pytest.mark.skipif(NODEPS,
|
|||
class TestIntegration:
|
||||
|
||||
@pytest.fixture
|
||||
def src_valid(self):
|
||||
def src_valid_path(self):
|
||||
return os.path.join(os.getcwd(), 'tests/src_valid')
|
||||
|
||||
@pytest.fixture
|
||||
def src_invalid(self):
|
||||
def src_invalid_path(self):
|
||||
return os.path.join(os.getcwd(), 'tests/src_invalid')
|
||||
|
||||
@pytest.fixture
|
||||
def dst(self):
|
||||
return os.path.join(os.getcwd(), 'tests/dst')
|
||||
|
||||
def test_filecheck(self, src_invalid, dst):
|
||||
groomer = KittenGroomerFileCheck(src_invalid, dst, debug=True)
|
||||
def test_filecheck_src_invalid(self, src_invalid_path):
|
||||
dst_path = self.make_dst_dir_path(src_invalid_path)
|
||||
groomer = KittenGroomerFileCheck(src_invalid_path, dst_path, debug=True)
|
||||
groomer.run()
|
||||
test_description = "filecheck_invalid"
|
||||
save_logs(groomer, test_description)
|
||||
|
||||
def test_filecheck_2(self, src_valid, dst):
|
||||
groomer = KittenGroomerFileCheck(src_valid, dst, debug=True)
|
||||
def test_filecheck_2(self, src_valid_path):
|
||||
dst_path = self.make_dst_dir_path(src_valid_path)
|
||||
groomer = KittenGroomerFileCheck(src_valid_path, dst_path, debug=True)
|
||||
groomer.run()
|
||||
test_description = "filecheck_valid"
|
||||
save_logs(groomer, test_description)
|
||||
|
@ -46,8 +49,18 @@ class TestIntegration:
|
|||
def test_processdir(self):
|
||||
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:
|
||||
def test_autorun(self):
|
||||
# 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
|
||||
|
|
Loading…
Reference in New Issue