LEFT | RIGHT |
(no file at all) | |
1 #!/usr/bin/python | 1 #!/usr/bin/python |
2 # -*- coding: utf-8 -*- | 2 # -*- coding: utf-8 -*- |
3 """Tests for the Mac OS X preprocess plug-ins.""" | 3 """Tests for the MacOS 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 macosx | 10 from plaso.preprocessors import macos |
11 | 11 |
12 from tests import test_lib as shared_test_lib | 12 from tests import test_lib as shared_test_lib |
13 from tests.preprocessors import test_lib | 13 from tests.preprocessors import test_lib |
14 | 14 |
15 | 15 |
16 class MacOSXHostnamePreprocessPluginTest(test_lib.PreprocessPluginTestCase): | 16 class MacOSHostnamePluginTest(test_lib.ArtifactPreprocessorPluginTestCase): |
17 """Tests for the Mac OS X hostname preprocess plug-in object.""" | 17 """Tests for the MacOS hostname plugin.""" |
18 | 18 |
19 # Note that is only part of the normal preferences.plist file data. | 19 # Note that is only part of the normal preferences.plist file data. |
20 _FILE_DATA = ( | 20 _FILE_DATA = ( |
21 '<?xml version="1.0" encoding="UTF-8"?>\n' | 21 b'<?xml version="1.0" encoding="UTF-8"?>\n' |
22 '<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" ' | 22 b'<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" ' |
23 '"http://www.apple.com/DTDs/PropertyList-1.0.dtd">\n' | 23 b'"http://www.apple.com/DTDs/PropertyList-1.0.dtd">\n' |
24 '<plist version="1.0">\n' | 24 b'<plist version="1.0">\n' |
25 '<dict>\n' | 25 b'<dict>\n' |
26 '\t<key>System</key>\n' | 26 b'\t<key>System</key>\n' |
27 '\t<dict>\n' | 27 b'\t<dict>\n' |
28 '\t\t<key>Network</key>\n' | 28 b'\t\t<key>Network</key>\n' |
29 '\t\t<dict>\n' | 29 b'\t\t<dict>\n' |
30 '\t\t\t<key>HostNames</key>\n' | 30 b'\t\t\t<key>HostNames</key>\n' |
31 '\t\t\t<dict>\n' | 31 b'\t\t\t<dict>\n' |
32 '\t\t\t\t<key>LocalHostName</key>\n' | 32 b'\t\t\t\t<key>LocalHostName</key>\n' |
33 '\t\t\t\t<string>Plaso\'s Mac mini</string>\n' | 33 b'\t\t\t\t<string>Plaso\'s Mac mini</string>\n' |
34 '\t\t\t</dict>\n' | 34 b'\t\t\t</dict>\n' |
35 '\t\t</dict>\n' | 35 b'\t\t</dict>\n' |
36 '\t\t<key>System</key>\n' | 36 b'\t\t<key>System</key>\n' |
37 '\t\t<dict>\n' | 37 b'\t\t<dict>\n' |
38 '\t\t\t<key>ComputerName</key>\n' | 38 b'\t\t\t<key>ComputerName</key>\n' |
39 '\t\t\t<string>Plaso\'s Mac mini</string>\n' | 39 b'\t\t\t<string>Plaso\'s Mac mini</string>\n' |
40 '\t\t\t<key>ComputerNameEncoding</key>\n' | 40 b'\t\t\t<key>ComputerNameEncoding</key>\n' |
41 '\t\t\t<integer>0</integer>\n' | 41 b'\t\t\t<integer>0</integer>\n' |
42 '\t\t</dict>\n' | 42 b'\t\t</dict>\n' |
43 '\t</dict>\n' | 43 b'\t</dict>\n' |
44 '</dict>\n' | 44 b'</dict>\n' |
45 '</plist>\n') | 45 b'</plist>\n') |
46 | 46 |
47 def testRun(self): | 47 def testParsePlistKeyValue(self): |
48 """Tests the Run function.""" | 48 """Tests the _ParsePlistKeyValue function.""" |
49 file_system_builder = fake_file_system_builder.FakeFileSystemBuilder() | 49 file_system_builder = fake_file_system_builder.FakeFileSystemBuilder() |
50 file_system_builder.AddFile( | 50 file_system_builder.AddFile( |
51 u'/Library/Preferences/SystemConfiguration/preferences.plist', | 51 u'/Library/Preferences/SystemConfiguration/preferences.plist', |
52 self._FILE_DATA) | 52 self._FILE_DATA) |
53 | 53 |
54 mount_point = fake_path_spec.FakePathSpec(location=u'/') | 54 mount_point = fake_path_spec.FakePathSpec(location=u'/') |
55 | 55 |
56 plugin = macosx.MacOSXHostnamePreprocessPlugin() | 56 plugin = macos.MacOSHostnamePlugin() |
57 knowledge_base = self._RunFileSystemPlugin( | 57 knowledge_base = self._RunPreprocessorPluginOnFileSystem( |
58 file_system_builder.file_system, mount_point, plugin) | 58 file_system_builder.file_system, mount_point, plugin) |
59 | 59 |
60 self.assertEqual(knowledge_base.hostname, u'Plaso\'s Mac mini') | 60 self.assertEqual(knowledge_base.hostname, u'Plaso\'s Mac mini') |
61 | 61 |
62 | 62 |
63 class MacOSXKeyboardLayoutPreprocessPluginTest( | 63 class MacOSKeyboardLayoutPluginTest( |
64 test_lib.PreprocessPluginTestCase): | 64 test_lib.ArtifactPreprocessorPluginTestCase): |
65 """Tests for the Mac OS X keyboard layout preprocess plug-in object.""" | 65 """Tests for the MacOS keyboard layout plugin.""" |
66 | 66 |
67 @shared_test_lib.skipUnlessHasTestFile([u'com.apple.HIToolbox.plist']) | 67 @shared_test_lib.skipUnlessHasTestFile([u'com.apple.HIToolbox.plist']) |
68 def testRun(self): | 68 def testParsePlistKeyValue(self): |
69 """Tests the Run function.""" | 69 """Tests the _ParsePlistKeyValue function.""" |
70 file_system_builder = fake_file_system_builder.FakeFileSystemBuilder() | 70 file_system_builder = fake_file_system_builder.FakeFileSystemBuilder() |
71 test_file_path = self._GetTestFilePath([u'com.apple.HIToolbox.plist']) | 71 test_file_path = self._GetTestFilePath([u'com.apple.HIToolbox.plist']) |
72 file_system_builder.AddFileReadData( | 72 file_system_builder.AddFileReadData( |
73 u'/Library/Preferences/com.apple.HIToolbox.plist', test_file_path) | 73 u'/Library/Preferences/com.apple.HIToolbox.plist', test_file_path) |
74 | 74 |
75 mount_point = fake_path_spec.FakePathSpec(location=u'/') | 75 mount_point = fake_path_spec.FakePathSpec(location=u'/') |
76 | 76 |
77 plugin = macosx.MacOSXKeyboardLayoutPreprocessPlugin() | 77 plugin = macos.MacOSKeyboardLayoutPlugin() |
78 knowledge_base = self._RunFileSystemPlugin( | 78 knowledge_base = self._RunPreprocessorPluginOnFileSystem( |
79 file_system_builder.file_system, mount_point, plugin) | 79 file_system_builder.file_system, mount_point, plugin) |
80 | 80 |
81 keyboard_layout = knowledge_base.GetValue('keyboard_layout') | 81 keyboard_layout = knowledge_base.GetValue('keyboard_layout') |
82 self.assertEqual(keyboard_layout, u'US') | 82 self.assertEqual(keyboard_layout, u'US') |
83 | 83 |
84 | 84 |
85 class MacOSXSystemVersionPreprocessPluginTest( | 85 class MacOSSystemVersionPluginTest(test_lib.ArtifactPreprocessorPluginTestCase): |
86 test_lib.PreprocessPluginTestCase): | 86 """Tests for the MacOS system version information plugin.""" |
87 """Tests for the plugin to determine Mac OS X system version information.""" | |
88 | 87 |
89 _FILE_DATA = ( | 88 _FILE_DATA = ( |
90 '<?xml version="1.0" encoding="UTF-8"?>\n' | 89 b'<?xml version="1.0" encoding="UTF-8"?>\n' |
91 '<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" ' | 90 b'<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" ' |
92 '"http://www.apple.com/DTDs/PropertyList-1.0.dtd">\n' | 91 b'"http://www.apple.com/DTDs/PropertyList-1.0.dtd">\n' |
93 '<plist version="1.0">\n' | 92 b'<plist version="1.0">\n' |
94 '<dict>\n' | 93 b'<dict>\n' |
95 '\t<key>ProductBuildVersion</key>\n' | 94 b'\t<key>ProductBuildVersion</key>\n' |
96 '\t<string>13C64</string>\n' | 95 b'\t<string>13C64</string>\n' |
97 '\t<key>ProductCopyright</key>\n' | 96 b'\t<key>ProductCopyright</key>\n' |
98 '\t<string>1983-2014 Apple Inc.</string>\n' | 97 b'\t<string>1983-2014 Apple Inc.</string>\n' |
99 '\t<key>ProductName</key>\n' | 98 b'\t<key>ProductName</key>\n' |
100 '\t<string>Mac OS X</string>\n' | 99 b'\t<string>Mac OS X</string>\n' |
101 '\t<key>ProductUserVisibleVersion</key>\n' | 100 b'\t<key>ProductUserVisibleVersion</key>\n' |
102 '\t<string>10.9.2</string>\n' | 101 b'\t<string>10.9.2</string>\n' |
103 '\t<key>ProductVersion</key>\n' | 102 b'\t<key>ProductVersion</key>\n' |
104 '\t<string>10.9.2</string>\n' | 103 b'\t<string>10.9.2</string>\n' |
105 '</dict>\n' | 104 b'</dict>\n' |
106 '</plist>\n') | 105 b'</plist>\n') |
107 | 106 |
108 def testRun(self): | 107 def testParsePlistKeyValue(self): |
109 """Tests the Run function.""" | 108 """Tests the _ParsePlistKeyValue function.""" |
110 file_system_builder = fake_file_system_builder.FakeFileSystemBuilder() | 109 file_system_builder = fake_file_system_builder.FakeFileSystemBuilder() |
111 file_system_builder.AddFile( | 110 file_system_builder.AddFile( |
112 u'/System/Library/CoreServices/SystemVersion.plist', | 111 u'/System/Library/CoreServices/SystemVersion.plist', |
113 self._FILE_DATA) | 112 self._FILE_DATA) |
114 | 113 |
115 mount_point = fake_path_spec.FakePathSpec(location=u'/') | 114 mount_point = fake_path_spec.FakePathSpec(location=u'/') |
116 | 115 |
117 plugin = macosx.MacOSXSystemVersionPreprocessPlugin() | 116 plugin = macos.MacOSSystemVersionPlugin() |
118 knowledge_base = self._RunFileSystemPlugin( | 117 knowledge_base = self._RunPreprocessorPluginOnFileSystem( |
119 file_system_builder.file_system, mount_point, plugin) | 118 file_system_builder.file_system, mount_point, plugin) |
120 | 119 |
121 build = knowledge_base.GetValue(u'operating_system_version') | 120 build = knowledge_base.GetValue(u'operating_system_version') |
122 self.assertEqual(build, u'10.9.2') | 121 self.assertEqual(build, u'10.9.2') |
123 | 122 |
124 | 123 |
125 class MacOSXTimeZonePreprocessPluginTest(test_lib.PreprocessPluginTestCase): | 124 class MacOSTimeZonePluginTest(test_lib.ArtifactPreprocessorPluginTestCase): |
126 """Tests for the Mac OS X timezone preprocess plug-in object.""" | 125 """Tests for the MacOS time zone plugin.""" |
127 | 126 |
128 def testRun(self): | 127 def testParseFileEntry(self): |
129 """Tests the Run function.""" | 128 """Tests the _ParseFileEntry function.""" |
130 file_system_builder = fake_file_system_builder.FakeFileSystemBuilder() | 129 file_system_builder = fake_file_system_builder.FakeFileSystemBuilder() |
131 file_system_builder.AddSymbolicLink( | 130 file_system_builder.AddSymbolicLink( |
132 u'/private/etc/localtime', u'/usr/share/zoneinfo/Europe/Amsterdam') | 131 u'/private/etc/localtime', u'/usr/share/zoneinfo/Europe/Amsterdam') |
133 | 132 |
134 mount_point = fake_path_spec.FakePathSpec(location=u'/') | 133 mount_point = fake_path_spec.FakePathSpec(location=u'/') |
135 | 134 |
136 plugin = macosx.MacOSXTimeZonePreprocessPlugin() | 135 plugin = macos.MacOSTimeZonePlugin() |
137 knowledge_base = self._RunFileSystemPlugin( | 136 knowledge_base = self._RunPreprocessorPluginOnFileSystem( |
138 file_system_builder.file_system, mount_point, plugin) | 137 file_system_builder.file_system, mount_point, plugin) |
139 | 138 |
140 self.assertEqual(knowledge_base.timezone.zone, u'Europe/Amsterdam') | 139 self.assertEqual(knowledge_base.timezone.zone, u'Europe/Amsterdam') |
141 | 140 |
142 | 141 |
143 class MacOSXUserAccountsPreprocessPluginTest(test_lib.PreprocessPluginTestCase): | 142 class MacOSUserAccountsPluginTest(test_lib.ArtifactPreprocessorPluginTestCase): |
144 """Tests for the Mac OS X usernames preprocess plug-in object.""" | 143 """Tests for the MacOS user accounts plugin.""" |
145 | 144 |
146 # pylint: disable=protected-access | 145 # pylint: disable=protected-access |
147 | 146 |
148 @shared_test_lib.skipUnlessHasTestFile([u'nobody.plist']) | 147 @shared_test_lib.skipUnlessHasTestFile([u'nobody.plist']) |
149 def testRun(self): | 148 def testRun(self): |
150 """Tests the Run function.""" | 149 """Tests the Run function.""" |
151 file_system_builder = fake_file_system_builder.FakeFileSystemBuilder() | 150 file_system_builder = fake_file_system_builder.FakeFileSystemBuilder() |
152 test_file_path = self._GetTestFilePath([u'nobody.plist']) | 151 test_file_path = self._GetTestFilePath([u'nobody.plist']) |
153 file_system_builder.AddFileReadData( | 152 file_system_builder.AddFileReadData( |
154 u'/private/var/db/dslocal/nodes/Default/users/nobody.plist', | 153 u'/private/var/db/dslocal/nodes/Default/users/nobody.plist', |
155 test_file_path) | 154 test_file_path) |
156 | 155 |
157 mount_point = fake_path_spec.FakePathSpec(location=u'/') | 156 mount_point = fake_path_spec.FakePathSpec(location=u'/') |
158 | 157 |
159 plugin = macosx.MacOSXUserAccountsPreprocessPlugin() | 158 plugin = macos.MacOSUserAccountsPlugin() |
160 knowledge_base = self._RunFileSystemPlugin( | 159 knowledge_base = self._RunPreprocessorPluginOnFileSystem( |
161 file_system_builder.file_system, mount_point, plugin) | 160 file_system_builder.file_system, mount_point, plugin) |
162 | 161 |
163 users = sorted( | 162 users = sorted( |
164 knowledge_base.user_accounts, | 163 knowledge_base.user_accounts, |
165 key=lambda user_account: user_account.identifier) | 164 key=lambda user_account: user_account.identifier) |
166 self.assertEqual(len(users), 1) | 165 self.assertEqual(len(users), 1) |
167 | 166 |
168 user_account = users[0] | 167 user_account = users[0] |
169 | 168 |
170 self.assertEqual(user_account.identifier, u'-2') | 169 self.assertEqual(user_account.identifier, u'-2') |
171 self.assertEqual(user_account.full_name, u'Unprivileged User') | 170 self.assertEqual(user_account.full_name, u'Unprivileged User') |
172 self.assertEqual(user_account.user_directory, u'/var/empty') | 171 self.assertEqual(user_account.user_directory, u'/var/empty') |
173 self.assertEqual(user_account.username, u'nobody') | 172 self.assertEqual(user_account.username, u'nobody') |
174 | 173 |
175 | 174 |
176 if __name__ == '__main__': | 175 if __name__ == '__main__': |
177 unittest.main() | 176 unittest.main() |
LEFT | RIGHT |