Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Changed tests to use path spec factory log2timeline#535
Browse files Browse the repository at this point in the history
joachimmetz committed Jan 11, 2021
1 parent 23b05cc commit cacb779
Showing 20 changed files with 1,124 additions and 852 deletions.
102 changes: 59 additions & 43 deletions tests/vfs/apfs_container_file_entry.py
Original file line number Diff line number Diff line change
@@ -4,9 +4,8 @@

import unittest

from dfvfs.path import apfs_container_path_spec
from dfvfs.path import os_path_spec
from dfvfs.path import raw_path_spec
from dfvfs.lib import definitions
from dfvfs.path import factory as path_spec_factory
from dfvfs.resolver import context
from dfvfs.vfs import apfs_container_file_entry
from dfvfs.vfs import apfs_container_file_system
@@ -20,14 +19,16 @@ class APFSContainerDirectoryTest(shared_test_lib.BaseTestCase):
def setUp(self):
"""Sets up the needed objects used throughout the test."""
self._resolver_context = context.Context()
test_file = self._GetTestFilePath(['apfs.raw'])
self._SkipIfPathNotExists(test_file)
test_path = self._GetTestFilePath(['apfs.raw'])
self._SkipIfPathNotExists(test_path)

path_spec = os_path_spec.OSPathSpec(location=test_file)
self._raw_path_spec = raw_path_spec.RawPathSpec(parent=path_spec)
self._apfs_container_path_spec = (
apfs_container_path_spec.APFSContainerPathSpec(
location='/', parent=self._raw_path_spec))
test_os_path_spec = path_spec_factory.Factory.NewPathSpec(
definitions.TYPE_INDICATOR_OS, location=test_path)
self._raw_path_spec = path_spec_factory.Factory.NewPathSpec(
definitions.TYPE_INDICATOR_RAW, parent=test_os_path_spec)
self._apfs_container_path_spec = path_spec_factory.Factory.NewPathSpec(
definitions.TYPE_INDICATOR_APFS_CONTAINER, location='/',
parent=self._raw_path_spec)

self._file_system = apfs_container_file_system.APFSContainerFileSystem(
self._resolver_context, self._apfs_container_path_spec)
@@ -61,14 +62,16 @@ class APFSContainerFileEntryTest(shared_test_lib.BaseTestCase):
def setUp(self):
"""Sets up the needed objects used throughout the test."""
self._resolver_context = context.Context()
test_file = self._GetTestFilePath(['apfs.raw'])
self._SkipIfPathNotExists(test_file)
test_path = self._GetTestFilePath(['apfs.raw'])
self._SkipIfPathNotExists(test_path)

path_spec = os_path_spec.OSPathSpec(location=test_file)
self._raw_path_spec = raw_path_spec.RawPathSpec(parent=path_spec)
self._apfs_container_path_spec = (
apfs_container_path_spec.APFSContainerPathSpec(
location='/', parent=self._raw_path_spec))
test_os_path_spec = path_spec_factory.Factory.NewPathSpec(
definitions.TYPE_INDICATOR_OS, location=test_path)
self._raw_path_spec = path_spec_factory.Factory.NewPathSpec(
definitions.TYPE_INDICATOR_RAW, parent=test_os_path_spec)
self._apfs_container_path_spec = path_spec_factory.Factory.NewPathSpec(
definitions.TYPE_INDICATOR_APFS_CONTAINER, location='/',
parent=self._raw_path_spec)

self._file_system = apfs_container_file_system.APFSContainerFileSystem(
self._resolver_context, self._apfs_container_path_spec)
@@ -91,34 +94,38 @@ def testInitialize(self):

def testName(self):
"""Test the name property."""
path_spec = apfs_container_path_spec.APFSContainerPathSpec(
parent=self._raw_path_spec, volume_index=0)
path_spec = path_spec_factory.Factory.NewPathSpec(
definitions.TYPE_INDICATOR_APFS_CONTAINER, parent=self._raw_path_spec,
volume_index=0)
file_entry = self._file_system.GetFileEntryByPathSpec(path_spec)

self.assertIsNotNone(file_entry)
self.assertEqual(file_entry.name, 'apfs1')

def testSize(self):
"""Test the size property."""
path_spec = apfs_container_path_spec.APFSContainerPathSpec(
parent=self._raw_path_spec, volume_index=0)
path_spec = path_spec_factory.Factory.NewPathSpec(
definitions.TYPE_INDICATOR_APFS_CONTAINER, parent=self._raw_path_spec,
volume_index=0)
file_entry = self._file_system.GetFileEntryByPathSpec(path_spec)

self.assertIsNotNone(file_entry)
self.assertEqual(file_entry.size, 0)

def testGetAPFSVolume(self):
"""Test the GetAPFSVolume function."""
path_spec = apfs_container_path_spec.APFSContainerPathSpec(
parent=self._raw_path_spec, volume_index=0)
path_spec = path_spec_factory.Factory.NewPathSpec(
definitions.TYPE_INDICATOR_APFS_CONTAINER, parent=self._raw_path_spec,
volume_index=0)
file_entry = self._file_system.GetFileEntryByPathSpec(path_spec)
self.assertIsNotNone(file_entry)

fsapfs_volume = file_entry.GetAPFSVolume()
self.assertIsNotNone(fsapfs_volume)

path_spec = apfs_container_path_spec.APFSContainerPathSpec(
location='/', parent=self._raw_path_spec)
path_spec = path_spec_factory.Factory.NewPathSpec(
definitions.TYPE_INDICATOR_APFS_CONTAINER, location='/',
parent=self._raw_path_spec)
file_entry = self._file_system.GetFileEntryByPathSpec(path_spec)
self.assertIsNotNone(file_entry)

@@ -127,16 +134,18 @@ def testGetAPFSVolume(self):

def testGetParentFileEntry(self):
"""Tests the GetParentFileEntry function."""
path_spec = apfs_container_path_spec.APFSContainerPathSpec(
parent=self._raw_path_spec, volume_index=0)
path_spec = path_spec_factory.Factory.NewPathSpec(
definitions.TYPE_INDICATOR_APFS_CONTAINER, parent=self._raw_path_spec,
volume_index=0)
file_entry = self._file_system.GetFileEntryByPathSpec(path_spec)
self.assertIsNotNone(file_entry)

parent_file_entry = file_entry.GetParentFileEntry()
self.assertIsNotNone(parent_file_entry)

path_spec = apfs_container_path_spec.APFSContainerPathSpec(
location='/', parent=self._raw_path_spec)
path_spec = path_spec_factory.Factory.NewPathSpec(
definitions.TYPE_INDICATOR_APFS_CONTAINER, location='/',
parent=self._raw_path_spec)
file_entry = self._file_system.GetFileEntryByPathSpec(path_spec)
self.assertIsNotNone(file_entry)

@@ -145,8 +154,9 @@ def testGetParentFileEntry(self):

def testGetStat(self):
"""Tests the GetStat function."""
path_spec = apfs_container_path_spec.APFSContainerPathSpec(
parent=self._raw_path_spec, volume_index=0)
path_spec = path_spec_factory.Factory.NewPathSpec(
definitions.TYPE_INDICATOR_APFS_CONTAINER, parent=self._raw_path_spec,
volume_index=0)
file_entry = self._file_system.GetFileEntryByPathSpec(path_spec)
self.assertIsNotNone(file_entry)

@@ -157,8 +167,9 @@ def testGetStat(self):

def testIsFunctions(self):
"""Test the Is? functions."""
path_spec = apfs_container_path_spec.APFSContainerPathSpec(
parent=self._raw_path_spec, volume_index=0)
path_spec = path_spec_factory.Factory.NewPathSpec(
definitions.TYPE_INDICATOR_APFS_CONTAINER, parent=self._raw_path_spec,
volume_index=0)
file_entry = self._file_system.GetFileEntryByPathSpec(path_spec)
self.assertIsNotNone(file_entry)

@@ -173,8 +184,9 @@ def testIsFunctions(self):
self.assertFalse(file_entry.IsPipe())
self.assertFalse(file_entry.IsSocket())

path_spec = apfs_container_path_spec.APFSContainerPathSpec(
location='/', parent=self._raw_path_spec)
path_spec = path_spec_factory.Factory.NewPathSpec(
definitions.TYPE_INDICATOR_APFS_CONTAINER, location='/',
parent=self._raw_path_spec)
file_entry = self._file_system.GetFileEntryByPathSpec(path_spec)
self.assertIsNotNone(file_entry)

@@ -191,8 +203,9 @@ def testIsFunctions(self):

def testSubFileEntries(self):
"""Test the sub file entries iteration functionality."""
path_spec = apfs_container_path_spec.APFSContainerPathSpec(
location='/', parent=self._raw_path_spec)
path_spec = path_spec_factory.Factory.NewPathSpec(
definitions.TYPE_INDICATOR_APFS_CONTAINER, location='/',
parent=self._raw_path_spec)
file_entry = self._file_system.GetFileEntryByPathSpec(path_spec)
self.assertIsNotNone(file_entry)

@@ -211,8 +224,9 @@ def testSubFileEntries(self):

def testDataStreams(self):
"""Test the data streams functionality."""
path_spec = apfs_container_path_spec.APFSContainerPathSpec(
parent=self._raw_path_spec, volume_index=0)
path_spec = path_spec_factory.Factory.NewPathSpec(
definitions.TYPE_INDICATOR_APFS_CONTAINER, parent=self._raw_path_spec,
volume_index=0)
file_entry = self._file_system.GetFileEntryByPathSpec(path_spec)
self.assertIsNotNone(file_entry)

@@ -224,8 +238,9 @@ def testDataStreams(self):

self.assertEqual(data_stream_names, [''])

path_spec = apfs_container_path_spec.APFSContainerPathSpec(
location='/', parent=self._raw_path_spec)
path_spec = path_spec_factory.Factory.NewPathSpec(
definitions.TYPE_INDICATOR_APFS_CONTAINER, location='/',
parent=self._raw_path_spec)
file_entry = self._file_system.GetFileEntryByPathSpec(path_spec)
self.assertIsNotNone(file_entry)

@@ -239,8 +254,9 @@ def testDataStreams(self):

def testGetDataStream(self):
"""Tests the GetDataStream function."""
path_spec = apfs_container_path_spec.APFSContainerPathSpec(
parent=self._raw_path_spec, volume_index=0)
path_spec = path_spec_factory.Factory.NewPathSpec(
definitions.TYPE_INDICATOR_APFS_CONTAINER, parent=self._raw_path_spec,
volume_index=0)
file_entry = self._file_system.GetFileEntryByPathSpec(path_spec)
self.assertIsNotNone(file_entry)

81 changes: 47 additions & 34 deletions tests/vfs/apfs_container_file_system.py
Original file line number Diff line number Diff line change
@@ -4,9 +4,8 @@

import unittest

from dfvfs.path import apfs_container_path_spec
from dfvfs.path import os_path_spec
from dfvfs.path import raw_path_spec
from dfvfs.lib import definitions
from dfvfs.path import factory as path_spec_factory
from dfvfs.resolver import context
from dfvfs.vfs import apfs_container_file_system

@@ -19,14 +18,16 @@ class APFSContainerFileSystemTest(shared_test_lib.BaseTestCase):
def setUp(self):
"""Sets up the needed objects used throughout the test."""
self._resolver_context = context.Context()
test_file = self._GetTestFilePath(['apfs.raw'])
self._SkipIfPathNotExists(test_file)
test_path = self._GetTestFilePath(['apfs.raw'])
self._SkipIfPathNotExists(test_path)

test_os_path_spec = os_path_spec.OSPathSpec(location=test_file)
self._raw_path_spec = raw_path_spec.RawPathSpec(parent=test_os_path_spec)
self._apfs_container_path_spec = (
apfs_container_path_spec.APFSContainerPathSpec(
location='/', parent=self._raw_path_spec))
test_os_path_spec = path_spec_factory.Factory.NewPathSpec(
definitions.TYPE_INDICATOR_OS, location=test_path)
self._raw_path_spec = path_spec_factory.Factory.NewPathSpec(
definitions.TYPE_INDICATOR_RAW, parent=test_os_path_spec)
self._apfs_container_path_spec = path_spec_factory.Factory.NewPathSpec(
definitions.TYPE_INDICATOR_APFS_CONTAINER, location='/',
parent=self._raw_path_spec)

def tearDown(self):
"""Cleans up the needed objects used throughout the test."""
@@ -48,28 +49,34 @@ def testFileEntryExistsByPathSpec(self):

file_system.Open()

path_spec = apfs_container_path_spec.APFSContainerPathSpec(
location='/', parent=self._raw_path_spec)
path_spec = path_spec_factory.Factory.NewPathSpec(
definitions.TYPE_INDICATOR_APFS_CONTAINER, location='/',
parent=self._raw_path_spec)
self.assertTrue(file_system.FileEntryExistsByPathSpec(path_spec))

path_spec = apfs_container_path_spec.APFSContainerPathSpec(
parent=self._raw_path_spec, volume_index=0)
path_spec = path_spec_factory.Factory.NewPathSpec(
definitions.TYPE_INDICATOR_APFS_CONTAINER, parent=self._raw_path_spec,
volume_index=0)
self.assertTrue(file_system.FileEntryExistsByPathSpec(path_spec))

path_spec = apfs_container_path_spec.APFSContainerPathSpec(
location='/apfs1', parent=self._raw_path_spec)
path_spec = path_spec_factory.Factory.NewPathSpec(
definitions.TYPE_INDICATOR_APFS_CONTAINER, location='/apfs1',
parent=self._raw_path_spec)
self.assertTrue(file_system.FileEntryExistsByPathSpec(path_spec))

path_spec = apfs_container_path_spec.APFSContainerPathSpec(
parent=self._raw_path_spec, volume_index=9)
path_spec = path_spec_factory.Factory.NewPathSpec(
definitions.TYPE_INDICATOR_APFS_CONTAINER, parent=self._raw_path_spec,
volume_index=9)
self.assertFalse(file_system.FileEntryExistsByPathSpec(path_spec))

path_spec = apfs_container_path_spec.APFSContainerPathSpec(
location='/apfs0', parent=self._raw_path_spec)
path_spec = path_spec_factory.Factory.NewPathSpec(
definitions.TYPE_INDICATOR_APFS_CONTAINER, location='/apfs0',
parent=self._raw_path_spec)
self.assertFalse(file_system.FileEntryExistsByPathSpec(path_spec))

path_spec = apfs_container_path_spec.APFSContainerPathSpec(
location='/apfs9', parent=self._raw_path_spec)
path_spec = path_spec_factory.Factory.NewPathSpec(
definitions.TYPE_INDICATOR_APFS_CONTAINER, location='/apfs9',
parent=self._raw_path_spec)
self.assertFalse(file_system.FileEntryExistsByPathSpec(path_spec))

def testGetFileEntryByPathSpec(self):
@@ -80,41 +87,47 @@ def testGetFileEntryByPathSpec(self):

file_system.Open()

path_spec = apfs_container_path_spec.APFSContainerPathSpec(
location='/', parent=self._raw_path_spec)
path_spec = path_spec_factory.Factory.NewPathSpec(
definitions.TYPE_INDICATOR_APFS_CONTAINER, location='/',
parent=self._raw_path_spec)
file_entry = file_system.GetFileEntryByPathSpec(path_spec)

self.assertIsNotNone(file_entry)
self.assertEqual(file_entry.name, '')

path_spec = apfs_container_path_spec.APFSContainerPathSpec(
parent=self._raw_path_spec, volume_index=0)
path_spec = path_spec_factory.Factory.NewPathSpec(
definitions.TYPE_INDICATOR_APFS_CONTAINER, parent=self._raw_path_spec,
volume_index=0)
file_entry = file_system.GetFileEntryByPathSpec(path_spec)

self.assertIsNotNone(file_entry)
self.assertEqual(file_entry.name, 'apfs1')

path_spec = apfs_container_path_spec.APFSContainerPathSpec(
location='/apfs1', parent=self._raw_path_spec)
path_spec = path_spec_factory.Factory.NewPathSpec(
definitions.TYPE_INDICATOR_APFS_CONTAINER, location='/apfs1',
parent=self._raw_path_spec)
file_entry = file_system.GetFileEntryByPathSpec(path_spec)

self.assertIsNotNone(file_entry)
self.assertEqual(file_entry.name, 'apfs1')

path_spec = apfs_container_path_spec.APFSContainerPathSpec(
parent=self._raw_path_spec, volume_index=9)
path_spec = path_spec_factory.Factory.NewPathSpec(
definitions.TYPE_INDICATOR_APFS_CONTAINER, parent=self._raw_path_spec,
volume_index=9)
file_entry = file_system.GetFileEntryByPathSpec(path_spec)

self.assertIsNone(file_entry)

path_spec = apfs_container_path_spec.APFSContainerPathSpec(
location='/apfs0', parent=self._raw_path_spec)
path_spec = path_spec_factory.Factory.NewPathSpec(
definitions.TYPE_INDICATOR_APFS_CONTAINER, location='/apfs0',
parent=self._raw_path_spec)
file_entry = file_system.GetFileEntryByPathSpec(path_spec)

self.assertIsNone(file_entry)

path_spec = apfs_container_path_spec.APFSContainerPathSpec(
location='/apfs9', parent=self._raw_path_spec)
path_spec = path_spec_factory.Factory.NewPathSpec(
definitions.TYPE_INDICATOR_APFS_CONTAINER, location='/apfs9',
parent=self._raw_path_spec)
file_entry = file_system.GetFileEntryByPathSpec(path_spec)

self.assertIsNone(file_entry)
Loading

0 comments on commit cacb779

Please sign in to comment.