diff --git a/dfvfs/resolver/cache.py b/dfvfs/resolver/cache.py index 33602489..759b0d95 100644 --- a/dfvfs/resolver/cache.py +++ b/dfvfs/resolver/cache.py @@ -3,6 +3,9 @@ from __future__ import unicode_literals +import collections +import itertools + from dfvfs.lib import errors @@ -62,7 +65,7 @@ def __init__(self, maximum_number_of_cached_values): super(ObjectsCache, self).__init__() self._maximum_number_of_cached_values = maximum_number_of_cached_values - self._values = {} + self._values = collections.OrderedDict() def CacheObject(self, identifier, vfs_object): """Caches a VFS object. @@ -129,6 +132,22 @@ def GetCacheValueByObject(self, vfs_object): return None, None + def GetLastObject(self): + """Retrieves the last cached object. + + This method ignores the cache value reference count. + + Returns: + object: the last cached VFS object or None if the cache is empty. + """ + if not self._values: + return None + + # Get the last (or most recent added) cache value. + cache_value = next(itertools.islice( + self._values.values(), len(self._values) - 1, None)) + return cache_value.vfs_object + def GetObject(self, identifier): """Retrieves a cached object based on the identifier. diff --git a/dfvfs/resolver/context.py b/dfvfs/resolver/context.py index 762eee91..ffaaabd5 100644 --- a/dfvfs/resolver/context.py +++ b/dfvfs/resolver/context.py @@ -63,6 +63,11 @@ def CacheFileSystem(self, path_spec, file_system): def Empty(self): """Empties the caches.""" + file_object = self._file_object_cache.GetLastObject() + while file_object: + file_object.close() + file_object = self._file_object_cache.GetLastObject() + self._file_object_cache.Empty() self._file_system_cache.Empty() diff --git a/tests/file_io/apfs_file_io.py b/tests/file_io/apfs_file_io.py index e84d7fab..fec6dcab 100644 --- a/tests/file_io/apfs_file_io.py +++ b/tests/file_io/apfs_file_io.py @@ -13,10 +13,10 @@ from dfvfs.path import factory as path_spec_factory from dfvfs.resolver import context -from tests.file_io import test_lib +from tests import test_lib as shared_test_lib -class APFSFileTest(test_lib.ImageFileTestCase): +class APFSFileTest(shared_test_lib.BaseTestCase): """Tests the file-like object implementation using pyfsapfs.file_entry.""" _IDENTIFIER_ANOTHER_FILE = 21 @@ -37,6 +37,10 @@ def setUp(self): definitions.TYPE_INDICATOR_APFS_CONTAINER, location='/apfs1', parent=test_raw_path_spec) + def tearDown(self): + """Cleans up the needed objects used throughout the test.""" + self._resolver_context.Empty() + def testOpenCloseIdentifier(self): """Test the open and close functionality using an identifier.""" path_spec = path_spec_factory.Factory.NewPathSpec( @@ -66,7 +70,7 @@ def testOpenCloseLocation(self): path_spec.parent = None with self.assertRaises(errors.PathSpecError): - self._TestOpenCloseLocation(path_spec) + file_object.open(path_spec=path_spec) def testSeek(self): """Test the seek functionality.""" diff --git a/tests/file_io/compressed_stream_io.py b/tests/file_io/compressed_stream_io.py index 907cfc2d..43797a73 100644 --- a/tests/file_io/compressed_stream_io.py +++ b/tests/file_io/compressed_stream_io.py @@ -32,6 +32,10 @@ def setUp(self): compression_method=definitions.COMPRESSION_METHOD_BZIP2, parent=self._os_path_spec)) + def tearDown(self): + """Cleans up the needed objects used throughout the test.""" + self._resolver_context.Empty() + def testOpenCloseFileObject(self): """Test the open and close functionality using a file-like object.""" os_file_object = os_file_io.OSFile(self._resolver_context) @@ -101,6 +105,10 @@ def setUp(self): compression_method=definitions.COMPRESSION_METHOD_LZMA, parent=self._os_path_spec)) + def tearDown(self): + """Cleans up the needed objects used throughout the test.""" + self._resolver_context.Empty() + def testOpenCloseFileObject(self): """Test the open and close functionality using a file-like object.""" os_file_object = os_file_io.OSFile(self._resolver_context) @@ -170,6 +178,10 @@ def setUp(self): compression_method=definitions.COMPRESSION_METHOD_XZ, parent=self._os_path_spec)) + def tearDown(self): + """Cleans up the needed objects used throughout the test.""" + self._resolver_context.Empty() + def testOpenCloseFileObject(self): """Test the open and close functionality using a file-like object.""" os_file_object = os_file_io.OSFile(self._resolver_context) @@ -239,6 +251,10 @@ def setUp(self): compression_method=definitions.COMPRESSION_METHOD_ZLIB, parent=self._os_path_spec)) + def tearDown(self): + """Cleans up the needed objects used throughout the test.""" + self._resolver_context.Empty() + def testOpenCloseFileObject(self): """Test the open and close functionality using a file-like object.""" os_file_object = os_file_io.OSFile(self._resolver_context) diff --git a/tests/file_io/cpio_file_io.py b/tests/file_io/cpio_file_io.py index 791a4a76..b5a2cfe4 100644 --- a/tests/file_io/cpio_file_io.py +++ b/tests/file_io/cpio_file_io.py @@ -28,6 +28,10 @@ def setUp(self): self._cpio_path_spec = cpio_path_spec.CPIOPathSpec( location='/syslog', parent=path_spec) + def tearDown(self): + """Cleans up the needed objects used throughout the test.""" + self._resolver_context.Empty() + def testOpenClosePathSpec(self): """Test the open and close functionality using a path specification.""" file_object = cpio_file_io.CPIOFile(self._resolver_context) @@ -70,6 +74,10 @@ def setUp(self): self._cpio_path_spec = cpio_path_spec.CPIOPathSpec( location='/syslog', parent=path_spec) + def tearDown(self): + """Cleans up the needed objects used throughout the test.""" + self._resolver_context.Empty() + def testOpenClosePathSpec(self): """Test the open and close functionality using a path specification.""" file_object = cpio_file_io.CPIOFile(self._resolver_context) @@ -112,6 +120,10 @@ def setUp(self): self._cpio_path_spec = cpio_path_spec.CPIOPathSpec( location='/syslog', parent=path_spec) + def tearDown(self): + """Cleans up the needed objects used throughout the test.""" + self._resolver_context.Empty() + def testOpenClosePathSpec(self): """Test the open and close functionality using a path specification.""" file_object = cpio_file_io.CPIOFile(self._resolver_context) @@ -154,6 +166,10 @@ def setUp(self): self._cpio_path_spec = cpio_path_spec.CPIOPathSpec( location='/syslog', parent=path_spec) + def tearDown(self): + """Cleans up the needed objects used throughout the test.""" + self._resolver_context.Empty() + def testOpenClosePathSpec(self): """Test the open and close functionality using a path specification.""" file_object = cpio_file_io.CPIOFile(self._resolver_context) diff --git a/tests/file_io/data_range_io.py b/tests/file_io/data_range_io.py index e3755759..e3d2f61e 100644 --- a/tests/file_io/data_range_io.py +++ b/tests/file_io/data_range_io.py @@ -28,6 +28,10 @@ def setUp(self): self._data_range_path_spec = data_range_path_spec.DataRangePathSpec( range_offset=167, range_size=1080, parent=self._os_path_spec) + def tearDown(self): + """Cleans up the needed objects used throughout the test.""" + self._resolver_context.Empty() + def testOpenCloseFileObject(self): """Test the open and close functionality using a file-like object.""" os_file_object = os_file_io.OSFile(self._resolver_context) diff --git a/tests/file_io/encoded_stream_io.py b/tests/file_io/encoded_stream_io.py index 595127c4..70eac2f2 100644 --- a/tests/file_io/encoded_stream_io.py +++ b/tests/file_io/encoded_stream_io.py @@ -32,6 +32,10 @@ def setUp(self): encoding_method=definitions.ENCODING_METHOD_BASE16, parent=self._os_path_spec)) + def tearDown(self): + """Cleans up the needed objects used throughout the test.""" + self._resolver_context.Empty() + def testOpenCloseFileObject(self): """Test the open and close functionality using a file-like object.""" os_file_object = os_file_io.OSFile(self._resolver_context) @@ -101,6 +105,10 @@ def setUp(self): encoding_method=definitions.ENCODING_METHOD_BASE32, parent=self._os_path_spec)) + def tearDown(self): + """Cleans up the needed objects used throughout the test.""" + self._resolver_context.Empty() + def testOpenCloseFileObject(self): """Test the open and close functionality using a file-like object.""" os_file_object = os_file_io.OSFile(self._resolver_context) @@ -170,6 +178,10 @@ def setUp(self): encoding_method=definitions.ENCODING_METHOD_BASE64, parent=self._os_path_spec)) + def tearDown(self): + """Cleans up the needed objects used throughout the test.""" + self._resolver_context.Empty() + def testOpenCloseFileObject(self): """Test the open and close functionality using a file-like object.""" os_file_object = os_file_io.OSFile(self._resolver_context) diff --git a/tests/file_io/encrypted_stream_io.py b/tests/file_io/encrypted_stream_io.py index 0728cd38..9bbb4ecc 100644 --- a/tests/file_io/encrypted_stream_io.py +++ b/tests/file_io/encrypted_stream_io.py @@ -47,6 +47,10 @@ def setUp(self): self._encrypted_stream_path_spec, 'cipher_mode', self._AES_MODE) self.padding_size = 1 + def tearDown(self): + """Cleans up the needed objects used throughout the test.""" + self._resolver_context.Empty() + def testOpenCloseFileObject(self): """Test the open and close functionality using a file-like object.""" os_file_object = os_file_io.OSFile(self._resolver_context) @@ -126,6 +130,10 @@ def setUp(self): key=self._AES_KEY, parent=self._os_path_spec)) self.padding_size = 1 + def tearDown(self): + """Cleans up the needed objects used throughout the test.""" + self._resolver_context.Empty() + def testOpenCloseFileObject(self): """Test the open and close functionality using a file-like object.""" os_file_object = os_file_io.OSFile(self._resolver_context) @@ -209,6 +217,10 @@ def setUp(self): self._encrypted_stream_path_spec, 'cipher_mode', self._BLOWFISH_MODE) self.padding_size = 1 + def tearDown(self): + """Cleans up the needed objects used throughout the test.""" + self._resolver_context.Empty() + def testOpenCloseFileObject(self): """Test the open and close functionality using a file-like object.""" os_file_object = os_file_io.OSFile(self._resolver_context) @@ -292,6 +304,10 @@ def setUp(self): self._encrypted_stream_path_spec, 'cipher_mode', self._DES3_MODE) self.padding_size = 1 + def tearDown(self): + """Cleans up the needed objects used throughout the test.""" + self._resolver_context.Empty() + def testOpenCloseFileObject(self): """Test the open and close functionality using a file-like object.""" os_file_object = os_file_io.OSFile(self._resolver_context) @@ -367,6 +383,10 @@ def setUp(self): resolver.Resolver.key_chain.SetCredential( self._encrypted_stream_path_spec, 'key', self._RC4_KEY) + def tearDown(self): + """Cleans up the needed objects used throughout the test.""" + self._resolver_context.Empty() + def testOpenCloseFileObject(self): """Test the open and close functionality using a file-like object.""" os_file_object = os_file_io.OSFile(self._resolver_context) diff --git a/tests/file_io/ext_file_io.py b/tests/file_io/ext_file_io.py index bcd8c401..d3252d16 100644 --- a/tests/file_io/ext_file_io.py +++ b/tests/file_io/ext_file_io.py @@ -13,10 +13,10 @@ from dfvfs.path import factory as path_spec_factory from dfvfs.resolver import context -from tests.file_io import test_lib +from tests import test_lib as shared_test_lib -class EXTFileTest(test_lib.ImageFileTestCase): +class EXTFileTest(shared_test_lib.BaseTestCase): """Tests the file-like object implementation using pyfsext.file_entry.""" _IDENTIFIER_ANOTHER_FILE = 15 @@ -34,6 +34,10 @@ def setUp(self): self._raw_path_spec = path_spec_factory.Factory.NewPathSpec( definitions.TYPE_INDICATOR_RAW, parent=test_os_path_spec) + def tearDown(self): + """Cleans up the needed objects used throughout the test.""" + self._resolver_context.Empty() + def testOpenCloseIdentifier(self): """Test the open and close functionality using an inode.""" path_spec = path_spec_factory.Factory.NewPathSpec( @@ -63,7 +67,7 @@ def testOpenCloseLocation(self): path_spec.parent = None with self.assertRaises(errors.PathSpecError): - self._TestOpenCloseLocation(path_spec) + file_object.open(path_spec=path_spec) def testSeek(self): """Test the seek functionality.""" diff --git a/tests/file_io/fake_file_io.py b/tests/file_io/fake_file_io.py index 697b0c81..a97e4267 100644 --- a/tests/file_io/fake_file_io.py +++ b/tests/file_io/fake_file_io.py @@ -31,6 +31,10 @@ def setUp(self): """Sets up the needed objects used throughout the test.""" self._resolver_context = context.Context() + def tearDown(self): + """Cleans up the needed objects used throughout the test.""" + self._resolver_context.Empty() + def testOpenClosePathSpec(self): """Test the Open and Close functions with a path specification.""" test_file = '/test_data/password.txt' diff --git a/tests/file_io/gzip_file_io.py b/tests/file_io/gzip_file_io.py index 0a561359..971e19eb 100644 --- a/tests/file_io/gzip_file_io.py +++ b/tests/file_io/gzip_file_io.py @@ -28,6 +28,10 @@ def setUp(self): self._gzip_path_spec = path_spec_factory.Factory.NewPathSpec( definitions.TYPE_INDICATOR_GZIP, parent=test_os_path_spec) + def tearDown(self): + """Cleans up the needed objects used throughout the test.""" + self._resolver_context.Empty() + def testOpenClosePathSpec(self): """Test the open and close functionality using a path specification.""" file_object = gzip_file_io.GzipFile(self._resolver_context) diff --git a/tests/file_io/hfs_file_io.py b/tests/file_io/hfs_file_io.py index 255aed22..fb7c6fca 100644 --- a/tests/file_io/hfs_file_io.py +++ b/tests/file_io/hfs_file_io.py @@ -13,10 +13,10 @@ from dfvfs.path import factory as path_spec_factory from dfvfs.resolver import context -from tests.file_io import test_lib +from tests import test_lib as shared_test_lib -class HFSFileTest(test_lib.ImageFileTestCase): +class HFSFileTest(shared_test_lib.BaseTestCase): """Tests the file-like object implementation using pyfshfs.file_entry.""" _IDENTIFIER_ANOTHER_FILE = 21 @@ -34,6 +34,10 @@ def setUp(self): self._raw_path_spec = path_spec_factory.Factory.NewPathSpec( definitions.TYPE_INDICATOR_RAW, parent=test_os_path_spec) + def tearDown(self): + """Cleans up the needed objects used throughout the test.""" + self._resolver_context.Empty() + def testOpenCloseIdentifier(self): """Test the open and close functionality using an identifier.""" path_spec = path_spec_factory.Factory.NewPathSpec( @@ -63,7 +67,7 @@ def testOpenCloseLocation(self): path_spec.parent = None with self.assertRaises(errors.PathSpecError): - self._TestOpenCloseLocation(path_spec) + file_object.open(path_spec=path_spec) def testSeek(self): """Test the seek functionality.""" diff --git a/tests/file_io/lvm_file_io.py b/tests/file_io/lvm_file_io.py index f31373ff..9e77b0b8 100644 --- a/tests/file_io/lvm_file_io.py +++ b/tests/file_io/lvm_file_io.py @@ -30,6 +30,10 @@ def setUp(self): path_spec = os_path_spec.OSPathSpec(location=test_file) self._raw_path_spec = raw_path_spec.RawPathSpec(parent=path_spec) + def tearDown(self): + """Cleans up the needed objects used throughout the test.""" + self._resolver_context.Empty() + def testOpenClose(self): """Test the open and close functionality.""" path_spec = lvm_path_spec.LVMPathSpec( diff --git a/tests/file_io/os_file_io.py b/tests/file_io/os_file_io.py index 99a61a5f..558b98be 100644 --- a/tests/file_io/os_file_io.py +++ b/tests/file_io/os_file_io.py @@ -34,6 +34,10 @@ def setUp(self): self._path_spec2 = os_path_spec.OSPathSpec(location=test_file) + def tearDown(self): + """Cleans up the needed objects used throughout the test.""" + self._resolver_context.Empty() + def testOpenClosePathSpec(self): """Test the open and close functionality using a path specification.""" file_object = os_file_io.OSFile(self._resolver_context) diff --git a/tests/file_io/sqlite_blob_file_io.py b/tests/file_io/sqlite_blob_file_io.py index 98e23b0d..fcd9619f 100644 --- a/tests/file_io/sqlite_blob_file_io.py +++ b/tests/file_io/sqlite_blob_file_io.py @@ -28,6 +28,10 @@ def setUp(self): table_name='blobs', column_name='blob', row_condition=('identifier', '==', 'myblob'), parent=path_spec) + def tearDown(self): + """Cleans up the needed objects used throughout the test.""" + self._resolver_context.Empty() + def testOpenClosePathSpec(self): """Test the open and close functionality using a path specification.""" file_object = sqlite_blob_file_io.SQLiteBlobFile(self._resolver_context) @@ -69,6 +73,10 @@ def setUp(self): self._sqlite_blob_path_spec = sqlite_blob_path_spec.SQLiteBlobPathSpec( table_name='blobs', column_name='blob', row_index=0, parent=path_spec) + def tearDown(self): + """Cleans up the needed objects used throughout the test.""" + self._resolver_context.Empty() + def testOpenClosePathSpec(self): """Test the open and close functionality using a path specification.""" file_object = sqlite_blob_file_io.SQLiteBlobFile(self._resolver_context) diff --git a/tests/file_io/tar_file_io.py b/tests/file_io/tar_file_io.py index 96a7522c..5f3280e1 100644 --- a/tests/file_io/tar_file_io.py +++ b/tests/file_io/tar_file_io.py @@ -28,6 +28,10 @@ def setUp(self): self._tar_path_spec = tar_path_spec.TARPathSpec( location='/syslog', parent=path_spec) + def tearDown(self): + """Cleans up the needed objects used throughout the test.""" + self._resolver_context.Empty() + def testOpenClosePathSpec(self): """Test the open and close functionality using a path specification.""" file_object = tar_file_io.TARFile(self._resolver_context) diff --git a/tests/file_io/test_lib.py b/tests/file_io/test_lib.py index 57575d81..c343c2c1 100644 --- a/tests/file_io/test_lib.py +++ b/tests/file_io/test_lib.py @@ -8,11 +8,14 @@ from dfvfs.file_io import ntfs_file_io from dfvfs.file_io import tsk_file_io from dfvfs.file_io import tsk_partition_file_io +from dfvfs.lib import definitions from dfvfs.lib import errors +from dfvfs.path import factory as path_spec_factory from dfvfs.path import ntfs_path_spec from dfvfs.path import tsk_path_spec from dfvfs.path import tsk_partition_path_spec from dfvfs.resolver import context +from dfvfs.resolver import resolver from tests import test_lib as shared_test_lib @@ -27,15 +30,21 @@ def setUp(self): """Sets up the needed objects used throughout the test.""" self._resolver_context = context.Context() + def tearDown(self): + """Cleans up the needed objects used throughout the test.""" + self._resolver_context.Empty() + def _TestOpenCloseInode(self, parent_path_spec): """Test the open and close functionality using an inode. Args: parent_path_spec (PathSpec): parent path specification. """ - path_spec = tsk_path_spec.TSKPathSpec( - inode=self._INODE_PASSWORDS_TXT, parent=parent_path_spec) - file_object = tsk_file_io.TSKFile(self._resolver_context) + path_spec = path_spec_factory.Factory.NewPathSpec( + definitions.PREFERRED_EXT_BACK_END, inode=self._INODE_PASSWORDS_TXT, + parent=parent_path_spec) + file_object = resolver.Resolver.OpenFileObject( + path_spec, resolver_context=self._resolver_context) file_object.open(path_spec=path_spec) self.assertEqual(file_object.get_size(), 116) @@ -47,9 +56,11 @@ def _TestOpenCloseLocation(self, parent_path_spec): Args: parent_path_spec (PathSpec): parent path specification. """ - path_spec = tsk_path_spec.TSKPathSpec( - location='/passwords.txt', parent=parent_path_spec) - file_object = tsk_file_io.TSKFile(self._resolver_context) + path_spec = path_spec_factory.Factory.NewPathSpec( + definitions.PREFERRED_EXT_BACK_END, location='/passwords.txt', + parent=parent_path_spec) + file_object = resolver.Resolver.OpenFileObject( + path_spec, resolver_context=self._resolver_context) file_object.open(path_spec=path_spec) self.assertEqual(file_object.get_size(), 116) @@ -61,10 +72,11 @@ def _TestSeek(self, parent_path_spec): Args: parent_path_spec (PathSpec): parent path specification. """ - path_spec = tsk_path_spec.TSKPathSpec( - inode=self._INODE_ANOTHER_FILE, location='/a_directory/another_file', - parent=parent_path_spec) - file_object = tsk_file_io.TSKFile(self._resolver_context) + path_spec = path_spec_factory.Factory.NewPathSpec( + definitions.PREFERRED_EXT_BACK_END, inode=self._INODE_ANOTHER_FILE, + location='/a_directory/another_file', parent=parent_path_spec) + file_object = resolver.Resolver.OpenFileObject( + path_spec, resolver_context=self._resolver_context) file_object.open(path_spec=path_spec) self.assertEqual(file_object.get_size(), 22) @@ -105,10 +117,11 @@ def _TestRead(self, parent_path_spec): Args: parent_path_spec (PathSpec): parent path specification. """ - path_spec = tsk_path_spec.TSKPathSpec( - inode=self._INODE_PASSWORDS_TXT, location='/passwords.txt', - parent=parent_path_spec) - file_object = tsk_file_io.TSKFile(self._resolver_context) + path_spec = path_spec_factory.Factory.NewPathSpec( + definitions.PREFERRED_EXT_BACK_END, inode=self._INODE_PASSWORDS_TXT, + location='/passwords.txt', parent=parent_path_spec) + file_object = resolver.Resolver.OpenFileObject( + path_spec, resolver_context=self._resolver_context) file_object.open(path_spec=path_spec) read_buffer = file_object.read() @@ -137,6 +150,10 @@ def setUp(self): """Sets up the needed objects used throughout the test.""" self._resolver_context = context.Context() + def tearDown(self): + """Cleans up the needed objects used throughout the test.""" + self._resolver_context.Empty() + def _TestOpenCloseInode(self, parent_path_spec): """Test the open and close functionality using an inode. @@ -247,6 +264,10 @@ def setUp(self): """Sets up the needed objects used throughout the test.""" self._resolver_context = context.Context() + def tearDown(self): + """Cleans up the needed objects used throughout the test.""" + self._resolver_context.Empty() + def _TestOpenCloseMFTEntry(self, path_spec, file_object): """Test the open and close functionality using a MFT entry. @@ -393,6 +414,10 @@ def setUp(self): """Sets up the needed objects used throughout the test.""" self._resolver_context = context.Context() + def tearDown(self): + """Cleans up the needed objects used throughout the test.""" + self._resolver_context.Empty() + def _TestOpenClose(self, parent_path_spec): """Test the open and close functionality. @@ -671,6 +696,10 @@ def setUp(self): """Sets up the needed objects used throughout the test.""" self._resolver_context = context.Context() + def tearDown(self): + """Cleans up the needed objects used throughout the test.""" + self._resolver_context.Empty() + def _TestOpenCloseMFTEntry(self, parent_path_spec): """Test the open and close functionality using a MFT entry. @@ -789,6 +818,10 @@ def setUp(self): """Sets up the needed objects used throughout the test.""" self._resolver_context = context.Context() + def tearDown(self): + """Cleans up the needed objects used throughout the test.""" + self._resolver_context.Empty() + def _TestOpenCloseMFTEntry(self, parent_path_spec): """Test the open and close functionality using a MFT entry. diff --git a/tests/file_io/vshadow_file_io.py b/tests/file_io/vshadow_file_io.py index c1042dba..ce40a413 100644 --- a/tests/file_io/vshadow_file_io.py +++ b/tests/file_io/vshadow_file_io.py @@ -29,6 +29,10 @@ def setUp(self): path_spec = os_path_spec.OSPathSpec(location=test_file) self._qcow_path_spec = qcow_path_spec.QCOWPathSpec(parent=path_spec) + def tearDown(self): + """Cleans up the needed objects used throughout the test.""" + self._resolver_context.Empty() + def testOpenClose(self): """Test the open and close functionality.""" path_spec = vshadow_path_spec.VShadowPathSpec( diff --git a/tests/file_io/zip_file_io.py b/tests/file_io/zip_file_io.py index a75aabea..59314166 100644 --- a/tests/file_io/zip_file_io.py +++ b/tests/file_io/zip_file_io.py @@ -28,6 +28,10 @@ def setUp(self): self._zip_path_spec = zip_path_spec.ZipPathSpec( location='/syslog', parent=path_spec) + def tearDown(self): + """Cleans up the needed objects used throughout the test.""" + self._resolver_context.Empty() + def testOpenClosePathSpec(self): """Test the open and close functionality using a path specification.""" file_object = zip_file_io.ZipFile(self._resolver_context) diff --git a/tests/resolver/cache.py b/tests/resolver/cache.py index 41243b0d..c8c354a6 100644 --- a/tests/resolver/cache.py +++ b/tests/resolver/cache.py @@ -110,6 +110,8 @@ def testEmpty(self): cache_object.Empty() self.assertEqual(len(cache_object._values), 0) + # TODO: add tests for the GetLastObject method + def testGetObject(self): """Tests the GetObject method.""" cache_object = cache.ObjectsCache(1) diff --git a/tests/vfs/apfs_container_file_system.py b/tests/vfs/apfs_container_file_system.py index 1cc0afba..5e437454 100644 --- a/tests/vfs/apfs_container_file_system.py +++ b/tests/vfs/apfs_container_file_system.py @@ -30,6 +30,10 @@ def setUp(self): apfs_container_path_spec.APFSContainerPathSpec( location='/', parent=self._raw_path_spec)) + def tearDown(self): + """Cleans up the needed objects used throughout the test.""" + self._resolver_context.Empty() + def testOpenAndClose(self): """Test the open and close functionality.""" file_system = apfs_container_file_system.APFSContainerFileSystem( diff --git a/tests/vfs/apfs_file_system.py b/tests/vfs/apfs_file_system.py index 69678db0..3049a1c1 100644 --- a/tests/vfs/apfs_file_system.py +++ b/tests/vfs/apfs_file_system.py @@ -34,6 +34,10 @@ def setUp(self): definitions.TYPE_INDICATOR_APFS, location='/', parent=self._apfs_container_path_spec) + def tearDown(self): + """Cleans up the needed objects used throughout the test.""" + self._resolver_context.Empty() + def testOpenAndClose(self): """Test the open and close functionality.""" file_system = apfs_file_system.APFSFileSystem(self._resolver_context) diff --git a/tests/vfs/bde_file_system.py b/tests/vfs/bde_file_system.py index f6e20a0a..81859720 100644 --- a/tests/vfs/bde_file_system.py +++ b/tests/vfs/bde_file_system.py @@ -31,6 +31,10 @@ def setUp(self): resolver.Resolver.key_chain.SetCredential( self._bde_path_spec, 'password', self._BDE_PASSWORD) + def tearDown(self): + """Cleans up the needed objects used throughout the test.""" + self._resolver_context.Empty() + def testOpenAndClose(self): """Test the open and close functionality.""" file_system = bde_file_system.BDEFileSystem(self._resolver_context) diff --git a/tests/vfs/compressed_stream_file_system.py b/tests/vfs/compressed_stream_file_system.py index ee10f62f..221d64c3 100644 --- a/tests/vfs/compressed_stream_file_system.py +++ b/tests/vfs/compressed_stream_file_system.py @@ -30,6 +30,10 @@ def setUp(self): compression_method=definitions.COMPRESSION_METHOD_BZIP2, parent=path_spec)) + def tearDown(self): + """Cleans up the needed objects used throughout the test.""" + self._resolver_context.Empty() + def testOpenAndClose(self): """Test the open and close functionality.""" file_system = compressed_stream_file_system.CompressedStreamFileSystem( diff --git a/tests/vfs/cpio_file_system.py b/tests/vfs/cpio_file_system.py index 2d463256..f67b045f 100644 --- a/tests/vfs/cpio_file_system.py +++ b/tests/vfs/cpio_file_system.py @@ -27,6 +27,10 @@ def setUp(self): self._cpio_path_spec = cpio_path_spec.CPIOPathSpec( location='/syslog', parent=self._os_path_spec) + def tearDown(self): + """Cleans up the needed objects used throughout the test.""" + self._resolver_context.Empty() + def testOpenAndClose(self): """Test the open and close functionality.""" file_system = cpio_file_system.CPIOFileSystem(self._resolver_context) diff --git a/tests/vfs/data_range_file_system.py b/tests/vfs/data_range_file_system.py index cdcf876d..ea138c86 100644 --- a/tests/vfs/data_range_file_system.py +++ b/tests/vfs/data_range_file_system.py @@ -28,6 +28,10 @@ def setUp(self): data_range_path_spec.DataRangePathSpec( range_offset=0x1c0, range_size=0x41, parent=path_spec)) + def tearDown(self): + """Cleans up the needed objects used throughout the test.""" + self._resolver_context.Empty() + def testOpenAndClose(self): """Test the open and close functionality.""" file_system = data_range_file_system.DataRangeFileSystem( diff --git a/tests/vfs/encoded_stream_file_system.py b/tests/vfs/encoded_stream_file_system.py index de701fa3..7f1ebc98 100644 --- a/tests/vfs/encoded_stream_file_system.py +++ b/tests/vfs/encoded_stream_file_system.py @@ -30,6 +30,10 @@ def setUp(self): encoding_method=definitions.ENCODING_METHOD_BASE64, parent=path_spec)) + def tearDown(self): + """Cleans up the needed objects used throughout the test.""" + self._resolver_context.Empty() + def testOpenAndClose(self): """Test the open and close functionality.""" file_system = encoded_stream_file_system.EncodedStreamFileSystem( diff --git a/tests/vfs/encrypted_stream_file_system.py b/tests/vfs/encrypted_stream_file_system.py index 7ca73096..9b046e51 100644 --- a/tests/vfs/encrypted_stream_file_system.py +++ b/tests/vfs/encrypted_stream_file_system.py @@ -35,6 +35,10 @@ def setUp(self): resolver.Resolver.key_chain.SetCredential( self._encrypted_stream_path_spec, 'key', self._RC4_KEY) + def tearDown(self): + """Cleans up the needed objects used throughout the test.""" + self._resolver_context.Empty() + def testOpenAndClose(self): """Test the open and close functionality.""" file_system = encrypted_stream_file_system.EncryptedStreamFileSystem( diff --git a/tests/vfs/ext_file_system.py b/tests/vfs/ext_file_system.py index 69794f1b..57552fd9 100644 --- a/tests/vfs/ext_file_system.py +++ b/tests/vfs/ext_file_system.py @@ -31,6 +31,10 @@ def setUp(self): definitions.TYPE_INDICATOR_EXT, location='/', parent=self._raw_path_spec) + def tearDown(self): + """Cleans up the needed objects used throughout the test.""" + self._resolver_context.Empty() + def testOpenAndClose(self): """Test the open and close functionality.""" file_system = ext_file_system.EXTFileSystem(self._resolver_context) diff --git a/tests/vfs/fake_file_system.py b/tests/vfs/fake_file_system.py index 27338b93..8e99a7fa 100644 --- a/tests/vfs/fake_file_system.py +++ b/tests/vfs/fake_file_system.py @@ -21,6 +21,10 @@ def setUp(self): self._resolver_context = context.Context() self._fake_path_spec = fake_path_spec.FakePathSpec(location='/') + def tearDown(self): + """Cleans up the needed objects used throughout the test.""" + self._resolver_context.Empty() + def testOpenAndClose(self): """Test the open and close functionality.""" file_system = fake_file_system.FakeFileSystem(self._resolver_context) diff --git a/tests/vfs/fvde_file_system.py b/tests/vfs/fvde_file_system.py index 94e3513c..01e5406e 100644 --- a/tests/vfs/fvde_file_system.py +++ b/tests/vfs/fvde_file_system.py @@ -36,6 +36,10 @@ def setUp(self): resolver.Resolver.key_chain.SetCredential( self._fvde_path_spec, 'password', self._FVDE_PASSWORD) + def tearDown(self): + """Cleans up the needed objects used throughout the test.""" + self._resolver_context.Empty() + def testOpenAndClose(self): """Test the open and close functionality.""" file_system = fvde_file_system.FVDEFileSystem(self._resolver_context) diff --git a/tests/vfs/gzip_file_system.py b/tests/vfs/gzip_file_system.py index aba7e6fa..69183770 100644 --- a/tests/vfs/gzip_file_system.py +++ b/tests/vfs/gzip_file_system.py @@ -26,6 +26,10 @@ def setUp(self): path_spec = os_path_spec.OSPathSpec(location=test_file) self._gzip_path_spec = gzip_path_spec.GzipPathSpec(parent=path_spec) + def tearDown(self): + """Cleans up the needed objects used throughout the test.""" + self._resolver_context.Empty() + def testOpenAndClose(self): """Test the open and close functionality.""" file_system = gzip_file_system.GzipFileSystem(self._resolver_context) diff --git a/tests/vfs/hfs_file_system.py b/tests/vfs/hfs_file_system.py index 4c92b9ad..51d0138d 100644 --- a/tests/vfs/hfs_file_system.py +++ b/tests/vfs/hfs_file_system.py @@ -33,6 +33,10 @@ def setUp(self): definitions.TYPE_INDICATOR_HFS, location='/', parent=self._raw_path_spec) + def tearDown(self): + """Cleans up the needed objects used throughout the test.""" + self._resolver_context.Empty() + def testOpenAndClose(self): """Test the open and close functionality.""" file_system = hfs_file_system.HFSFileSystem(self._resolver_context) diff --git a/tests/vfs/luksde_file_system.py b/tests/vfs/luksde_file_system.py index ed08a7b3..edf8c078 100644 --- a/tests/vfs/luksde_file_system.py +++ b/tests/vfs/luksde_file_system.py @@ -31,6 +31,10 @@ def setUp(self): resolver.Resolver.key_chain.SetCredential( self._luksde_path_spec, 'password', self._LUKSDE_PASSWORD) + def tearDown(self): + """Cleans up the needed objects used throughout the test.""" + self._resolver_context.Empty() + def testOpenAndClose(self): """Test the open and close functionality.""" file_system = luksde_file_system.LUKSDEFileSystem(self._resolver_context) diff --git a/tests/vfs/lvm_file_system.py b/tests/vfs/lvm_file_system.py index 4d21c2fa..03a5e094 100644 --- a/tests/vfs/lvm_file_system.py +++ b/tests/vfs/lvm_file_system.py @@ -29,6 +29,10 @@ def setUp(self): self._lvm_path_spec = lvm_path_spec.LVMPathSpec( location='/', parent=self._raw_path_spec) + def tearDown(self): + """Cleans up the needed objects used throughout the test.""" + self._resolver_context.Empty() + # vslvminfo fuse/lvm.raw # # Linux Logical Volume Manager (LVM) information: diff --git a/tests/vfs/ntfs_file_system.py b/tests/vfs/ntfs_file_system.py index 77182a89..479409d0 100644 --- a/tests/vfs/ntfs_file_system.py +++ b/tests/vfs/ntfs_file_system.py @@ -29,6 +29,10 @@ def setUp(self): self._ntfs_path_spec = ntfs_path_spec.NTFSPathSpec( location='\\', parent=self._qcow_path_spec) + def tearDown(self): + """Cleans up the needed objects used throughout the test.""" + self._resolver_context.Empty() + def testOpenAndClose(self): """Test the open and close functionality.""" file_system = ntfs_file_system.NTFSFileSystem(self._resolver_context) diff --git a/tests/vfs/os_file_system.py b/tests/vfs/os_file_system.py index 88039a12..9aeede4e 100644 --- a/tests/vfs/os_file_system.py +++ b/tests/vfs/os_file_system.py @@ -25,6 +25,10 @@ def setUp(self): """Sets up the needed objects used throughout the test.""" self._resolver_context = context.Context() + def tearDown(self): + """Cleans up the needed objects used throughout the test.""" + self._resolver_context.Empty() + def testIntialize(self): """Test the __init__ function.""" file_system = os_file_system.OSFileSystem(self._resolver_context) diff --git a/tests/vfs/sqlite_blob_file_system.py b/tests/vfs/sqlite_blob_file_system.py index 0f93d347..323432e2 100644 --- a/tests/vfs/sqlite_blob_file_system.py +++ b/tests/vfs/sqlite_blob_file_system.py @@ -31,6 +31,10 @@ def setUp(self): table_name='myblobs', column_name='blobs', row_index=2, parent=path_spec) + def tearDown(self): + """Cleans up the needed objects used throughout the test.""" + self._resolver_context.Empty() + def testOpenAndClose(self): """Test the open and close functionality.""" file_system = sqlite_blob_file_system.SQLiteBlobFileSystem( diff --git a/tests/vfs/tar_file_system.py b/tests/vfs/tar_file_system.py index ebe9ed00..c25bcca9 100644 --- a/tests/vfs/tar_file_system.py +++ b/tests/vfs/tar_file_system.py @@ -27,6 +27,10 @@ def setUp(self): self._tar_path_spec = tar_path_spec.TARPathSpec( location='/syslog', parent=self._os_path_spec) + def tearDown(self): + """Cleans up the needed objects used throughout the test.""" + self._resolver_context.Empty() + def testOpenAndClose(self): """Test the open and close functionality.""" file_system = tar_file_system.TARFileSystem(self._resolver_context) diff --git a/tests/vfs/tsk_file_system.py b/tests/vfs/tsk_file_system.py index 1305ce70..426e35ac 100644 --- a/tests/vfs/tsk_file_system.py +++ b/tests/vfs/tsk_file_system.py @@ -29,6 +29,10 @@ def setUp(self): self._tsk_path_spec = tsk_path_spec.TSKPathSpec( location='/', parent=self._os_path_spec) + def tearDown(self): + """Cleans up the needed objects used throughout the test.""" + self._resolver_context.Empty() + def testOpenAndClose(self): """Test the open and close functionality.""" file_system = tsk_file_system.TSKFileSystem(self._resolver_context) diff --git a/tests/vfs/tsk_partition_file_system.py b/tests/vfs/tsk_partition_file_system.py index af02cbca..a766e4cc 100644 --- a/tests/vfs/tsk_partition_file_system.py +++ b/tests/vfs/tsk_partition_file_system.py @@ -28,6 +28,10 @@ def setUp(self): tsk_partition_path_spec.TSKPartitionPathSpec( location='/', parent=self._os_path_spec)) + def tearDown(self): + """Cleans up the needed objects used throughout the test.""" + self._resolver_context.Empty() + # mmls test_data/mbr.raw # DOS Partition Table # Offset Sector: 0 diff --git a/tests/vfs/vshadow_file_system.py b/tests/vfs/vshadow_file_system.py index d2f04641..fc84d4dc 100644 --- a/tests/vfs/vshadow_file_system.py +++ b/tests/vfs/vshadow_file_system.py @@ -29,6 +29,10 @@ def setUp(self): self._vshadow_path_spec = vshadow_path_spec.VShadowPathSpec( location='/', parent=self._qcow_path_spec) + def tearDown(self): + """Cleans up the needed objects used throughout the test.""" + self._resolver_context.Empty() + # qcowmount test_data/vsstest.qcow2 fuse/ # vshadowinfo fuse/qcow1 # diff --git a/tests/vfs/zip_file_system.py b/tests/vfs/zip_file_system.py index a5b4558a..cf78e5cb 100644 --- a/tests/vfs/zip_file_system.py +++ b/tests/vfs/zip_file_system.py @@ -27,6 +27,10 @@ def setUp(self): self._zip_path_spec = zip_path_spec.ZipPathSpec( location='/', parent=self._os_path_spec) + def tearDown(self): + """Cleans up the needed objects used throughout the test.""" + self._resolver_context.Empty() + def testOpenAndClose(self): """Test the open and close functionality.""" file_system = zip_file_system.ZipFileSystem(self._resolver_context)