Skip to content

Commit

Permalink
Change the way test dst dirs are handled
Browse files Browse the repository at this point in the history
* 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 directory
  • Loading branch information
dputtick committed Mar 16, 2017
1 parent 0175ee4 commit ac94cf5
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 8 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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_*
5 changes: 3 additions & 2 deletions bin/filecheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,7 @@ def __init__(self, root_src, root_dst, max_recursive_depth=2, debug=False):

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?
Expand Down Expand Up @@ -509,12 +510,12 @@ def process_archive(self, file):
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
Expand Down
Empty file removed tests/dst/.keepdir
Empty file.
25 changes: 19 additions & 6 deletions tests/test_filecheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# -*- coding: utf-8 -*-

import os
import shutil

import pytest

Expand All @@ -20,34 +21,46 @@
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)

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

0 comments on commit ac94cf5

Please sign in to comment.