def testMatches(self): """Tests the Matches function.""" test_path = self._GetTestFilePath(['ímynd.dd']) os_path_spec = path_spec_factory.Factory.NewPathSpec( dfvfs_definitions.TYPE_INDICATOR_OS, location=test_path) test_filter = file_entry_filters.NamesFileEntryFilter(['passwords.txt']) # Test a filter non-match. tsk_path_spec = path_spec_factory.Factory.NewPathSpec( dfvfs_definitions.TYPE_INDICATOR_TSK, inode=16, location='/a_directory/another_file', parent=os_path_spec) file_entry = path_spec_resolver.Resolver.OpenFileEntry(tsk_path_spec) self.assertFalse(test_filter.Matches(file_entry)) # Test a filter on a directory. tsk_path_spec = path_spec_factory.Factory.NewPathSpec( dfvfs_definitions.TYPE_INDICATOR_TSK, inode=12, location='/a_directory', parent=os_path_spec) file_entry = path_spec_resolver.Resolver.OpenFileEntry(tsk_path_spec) self.assertFalse(test_filter.Matches(file_entry)) # Test a filter match. tsk_path_spec = path_spec_factory.Factory.NewPathSpec( dfvfs_definitions.TYPE_INDICATOR_TSK, inode=15, location='/passwords.txt', parent=os_path_spec) file_entry = path_spec_resolver.Resolver.OpenFileEntry(tsk_path_spec) self.assertTrue(test_filter.Matches(file_entry)) # Test a filter without names. test_filter = file_entry_filters.NamesFileEntryFilter([]) self.assertFalse(test_filter.Matches(file_entry))
def testHasFilters(self): """Tests the HasFilters function.""" test_filter_collection = file_entry_filters.FileEntryFilterCollection() self.assertFalse(test_filter_collection.HasFilters()) test_filter_collection = file_entry_filters.FileEntryFilterCollection() file_entry_filter = file_entry_filters.NamesFileEntryFilter(['name']) test_filter_collection.AddFilter(file_entry_filter) self.assertTrue(test_filter_collection.HasFilters())
def testAddFilter(self): """Tests the AddFilter function.""" test_filter_collection = file_entry_filters.FileEntryFilterCollection() self.assertEqual(len(test_filter_collection._filters), 0) file_entry_filter = file_entry_filters.NamesFileEntryFilter(['name']) test_filter_collection.AddFilter(file_entry_filter) self.assertEqual(len(test_filter_collection._filters), 1)
def _ParseNamesString(self, names_string): """Parses the name string. Args: names_string (str): comma separated filenames to filter. """ if not names_string: return names_string = names_string.lower() names = [name.strip() for name in names_string.split(',')] file_entry_filter = file_entry_filters.NamesFileEntryFilter(names) self._filter_collection.AddFilter(file_entry_filter)
def testPrint(self): """Tests the Print function.""" output_writer = cli_test_lib.TestBinaryOutputWriter(encoding='utf-8') test_filter = file_entry_filters.NamesFileEntryFilter(['myfile']) test_filter.Print(output_writer) expected_output = [b'\tnames: myfile', b''] output = output_writer.ReadOutput() # Compare the output as list of lines which makes it easier to spot # differences. self.assertEqual(output.split(b'\n'), expected_output)