Commit bd81d785817d69d946b3449af113ac5f7f78b9c5

Authored by decalage2
2 parents 6b7a773f 180a24ba

Merge remote-tracking branch 'origin/master'

tests/ooxml/test_basic.py
@@ -39,7 +39,7 @@ class TestOOXML(unittest.TestCase): @@ -39,7 +39,7 @@ class TestOOXML(unittest.TestCase):
39 39
40 # files that are neither OLE nor xml: 40 # files that are neither OLE nor xml:
41 except_files = 'empty', 'text' 41 except_files = 'empty', 'text'
42 - except_extns = 'rtf', 'csv' 42 + except_extns = 'rtf', 'csv', 'zip'
43 43
44 # analyse all files in data dir 44 # analyse all files in data dir
45 for base_dir, _, files in os.walk(DATA_BASE_DIR): 45 for base_dir, _, files in os.walk(DATA_BASE_DIR):
tests/rtfobj/test_issue_185.py
@@ -5,7 +5,7 @@ from oletools import rtfobj @@ -5,7 +5,7 @@ from oletools import rtfobj
5 5
6 class TestRtfObjIssue185(unittest.TestCase): 6 class TestRtfObjIssue185(unittest.TestCase):
7 def test_skip_space_after_bin_control_word(self): 7 def test_skip_space_after_bin_control_word(self):
8 - data = testdata_reader.read('rtfobj/issue_185.rtf') 8 + data = testdata_reader.read_encrypted('rtfobj/issue_185.rtf.zip')
9 rtfp = rtfobj.RtfObjParser(data) 9 rtfp = rtfobj.RtfObjParser(data)
10 rtfp.parse() 10 rtfp.parse()
11 objects = rtfp.objects 11 objects = rtfp.objects
tests/test-data/rtfobj/issue_185.rtf deleted
1 -{\rt{\object\objautlink\objupdate\rsltpict\objw37542\objh829\objscalex59286\objscaley86308{\*\objclass \'77}{\*\objdata 32\bin6 FF}}}  
2 \ No newline at end of file 0 \ No newline at end of file
tests/test-data/rtfobj/issue_185.rtf.zip 0 → 100644
No preview for this file type
tests/test_utils/testdata_reader.py
1 -import os 1 +import os, sys, zipfile
2 from os.path import dirname, abspath, normpath, join 2 from os.path import dirname, abspath, normpath, join
3 from . import DATA_BASE_DIR 3 from . import DATA_BASE_DIR
4 4
  5 +ENCRYPTED_FILES_PASSWORD='infected-test'
  6 +
  7 +if sys.version_info[0] <= 2:
  8 + # Python 2.x
  9 + if sys.version_info[1] <= 6:
  10 + # Python 2.6
  11 + # use is_zipfile backported from Python 2.7:
  12 + from thirdparty.zipfile27 import is_zipfile
  13 + else:
  14 + # Python 2.7
  15 + from zipfile import is_zipfile
  16 +else:
  17 + # Python 3.x+
  18 + from zipfile import is_zipfile
  19 + ENCRYPTED_FILES_PASSWORD = ENCRYPTED_FILES_PASSWORD.encode()
5 20
6 def read(relative_path): 21 def read(relative_path):
7 - with open(join(DATA_BASE_DIR, relative_path), 'rb') as file_handle: 22 + with open(get_path_from_root(relative_path), 'rb') as file_handle:
8 return file_handle.read() 23 return file_handle.read()
  24 +
  25 +def read_encrypted(relative_path, filename=None):
  26 + z = zipfile.ZipFile(get_path_from_root(relative_path))
  27 +
  28 + if filename == None:
  29 + contents = z.read(z.namelist()[0], pwd=ENCRYPTED_FILES_PASSWORD)
  30 + else:
  31 + contents = z.read(filename, pwd=ENCRYPTED_FILES_PASSWORD)
  32 +
  33 + z.close()
  34 + return contents
  35 +
  36 +def get_path_from_root(relative_path):
  37 + return join(DATA_BASE_DIR, relative_path)
9 \ No newline at end of file 38 \ No newline at end of file