Beispiel #1
0
    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
Beispiel #2
0
    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)
Beispiel #3
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)
Beispiel #4
0
    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
Beispiel #5
0
    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()
Beispiel #6
0
    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
Beispiel #7
0
    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)
Beispiel #8
0
    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
Beispiel #9
0
    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)
Beispiel #10
0
    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()
Beispiel #11
0
    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
Beispiel #12
0
    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()
Beispiel #13
0
    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, '')
Beispiel #14
0
    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()
Beispiel #15
0
    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))
Beispiel #16
0
    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)
Beispiel #17
0
    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()
Beispiel #18
0
 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)