Skip to content

Commit

Permalink
tests: Start test to run all tools on all data
Browse files Browse the repository at this point in the history
In another branch I missed a bug that occurred in one of our test samples.
Avoid this by running all tools over all data
  • Loading branch information
christian-intra2net committed Nov 22, 2022
1 parent e89c678 commit 799b588
Showing 1 changed file with 62 additions and 0 deletions.
62 changes: 62 additions & 0 deletions tests/test_on_all.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
"""
Run all tools on all test data to check for regressions.
"""

import unittest

# Directory with test data, independent of current working directory
from tests.test_utils import loop_and_extract, call_and_capture, DATA_BASE_DIR


class TestOnAll(unittest.TestCase):
"""Run all tools on all test data."""

def do_test(self, module, skip_list_arg=None):
"""Helper for the tests that does the actual work."""
if skip_list_arg is None:
skip_list = []
else:
skip_list = skip_list_arg

for full_path, rel_path in loop_and_extract():
if rel_path in skip_list:
print('Run {0} on all test data: skip {1}'
.format(module, rel_path))
continue

output, return_code = call_and_capture(module, [full_path,],
accept_nonzero_exit=True)
if return_code == 0:
continue

error = '{0} returned {1} for sample {2}' \
.format(module, return_code, rel_path)
print(error)
for line in output.splitlines():
print(line.rstrip())
self.fail(error)

def test_olevba(self):
"""Run olevba on all test data"""
skip_list = ('rtfobj/issue_185.rtf.zip',
'rtfobj/issue_251.rtf',
'msodde/RTF-Spec-1.7.rtf',
'basic/encrypted.docx',
'encrypted/encrypted.doc',
'encrypted/encrypted.docm',
'encrypted/encrypted.docx',
'encrypted/encrypted.ppt',
'encrypted/encrypted.pptm',
'encrypted/encrypted.pptx',
'encrypted/encrypted.xls',
'encrypted/encrypted.xlsm',
'encrypted/encrypted.xlsx',
'encrypted/encrypted.xlsb',
)
self.do_test('olevba', skip_list)

# todo: add all the others as well

# just in case somebody calls this file as a script
if __name__ == '__main__':
unittest.main()

0 comments on commit 799b588

Please sign in to comment.