test_basic.py
1.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
"""
Test basic functionality of olevba[3]
"""
import unittest
import sys
if sys.version_info.major <= 2:
from oletools import olevba
else:
from oletools import olevba3 as olevba
import os
from os.path import join
# Directory with test data, independent of current working directory
from tests.test_utils import DATA_BASE_DIR
class TestOlevbaBasic(unittest.TestCase):
"""Tests olevba basic functionality"""
def test_crypt_return(self):
"""
Tests that encrypted files give a certain return code.
Currently, only the encryption applied by Office 2010 (CryptoApi RC4
Encryption) is tested.
"""
CRYPT_DIR = join(DATA_BASE_DIR, 'encrypted')
CRYPT_RETURN_CODE = 9
ADD_ARGS = [], ['-d', ], ['-a', ], ['-j', ], ['-t', ]
EXCEPTIONS = ['autostart-encrypt-standardpassword.xls', # These ...
'autostart-encrypt-standardpassword.xlsm', # files ...
'autostart-encrypt-standardpassword.xlsb', # are ...
'dde-test-encrypt-standardpassword.xls', # automati...
'dde-test-encrypt-standardpassword.xlsx', # ...cally...
'dde-test-encrypt-standardpassword.xlsm', # decrypted.
'dde-test-encrypt-standardpassword.xlsb']
for filename in os.listdir(CRYPT_DIR):
if filename in EXCEPTIONS:
continue
full_name = join(CRYPT_DIR, filename)
for args in ADD_ARGS:
try:
ret_code = olevba.main(args + [full_name, ])
except SystemExit as se:
ret_code = se.code or 0 # se.code can be None
self.assertEqual(ret_code, CRYPT_RETURN_CODE,
msg='Wrong return code {} for args {}'
.format(ret_code, args + [filename, ]))
# just in case somebody calls this file as a script
if __name__ == '__main__':
unittest.main()