OLD | NEW |
1 #!/usr/bin/python | 1 #!/usr/bin/python |
2 # -*- coding: utf-8 -*- | 2 # -*- coding: utf-8 -*- |
3 """Tests for the image export CLI tool.""" | 3 """Tests for the image export CLI tool.""" |
4 | 4 |
5 import unittest | 5 import unittest |
6 | 6 |
| 7 from plaso.cli import image_export_tool |
7 from plaso.lib import errors | 8 from plaso.lib import errors |
8 | 9 |
9 from tests import test_lib as shared_test_lib | 10 from tests import test_lib as shared_test_lib |
10 from tests.cli import test_lib as cli_test_lib | 11 from tests.cli import test_lib as test_lib |
11 | |
12 from tools import image_export | |
13 | 12 |
14 | 13 |
15 class ImageExportToolTest(cli_test_lib.CLIToolTestCase): | 14 class ImageExportToolTest(test_lib.CLIToolTestCase): |
16 """Tests for the image export CLI tool.""" | 15 """Tests for the image export CLI tool.""" |
17 | 16 |
18 # pylint: disable=protected-access | 17 # pylint: disable=protected-access |
19 | 18 |
20 def testListSignatureIdentifiers(self): | 19 def testListSignatureIdentifiers(self): |
21 """Tests the ListSignatureIdentifiers function.""" | 20 """Tests the ListSignatureIdentifiers function.""" |
22 output_writer = cli_test_lib.TestOutputWriter(encoding=u'utf-8') | 21 output_writer = test_lib.TestOutputWriter(encoding=u'utf-8') |
23 test_tool = image_export.ImageExportTool(output_writer=output_writer) | 22 test_tool = image_export_tool.ImageExportTool(output_writer=output_writer) |
24 | 23 |
25 test_tool._data_location = self._TEST_DATA_PATH | 24 test_tool._data_location = self._TEST_DATA_PATH |
26 | 25 |
27 test_tool.ListSignatureIdentifiers() | 26 test_tool.ListSignatureIdentifiers() |
28 | 27 |
29 expected_output = ( | 28 expected_output = ( |
30 b'Available signature identifiers:\n' | 29 b'Available signature identifiers:\n' |
31 b'7z, bzip2, esedb, evt, evtx, ewf_e01, ewf_l01, exe_mz, gzip, lnk, ' | 30 b'7z, bzip2, esedb, evt, evtx, ewf_e01, ewf_l01, exe_mz, gzip, lnk, ' |
32 b'msiecf, nk2,\n' | 31 b'msiecf, nk2,\n' |
33 b'olecf, olecf_beta, pdf, pff, qcow, rar, regf, tar, tar_old, ' | 32 b'olecf, olecf_beta, pdf, pff, qcow, rar, regf, tar, tar_old, ' |
34 b'vhdi_footer,\n' | 33 b'vhdi_footer,\n' |
35 b'vhdi_header, wtcdb_cache, wtcdb_index, zip\n' | 34 b'vhdi_header, wtcdb_cache, wtcdb_index, zip\n' |
36 b'\n') | 35 b'\n') |
37 | 36 |
38 output = output_writer.ReadOutput() | 37 output = output_writer.ReadOutput() |
39 | 38 |
40 # Compare the output as list of lines which makes it easier to spot | 39 # Compare the output as list of lines which makes it easier to spot |
41 # differences. | 40 # differences. |
42 self.assertEqual(output.split(b'\n'), expected_output.split(b'\n')) | 41 self.assertEqual(output.split(b'\n'), expected_output.split(b'\n')) |
43 | 42 |
44 test_tool._data_location = self._GetTestFilePath([u'tmp']) | 43 test_tool._data_location = self._GetTestFilePath([u'tmp']) |
45 | 44 |
46 with self.assertRaises(errors.BadConfigOption): | 45 with self.assertRaises(errors.BadConfigOption): |
47 test_tool.ListSignatureIdentifiers() | 46 test_tool.ListSignatureIdentifiers() |
48 | 47 |
49 def testParseArguments(self): | 48 def testParseArguments(self): |
50 """Tests the ParseArguments function.""" | 49 """Tests the ParseArguments function.""" |
51 output_writer = cli_test_lib.TestOutputWriter(encoding=u'utf-8') | 50 output_writer = test_lib.TestOutputWriter(encoding=u'utf-8') |
52 test_tool = image_export.ImageExportTool(output_writer=output_writer) | 51 test_tool = image_export_tool.ImageExportTool(output_writer=output_writer) |
53 | 52 |
54 result = test_tool.ParseArguments() | 53 result = test_tool.ParseArguments() |
55 self.assertFalse(result) | 54 self.assertFalse(result) |
56 | 55 |
57 # TODO: check output. | 56 # TODO: check output. |
58 # TODO: improve test coverage. | 57 # TODO: improve test coverage. |
59 | 58 |
60 def testParseOptions(self): | 59 def testParseOptions(self): |
61 """Tests the ParseOptions function.""" | 60 """Tests the ParseOptions function.""" |
62 output_writer = cli_test_lib.TestOutputWriter(encoding=u'utf-8') | 61 output_writer = test_lib.TestOutputWriter(encoding=u'utf-8') |
63 test_tool = image_export.ImageExportTool(output_writer=output_writer) | 62 test_tool = image_export_tool.ImageExportTool(output_writer=output_writer) |
64 | 63 |
65 options = cli_test_lib.TestOptions() | 64 options = test_lib.TestOptions() |
66 options.image = self._GetTestFilePath([u'image.qcow2']) | 65 options.image = self._GetTestFilePath([u'image.qcow2']) |
67 | 66 |
68 test_tool.ParseOptions(options) | 67 test_tool.ParseOptions(options) |
69 | 68 |
70 options = cli_test_lib.TestOptions() | 69 options = test_lib.TestOptions() |
71 | 70 |
72 with self.assertRaises(errors.BadConfigOption): | 71 with self.assertRaises(errors.BadConfigOption): |
73 test_tool.ParseOptions(options) | 72 test_tool.ParseOptions(options) |
74 | 73 |
75 # TODO: improve test coverage. | 74 # TODO: improve test coverage. |
76 | 75 |
77 # TODO: add test for PrintFilterCollection | 76 # TODO: add test for PrintFilterCollection |
78 | 77 |
79 def testProcessSourcesImage(self): | 78 def testProcessSourcesImage(self): |
80 """Tests the ProcessSources function on a single partition image.""" | 79 """Tests the ProcessSources function on a single partition image.""" |
81 output_writer = cli_test_lib.TestOutputWriter(encoding=u'utf-8') | 80 output_writer = test_lib.TestOutputWriter(encoding=u'utf-8') |
82 test_tool = image_export.ImageExportTool(output_writer=output_writer) | 81 test_tool = image_export_tool.ImageExportTool(output_writer=output_writer) |
83 | 82 |
84 options = cli_test_lib.TestOptions() | 83 options = test_lib.TestOptions() |
85 options.image = self._GetTestFilePath([u'ímynd.dd']) | 84 options.image = self._GetTestFilePath([u'ímynd.dd']) |
86 options.quiet = True | 85 options.quiet = True |
87 | 86 |
88 with shared_test_lib.TempDirectory() as temp_directory: | 87 with shared_test_lib.TempDirectory() as temp_directory: |
89 options.path = temp_directory | 88 options.path = temp_directory |
90 | 89 |
91 test_tool.ParseOptions(options) | 90 test_tool.ParseOptions(options) |
92 | 91 |
93 test_tool.ProcessSources() | 92 test_tool.ProcessSources() |
94 | 93 |
95 expected_output = b'\n'.join([ | 94 expected_output = b'\n'.join([ |
96 b'Export started.', | 95 b'Export started.', |
97 b'Extracting file entries.', | 96 b'Extracting file entries.', |
98 b'Export completed.', | 97 b'Export completed.', |
99 b'', | 98 b'', |
100 b'']) | 99 b'']) |
101 | 100 |
102 output = output_writer.ReadOutput() | 101 output = output_writer.ReadOutput() |
103 self.assertEqual(output, expected_output) | 102 self.assertEqual(output, expected_output) |
104 | 103 |
105 | 104 |
106 if __name__ == '__main__': | 105 if __name__ == '__main__': |
107 unittest.main() | 106 unittest.main() |
OLD | NEW |