def _BuildFileFakeFileSystem(self, segment_filenames, segment_file_path_specs): """Builds a fake file system containing storage media RAW segment files. Args: segment_filenames (list[str]): segment filenames. segment_file_path_specs (list[PathSpec]): resulting segment file path specifications. Returns: FakeFileSystem: fake file system. """ resolver_context = context.Context() path_spec = fake_path_spec.FakePathSpec(location='/') file_system = fake_file_system.FakeFileSystem(resolver_context, path_spec) for segment_filename in segment_filenames: path = '/{0:s}'.format(segment_filename) file_system.AddFileEntry(path) segment_file_path_specs.append( fake_path_spec.FakePathSpec(location=path)) return file_system
def testCacheFileSystem(self): """Tests the cache file system object functionality.""" resolver_context = context.Context() # pylint: disable=protected-access self.assertEqual(len(resolver_context._file_system_cache._values), 0) path_spec = fake_path_spec.FakePathSpec(location='/') file_system = fake_file_system.FakeFileSystem(resolver_context) resolver_context.CacheFileSystem(path_spec, file_system) self.assertEqual(len(resolver_context._file_system_cache._values), 1) cached_object = resolver_context.GetFileSystem(path_spec) self.assertEqual(cached_object, file_system) resolver_context.GrabFileSystem(path_spec) self.assertEqual(len(resolver_context._file_system_cache._values), 1) resolver_context.GrabFileSystem(path_spec) self.assertEqual(len(resolver_context._file_system_cache._values), 1) resolver_context.ReleaseFileSystem(file_system) self.assertEqual(len(resolver_context._file_system_cache._values), 1) resolver_context.ReleaseFileSystem(file_system) self.assertEqual(len(resolver_context._file_system_cache._values), 0)
def __init__(self): """Initializes a fake file system builder.""" super(FakeFileSystemBuilder, self).__init__() resolver_context = context.Context() path_spec = fake_path_spec.FakePathSpec(location='/') self.file_system = fake_file_system.FakeFileSystem( resolver_context, path_spec)
def _BuildSingleLinkFakeFileSystem(self, path, linked_path): """Builds a single link fake file system. Args: path: The path of the link. linked_path: The path that is linked. Returns: The fake file system (instance of dvfvs.FakeFileSystem). """ resolver_context = context.Context() file_system = fake_file_system.FakeFileSystem(resolver_context) file_system.AddFileEntry( u'/', file_entry_type=dfvfs_definitions.FILE_ENTRY_TYPE_DIRECTORY) path_segments = path.split(u'/') for segment_index in range(2, len(path_segments)): path_segment = u'{0:s}'.format(u'/'.join( path_segments[:segment_index])) file_system.AddFileEntry( path_segment, file_entry_type=dfvfs_definitions.FILE_ENTRY_TYPE_DIRECTORY) file_system.AddFileEntry( path, file_entry_type=dfvfs_definitions.FILE_ENTRY_TYPE_LINK, link_data=linked_path) return file_system
def testOpenAndClose(self): """Test the open and close functionality.""" file_system = fake_file_system.FakeFileSystem(self._resolver_context, self._fake_path_spec) self.assertIsNotNone(file_system) file_system.Open()
def _BuildFileFakeFileSystem(self, segment_filenames, segment_file_path_specs): """Builds a fake file system containing storage media RAW segment files. Args: filename: the filename of the first segment file with extension. segment_filenames: a list of segment filenames. segment_file_path_specs: a list to store the segment file path specifications in. Returns: The fake file system (instance of dvfvs.FakeFileSystem). """ resolver_context = context.Context() file_system = fake_file_system.FakeFileSystem(resolver_context) file_system.AddFileEntry( u'/', file_entry_type=definitions.FILE_ENTRY_TYPE_DIRECTORY) for segment_filename in segment_filenames: path = u'/{0:s}'.format(segment_filename) file_system.AddFileEntry(path) segment_file_path_specs.append( fake_path_spec.FakePathSpec(location=path)) return file_system
def setUp(self): """Sets up the needed objects used throughout the test.""" self._resolver_context = context.Context() self._file_system = fake_file_system.FakeFileSystem( self._resolver_context) self._file_system.AddFileEntry( u'/test_data/testdir_fake', file_entry_type=definitions.FILE_ENTRY_TYPE_DIRECTORY) self._file_system.AddFileEntry(u'/test_data/testdir_fake/file1.txt', file_data=b'FILE1') self._file_system.AddFileEntry(u'/test_data/testdir_fake/file2.txt', file_data=b'FILE2') self._file_system.AddFileEntry(u'/test_data/testdir_fake/file3.txt', file_data=b'FILE3') self._file_system.AddFileEntry(u'/test_data/testdir_fake/file4.txt', file_data=b'FILE4') self._file_system.AddFileEntry(u'/test_data/testdir_fake/file5.txt', file_data=b'FILE5') self._file_system.AddFileEntry( u'/test_data/testdir_fake/link1.txt', file_entry_type=definitions.FILE_ENTRY_TYPE_LINK, link_data=u'/test_data/testdir_fake/file1.txt') self._test_file = u'/test_data/testdir_fake' self._fake_path_spec = fake_path_spec.FakePathSpec(location=u'/') self._file_system.Open(path_spec=self._fake_path_spec)
def _BuildFileFakeFileSystem(self, filename, number_of_segments, segment_file_path_specs): """Builds a fake file system containing EWF segment files. Args: filename: the filename of the first segment file with extension. number_of_segments: the number of segments. segment_file_path_specs: a list to store the segment file path specifications in. Returns: The fake file system (instance of dvfvs.FakeFileSystem). """ resolver_context = context.Context() file_system = fake_file_system.FakeFileSystem(resolver_context) file_system.AddFileEntry( u'/', file_entry_type=definitions.FILE_ENTRY_TYPE_DIRECTORY) filename, _, extension = filename.partition(u'.') number_of_segments += 1 for segment_number in range(1, number_of_segments): if segment_number < 100: if extension[1] == u'x': path = u'/{0:s}.{1:s}x{2:02d}'.format( filename, extension[0], segment_number) else: path = u'/{0:s}.{1:s}{2:02d}'.format( filename, extension[0], segment_number) else: segment_index = segment_number - 100 segment_index, remainder = divmod(segment_index, 26) if extension[0].islower(): third_letter = chr(ord(u'a') + remainder) else: third_letter = chr(ord(u'A') + remainder) segment_index, remainder = divmod(segment_index, 26) if extension[0].islower(): second_letter = chr(ord(u'a') + remainder) else: second_letter = chr(ord(u'A') + remainder) first_letter = chr(ord(extension[0]) + segment_index) if extension[1] == u'x': path = u'/{0:s}.{1:s}x{2:s}{3:s}'.format( filename, first_letter, second_letter, third_letter) else: path = u'/{0:s}.{1:s}{2:s}{3:s}'.format( filename, first_letter, second_letter, third_letter) file_system.AddFileEntry(path) segment_file_path_specs.append( fake_path_spec.FakePathSpec(location=path)) return file_system
def setUp(self): """Sets up the needed objects used throughout the test.""" self._resolver_context = context.Context() self._path_spec = fake_path_spec.FakePathSpec(location='/') self._file_system = fake_file_system.FakeFileSystem( self._resolver_context) self._file_system.Open(self._path_spec)
def testOpenAndClose(self): """Test the open and close functionality.""" file_system = fake_file_system.FakeFileSystem(self._resolver_context) self.assertNotEqual(file_system, None) file_system.Open(path_spec=self._fake_path_spec) file_system.Close()
def _BuildFileFakeFileSystem(self, filename, number_of_segments, segment_file_path_specs): """Builds a fake file system containing EWF segment files. Args: filename (str): filename of the first segment file with extension. number_of_segments (int): number of segments. segment_file_path_specs (list[PathSpec]): resulting segment file path specifications. Returns: FakeFileSystem: fake file system. """ resolver_context = context.Context() path_spec = fake_path_spec.FakePathSpec(location='/') file_system = fake_file_system.FakeFileSystem(resolver_context, path_spec) filename, _, extension = filename.partition('.') number_of_segments += 1 for segment_number in range(1, number_of_segments): if segment_number < 100: if extension[1] == 'x': path = '/{0:s}.{1:s}x{2:02d}'.format( filename, extension[0], segment_number) else: path = '/{0:s}.{1:s}{2:02d}'.format( filename, extension[0], segment_number) else: segment_index = segment_number - 100 segment_index, remainder = divmod(segment_index, 26) if extension[0].islower(): third_letter = chr(ord('a') + remainder) else: third_letter = chr(ord('A') + remainder) segment_index, remainder = divmod(segment_index, 26) if extension[0].islower(): second_letter = chr(ord('a') + remainder) else: second_letter = chr(ord('A') + remainder) first_letter = chr(ord(extension[0]) + segment_index) if extension[1] == 'x': path = '/{0:s}.{1:s}x{2:s}{3:s}'.format( filename, first_letter, second_letter, third_letter) else: path = '/{0:s}.{1:s}{2:s}{3:s}'.format( filename, first_letter, second_letter, third_letter) file_system.AddFileEntry(path) path_spec = fake_path_spec.FakePathSpec(location=path) segment_file_path_specs.append(path_spec) return file_system
def testEntries(self): """Test the entries property.""" file_system = fake_file_system.FakeFileSystem(self._resolver_context) file_system.Open(self._fake_path_spec) test_directory = file_entry.Directory(file_system, self._fake_path_spec) self.assertEqual(list(test_directory.entries), []) file_system.Close()
def testGetRootFileEntry(self): """Test the get root file entry functionality.""" file_system = fake_file_system.FakeFileSystem(self._resolver_context, self._fake_path_spec) self.assertIsNotNone(file_system) file_system.Open() file_entry = file_system.GetRootFileEntry() self.assertIsNotNone(file_entry) self.assertEqual(file_entry.name, '')
def testGetRootFileEntry(self): """Test the get root file entry functionality.""" file_system = fake_file_system.FakeFileSystem(self._resolver_context) self.assertNotEqual(file_system, None) file_system.Open(path_spec=self._fake_path_spec) file_entry = file_system.GetRootFileEntry() self.assertNotEqual(file_entry, None) self.assertEqual(file_entry.name, u'') file_system.Close()
def testFileEntryExistsByPathSpec(self): """Test the file entry exists by path specification functionality.""" file_system = fake_file_system.FakeFileSystem(self._resolver_context, self._fake_path_spec) self.assertIsNotNone(file_system) file_system.AddFileEntry('/test_data/testdir_fake/file1.txt', file_data=b'FILE1') file_system.Open() path_spec = fake_path_spec.FakePathSpec( location='/test_data/testdir_fake/file1.txt') self.assertTrue(file_system.FileEntryExistsByPathSpec(path_spec)) path_spec = fake_path_spec.FakePathSpec( location='/test_data/testdir_fake/file6.txt') self.assertFalse(file_system.FileEntryExistsByPathSpec(path_spec))
def testGetFileEntryByPathSpec(self): """Tests the GetFileEntryByPathSpec function.""" file_system = fake_file_system.FakeFileSystem(self._resolver_context, self._fake_path_spec) self.assertIsNotNone(file_system) file_system.AddFileEntry('/test_data/testdir_fake/file1.txt', file_data=b'FILE1') file_system.Open() path_spec = fake_path_spec.FakePathSpec( location='/test_data/testdir_fake/file1.txt') file_entry = file_system.GetFileEntryByPathSpec(path_spec) self.assertIsNotNone(file_entry) self.assertEqual(file_entry.name, 'file1.txt') path_spec = fake_path_spec.FakePathSpec( location='/test_data/testdir_fake/file6.txt') file_entry = file_system.GetFileEntryByPathSpec(path_spec) self.assertIsNone(file_entry)
def testGetFileEntryByPathSpec(self): """Test the get entry by path specification functionality.""" file_system = fake_file_system.FakeFileSystem(self._resolver_context) self.assertNotEqual(file_system, None) file_system.AddFileEntry(u'/test_data/testdir_fake/file1.txt', file_data=b'FILE1') file_system.Open(path_spec=self._fake_path_spec) path_spec = fake_path_spec.FakePathSpec( location=u'/test_data/testdir_fake/file1.txt') file_entry = file_system.GetFileEntryByPathSpec(path_spec) self.assertNotEqual(file_entry, None) self.assertEqual(file_entry.name, u'file1.txt') path_spec = fake_path_spec.FakePathSpec( location=u'/test_data/testdir_fake/file6.txt') file_entry = file_system.GetFileEntryByPathSpec(path_spec) self.assertEqual(file_entry, None) file_system.Close()
def __init__(self): """Initializes the fake file system builder object.""" super(FakeFileSystemBuilder, self).__init__() resolver_context = context.Context() self.file_system = fake_file_system.FakeFileSystem(resolver_context)