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