def test_convert_autosave(self): filename = '~$autosave.docx' self.copy_file(filename) issue_dir = self.outpath('issue') target_dir = self.outpath('testfiles') self.assertEqual((0, 0), process_folder(issue_dir, target_dir)) self.assertFalse(os.path.exists(target_dir + os.path.sep + filename))
def test_convert_rar_password(self): filename = 'rar_password.rar' expected = 'rar_password.rar.txt' self.copy_file(filename) issue_dir = self.outpath('issue') target_dir = self.outpath('testfiles') self.assertEqual((0, 1), process_folder(issue_dir, target_dir)) self.assertFalse(os.path.exists(target_dir + os.path.sep + filename)) self.assertTrue(os.path.exists(target_dir + os.path.sep + expected))
def test_convert_msg_malicious(self): filename = 'malicious_attachment.msg' expected = 'malicious_attachment.pdf' self.copy_file(filename) issue_dir = self.outpath('issue') target_dir = self.outpath('testfiles') self.assertEqual((1, 0), process_folder(issue_dir, target_dir)) self.assertFalse(os.path.exists(target_dir + os.path.sep + filename)) self.assertTrue(os.path.exists(target_dir + os.path.sep + expected)) self.assertTrue(os.path.exists(target_dir + os.path.sep + 'malicious_attachment.doc.docx'))
def run_test(self, filename, expected, result=(1, 0), check_file=True, check_magic=True): self.copy_file(filename) issue_dir = self.outpath('issue') target_dir = self.outpath('testfiles') self.assertEqual(result, process_folder(issue_dir, target_dir)) if check_file: self.assertFalse(os.path.exists(target_dir + os.path.sep + filename)) self.assertTrue(os.path.exists(target_dir + os.path.sep + expected)) if check_magic: self.assertTrue(ZIP_FILE_MAGIC in get_magic(target_dir + os.path.sep + expected))
def test_convert_rar_space(self): filename = 'rar_space .rar' expected = 'rar_space.zip' self.copy_file(filename) issue_dir = self.outpath('issue') target_dir = self.outpath('testfiles') self.assertEqual((1, 0), process_folder(issue_dir, target_dir)) self.assertFalse(os.path.exists(target_dir + os.path.sep + 'doc')) self.assertTrue(os.path.exists(target_dir + os.path.sep + expected)) zip = zipfile.ZipFile(target_dir + os.path.sep + expected) self.assertFalse('doc.doc' in zip.namelist()) self.assertTrue('doc.docx' in zip.namelist())