From 5f0b3beb46d09af26107fe5f80e63ddccb127a59 Mon Sep 17 00:00:00 2001 From: jvoisin Date: Sat, 12 Oct 2019 16:13:49 -0700 Subject: Add a way to disable the sandbox Due to bubblewrap's pickiness, mat2 can now be run without a sandbox, even if bubblewrap is installed. --- tests/test_climat2.py | 31 +++++++++++++++++++++++++++---- tests/test_libmat2.py | 40 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 67 insertions(+), 4 deletions(-) (limited to 'tests') diff --git a/tests/test_climat2.py b/tests/test_climat2.py index 6cf8a39..9d816b1 100644 --- a/tests/test_climat2.py +++ b/tests/test_climat2.py @@ -20,17 +20,17 @@ class TestHelp(unittest.TestCase): def test_help(self): proc = subprocess.Popen(mat2_binary + ['--help'], stdout=subprocess.PIPE) stdout, _ = proc.communicate() - self.assertIn(b'mat2 [-h] [-V] [--unknown-members policy] [--inplace] [-v] [-l]', + self.assertIn(b'mat2 [-h] [-V] [--unknown-members policy] [--inplace] [--no-sandbox]', stdout) - self.assertIn(b'[--check-dependencies] [-L | -s]', stdout) + self.assertIn(b' [-v] [-l] [--check-dependencies] [-L | -s]', stdout) self.assertIn(b'[files [files ...]]', stdout) def test_no_arg(self): proc = subprocess.Popen(mat2_binary, stdout=subprocess.PIPE) stdout, _ = proc.communicate() - self.assertIn(b'mat2 [-h] [-V] [--unknown-members policy] [--inplace] [-v] [-l]', + self.assertIn(b'mat2 [-h] [-V] [--unknown-members policy] [--inplace] [--no-sandbox]', stdout) - self.assertIn(b'[--check-dependencies] [-L | -s]', stdout) + self.assertIn(b' [-v] [-l] [--check-dependencies] [-L | -s]', stdout) self.assertIn(b'[files [files ...]]', stdout) @@ -40,12 +40,14 @@ class TestVersion(unittest.TestCase): stdout, _ = proc.communicate() self.assertTrue(stdout.startswith(b'MAT2 ')) + class TestDependencies(unittest.TestCase): def test_dependencies(self): proc = subprocess.Popen(mat2_binary + ['--check-dependencies'], stdout=subprocess.PIPE) stdout, _ = proc.communicate() self.assertTrue(b'MAT2' in stdout) + class TestReturnValue(unittest.TestCase): def test_nonzero(self): ret = subprocess.call(mat2_binary + ['mat2'], stdout=subprocess.DEVNULL) @@ -112,6 +114,25 @@ class TestCleanMeta(unittest.TestCase): os.remove('./tests/data/clean.jpg') + def test_jpg_nosandbox(self): + shutil.copy('./tests/data/dirty.jpg', './tests/data/clean.jpg') + + proc = subprocess.Popen(mat2_binary + ['--show', '--no-sandbox', './tests/data/clean.jpg'], + stdout=subprocess.PIPE) + stdout, _ = proc.communicate() + self.assertIn(b'Comment: Created with GIMP', stdout) + + proc = subprocess.Popen(mat2_binary + ['./tests/data/clean.jpg'], + stdout=subprocess.PIPE) + stdout, _ = proc.communicate() + + proc = subprocess.Popen(mat2_binary + ['--show', './tests/data/clean.cleaned.jpg'], + stdout=subprocess.PIPE) + stdout, _ = proc.communicate() + self.assertNotIn(b'Comment: Created with GIMP', stdout) + + os.remove('./tests/data/clean.jpg') + class TestIsSupported(unittest.TestCase): def test_pdf(self): @@ -181,6 +202,7 @@ class TestGetMeta(unittest.TestCase): self.assertIn(b'i am a : various comment', stdout) self.assertIn(b'artist: jvoisin', stdout) + class TestControlCharInjection(unittest.TestCase): def test_jpg(self): proc = subprocess.Popen(mat2_binary + ['--show', './tests/data/control_chars.jpg'], @@ -242,6 +264,7 @@ class TestCommandLineParallel(unittest.TestCase): os.remove(path) os.remove('./tests/data/dirty_%d.docx' % i) + class TestInplaceCleaning(unittest.TestCase): def test_cleaning(self): shutil.copy('./tests/data/dirty.jpg', './tests/data/clean.jpg') diff --git a/tests/test_libmat2.py b/tests/test_libmat2.py index 13d861d..20e6a01 100644 --- a/tests/test_libmat2.py +++ b/tests/test_libmat2.py @@ -721,3 +721,43 @@ class TestCleaningArchives(unittest.TestCase): os.remove('./tests/data/dirty.tar.xz') os.remove('./tests/data/dirty.cleaned.tar.xz') os.remove('./tests/data/dirty.cleaned.cleaned.tar.xz') + +class TestNoSandbox(unittest.TestCase): + def test_avi_nosandbox(self): + shutil.copy('./tests/data/dirty.avi', './tests/data/clean.avi') + p = video.AVIParser('./tests/data/clean.avi') + p.sandbox = False + + meta = p.get_meta() + self.assertEqual(meta['Software'], 'MEncoder SVN-r33148-4.0.1') + + ret = p.remove_all() + self.assertTrue(ret) + + p = video.AVIParser('./tests/data/clean.cleaned.avi') + self.assertEqual(p.get_meta(), {}) + self.assertTrue(p.remove_all()) + + os.remove('./tests/data/clean.avi') + os.remove('./tests/data/clean.cleaned.avi') + os.remove('./tests/data/clean.cleaned.cleaned.avi') + + def test_png_nosandbox(self): + shutil.copy('./tests/data/dirty.png', './tests/data/clean.png') + p = images.PNGParser('./tests/data/clean.png') + p.sandbox = False + p.lightweight_cleaning = True + + meta = p.get_meta() + self.assertEqual(meta['Comment'], 'This is a comment, be careful!') + + ret = p.remove_all() + self.assertTrue(ret) + + p = images.PNGParser('./tests/data/clean.cleaned.png') + self.assertEqual(p.get_meta(), {}) + self.assertTrue(p.remove_all()) + + os.remove('./tests/data/clean.png') + os.remove('./tests/data/clean.cleaned.png') + os.remove('./tests/data/clean.cleaned.cleaned.png') -- cgit v1.3