diff options
| -rw-r--r-- | libmat/archive.py | 4 | ||||
| -rw-r--r-- | libmat/exiftool.py | 4 | ||||
| -rw-r--r-- | test/test_cli.py | 24 |
3 files changed, 15 insertions, 17 deletions
diff --git a/libmat/archive.py b/libmat/archive.py index 12ca55e..cfc818d 100644 --- a/libmat/archive.py +++ b/libmat/archive.py | |||
| @@ -194,9 +194,9 @@ class ZipStripper(GenericArchiveStripper): | |||
| 194 | zinfo = zipfile.ZipInfo(item.filename, date_time=ZIP_EPOCH) | 194 | zinfo = zipfile.ZipInfo(item.filename, date_time=ZIP_EPOCH) |
| 195 | zinfo.compress_type = zipfile.ZIP_DEFLATED | 195 | zinfo.compress_type = zipfile.ZIP_DEFLATED |
| 196 | zinfo.create_system = 3 # Linux | 196 | zinfo.create_system = 3 # Linux |
| 197 | zinfo.comment = '' | 197 | zinfo.comment = b'' |
| 198 | with open(path, 'r') as f: | 198 | with open(path, 'r') as f: |
| 199 | zipout.writestr(zinfo, f.read()) | 199 | zipout.writestr(zinfo, str(f.read())) |
| 200 | # os.utime(path, (ZIP_EPOCH_SECONDS, ZIP_EPOCH_SECONDS)) | 200 | # os.utime(path, (ZIP_EPOCH_SECONDS, ZIP_EPOCH_SECONDS)) |
| 201 | # zipout.write(path, item.filename) | 201 | # zipout.write(path, item.filename) |
| 202 | zipin.close() | 202 | zipin.close() |
diff --git a/libmat/exiftool.py b/libmat/exiftool.py index efe6002..83513b4 100644 --- a/libmat/exiftool.py +++ b/libmat/exiftool.py | |||
| @@ -47,8 +47,8 @@ class ExiftoolStripper(parser.GenericParser): | |||
| 47 | field name : value | 47 | field name : value |
| 48 | field name : value | 48 | field name : value |
| 49 | """ | 49 | """ |
| 50 | output = subprocess.Popen(['exiftool', self.filename], | 50 | output = str(subprocess.Popen(['exiftool', self.filename], |
| 51 | stdout=subprocess.PIPE).communicate()[0] | 51 | stdout=subprocess.PIPE).communicate()[0]) |
| 52 | meta = {} | 52 | meta = {} |
| 53 | for i in output.split('\n')[:-1]: # chop last char ('\n') | 53 | for i in output.split('\n')[:-1]: # chop last char ('\n') |
| 54 | key = i.split(':')[0].strip() | 54 | key = i.split(':')[0].strip() |
diff --git a/test/test_cli.py b/test/test_cli.py index 9f682b9..5060a66 100644 --- a/test/test_cli.py +++ b/test/test_cli.py | |||
| @@ -55,8 +55,7 @@ class TestListcli(test.MATTest): | |||
| 55 | proc = subprocess.Popen(['mat', '-d', clean], | 55 | proc = subprocess.Popen(['mat', '-d', clean], |
| 56 | stdout=subprocess.PIPE) | 56 | stdout=subprocess.PIPE) |
| 57 | stdout, _ = proc.communicate() | 57 | stdout, _ = proc.communicate() |
| 58 | self.assertEqual(str(stdout).strip('\n'), "[+] File %s \ | 58 | self.assertIn('No harmful metadata found', str(stdout)) |
| 59 | :\nNo harmful metadata found" % clean) | ||
| 60 | 59 | ||
| 61 | def test_list_dirty(self): | 60 | def test_list_dirty(self): |
| 62 | """check if get_meta returns all the expected meta""" | 61 | """check if get_meta returns all the expected meta""" |
| @@ -64,8 +63,7 @@ class TestListcli(test.MATTest): | |||
| 64 | proc = subprocess.Popen(['mat', '-d', dirty], | 63 | proc = subprocess.Popen(['mat', '-d', dirty], |
| 65 | stdout=subprocess.PIPE) | 64 | stdout=subprocess.PIPE) |
| 66 | stdout, _ = proc.communicate() | 65 | stdout, _ = proc.communicate() |
| 67 | self.assertNotEqual(str(stdout), "[+] File %s :\n No\ | 66 | self.assertNotIn('No harmful metadata found', str(stdout)) |
| 68 | harmul metadata found" % dirty) | ||
| 69 | 67 | ||
| 70 | 68 | ||
| 71 | class TestisCleancli(test.MATTest): | 69 | class TestisCleancli(test.MATTest): |
| @@ -79,7 +77,7 @@ class TestisCleancli(test.MATTest): | |||
| 79 | proc = subprocess.Popen(['mat', '-c', clean], | 77 | proc = subprocess.Popen(['mat', '-c', clean], |
| 80 | stdout=subprocess.PIPE) | 78 | stdout=subprocess.PIPE) |
| 81 | stdout, _ = proc.communicate() | 79 | stdout, _ = proc.communicate() |
| 82 | self.assertEqual(str(stdout).strip('\n'), '[+] %s is clean' % clean) | 80 | self.assertIn('is clean', str(stdout)) |
| 83 | 81 | ||
| 84 | def test_dirty(self): | 82 | def test_dirty(self): |
| 85 | """test is_clean on dirty files""" | 83 | """test is_clean on dirty files""" |
| @@ -87,7 +85,7 @@ class TestisCleancli(test.MATTest): | |||
| 87 | proc = subprocess.Popen(['mat', '-c', dirty], | 85 | proc = subprocess.Popen(['mat', '-c', dirty], |
| 88 | stdout=subprocess.PIPE) | 86 | stdout=subprocess.PIPE) |
| 89 | stdout, _ = proc.communicate() | 87 | stdout, _ = proc.communicate() |
| 90 | self.assertEqual(str(stdout).strip('\n'), '[+] %s is not clean' % dirty) | 88 | self.assertIn('is not clean', str(stdout)) |
| 91 | 89 | ||
| 92 | 90 | ||
| 93 | class TestFileAttributes(unittest.TestCase): | 91 | class TestFileAttributes(unittest.TestCase): |
| @@ -100,20 +98,20 @@ class TestFileAttributes(unittest.TestCase): | |||
| 100 | proc = subprocess.Popen(['mat', 'not_writtable'], | 98 | proc = subprocess.Popen(['mat', 'not_writtable'], |
| 101 | stdout=subprocess.PIPE) | 99 | stdout=subprocess.PIPE) |
| 102 | stdout, _ = proc.communicate() | 100 | stdout, _ = proc.communicate() |
| 103 | self.assertEqual(str(stdout).strip('\n'), '[-] Unable to process not_writtable') | 101 | self.assertIn('[-] Unable to process not_writtable', str(stdout)) |
| 104 | 102 | ||
| 105 | def test_not_exist(self): | 103 | def test_not_exist(self): |
| 106 | """ test MAT's behaviour on non-existent file""" | 104 | """ test MAT's behaviour on non-existent file""" |
| 107 | proc = subprocess.Popen(['mat', 'ilikecookies'], | 105 | proc = subprocess.Popen(['mat', 'ilikecookies'], |
| 108 | stdout=subprocess.PIPE) | 106 | stdout=subprocess.PIPE) |
| 109 | stdout, _ = proc.communicate() | 107 | stdout, _ = proc.communicate() |
| 110 | self.assertEqual(str(stdout).strip('\n'), '[-] Unable to process ilikecookies') | 108 | self.assertIn('[-] Unable to process ilikecookies', str(stdout)) |
| 111 | 109 | ||
| 112 | def test_empty(self): | 110 | def test_empty(self): |
| 113 | """ test MAT's behaviour on empty file""" | 111 | """ test MAT's behaviour on empty file""" |
| 114 | proc = subprocess.Popen(['mat', 'empty_file'], stdout=subprocess.PIPE) | 112 | proc = subprocess.Popen(['mat', 'empty_file'], stdout=subprocess.PIPE) |
| 115 | stdout, _ = proc.communicate() | 113 | stdout, _ = proc.communicate() |
| 116 | self.assertEqual(str(stdout).strip('\n'), '[-] Unable to process empty_file') | 114 | self.assertIn('[-] Unable to process empty_file', str(stdout) ) |
| 117 | 115 | ||
| 118 | def test_not_readable(self): | 116 | def test_not_readable(self): |
| 119 | """ test MAT's behaviour on non-writable file""" | 117 | """ test MAT's behaviour on non-writable file""" |
| @@ -147,23 +145,23 @@ class TestHelp(test.MATTest): | |||
| 147 | """ test help invocation with `-h` and `--help` """ | 145 | """ test help invocation with `-h` and `--help` """ |
| 148 | proc = subprocess.Popen(['mat', '-h'], stdout=subprocess.PIPE) | 146 | proc = subprocess.Popen(['mat', '-h'], stdout=subprocess.PIPE) |
| 149 | stdout, _ = proc.communicate() | 147 | stdout, _ = proc.communicate() |
| 150 | self.assertTrue('show this help message and exit' in stdout) | 148 | self.assertIn('show this help message and exit', str(stdout)) |
| 151 | 149 | ||
| 152 | proc = subprocess.Popen(['mat', '--help'], stdout=subprocess.PIPE) | 150 | proc = subprocess.Popen(['mat', '--help'], stdout=subprocess.PIPE) |
| 153 | stdout, _ = proc.communicate() | 151 | stdout, _ = proc.communicate() |
| 154 | self.assertTrue('show this help message and exit' in stdout) | 152 | self.assertIn('show this help message and exit', str(stdout)) |
| 155 | 153 | ||
| 156 | def test_no_argument(self): | 154 | def test_no_argument(self): |
| 157 | """ test help invocation when no argument is provided """ | 155 | """ test help invocation when no argument is provided """ |
| 158 | proc = subprocess.Popen(['mat'], stdout=subprocess.PIPE) | 156 | proc = subprocess.Popen(['mat'], stdout=subprocess.PIPE) |
| 159 | stdout, _ = proc.communicate() | 157 | stdout, _ = proc.communicate() |
| 160 | self.assertTrue('show this help message and exit' in stdout) | 158 | self.assertIn('show this help message and exit', str(stdout)) |
| 161 | 159 | ||
| 162 | def test_wrong_argument(self): | 160 | def test_wrong_argument(self): |
| 163 | """ Test MAT's behaviour on wrong argument """ | 161 | """ Test MAT's behaviour on wrong argument """ |
| 164 | proc = subprocess.Popen(['mat', '--obviously-wrong-argument'], stderr=subprocess.PIPE) | 162 | proc = subprocess.Popen(['mat', '--obviously-wrong-argument'], stderr=subprocess.PIPE) |
| 165 | _, stderr = proc.communicate() | 163 | _, stderr = proc.communicate() |
| 166 | self.assertTrue(('usage: mat [-h]' and ' error: unrecognized arguments:') in stderr) | 164 | self.assertIn(('usage: mat [-h]' and ' error: unrecognized arguments:'), str(stderr)) |
| 167 | 165 | ||
| 168 | 166 | ||
| 169 | def get_tests(): | 167 | def get_tests(): |
