summaryrefslogtreecommitdiff
path: root/tests/test_corrupted_files.py
diff options
context:
space:
mode:
authorjvoisin2019-04-27 04:05:36 -0700
committerjvoisin2019-04-27 04:05:36 -0700
commit82cc822a1dc7090f7a6af977ed6d4b7b945d038a (patch)
tree8ab4dd83c074395f18e4b53730fd4a62edbffa02 /tests/test_corrupted_files.py
parent20ed5eb7d665ac9cb8b33929b4898c0a837fdb66 (diff)
Add tar archive support
Diffstat (limited to 'tests/test_corrupted_files.py')
-rw-r--r--tests/test_corrupted_files.py29
1 files changed, 27 insertions, 2 deletions
diff --git a/tests/test_corrupted_files.py b/tests/test_corrupted_files.py
index 4a16d51..1331f1c 100644
--- a/tests/test_corrupted_files.py
+++ b/tests/test_corrupted_files.py
@@ -1,13 +1,15 @@
1#!/usr/bin/env python3 1#!/usr/bin/env python3
2 2
3import unittest 3import unittest
4import time
4import shutil 5import shutil
5import os 6import os
6import logging 7import logging
7import zipfile 8import zipfile
9import tarfile
8 10
9from libmat2 import pdf, images, audio, office, parser_factory, torrent 11from libmat2 import pdf, images, audio, office, parser_factory, torrent
10from libmat2 import harmless, video, web 12from libmat2 import harmless, video, web, archive
11 13
12# No need to logging messages, should something go wrong, 14# No need to logging messages, should something go wrong,
13# the testsuite _will_ fail. 15# the testsuite _will_ fail.
@@ -278,7 +280,6 @@ class TestCorruptedFiles(unittest.TestCase):
278 p.remove_all() 280 p.remove_all()
279 os.remove('./tests/data/clean.html') 281 os.remove('./tests/data/clean.html')
280 282
281
282 def test_epub(self): 283 def test_epub(self):
283 with zipfile.ZipFile('./tests/data/clean.epub', 'w') as zout: 284 with zipfile.ZipFile('./tests/data/clean.epub', 'w') as zout:
284 zout.write('./tests/data/dirty.jpg', 'OEBPS/content.opf') 285 zout.write('./tests/data/dirty.jpg', 'OEBPS/content.opf')
@@ -291,3 +292,27 @@ class TestCorruptedFiles(unittest.TestCase):
291 self.assertFalse(p.remove_all()) 292 self.assertFalse(p.remove_all())
292 os.remove('./tests/data/clean.epub') 293 os.remove('./tests/data/clean.epub')
293 294
295 def test_tar(self):
296 with tarfile.TarFile('./tests/data/clean.tar', 'w') as zout:
297 zout.add('./tests/data/dirty.flac')
298 zout.add('./tests/data/dirty.docx')
299 zout.add('./tests/data/dirty.jpg')
300 zout.add('./tests/data/embedded_corrupted.docx')
301 tarinfo = tarfile.TarInfo(name='./tests/data/dirty.png')
302 tarinfo.mtime = time.time()
303 tarinfo.uid = 1337
304 tarinfo.gid = 1338
305 with open('./tests/data/dirty.png', 'rb') as f:
306 zout.addfile(tarinfo, f)
307 p, mimetype = parser_factory.get_parser('./tests/data/clean.tar')
308 self.assertEqual(mimetype, 'application/x-tar')
309 meta = p.get_meta()
310 self.assertEqual(meta['./tests/data/dirty.flac']['comments'], 'Thank you for using MAT !')
311 self.assertEqual(meta['./tests/data/dirty.docx']['word/media/image1.png']['Comment'], 'This is a comment, be careful!')
312 self.assertFalse(p.remove_all())
313 os.remove('./tests/data/clean.tar')
314
315 shutil.copy('./tests/data/dirty.png', './tests/data/clean.tar')
316 with self.assertRaises(ValueError):
317 archive.TarParser('./tests/data/clean.tar')
318 os.remove('./tests/data/clean.tar')