def testDataStreams(self): """Test the data streams functionality.""" path_spec = apfs_container_path_spec.APFSContainerPathSpec( parent=self._partition_path_spec, volume_index=0) file_entry = self._file_system.GetFileEntryByPathSpec(path_spec) self.assertIsNotNone(file_entry) self.assertEqual(file_entry.number_of_data_streams, 1) data_stream_names = [] for data_stream in file_entry.data_streams: data_stream_names.append(data_stream.name) self.assertEqual(data_stream_names, ['']) path_spec = apfs_container_path_spec.APFSContainerPathSpec( location='/', parent=self._partition_path_spec) file_entry = self._file_system.GetFileEntryByPathSpec(path_spec) self.assertIsNotNone(file_entry) self.assertEqual(file_entry.number_of_data_streams, 0) data_stream_names = [] for data_stream in file_entry.data_streams: data_stream_names.append(data_stream.name) self.assertEqual(data_stream_names, [])
def testIsFunctions(self): """Test the Is? functions.""" path_spec = apfs_container_path_spec.APFSContainerPathSpec( parent=self._partition_path_spec, volume_index=0) file_entry = self._file_system.GetFileEntryByPathSpec(path_spec) self.assertIsNotNone(file_entry) self.assertFalse(file_entry.IsRoot()) self.assertFalse(file_entry.IsVirtual()) self.assertTrue(file_entry.IsAllocated()) self.assertFalse(file_entry.IsDevice()) self.assertFalse(file_entry.IsDirectory()) self.assertTrue(file_entry.IsFile()) self.assertFalse(file_entry.IsLink()) self.assertFalse(file_entry.IsPipe()) self.assertFalse(file_entry.IsSocket()) path_spec = apfs_container_path_spec.APFSContainerPathSpec( location='/', parent=self._partition_path_spec) file_entry = self._file_system.GetFileEntryByPathSpec(path_spec) self.assertIsNotNone(file_entry) self.assertTrue(file_entry.IsRoot()) self.assertTrue(file_entry.IsVirtual()) self.assertTrue(file_entry.IsAllocated()) self.assertFalse(file_entry.IsDevice()) self.assertTrue(file_entry.IsDirectory()) self.assertFalse(file_entry.IsFile()) self.assertFalse(file_entry.IsLink()) self.assertFalse(file_entry.IsPipe()) self.assertFalse(file_entry.IsSocket())
def _EntriesGenerator(self): """Retrieves directory entries. Since a directory can contain a vast number of entries using a generator is more memory efficient. Yields: APFSContainerPathSpec: a path specification. """ # Only the virtual root file has directory entries. volume_index = apfs_helper.APFSContainerPathSpecGetVolumeIndex( self.path_spec) if volume_index is not None: return location = getattr(self.path_spec, 'location', None) if location is None or location != self._file_system.LOCATION_ROOT: return fsapfs_container = self._file_system.GetAPFSContainer() for volume_index in range(0, fsapfs_container.number_of_volumes): yield apfs_container_path_spec.APFSContainerPathSpec( location='/apfs{0:d}'.format(volume_index + 1), volume_index=volume_index, parent=self.path_spec.parent)
def testGetParentFileEntry(self): """Tests the GetParentFileEntry function.""" path_spec = apfs_container_path_spec.APFSContainerPathSpec( parent=self._partition_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._partition_path_spec) file_entry = self._file_system.GetFileEntryByPathSpec(path_spec) self.assertIsNotNone(file_entry) parent_file_entry = file_entry.GetParentFileEntry() self.assertIsNone(parent_file_entry)
def GetRootFileEntry(self): """Retrieves the root file entry. Returns: APFSContainerFileEntry: a file entry. """ path_spec = apfs_container_path_spec.APFSContainerPathSpec( location=self.LOCATION_ROOT, parent=self._path_spec.parent) return self.GetFileEntryByPathSpec(path_spec)
def testComparable(self): """Tests the path specification comparable property.""" path_spec = apfs_container_path_spec.APFSContainerPathSpec( parent=self._path_spec) self.assertIsNotNone(path_spec) expected_comparable = '\n'.join( ['type: TEST', 'type: APFS_CONTAINER', '']) self.assertEqual(path_spec.comparable, expected_comparable) path_spec = apfs_container_path_spec.APFSContainerPathSpec( location='/apfs2', parent=self._path_spec) self.assertIsNotNone(path_spec) expected_comparable = '\n'.join( ['type: TEST', 'type: APFS_CONTAINER, location: /apfs2', '']) self.assertEqual(path_spec.comparable, expected_comparable) path_spec = apfs_container_path_spec.APFSContainerPathSpec( volume_index=1, parent=self._path_spec) self.assertIsNotNone(path_spec) expected_comparable = '\n'.join( ['type: TEST', 'type: APFS_CONTAINER, volume index: 1', '']) self.assertEqual(path_spec.comparable, expected_comparable) path_spec = apfs_container_path_spec.APFSContainerPathSpec( location='/apfs2', volume_index=1, parent=self._path_spec) self.assertIsNotNone(path_spec) expected_comparable = '\n'.join([ 'type: TEST', 'type: APFS_CONTAINER, location: /apfs2, volume index: 1', '' ]) self.assertEqual(path_spec.comparable, expected_comparable)
def setUp(self): """Sets up the needed objects used throughout the test.""" test_file = self._GetTestFilePath(['apfs.dmg']) path_spec = os_path_spec.OSPathSpec(location=test_file) path_spec = raw_path_spec.RawPathSpec(parent=path_spec) self._partition_path_spec = tsk_partition_path_spec.TSKPartitionPathSpec( location='/p1', parent=path_spec) self._apfs_container_path_spec = ( apfs_container_path_spec.APFSContainerPathSpec( location='/', parent=self._partition_path_spec))
def setUp(self): """Sets up the needed objects used throughout the test.""" test_file = self._GetTestFilePath(['apfs.raw']) self._SkipIfPathNotExists(test_file) path_spec = os_path_spec.OSPathSpec(location=test_file) path_spec = raw_path_spec.RawPathSpec(parent=path_spec) self._apfs_container_path_spec = ( apfs_container_path_spec.APFSContainerPathSpec(location='/', parent=path_spec))
def testGetStat(self): """Tests the GetStat function.""" path_spec = apfs_container_path_spec.APFSContainerPathSpec( parent=self._partition_path_spec, volume_index=0) file_entry = self._file_system.GetFileEntryByPathSpec(path_spec) self.assertIsNotNone(file_entry) stat_object = file_entry.GetStat() self.assertIsNotNone(stat_object) self.assertEqual(stat_object.type, stat_object.TYPE_FILE)
def testFileEntryExistsByPathSpec(self): """Test the file entry exists by path specification functionality.""" file_system = apfs_container_file_system.APFSContainerFileSystem( self._resolver_context) self.assertIsNotNone(file_system) file_system.Open(self._apfs_container_path_spec) path_spec = apfs_container_path_spec.APFSContainerPathSpec( location='/', parent=self._partition_path_spec) self.assertTrue(file_system.FileEntryExistsByPathSpec(path_spec)) path_spec = apfs_container_path_spec.APFSContainerPathSpec( parent=self._partition_path_spec, volume_index=0) self.assertTrue(file_system.FileEntryExistsByPathSpec(path_spec)) path_spec = apfs_container_path_spec.APFSContainerPathSpec( location='/apfs1', parent=self._partition_path_spec) self.assertTrue(file_system.FileEntryExistsByPathSpec(path_spec)) path_spec = apfs_container_path_spec.APFSContainerPathSpec( parent=self._partition_path_spec, volume_index=9) self.assertFalse(file_system.FileEntryExistsByPathSpec(path_spec)) path_spec = apfs_container_path_spec.APFSContainerPathSpec( location='/apfs0', parent=self._partition_path_spec) self.assertFalse(file_system.FileEntryExistsByPathSpec(path_spec)) path_spec = apfs_container_path_spec.APFSContainerPathSpec( location='/apfs9', parent=self._partition_path_spec) self.assertFalse(file_system.FileEntryExistsByPathSpec(path_spec)) file_system.Close()
def testInitialize(self): """Tests the path specification initialization.""" path_spec = apfs_container_path_spec.APFSContainerPathSpec( parent=self._path_spec) self.assertIsNotNone(path_spec) path_spec = apfs_container_path_spec.APFSContainerPathSpec( location='/apfs2', parent=self._path_spec) self.assertIsNotNone(path_spec) path_spec = apfs_container_path_spec.APFSContainerPathSpec( volume_index=1, parent=self._path_spec) self.assertIsNotNone(path_spec) path_spec = apfs_container_path_spec.APFSContainerPathSpec( location='/apfs2', volume_index=1, parent=self._path_spec) self.assertIsNotNone(path_spec) with self.assertRaises(ValueError): apfs_container_path_spec.APFSContainerPathSpec(parent=None) with self.assertRaises(ValueError): apfs_container_path_spec.APFSContainerPathSpec( parent=self._path_spec, bogus='BOGUS')
def testGetDataStream(self): """Tests the GetDataStream function.""" path_spec = apfs_container_path_spec.APFSContainerPathSpec( parent=self._partition_path_spec, volume_index=0) file_entry = self._file_system.GetFileEntryByPathSpec(path_spec) self.assertIsNotNone(file_entry) data_stream_name = '' data_stream = file_entry.GetDataStream(data_stream_name) self.assertIsNotNone(data_stream) self.assertEqual(data_stream.name, data_stream_name) data_stream = file_entry.GetDataStream('bogus') self.assertIsNone(data_stream)
def testGetCredentials(self): """Function to test the GetCredentials function.""" test_path_spec = fake_path_spec.FakePathSpec(location='/fake') test_path_spec = apfs_container_path_spec.APFSContainerPathSpec( location='/', parent=fake_path_spec) credentials_object = manager.CredentialsManager.GetCredentials( test_path_spec) self.assertIsInstance(credentials_object, apfs_credentials.APFSCredentials) test_path_spec = fake_path_spec.FakePathSpec(location='/fake') credentials_object = manager.CredentialsManager.GetCredentials( test_path_spec) self.assertIsNone(credentials_object)
def setUp(self): """Sets up the needed objects used throughout the test.""" self._resolver_context = context.Context() test_file = self._GetTestFilePath(['apfs.dmg']) path_spec = os_path_spec.OSPathSpec(location=test_file) path_spec = raw_path_spec.RawPathSpec(parent=path_spec) self._partition_path_spec = tsk_partition_path_spec.TSKPartitionPathSpec( location='/p1', parent=path_spec) self._apfs_container_path_spec = ( apfs_container_path_spec.APFSContainerPathSpec( location='/', parent=self._partition_path_spec)) self._file_system = apfs_container_file_system.APFSContainerFileSystem( self._resolver_context) self._file_system.Open(self._apfs_container_path_spec)
def testAPFSContainerPathSpecGetVolumeIndex(self): """Tests the APFSContainerPathSpecGetVolumeIndex function.""" test_fake_path_spec = fake_path_spec.FakePathSpec(location='/') path_spec = apfs_container_path_spec.APFSContainerPathSpec( parent=test_fake_path_spec) self.assertIsNotNone(path_spec) volume_index = apfs_helper.APFSContainerPathSpecGetVolumeIndex( path_spec) self.assertIsNone(volume_index) path_spec = apfs_container_path_spec.APFSContainerPathSpec( location='/apfs2', parent=test_fake_path_spec) self.assertIsNotNone(path_spec) volume_index = apfs_helper.APFSContainerPathSpecGetVolumeIndex( path_spec) self.assertEqual(volume_index, 1) path_spec = apfs_container_path_spec.APFSContainerPathSpec( volume_index=1, parent=test_fake_path_spec) self.assertIsNotNone(path_spec) volume_index = apfs_helper.APFSContainerPathSpecGetVolumeIndex( path_spec) self.assertEqual(volume_index, 1) path_spec = apfs_container_path_spec.APFSContainerPathSpec( location='/apfs2', volume_index=1, parent=test_fake_path_spec) self.assertIsNotNone(path_spec) volume_index = apfs_helper.APFSContainerPathSpecGetVolumeIndex( path_spec) self.assertEqual(volume_index, 1) path_spec = apfs_container_path_spec.APFSContainerPathSpec( location='/apfs', parent=test_fake_path_spec) volume_index = apfs_helper.APFSContainerPathSpecGetVolumeIndex( path_spec) self.assertIsNone(volume_index) path_spec = apfs_container_path_spec.APFSContainerPathSpec( location='/apfs101', parent=test_fake_path_spec) volume_index = apfs_helper.APFSContainerPathSpecGetVolumeIndex( path_spec) self.assertIsNone(volume_index)
def testSubFileEntries(self): """Test the sub file entries iteration functionality.""" path_spec = apfs_container_path_spec.APFSContainerPathSpec( location='/', parent=self._partition_path_spec) file_entry = self._file_system.GetFileEntryByPathSpec(path_spec) self.assertIsNotNone(file_entry) self.assertEqual(file_entry.number_of_sub_file_entries, 1) expected_sub_file_entry_names = ['apfs1'] sub_file_entry_names = [] for sub_file_entry in file_entry.sub_file_entries: sub_file_entry_names.append(sub_file_entry.name) self.assertEqual(len(sub_file_entry_names), len(expected_sub_file_entry_names)) self.assertEqual(sorted(sub_file_entry_names), sorted(expected_sub_file_entry_names))
def setUp(self): """Sets up the needed objects used throughout the test.""" self._resolver_context = context.Context() test_file = self._GetTestFilePath(['apfs_encrypted.dmg']) path_spec = os_path_spec.OSPathSpec(location=test_file) path_spec = raw_path_spec.RawPathSpec(parent=path_spec) partition_path_spec = tsk_partition_path_spec.TSKPartitionPathSpec( location='/p1', parent=path_spec) self._apfs_container_path_spec = ( apfs_container_path_spec.APFSContainerPathSpec( location='/apfs1', parent=partition_path_spec)) self._apfs_path_spec = apfs_path_spec.APFSPathSpec( location='/', parent=self._apfs_container_path_spec) resolver.Resolver.key_chain.SetCredential( self._apfs_container_path_spec, 'password', self._APFS_PASSWORD) self._file_system = apfs_file_system.APFSFileSystem( self._resolver_context) self._file_system.Open(self._apfs_path_spec)
def testGetFileEntryByPathSpec(self): """Tests the GetFileEntryByPathSpec function.""" file_system = apfs_container_file_system.APFSContainerFileSystem( self._resolver_context) self.assertIsNotNone(file_system) file_system.Open(self._apfs_container_path_spec) path_spec = apfs_container_path_spec.APFSContainerPathSpec( location='/', parent=self._partition_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._partition_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._partition_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._partition_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._partition_path_spec) file_entry = file_system.GetFileEntryByPathSpec(path_spec) self.assertIsNone(file_entry) path_spec = apfs_container_path_spec.APFSContainerPathSpec( location='/apfs9', parent=self._partition_path_spec) file_entry = file_system.GetFileEntryByPathSpec(path_spec) self.assertIsNone(file_entry) file_system.Close()