Skip to content

Commit

Permalink
Changed tests to use path spec factory log2timeline#535
Browse files Browse the repository at this point in the history
  • Loading branch information
joachimmetz committed Feb 19, 2021
1 parent fbda6d3 commit 5a5bd38
Show file tree
Hide file tree
Showing 23 changed files with 534 additions and 413 deletions.
34 changes: 20 additions & 14 deletions tests/file_io/bde_file_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

import unittest

from dfvfs.lib import definitions
from dfvfs.lib import errors
from dfvfs.path import bde_path_spec
from dfvfs.path import os_path_spec
from dfvfs.path import factory as path_spec_factory
from dfvfs.resolver import resolver

from tests.file_io import test_lib
Expand All @@ -25,11 +25,13 @@ class BDEFileWithKeyChainTest(test_lib.ImageFileTestCase):
def setUp(self):
"""Sets up the needed objects used throughout the test."""
super(BDEFileWithKeyChainTest, self).setUp()
test_file = self._GetTestFilePath(['bdetogo.raw'])
self._SkipIfPathNotExists(test_file)
test_path = self._GetTestFilePath(['bdetogo.raw'])
self._SkipIfPathNotExists(test_path)

self._os_path_spec = os_path_spec.OSPathSpec(location=test_file)
self._bde_path_spec = bde_path_spec.BDEPathSpec(parent=self._os_path_spec)
self._os_path_spec = path_spec_factory.Factory.NewPathSpec(
definitions.TYPE_INDICATOR_OS, location=test_path)
self._bde_path_spec = path_spec_factory.Factory.NewPathSpec(
definitions.TYPE_INDICATOR_BDE, parent=self._os_path_spec)
resolver.Resolver.key_chain.SetCredential(
self._bde_path_spec, 'password', self._BDE_PASSWORD)

Expand All @@ -42,7 +44,8 @@ def testOpenCloseLocation(self):
self._TestOpenCloseLocation(self._bde_path_spec)

# Try open with a path specification that has no parent.
path_spec = bde_path_spec.BDEPathSpec(parent=self._os_path_spec)
path_spec = path_spec_factory.Factory.NewPathSpec(
definitions.TYPE_INDICATOR_BDE, parent=self._os_path_spec)
path_spec.parent = None

with self.assertRaises(errors.PathSpecError):
Expand Down Expand Up @@ -70,12 +73,14 @@ class BDEFileWithPathSpecCredentialsTest(test_lib.ImageFileTestCase):
def setUp(self):
"""Sets up the needed objects used throughout the test."""
super(BDEFileWithPathSpecCredentialsTest, self).setUp()
test_file = self._GetTestFilePath(['bdetogo.raw'])
self._SkipIfPathNotExists(test_file)
test_path = self._GetTestFilePath(['bdetogo.raw'])
self._SkipIfPathNotExists(test_path)

self._os_path_spec = os_path_spec.OSPathSpec(location=test_file)
self._bde_path_spec = bde_path_spec.BDEPathSpec(
password=self._BDE_PASSWORD, parent=self._os_path_spec)
self._os_path_spec = path_spec_factory.Factory.NewPathSpec(
definitions.TYPE_INDICATOR_OS, location=test_path)
self._bde_path_spec = path_spec_factory.Factory.NewPathSpec(
definitions.TYPE_INDICATOR_BDE, parent=self._os_path_spec,
password=self._BDE_PASSWORD)

def testOpenCloseInode(self):
"""Test the open and close functionality using an inode."""
Expand All @@ -86,8 +91,9 @@ def testOpenCloseLocation(self):
self._TestOpenCloseLocation(self._bde_path_spec)

# Try open with a path specification that has no parent.
path_spec = bde_path_spec.BDEPathSpec(
password=self._BDE_PASSWORD, parent=self._os_path_spec)
path_spec = path_spec_factory.Factory.NewPathSpec(
definitions.TYPE_INDICATOR_BDE, parent=self._os_path_spec,
password=self._BDE_PASSWORD)
path_spec.parent = None

with self.assertRaises(errors.PathSpecError):
Expand Down
54 changes: 31 additions & 23 deletions tests/file_io/cpio_file_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
import unittest

from dfvfs.file_io import cpio_file_io
from dfvfs.path import cpio_path_spec
from dfvfs.path import os_path_spec
from dfvfs.lib import definitions
from dfvfs.path import factory as path_spec_factory
from dfvfs.resolver import context

from tests.file_io import test_lib
Expand All @@ -19,12 +19,14 @@ def setUp(self):
"""Sets up the needed objects used throughout the test."""
super(CPIOBinaryFileTest, self).setUp()
self._resolver_context = context.Context()
test_file = self._GetTestFilePath(['syslog.bin.cpio'])
self._SkipIfPathNotExists(test_file)
test_path = self._GetTestFilePath(['syslog.bin.cpio'])
self._SkipIfPathNotExists(test_path)

path_spec = os_path_spec.OSPathSpec(location=test_file)
self._cpio_path_spec = cpio_path_spec.CPIOPathSpec(
location='/syslog', parent=path_spec)
test_os_path_spec = path_spec_factory.Factory.NewPathSpec(
definitions.TYPE_INDICATOR_OS, location=test_path)
self._cpio_path_spec = path_spec_factory.Factory.NewPathSpec(
definitions.TYPE_INDICATOR_CPIO, location='/syslog',
parent=test_os_path_spec)

def tearDown(self):
"""Cleans up the needed objects used throughout the test."""
Expand Down Expand Up @@ -62,12 +64,14 @@ def setUp(self):
"""Sets up the needed objects used throughout the test."""
super(CPIOPortableASCIIFileTest, self).setUp()
self._resolver_context = context.Context()
test_file = self._GetTestFilePath(['syslog.odc.cpio'])
self._SkipIfPathNotExists(test_file)
test_path = self._GetTestFilePath(['syslog.odc.cpio'])
self._SkipIfPathNotExists(test_path)

path_spec = os_path_spec.OSPathSpec(location=test_file)
self._cpio_path_spec = cpio_path_spec.CPIOPathSpec(
location='/syslog', parent=path_spec)
test_os_path_spec = path_spec_factory.Factory.NewPathSpec(
definitions.TYPE_INDICATOR_OS, location=test_path)
self._cpio_path_spec = path_spec_factory.Factory.NewPathSpec(
definitions.TYPE_INDICATOR_CPIO, location='/syslog',
parent=test_os_path_spec)

def tearDown(self):
"""Cleans up the needed objects used throughout the test."""
Expand Down Expand Up @@ -105,12 +109,14 @@ def setUp(self):
"""Sets up the needed objects used throughout the test."""
super(CPIONewASCIIFileTest, self).setUp()
self._resolver_context = context.Context()
test_file = self._GetTestFilePath(['syslog.newc.cpio'])
self._SkipIfPathNotExists(test_file)
test_path = self._GetTestFilePath(['syslog.newc.cpio'])
self._SkipIfPathNotExists(test_path)

path_spec = os_path_spec.OSPathSpec(location=test_file)
self._cpio_path_spec = cpio_path_spec.CPIOPathSpec(
location='/syslog', parent=path_spec)
test_os_path_spec = path_spec_factory.Factory.NewPathSpec(
definitions.TYPE_INDICATOR_OS, location=test_path)
self._cpio_path_spec = path_spec_factory.Factory.NewPathSpec(
definitions.TYPE_INDICATOR_CPIO, location='/syslog',
parent=test_os_path_spec)

def tearDown(self):
"""Cleans up the needed objects used throughout the test."""
Expand Down Expand Up @@ -148,12 +154,14 @@ def setUp(self):
"""Sets up the needed objects used throughout the test."""
super(CPIONewASCIIFileWithChecksumTest, self).setUp()
self._resolver_context = context.Context()
test_file = self._GetTestFilePath(['syslog.crc.cpio'])
self._SkipIfPathNotExists(test_file)

path_spec = os_path_spec.OSPathSpec(location=test_file)
self._cpio_path_spec = cpio_path_spec.CPIOPathSpec(
location='/syslog', parent=path_spec)
test_path = self._GetTestFilePath(['syslog.crc.cpio'])
self._SkipIfPathNotExists(test_path)

test_os_path_spec = path_spec_factory.Factory.NewPathSpec(
definitions.TYPE_INDICATOR_OS, location=test_path)
self._cpio_path_spec = path_spec_factory.Factory.NewPathSpec(
definitions.TYPE_INDICATOR_CPIO, location='/syslog',
parent=test_os_path_spec)

def tearDown(self):
"""Cleans up the needed objects used throughout the test."""
Expand Down
30 changes: 18 additions & 12 deletions tests/file_io/ewf_file_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

import unittest

from dfvfs.lib import definitions
from dfvfs.lib import errors
from dfvfs.path import ewf_path_spec
from dfvfs.path import os_path_spec
from dfvfs.path import factory as path_spec_factory

from tests.file_io import test_lib

Expand All @@ -17,11 +17,13 @@ class EWFFileTest(test_lib.Ext2ImageFileTestCase):
def setUp(self):
"""Sets up the needed objects used throughout the test."""
super(EWFFileTest, self).setUp()
test_file = self._GetTestFilePath(['ext2.E01'])
self._SkipIfPathNotExists(test_file)
test_path = self._GetTestFilePath(['ext2.E01'])
self._SkipIfPathNotExists(test_path)

self._os_path_spec = os_path_spec.OSPathSpec(location=test_file)
self._ewf_path_spec = ewf_path_spec.EWFPathSpec(parent=self._os_path_spec)
self._os_path_spec = path_spec_factory.Factory.NewPathSpec(
definitions.TYPE_INDICATOR_OS, location=test_path)
self._ewf_path_spec = path_spec_factory.Factory.NewPathSpec(
definitions.TYPE_INDICATOR_EWF, parent=self._os_path_spec)

def testOpenCloseInode(self):
"""Test the open and close functionality using an inode."""
Expand All @@ -32,7 +34,8 @@ def testOpenCloseLocation(self):
self._TestOpenCloseLocation(self._ewf_path_spec)

# Try open with a path specification that has no parent.
path_spec = ewf_path_spec.EWFPathSpec(parent=self._os_path_spec)
path_spec = path_spec_factory.Factory.NewPathSpec(
definitions.TYPE_INDICATOR_EWF, parent=self._os_path_spec)
path_spec.parent = None

with self.assertRaises(errors.PathSpecError):
Expand All @@ -53,11 +56,13 @@ class SplitEWFFileTest(test_lib.Ext2ImageFileTestCase):
def setUp(self):
"""Sets up the needed objects used throughout the test."""
super(SplitEWFFileTest, self).setUp()
test_file = self._GetTestFilePath(['ext2.split.E01'])
self._SkipIfPathNotExists(test_file)
test_path = self._GetTestFilePath(['ext2.split.E01'])
self._SkipIfPathNotExists(test_path)

self._os_path_spec = os_path_spec.OSPathSpec(location=test_file)
self._ewf_path_spec = ewf_path_spec.EWFPathSpec(parent=self._os_path_spec)
self._os_path_spec = path_spec_factory.Factory.NewPathSpec(
definitions.TYPE_INDICATOR_OS, location=test_path)
self._ewf_path_spec = path_spec_factory.Factory.NewPathSpec(
definitions.TYPE_INDICATOR_EWF, parent=self._os_path_spec)

def testOpenCloseInode(self):
"""Test the open and close functionality using an inode."""
Expand All @@ -68,7 +73,8 @@ def testOpenCloseLocation(self):
self._TestOpenCloseLocation(self._ewf_path_spec)

# Try open with a path specification that has no parent.
path_spec = ewf_path_spec.EWFPathSpec(parent=self._os_path_spec)
path_spec = path_spec_factory.Factory.NewPathSpec(
definitions.TYPE_INDICATOR_EWF, parent=self._os_path_spec)
path_spec.parent = None

with self.assertRaises(errors.PathSpecError):
Expand Down
12 changes: 6 additions & 6 deletions tests/file_io/fake_file_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ def tearDown(self):

def testOpenClosePathSpec(self):
"""Test the Open and Close functions with a path specification."""
test_file = '/test_data/password.txt'
test_path_spec = fake_path_spec.FakePathSpec(location=test_file)
test_path = '/test_data/password.txt'
test_path_spec = fake_path_spec.FakePathSpec(location=test_path)

file_object = fake_file_io.FakeFile(
self._resolver_context, test_path_spec, self._FILE_DATA1)
Expand All @@ -54,8 +54,8 @@ def testOpenClosePathSpec(self):

def testSeek(self):
"""Test the seek function."""
test_file = '/test_data/another_file'
test_path_spec = fake_path_spec.FakePathSpec(location=test_file)
test_path = '/test_data/another_file'
test_path_spec = fake_path_spec.FakePathSpec(location=test_path)

file_object = fake_file_io.FakeFile(
self._resolver_context, test_path_spec, self._FILE_DATA2)
Expand Down Expand Up @@ -93,8 +93,8 @@ def testSeek(self):

def testRead(self):
"""Test the read function."""
test_file = '/test_data/password.txt'
test_path_spec = fake_path_spec.FakePathSpec(location=test_file)
test_path = '/test_data/password.txt'
test_path_spec = fake_path_spec.FakePathSpec(location=test_path)

file_object = fake_file_io.FakeFile(
self._resolver_context, test_path_spec, self._FILE_DATA1)
Expand Down
61 changes: 33 additions & 28 deletions tests/file_io/fvde_file_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@

import unittest

from dfvfs.lib import definitions
from dfvfs.lib import errors
from dfvfs.path import fvde_path_spec
from dfvfs.path import os_path_spec
from dfvfs.path import qcow_path_spec
from dfvfs.path import tsk_partition_path_spec
from dfvfs.path import factory as path_spec_factory
from dfvfs.resolver import resolver

from tests.file_io import test_lib
Expand All @@ -28,16 +26,19 @@ class FVDEFileTestWithKeyChainTest(test_lib.ImageFileTestCase):
def setUp(self):
"""Sets up the needed objects used throughout the test."""
super(FVDEFileTestWithKeyChainTest, self).setUp()
test_file = self._GetTestFilePath(['fvdetest.qcow2'])
self._SkipIfPathNotExists(test_file)

path_spec = os_path_spec.OSPathSpec(location=test_file)
path_spec = qcow_path_spec.QCOWPathSpec(parent=path_spec)
self._tsk_partition_path_spec = (
tsk_partition_path_spec.TSKPartitionPathSpec(
location='/p1', parent=path_spec))
self._fvde_path_spec = fvde_path_spec.FVDEPathSpec(
parent=self._tsk_partition_path_spec)
test_path = self._GetTestFilePath(['fvdetest.qcow2'])
self._SkipIfPathNotExists(test_path)

test_os_path_spec = path_spec_factory.Factory.NewPathSpec(
definitions.TYPE_INDICATOR_OS, location=test_path)
test_qcow_path_spec = path_spec_factory.Factory.NewPathSpec(
definitions.TYPE_INDICATOR_QCOW, parent=test_os_path_spec)
self._tsk_partition_path_spec = path_spec_factory.Factory.NewPathSpec(
definitions.TYPE_INDICATOR_TSK_PARTITION, location='/p1',
parent=test_qcow_path_spec)
self._fvde_path_spec = path_spec_factory.Factory.NewPathSpec(
definitions.TYPE_INDICATOR_FVDE, parent=self._tsk_partition_path_spec)

resolver.Resolver.key_chain.SetCredential(
self._fvde_path_spec, 'password', self._FVDE_PASSWORD)

Expand All @@ -50,8 +51,8 @@ def testOpenCloseLocation(self):
self._TestOpenCloseLocation(self._fvde_path_spec)

# Try open with a path specification that has no parent.
path_spec = fvde_path_spec.FVDEPathSpec(
parent=self._tsk_partition_path_spec)
path_spec = path_spec_factory.Factory.NewPathSpec(
definitions.TYPE_INDICATOR_FVDE, parent=self._tsk_partition_path_spec)
path_spec.parent = None

with self.assertRaises(errors.PathSpecError):
Expand Down Expand Up @@ -79,16 +80,20 @@ class FVDEFileWithPathSpecCredentialsTest(test_lib.ImageFileTestCase):
def setUp(self):
"""Sets up the needed objects used throughout the test."""
super(FVDEFileWithPathSpecCredentialsTest, self).setUp()
test_file = self._GetTestFilePath(['fvdetest.qcow2'])
self._SkipIfPathNotExists(test_file)

path_spec = os_path_spec.OSPathSpec(location=test_file)
path_spec = qcow_path_spec.QCOWPathSpec(parent=path_spec)
self._tsk_partition_path_spec = (
tsk_partition_path_spec.TSKPartitionPathSpec(
location='/p1', parent=path_spec))
self._fvde_path_spec = fvde_path_spec.FVDEPathSpec(
password=self._FVDE_PASSWORD, parent=self._tsk_partition_path_spec)
test_path = self._GetTestFilePath(['fvdetest.qcow2'])
self._SkipIfPathNotExists(test_path)

test_os_path_spec = path_spec_factory.Factory.NewPathSpec(
definitions.TYPE_INDICATOR_OS, location=test_path)
test_qcow_path_spec = path_spec_factory.Factory.NewPathSpec(
definitions.TYPE_INDICATOR_QCOW, parent=test_os_path_spec)
self._tsk_partition_path_spec = path_spec_factory.Factory.NewPathSpec(
definitions.TYPE_INDICATOR_TSK_PARTITION, location='/p1',
parent=test_qcow_path_spec)
self._fvde_path_spec = path_spec_factory.Factory.NewPathSpec(
definitions.TYPE_INDICATOR_FVDE, parent=self._tsk_partition_path_spec,
password=self._FVDE_PASSWORD)

resolver.Resolver.key_chain.SetCredential(
self._fvde_path_spec, 'password', self._FVDE_PASSWORD)

Expand All @@ -101,8 +106,8 @@ def testOpenCloseLocation(self):
self._TestOpenCloseLocation(self._fvde_path_spec)

# Try open with a path specification that has no parent.
path_spec = fvde_path_spec.FVDEPathSpec(
parent=self._tsk_partition_path_spec)
path_spec = path_spec_factory.Factory.NewPathSpec(
definitions.TYPE_INDICATOR_FVDE, parent=self._tsk_partition_path_spec)
path_spec.parent = None

with self.assertRaises(errors.PathSpecError):
Expand Down
Loading

0 comments on commit 5a5bd38

Please sign in to comment.