summaryrefslogtreecommitdiff
path: root/tests/test_corrupted_files.py
diff options
context:
space:
mode:
authorjvoisin2019-04-27 22:33:54 +0200
committerjvoisin2019-04-27 22:48:40 +0200
commita7ebb587e19ce1177a7ef067e2da74e4964ff19e (patch)
tree63d140b6748243dbef4e8bff191ed48f40e069d4 /tests/test_corrupted_files.py
parent14a4cddb8b0d68aa90facf8452a09c81125d8570 (diff)
Handle weird permissions in tar archives
Diffstat (limited to 'tests/test_corrupted_files.py')
-rw-r--r--tests/test_corrupted_files.py26
1 files changed, 25 insertions, 1 deletions
diff --git a/tests/test_corrupted_files.py b/tests/test_corrupted_files.py
index 1331f1c..b7240fe 100644
--- a/tests/test_corrupted_files.py
+++ b/tests/test_corrupted_files.py
@@ -293,7 +293,7 @@ class TestCorruptedFiles(unittest.TestCase):
293 os.remove('./tests/data/clean.epub') 293 os.remove('./tests/data/clean.epub')
294 294
295 def test_tar(self): 295 def test_tar(self):
296 with tarfile.TarFile('./tests/data/clean.tar', 'w') as zout: 296 with tarfile.TarFile.open('./tests/data/clean.tar', 'w') as zout:
297 zout.add('./tests/data/dirty.flac') 297 zout.add('./tests/data/dirty.flac')
298 zout.add('./tests/data/dirty.docx') 298 zout.add('./tests/data/dirty.docx')
299 zout.add('./tests/data/dirty.jpg') 299 zout.add('./tests/data/dirty.jpg')
@@ -302,6 +302,7 @@ class TestCorruptedFiles(unittest.TestCase):
302 tarinfo.mtime = time.time() 302 tarinfo.mtime = time.time()
303 tarinfo.uid = 1337 303 tarinfo.uid = 1337
304 tarinfo.gid = 1338 304 tarinfo.gid = 1338
305 tarinfo.size = os.stat('./tests/data/dirty.png').st_size
305 with open('./tests/data/dirty.png', 'rb') as f: 306 with open('./tests/data/dirty.png', 'rb') as f:
306 zout.addfile(tarinfo, f) 307 zout.addfile(tarinfo, f)
307 p, mimetype = parser_factory.get_parser('./tests/data/clean.tar') 308 p, mimetype = parser_factory.get_parser('./tests/data/clean.tar')
@@ -316,3 +317,26 @@ class TestCorruptedFiles(unittest.TestCase):
316 with self.assertRaises(ValueError): 317 with self.assertRaises(ValueError):
317 archive.TarParser('./tests/data/clean.tar') 318 archive.TarParser('./tests/data/clean.tar')
318 os.remove('./tests/data/clean.tar') 319 os.remove('./tests/data/clean.tar')
320
321class TestReadOnlyArchiveMembers(unittest.TestCase):
322 def test_onlymember_tar(self):
323 with tarfile.open('./tests/data/clean.tar', 'w') as zout:
324 zout.add('./tests/data/dirty.png')
325 tarinfo = tarfile.TarInfo('./tests/data/dirty.jpg')
326 tarinfo.mtime = time.time()
327 tarinfo.uid = 1337
328 tarinfo.mode = 0o000
329 tarinfo.size = os.stat('./tests/data/dirty.jpg').st_size
330 with open('./tests/data/dirty.jpg', 'rb') as f:
331 zout.addfile(tarinfo=tarinfo, fileobj=f)
332 p, mimetype = parser_factory.get_parser('./tests/data/clean.tar')
333 self.assertEqual(mimetype, 'application/x-tar')
334 meta = p.get_meta()
335 self.assertEqual(meta['./tests/data/dirty.jpg']['uid'], '1337')
336 self.assertTrue(p.remove_all())
337
338 p = archive.TarParser('./tests/data/clean.cleaned.tar')
339 self.assertEqual(p.get_meta(), {})
340 os.remove('./tests/data/clean.tar')
341 os.remove('./tests/data/clean.cleaned.tar')
342