def setUp(self): """Sets up the needed objects used throughout the test.""" self._resolver_context = context.Context() test_file = os.path.join(u'test_data', u'testdir_os') self._os_path_spec = os_path_spec.OSPathSpec(location=test_file) self._file_system = os_file_system.OSFileSystem(self._resolver_context) self._file_system.Open(path_spec=self._os_path_spec)
def setUp(self): """Sets up the needed objects used throughout the test.""" self._resolver_context = context.Context() test_file = self._GetTestFilePath(['testdir_os']) self._os_path_spec = os_path_spec.OSPathSpec(location=test_file) self._file_system = os_file_system.OSFileSystem(self._resolver_context) self._file_system.Open(self._os_path_spec)
def NewFileSystem(self, resolver_context): """Creates a new file system object. Args: resolver_context (Context): resolver context. Returns: FileSystem: file system. """ return os_file_system.OSFileSystem(resolver_context)
def testJoinPathWindows(self): """Test the join path functionality for Windows.""" # In this test we emulate we are running on Windows. original_platform_system = platform.system platform.system = TestPlatformSystem file_system = os_file_system.OSFileSystem(self._resolver_context) file_system.PATH_SEPARATOR = u'\\' expected_path = u'\\\\.\\PhysicalDrive0' path = file_system.JoinPath([u'\\\\.\\PhysicalDrive0']) self.assertEqual(path, expected_path) expected_path = u'\\\\.\\C:' path = file_system.JoinPath([u'\\\\.\\C:']) self.assertEqual(path, expected_path) expected_path = u'C:' path = file_system.JoinPath([u'\\\\.\\C:\\']) self.assertEqual(path, expected_path) expected_path = ( u'\\\\?\\Volume{26a21bda-a627-11d7-9931-806e6f6e6963}\\test1') path = file_system.JoinPath([ u'\\\\?\\Volume{26a21bda-a627-11d7-9931-806e6f6e6963}\\', u'test1' ]) self.assertEqual(path, expected_path) expected_path = u'C:\\test1\\test2\\test3' path = file_system.JoinPath([u'C:', u'test1', u'test2', u'test3']) self.assertEqual(path, expected_path) path = file_system.JoinPath( [u'C:\\', u'test1\\\\', u'\\\\test2', u'test3\\']) self.assertEqual(path, expected_path) path = file_system.JoinPath([u'C:\\test1\\\\', u'\\\\test2\\test3']) self.assertEqual(path, expected_path) path = file_system.JoinPath( [u'\\\\.\\C:\\', u'test1', u'test2', u'test3']) self.assertEqual(path, expected_path) expected_path = u'\\\\server\\share\\directory\\file.txt' path = file_system.JoinPath( [u'\\\\server\\share', u'directory', u'file.txt']) self.assertEqual(path, expected_path) platform.system = original_platform_system
def NewFileSystem(self, resolver_context, path_spec): """Creates a new file system object. Args: resolver_context (Context): resolver context. path_spec (PathSpec): a path specification. Returns: FileSystem: file system. """ return os_file_system.OSFileSystem(resolver_context, path_spec)
def testFileEntryExistsByPathSpec(self): """Test the file entry exists by path specification functionality.""" file_system = os_file_system.OSFileSystem(self._resolver_context) test_file = self._GetTestFilePath(['testdir_os', 'file1.txt']) path_spec = os_path_spec.OSPathSpec(location=test_file) self.assertTrue(file_system.FileEntryExistsByPathSpec(path_spec)) test_file = self._GetTestFilePath(['testdir_os', 'file6.txt']) path_spec = os_path_spec.OSPathSpec(location=test_file) self.assertFalse(file_system.FileEntryExistsByPathSpec(path_spec))
def testFileEntryExistsByPathSpec(self): """Test the file entry exists by path specification functionality.""" file_system = os_file_system.OSFileSystem(self._resolver_context) path_spec = os_path_spec.OSPathSpec( location=os.path.join(u'test_data', u'testdir_os', u'file1.txt')) self.assertTrue(file_system.FileEntryExistsByPathSpec(path_spec)) path_spec = os_path_spec.OSPathSpec( location=os.path.join(u'test_data', u'testdir_os', u'file6.txt')) self.assertFalse(file_system.FileEntryExistsByPathSpec(path_spec))
def testGetRootFileEntry(self): """Test the get root file entry functionality.""" file_system = os_file_system.OSFileSystem(self._resolver_context) if platform.system() == 'Windows': # Return the root with the drive letter of the volume the current # working directory is on. expected_location = os.getcwd() expected_location, _, _ = expected_location.partition('\\') else: expected_location = '' file_entry = file_system.GetRootFileEntry() self.assertIsNotNone(file_entry) self.assertEqual(file_entry.name, expected_location)
def testGetFileEntryByPathSpec(self): """Tests the GetFileEntryByPathSpec function.""" file_system = os_file_system.OSFileSystem(self._resolver_context) test_file = self._GetTestFilePath(['testdir_os', 'file1.txt']) path_spec = os_path_spec.OSPathSpec(location=test_file) file_entry = file_system.GetFileEntryByPathSpec(path_spec) self.assertIsNotNone(file_entry) self.assertEqual(file_entry.name, 'file1.txt') test_file = self._GetTestFilePath(['testdir_os', 'file6.txt']) path_spec = os_path_spec.OSPathSpec(location=test_file) file_entry = file_system.GetFileEntryByPathSpec(path_spec) self.assertIsNone(file_entry)
def testGetFileEntryByPathSpec(self): """Tests the GetFileEntryByPathSpec function.""" file_system = os_file_system.OSFileSystem(self._resolver_context) path_spec = os_path_spec.OSPathSpec( location=os.path.join(u'test_data', u'testdir_os', u'file1.txt')) file_entry = file_system.GetFileEntryByPathSpec(path_spec) self.assertIsNotNone(file_entry) self.assertEqual(file_entry.name, u'file1.txt') path_spec = os_path_spec.OSPathSpec( location=os.path.join(u'test_data', u'testdir_os', u'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 = os_file_system.OSFileSystem(self._resolver_context) path_spec = os_path_spec.OSPathSpec( location=os.path.join(u'test_data', u'testdir_os', u'file1.txt')) file_entry = file_system.GetFileEntryByPathSpec(path_spec) self.assertNotEqual(file_entry, None) self.assertEqual(file_entry.name, u'file1.txt') path_spec = os_path_spec.OSPathSpec( location=os.path.join(u'test_data', u'testdir_os', u'file6.txt')) file_entry = file_system.GetFileEntryByPathSpec(path_spec) self.assertEqual(file_entry, None)
def setUp(self): """Sets up the needed objects used throughout the test.""" self._resolver_context = context.Context() test_file = os.path.join(os.getcwd(), u'test_data') self._os_path_spec = os_path_spec.OSPathSpec(location=test_file) self._os_file_system = os_file_system.OSFileSystem(self._resolver_context) # TODO: add RAW volume only test image. test_file = os.path.join(u'test_data', u'vsstest.qcow2') path_spec = os_path_spec.OSPathSpec(location=test_file) self._qcow_path_spec = qcow_path_spec.QcowPathSpec(parent=path_spec) self._tsk_path_spec = tsk_path_spec.TSKPathSpec( location=u'/', parent=self._qcow_path_spec) self._tsk_file_system = tsk_file_system.TSKFileSystem( self._resolver_context) self._tsk_file_system.Open(path_spec=self._tsk_path_spec)
def setUp(self): """Sets up the needed objects used throughout the test.""" self._resolver_context = context.Context() self._os_path = self._GetTestFilePath([]) self._os_path_spec = os_path_spec.OSPathSpec(location=self._os_path) self._os_file_system = os_file_system.OSFileSystem( self._resolver_context) # TODO: add RAW volume only test image. test_file = self._GetTestFilePath([u'vsstest.qcow2']) path_spec = os_path_spec.OSPathSpec(location=test_file) self._qcow_path_spec = qcow_path_spec.QCOWPathSpec(parent=path_spec) self._tsk_path_spec = tsk_path_spec.TSKPathSpec( location=u'/', parent=self._qcow_path_spec) self._tsk_file_system = tsk_file_system.TSKFileSystem( self._resolver_context) self._tsk_file_system.Open(self._tsk_path_spec)
def testIntialize(self): """Test the __init__ function.""" file_system = os_file_system.OSFileSystem(self._resolver_context) self.assertIsNotNone(file_system)
def testIntialize(self): """Test the intialize functionality.""" file_system = os_file_system.OSFileSystem(self._resolver_context) self.assertNotEqual(file_system, None)