Commit c2018fd86f94d91348544350073e79592363f132
1 parent
ca1940b7
tests: create unittest for olevba with encrypted input
Showing
2 changed files
with
45 additions
and
0 deletions
tests/olevba/__init__.py
0 → 100644
tests/olevba/test_basic.py
0 → 100644
| 1 | +""" | |
| 2 | +Test basic functionality of olevba[3] | |
| 3 | +""" | |
| 4 | + | |
| 5 | +import unittest | |
| 6 | +import sys | |
| 7 | +if sys.version_info.major <= 2: | |
| 8 | + from oletools import olevba | |
| 9 | +else: | |
| 10 | + from oletools import olevba3 as olevba | |
| 11 | +import os | |
| 12 | +from os.path import join | |
| 13 | + | |
| 14 | +# Directory with test data, independent of current working directory | |
| 15 | +from tests.test_utils import DATA_BASE_DIR | |
| 16 | + | |
| 17 | + | |
| 18 | +class TestOlevbaBasic(unittest.TestCase): | |
| 19 | + """Tests olevba basic functionality""" | |
| 20 | + | |
| 21 | + def test_crypt_return(self): | |
| 22 | + """ | |
| 23 | + Tests that encrypted files give a certain return code. | |
| 24 | + | |
| 25 | + Currently, only the encryption applied by Office 2010 (CryptoApi RC4 | |
| 26 | + Encryption) is tested. | |
| 27 | + """ | |
| 28 | + CRYPT_DIR = join(DATA_BASE_DIR, 'encrypted') | |
| 29 | + CRYPT_RETURN_CODE = 9 | |
| 30 | + ADD_ARGS = [], ['-d', ], ['-a', ], ['-j', ], ['-t', ] | |
| 31 | + for filename in os.listdir(CRYPT_DIR): | |
| 32 | + full_name = join(CRYPT_DIR, filename) | |
| 33 | + for args in ADD_ARGS: | |
| 34 | + try: | |
| 35 | + ret_code = olevba.main(args + [full_name, ]) | |
| 36 | + except SystemExit as se: | |
| 37 | + ret_code = se.code or 0 # se.code can be None | |
| 38 | + self.assertEqual(ret_code, CRYPT_RETURN_CODE, | |
| 39 | + msg='Wrong return code {} for args {}' | |
| 40 | + .format(ret_code, args + [filename, ])) | |
| 41 | + | |
| 42 | + | |
| 43 | +# just in case somebody calls this file as a script | |
| 44 | +if __name__ == '__main__': | |
| 45 | + unittest.main() | ... | ... |