def testGetFileEntryByPathSpec(self): """Tests the GetFileEntryByPathSpec function.""" file_system = tar_file_system.TARFileSystem(self._resolver_context, self._tar_path_spec) self.assertIsNotNone(file_system) file_system.Open() path_spec = path_spec_factory.Factory.NewPathSpec( definitions.TYPE_INDICATOR_TAR, location='/syslog', parent=self._os_path_spec) file_entry = file_system.GetFileEntryByPathSpec(path_spec) self.assertIsNotNone(file_entry) self.assertEqual(file_entry.name, 'syslog') path_spec = path_spec_factory.Factory.NewPathSpec( definitions.TYPE_INDICATOR_TAR, location='/bogus', parent=self._os_path_spec) file_entry = file_system.GetFileEntryByPathSpec(path_spec) self.assertIsNone(file_entry) # Test on a tar file that has missing directory entries. test_path = self._GetTestFilePath(['missing_directory_entries.tar']) self._SkipIfPathNotExists(test_path) test_os_path_spec = path_spec_factory.Factory.NewPathSpec( definitions.TYPE_INDICATOR_OS, location=test_path) path_spec = path_spec_factory.Factory.NewPathSpec( definitions.TYPE_INDICATOR_TAR, location='/', parent=test_os_path_spec) file_system = tar_file_system.TARFileSystem(self._resolver_context, path_spec) self.assertIsNotNone(file_system) file_system.Open() path_spec = path_spec_factory.Factory.NewPathSpec( definitions.TYPE_INDICATOR_TAR, location='/File System', parent=test_os_path_spec) file_entry = file_system.GetFileEntryByPathSpec(path_spec) self.assertIsNotNone(file_entry) self.assertEqual(file_entry.name, 'File System') path_spec = path_spec_factory.Factory.NewPathSpec( definitions.TYPE_INDICATOR_TAR, location='/File System/Recordings', parent=test_os_path_spec) file_entry = file_system.GetFileEntryByPathSpec(path_spec) self.assertIsNotNone(file_entry) self.assertEqual(file_entry.name, 'Recordings')
def testFileEntryExistsByPathSpec(self): """Test the file entry exists by path specification functionality.""" file_system = tar_file_system.TARFileSystem(self._resolver_context, self._tar_path_spec) self.assertIsNotNone(file_system) file_system.Open() path_spec = path_spec_factory.Factory.NewPathSpec( definitions.TYPE_INDICATOR_TAR, location='/syslog', parent=self._os_path_spec) self.assertTrue(file_system.FileEntryExistsByPathSpec(path_spec)) path_spec = path_spec_factory.Factory.NewPathSpec( definitions.TYPE_INDICATOR_TAR, location='/bogus', parent=self._os_path_spec) self.assertFalse(file_system.FileEntryExistsByPathSpec(path_spec)) # Test on a tar file that has missing directory entries. test_path = self._GetTestFilePath(['missing_directory_entries.tar']) self._SkipIfPathNotExists(test_path) test_os_path_spec = path_spec_factory.Factory.NewPathSpec( definitions.TYPE_INDICATOR_OS, location=test_path) path_spec = path_spec_factory.Factory.NewPathSpec( definitions.TYPE_INDICATOR_TAR, location='/', parent=test_os_path_spec) file_system = tar_file_system.TARFileSystem(self._resolver_context, path_spec) self.assertIsNotNone(file_system) file_system.Open() path_spec = path_spec_factory.Factory.NewPathSpec( definitions.TYPE_INDICATOR_TAR, location='/File System', parent=test_os_path_spec) self.assertTrue(file_system.FileEntryExistsByPathSpec(path_spec)) path_spec = path_spec_factory.Factory.NewPathSpec( definitions.TYPE_INDICATOR_TAR, location='/File System/Recordings', parent=test_os_path_spec) self.assertTrue(file_system.FileEntryExistsByPathSpec(path_spec))
def testOpenAndClose(self): """Test the open and close functionality.""" file_system = tar_file_system.TARFileSystem(self._resolver_context, self._tar_path_spec) self.assertIsNotNone(file_system) file_system.Open()
def testGetFileEntryByPathSpec(self): """Tests the GetFileEntryByPathSpec function.""" file_system = tar_file_system.TARFileSystem(self._resolver_context) self.assertIsNotNone(file_system) file_system.Open(self._tar_path_spec) path_spec = tar_path_spec.TARPathSpec(location='/syslog', parent=self._os_path_spec) file_entry = file_system.GetFileEntryByPathSpec(path_spec) self.assertIsNotNone(file_entry) self.assertEqual(file_entry.name, 'syslog') path_spec = tar_path_spec.TARPathSpec(location='/bogus', parent=self._os_path_spec) file_entry = file_system.GetFileEntryByPathSpec(path_spec) self.assertIsNone(file_entry) file_system.Close() # Test on a tar file that has missing directory entries. test_file = self._GetTestFilePath(['missing_directory_entries.tar']) self._SkipIfPathNotExists(test_file) test_file_path_spec = os_path_spec.OSPathSpec(location=test_file) path_spec = tar_path_spec.TARPathSpec(location='/', parent=test_file_path_spec) file_system = tar_file_system.TARFileSystem(self._resolver_context) self.assertIsNotNone(file_system) file_system.Open(path_spec) path_spec = tar_path_spec.TARPathSpec(location='/File System', parent=test_file_path_spec) file_entry = file_system.GetFileEntryByPathSpec(path_spec) self.assertIsNotNone(file_entry) self.assertEqual(file_entry.name, 'File System') path_spec = tar_path_spec.TARPathSpec( location='/File System/Recordings', parent=test_file_path_spec) file_entry = file_system.GetFileEntryByPathSpec(path_spec) self.assertIsNotNone(file_entry) self.assertEqual(file_entry.name, 'Recordings') file_system.Close()
def setUp(self): """Sets up the needed objects used throughout the test.""" self._resolver_context = context.Context() test_file = self._GetTestFilePath(['syslog.tar']) self._os_path_spec = os_path_spec.OSPathSpec(location=test_file) self._tar_path_spec = tar_path_spec.TARPathSpec( location='/syslog', parent=self._os_path_spec) self._file_system = tar_file_system.TARFileSystem(self._resolver_context) self._file_system.Open(self._tar_path_spec)
def NewFileSystem(self, resolver_context): """Creates a new file system object. Args: resolver_context (Context): resolver context. Returns: FileSystem: file system. """ return tar_file_system.TARFileSystem(resolver_context)
def testSubFileEntries(self): """Test the sub file entries iteration functionality.""" path_spec = path_spec_factory.Factory.NewPathSpec( definitions.TYPE_INDICATOR_TAR, location='/', parent=self._os_path_spec) file_entry = self._file_system.GetFileEntryByPathSpec(path_spec) self.assertIsNotNone(file_entry) self._assertSubFileEntries(file_entry, ['syslog']) # Test on a tar file that has missing directory entries. test_path = self._GetTestFilePath(['missing_directory_entries.tar']) self._SkipIfPathNotExists(test_path) test_os_path_spec = path_spec_factory.Factory.NewPathSpec( definitions.TYPE_INDICATOR_OS, location=test_path) path_spec = path_spec_factory.Factory.NewPathSpec( definitions.TYPE_INDICATOR_TAR, location='/', parent=test_os_path_spec) file_system = tar_file_system.TARFileSystem(self._resolver_context, path_spec) self.assertIsNotNone(file_system) file_system.Open() file_entry = file_system.GetFileEntryByPathSpec(path_spec) self.assertIsNotNone(file_entry) self._assertSubFileEntries( file_entry, ['File System', 'Non Missing Directory Entry']) file_system_sub_file_entry = None for sub_file_entry in file_entry.sub_file_entries: # The "File System" and its sub-directories have missing entries within # the tar file, but still should be found due to the AssetManifest.plist # file found within the directories. if sub_file_entry.name == 'File System': self.assertTrue(sub_file_entry.IsVirtual()) self._assertSubFileEntries(sub_file_entry, ['Recordings']) file_system_sub_file_entry = sub_file_entry else: self._assertSubFileEntries(sub_file_entry, ['test_file.txt']) if file_system_sub_file_entry: for sub_file_entry in file_system_sub_file_entry.sub_file_entries: self.assertTrue(sub_file_entry.IsVirtual()) self._assertSubFileEntries(sub_file_entry, ['AssetManifest.plist'])
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 tar_file_system.TARFileSystem(resolver_context, path_spec)
def testGetRootFileEntry(self): """Test the get root file entry functionality.""" file_system = tar_file_system.TARFileSystem(self._resolver_context, self._tar_path_spec) self.assertIsNotNone(file_system) file_system.Open() file_entry = file_system.GetRootFileEntry() self.assertIsNotNone(file_entry) self.assertEqual(file_entry.name, '')
def testFileEntryExistsByPathSpec(self): """Test the file entry exists by path specification functionality.""" file_system = tar_file_system.TARFileSystem(self._resolver_context) self.assertIsNotNone(file_system) file_system.Open(self._tar_path_spec) path_spec = tar_path_spec.TARPathSpec(location='/syslog', parent=self._os_path_spec) self.assertTrue(file_system.FileEntryExistsByPathSpec(path_spec)) path_spec = tar_path_spec.TARPathSpec(location='/bogus', parent=self._os_path_spec) self.assertFalse(file_system.FileEntryExistsByPathSpec(path_spec)) file_system.Close() # Test on a tar file that has missing directory entries. test_file = self._GetTestFilePath(['missing_directory_entries.tar']) self._SkipIfPathNotExists(test_file) test_file_path_spec = os_path_spec.OSPathSpec(location=test_file) path_spec = tar_path_spec.TARPathSpec(location='/', parent=test_file_path_spec) file_system = tar_file_system.TARFileSystem(self._resolver_context) self.assertIsNotNone(file_system) file_system.Open(path_spec) path_spec = tar_path_spec.TARPathSpec(location='/File System', parent=test_file_path_spec) self.assertTrue(file_system.FileEntryExistsByPathSpec(path_spec)) path_spec = tar_path_spec.TARPathSpec( location='/File System/Recordings', parent=test_file_path_spec) self.assertTrue(file_system.FileEntryExistsByPathSpec(path_spec)) file_system.Close()
def testSubFileEntries(self): """Test the sub file entries iteration functionality.""" path_spec = tar_path_spec.TARPathSpec(location=u'/', parent=self._os_path_spec) file_entry = self._file_system.GetFileEntryByPathSpec(path_spec) self.assertIsNotNone(file_entry) self._assertSubFileEntries(file_entry, [u'syslog']) # Test on a tar file that has missing directory entries. test_file = os.path.join(u'test_data', u'missing_directory_entries.tar') path_spec = os_path_spec.OSPathSpec(location=test_file) path_spec = tar_path_spec.TARPathSpec(location=u'/', parent=path_spec) file_system = tar_file_system.TARFileSystem(self._resolver_context) self.assertIsNotNone(file_system) file_system.Open(path_spec) file_entry = file_system.GetFileEntryByPathSpec(path_spec) self.assertIsNotNone(file_entry) self._assertSubFileEntries( file_entry, [u'File System', u'Non Missing Directory Entry']) file_system_sub_file_entry = None for sub_file_entry in file_entry.sub_file_entries: # The "File System" and its sub-directories have missing entries within # the tar file, but still should be found due to the AssetManifest.plist # file found within the directories. if sub_file_entry.name == u'File System': self.assertTrue(sub_file_entry.IsVirtual()) self._assertSubFileEntries(sub_file_entry, [u'Recordings']) file_system_sub_file_entry = sub_file_entry else: self._assertSubFileEntries(sub_file_entry, [u'test_file.txt']) if file_system_sub_file_entry: for sub_file_entry in file_system_sub_file_entry.sub_file_entries: self.assertTrue(sub_file_entry.IsVirtual()) self._assertSubFileEntries(sub_file_entry, [u'AssetManifest.plist']) file_system.Close()
def setUp(self): """Sets up the needed objects used throughout the test.""" self._resolver_context = context.Context() test_path = self._GetTestFilePath(['syslog.tar']) self._SkipIfPathNotExists(test_path) self._os_path_spec = path_spec_factory.Factory.NewPathSpec( definitions.TYPE_INDICATOR_OS, location=test_path) self._tar_path_spec = path_spec_factory.Factory.NewPathSpec( definitions.TYPE_INDICATOR_TAR, location='/syslog', parent=self._os_path_spec) self._file_system = tar_file_system.TARFileSystem( self._resolver_context, self._tar_path_spec) self._file_system.Open()