OLD | NEW |
1 #!/usr/bin/python | 1 #!/usr/bin/python |
2 # -*- coding: utf-8 -*- | 2 # -*- coding: utf-8 -*- |
3 """Tests for the Linux preprocess plug-ins.""" | 3 """Tests for the Linux preprocess plug-ins.""" |
4 | 4 |
5 import unittest | 5 import unittest |
6 | 6 |
7 from dfvfs.helpers import fake_file_system_builder | 7 from dfvfs.helpers import fake_file_system_builder |
8 from dfvfs.path import fake_path_spec | 8 from dfvfs.path import fake_path_spec |
9 | 9 |
10 from plaso.preprocessors import linux | 10 from plaso.preprocessors import linux |
11 | 11 |
12 from tests.preprocessors import test_lib | 12 from tests.preprocessors import test_lib |
13 | 13 |
14 | 14 |
15 class LinuxHostnamePreprocessPluginTest(test_lib.PreprocessPluginTestCase): | 15 class LinuxHostnamePluginTest(test_lib.ArtifactPreprocessorPluginTestCase): |
16 """Tests for the Linux hostname preprocess plug-in object.""" | 16 """Tests for the Linux hostname plugin.""" |
17 | 17 |
18 _FILE_DATA = 'plaso.kiddaland.net\n' | 18 _FILE_DATA = b'plaso.kiddaland.net\n' |
19 | 19 |
20 def testRun(self): | 20 def testParseFileData(self): |
21 """Tests the Run function.""" | 21 """Tests the _ParseFileData function.""" |
22 file_system_builder = fake_file_system_builder.FakeFileSystemBuilder() | 22 file_system_builder = fake_file_system_builder.FakeFileSystemBuilder() |
23 file_system_builder.AddFile(u'/etc/hostname', self._FILE_DATA) | 23 file_system_builder.AddFile(u'/etc/hostname', self._FILE_DATA) |
24 | 24 |
25 mount_point = fake_path_spec.FakePathSpec(location=u'/') | 25 mount_point = fake_path_spec.FakePathSpec(location=u'/') |
26 | 26 |
27 plugin = linux.LinuxHostnamePreprocessPlugin() | 27 plugin = linux.LinuxHostnamePlugin() |
28 knowledge_base = self._RunFileSystemPlugin( | 28 knowledge_base = self._RunPreprocessorPluginOnFileSystem( |
29 file_system_builder.file_system, mount_point, plugin) | 29 file_system_builder.file_system, mount_point, plugin) |
30 | 30 |
31 self.assertEqual(knowledge_base.hostname, u'plaso.kiddaland.net') | 31 self.assertEqual(knowledge_base.hostname, u'plaso.kiddaland.net') |
32 | 32 |
33 | 33 |
34 class LinuxTimeZonePreprocessPluginTest(test_lib.PreprocessPluginTestCase): | 34 class LinuxTimeZonePluginTest(test_lib.ArtifactPreprocessorPluginTestCase): |
35 """Test for the Linux timezone preprocess plug-in object.""" | 35 """Tests for the Linux time zone plugin.""" |
36 | 36 |
37 _FILE_DATA = 'Europe/Zurich\n' | 37 _FILE_DATA = b'Europe/Zurich\n' |
38 | 38 |
39 def testRun(self): | 39 def testParseFileData(self): |
40 """Test the Run function.""" | 40 """Tests the _ParseFileData function.""" |
41 file_system_builder = fake_file_system_builder.FakeFileSystemBuilder() | 41 file_system_builder = fake_file_system_builder.FakeFileSystemBuilder() |
42 file_system_builder.AddFile(u'/etc/timezone', self._FILE_DATA) | 42 file_system_builder.AddFile(u'/etc/timezone', self._FILE_DATA) |
43 | 43 |
44 mount_point = fake_path_spec.FakePathSpec(location=u'/') | 44 mount_point = fake_path_spec.FakePathSpec(location=u'/') |
45 | 45 |
46 plugin = linux.LinuxTimeZonePreprocessPlugin() | 46 plugin = linux.LinuxTimeZonePlugin() |
47 knowledge_base = self._RunFileSystemPlugin( | 47 knowledge_base = self._RunPreprocessorPluginOnFileSystem( |
48 file_system_builder.file_system, mount_point, plugin) | 48 file_system_builder.file_system, mount_point, plugin) |
49 | 49 |
50 self.assertEqual(knowledge_base.timezone.zone, u'Europe/Zurich') | 50 self.assertEqual(knowledge_base.timezone.zone, u'Europe/Zurich') |
51 | 51 |
52 | 52 |
53 class LinuxUserAccountsPreprocessPluginTest(test_lib.PreprocessPluginTestCase): | 53 class LinuxUserAccountsPluginTest(test_lib.ArtifactPreprocessorPluginTestCase): |
54 """Tests for the Linux usernames preprocess plug-in object.""" | 54 """Tests for the Linux user accounts plugin.""" |
55 | 55 |
56 _FILE_DATA = ( | 56 _FILE_DATA = ( |
57 'root:x:0:0:root:/root:/bin/bash\n' | 57 b'root:x:0:0:root:/root:/bin/bash\n' |
58 'bin:x:1:1:bin:/bin:/sbin/nologin\n' | 58 b'bin:x:1:1:bin:/bin:/sbin/nologin\n' |
59 'daemon:x:2:2:daemon:/sbin:/sbin/nologin\n' | 59 b'daemon:x:2:2:daemon:/sbin:/sbin/nologin\n' |
60 'adm:x:3:4:adm:/var/adm:/sbin/nologin\n' | 60 b'adm:x:3:4:adm:/var/adm:/sbin/nologin\n' |
61 'lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin\n' | 61 b'lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin\n' |
62 'sync:x:5:0:sync:/sbin:/bin/sync\n' | 62 b'sync:x:5:0:sync:/sbin:/bin/sync\n' |
63 'shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown\n' | 63 b'shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown\n' |
64 'halt:x:7:0:halt:/sbin:/sbin/halt\n' | 64 b'halt:x:7:0:halt:/sbin:/sbin/halt\n' |
65 'mail:x:8:12:mail:/var/spool/mail:/sbin/nologin\n' | 65 b'mail:x:8:12:mail:/var/spool/mail:/sbin/nologin\n' |
66 'operator:x:11:0:operator:/root:/sbin/nologin\n' | 66 b'operator:x:11:0:operator:/root:/sbin/nologin\n' |
67 'games:x:12:100:games:/usr/games:/sbin/nologin\n' | 67 b'games:x:12:100:games:/usr/games:/sbin/nologin\n' |
68 'ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin\n' | 68 b'ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin\n' |
69 'nobody:x:99:99:Nobody:/:/sbin/nologin\n') | 69 b'nobody:x:99:99:Nobody:/:/sbin/nologin\n') |
70 | 70 |
71 def testRun(self): | 71 def testParseFileData(self): |
72 """Tests the Run function.""" | 72 """Tests the _ParseFileData function.""" |
73 file_system_builder = fake_file_system_builder.FakeFileSystemBuilder() | 73 file_system_builder = fake_file_system_builder.FakeFileSystemBuilder() |
74 file_system_builder.AddFile(u'/etc/passwd', self._FILE_DATA) | 74 file_system_builder.AddFile(u'/etc/passwd', self._FILE_DATA) |
75 | 75 |
76 mount_point = fake_path_spec.FakePathSpec(location=u'/') | 76 mount_point = fake_path_spec.FakePathSpec(location=u'/') |
77 | 77 |
78 plugin = linux.LinuxUserAccountsPreprocessPlugin() | 78 plugin = linux.LinuxUserAccountsPlugin() |
79 knowledge_base = self._RunFileSystemPlugin( | 79 knowledge_base = self._RunPreprocessorPluginOnFileSystem( |
80 file_system_builder.file_system, mount_point, plugin) | 80 file_system_builder.file_system, mount_point, plugin) |
81 | 81 |
82 users = sorted( | 82 users = sorted( |
83 knowledge_base.user_accounts, | 83 knowledge_base.user_accounts, |
84 key=lambda user_account: user_account.identifier) | 84 key=lambda user_account: user_account.identifier) |
85 self.assertEqual(len(users), 13) | 85 self.assertEqual(len(users), 13) |
86 | 86 |
87 user_account = users[4] | 87 user_account = users[4] |
88 | 88 |
89 self.assertEqual(user_account.identifier, u'14') | 89 self.assertEqual(user_account.identifier, u'14') |
90 self.assertEqual(user_account.group_identifier, u'50') | 90 self.assertEqual(user_account.group_identifier, u'50') |
91 self.assertEqual(user_account.user_directory, u'/var/ftp') | 91 self.assertEqual(user_account.user_directory, u'/var/ftp') |
92 self.assertEqual(user_account.username, u'ftp') | 92 self.assertEqual(user_account.username, u'ftp') |
93 self.assertEqual(user_account.shell, u'/sbin/nologin') | 93 self.assertEqual(user_account.shell, u'/sbin/nologin') |
94 | 94 |
95 | 95 |
96 if __name__ == '__main__': | 96 if __name__ == '__main__': |
97 unittest.main() | 97 unittest.main() |
OLD | NEW |