OLD | NEW |
1 #!/usr/bin/python | 1 #!/usr/bin/python |
2 # -*- coding: utf-8 -*- | 2 # -*- coding: utf-8 -*- |
3 """Tests for the preprocess plugins manager.""" | 3 """Tests for the preprocess plugins manager.""" |
4 | 4 |
5 import unittest | 5 import unittest |
6 | 6 |
| 7 from artifacts import reader as artifacts_reader |
| 8 from artifacts import registry as artifacts_registry |
| 9 |
| 10 from plaso.engine import knowledge_base |
7 from plaso.preprocessors import interface | 11 from plaso.preprocessors import interface |
8 from plaso.preprocessors import manager | 12 from plaso.preprocessors import manager |
9 | 13 |
| 14 from tests import test_lib as shared_test_lib |
10 | 15 |
11 class TestFileSystemPreprocessPlugin(interface.FileSystemPreprocessPlugin): | |
12 """Test file system preprocess plugin.""" | |
13 | 16 |
14 def Run(self, unused_searcher, unused_knowledge_base): | 17 class TestArtifactPreprocessorPlugin(interface.ArtifactPreprocessorPlugin): |
15 """Runs the plugin to determine the value of the preprocessing attribute. | 18 """Test artifact preprocessor plugin.""" |
| 19 |
| 20 ARTIFACT_DEFINITION_NAME = u'TestArtifactDefinition' |
| 21 |
| 22 def ParseValueData(self, unused_knowledge_base, unused_value_data): |
| 23 """Parses artifact value data for a preprocessing attribute. |
16 | 24 |
17 Args: | 25 Args: |
18 searcher (dfvfs.FileSystemSearcher): file system searcher. | |
19 knowledge_base (KnowledgeBase): to fill with preprocessing information. | 26 knowledge_base (KnowledgeBase): to fill with preprocessing information. |
| 27 value_data (object): artifact value data. |
20 """ | 28 """ |
21 return | 29 return |
22 | 30 |
23 | 31 |
24 class TestWindowsRegistryKeyPreprocessPlugin( | 32 class PreprocessPluginsManagerTest(shared_test_lib.BaseTestCase): |
25 interface.WindowsRegistryKeyPreprocessPlugin): | |
26 """Test Windows Registry key preprocess plugin.""" | |
27 | |
28 def _ParseKey(self, unused_knowledge_base, unused_registry_key): | |
29 """Parses a Windows Registry key for a preprocessing attribute. | |
30 | |
31 Args: | |
32 knowledge_base (KnowledgeBase): to fill with preprocessing information. | |
33 registry_key (WinRegistryKey): Windows Registry key. | |
34 """ | |
35 return | |
36 | |
37 | |
38 class PreprocessPluginsManagerTest(unittest.TestCase): | |
39 """Tests for the preprocess plugins manager.""" | 33 """Tests for the preprocess plugins manager.""" |
40 | 34 |
41 # pylint: disable=protected-access | 35 # pylint: disable=protected-access |
42 | 36 |
43 def testRegistrationFileSystemPreprocessPlugin(self): | 37 @shared_test_lib.skipUnlessHasTestFile([u'artifacts']) |
44 """Tests the RegisterPlugin and DeregisterPlugin functions.""" | 38 def testCollectFromFileSystem(self): |
45 number_of_plugins = len( | 39 """Tests the CollectFromFileSystem function.""" |
46 manager.PreprocessPluginsManager._file_system_plugin_classes) | 40 path = self._GetTestFilePath([u'artifacts']) |
| 41 registry = artifacts_registry.ArtifactDefinitionsRegistry() |
| 42 reader = artifacts_reader.YamlArtifactsReader() |
| 43 registry.ReadFromDirectory(reader, path) |
| 44 |
| 45 knowledge_base_object = knowledge_base.KnowledgeBase() |
| 46 |
| 47 _ = knowledge_base_object |
| 48 |
| 49 # TODO: implement. |
| 50 # manager.PreprocessPluginsManager.CollectFromFileSystem( |
| 51 # registry, knowledge_base_object, None, None) |
| 52 |
| 53 # TODO: add tests for CollectFromWindowsRegistry |
| 54 # TODO: add tests for GetNames |
| 55 |
| 56 def testRegistrationPlugin(self): |
| 57 """Tests RegisterPlugin and DeregisterPlugin functions.""" |
| 58 number_of_plugins = len(manager.PreprocessPluginsManager._plugins) |
47 | 59 |
48 manager.PreprocessPluginsManager.RegisterPlugin( | 60 manager.PreprocessPluginsManager.RegisterPlugin( |
49 TestFileSystemPreprocessPlugin) | 61 TestArtifactPreprocessorPlugin) |
50 self.assertEqual( | 62 self.assertEqual( |
51 len(manager.PreprocessPluginsManager._file_system_plugin_classes), | 63 len(manager.PreprocessPluginsManager._plugins), number_of_plugins + 1) |
52 number_of_plugins + 1) | |
53 | 64 |
54 with self.assertRaises(KeyError): | 65 with self.assertRaises(KeyError): |
55 manager.PreprocessPluginsManager.RegisterPlugin( | 66 manager.PreprocessPluginsManager.RegisterPlugin( |
56 TestFileSystemPreprocessPlugin) | 67 TestArtifactPreprocessorPlugin) |
57 | 68 |
58 manager.PreprocessPluginsManager.DeregisterPlugin( | 69 manager.PreprocessPluginsManager.DeregisterPlugin( |
59 TestFileSystemPreprocessPlugin) | 70 TestArtifactPreprocessorPlugin) |
60 self.assertEqual( | 71 self.assertEqual( |
61 len(manager.PreprocessPluginsManager._file_system_plugin_classes), | 72 len(manager.PreprocessPluginsManager._plugins), number_of_plugins) |
62 number_of_plugins) | |
63 | 73 |
64 def testRegistrationWindowsRegistryKeyPreprocessPlugin(self): | 74 # TODO: add tests for RegisterPlugins |
65 """Tests the RegisterPlugin and DeregisterPlugin functions.""" | |
66 number_of_plugins = len( | |
67 manager.PreprocessPluginsManager._registry_plugin_classes) | |
68 | 75 |
69 manager.PreprocessPluginsManager.RegisterPlugin( | 76 # TODO: add tests for RunPlugins |
70 TestWindowsRegistryKeyPreprocessPlugin) | |
71 self.assertEqual( | |
72 len(manager.PreprocessPluginsManager._registry_plugin_classes), | |
73 number_of_plugins + 1) | |
74 | |
75 with self.assertRaises(KeyError): | |
76 manager.PreprocessPluginsManager.RegisterPlugin( | |
77 TestWindowsRegistryKeyPreprocessPlugin) | |
78 | |
79 manager.PreprocessPluginsManager.DeregisterPlugin( | |
80 TestWindowsRegistryKeyPreprocessPlugin) | |
81 self.assertEqual( | |
82 len(manager.PreprocessPluginsManager._registry_plugin_classes), | |
83 number_of_plugins) | |
84 | 77 |
85 | 78 |
86 if __name__ == '__main__': | 79 if __name__ == '__main__': |
87 unittest.main() | 80 unittest.main() |
OLD | NEW |