Esempio n. 1
0
    def testUnlockVolumeOk(self, exec_mock):
        mock_uuid = str(uuid.uuid4())
        mock_passphrase = str(uuid.uuid4())

        volume = apfs.APFSStorage()
        volume.UnlockVolume(mock_uuid, mock_passphrase)

        exec_mock.assert_called_once_with(
            (DISKUTIL, 'apfs', 'unlockVolume', mock_uuid, '-stdinpassphrase'),
            stdin=mock_passphrase)
Esempio n. 2
0
  def testIsBootVolumeEncryptedWhenEncrypted(self, get_plist_from_exec_mock):

    p1 = plistlib.readPlistFromString(APFS_PLIST_LIST_ENCRYPTED)
    get_plist_from_exec_mock.return_value = p1

    volume = apfs.APFSStorage()
    self.assertEqual(True, volume.IsBootVolumeEncrypted())

    get_plist_from_exec_mock.assert_has_calls([
        mock.call(['/usr/sbin/diskutil', 'apfs', 'list', '-plist', 'disk1'])])
Esempio n. 3
0
    def testRevertVolumeOk(self, revert_exec_mock, unlock_mock):
        mock_uuid = str(uuid.uuid4())
        mock_passphrase = str(uuid.uuid4())

        volume = apfs.APFSStorage()
        self.assertEqual(None, volume.RevertVolume(mock_uuid, mock_passphrase))

        revert_exec_mock.assert_called_once_with(
            ('sudo', '-k', '-S', FDESETUP, 'disable'), stdin='\n')
        unlock_mock.assert_called_once_with(mock_uuid, mock_passphrase)
Esempio n. 4
0
    def testGetAPFSStorageStateEncrypted(self, get_plist_from_exec_mock):
        pl = plistlib.readPlistFromString(APFS_PLIST_LIST_ENCRYPTED)

        get_plist_from_exec_mock.side_effect = [pl]

        volume = apfs.APFSStorage()

        self.assertEqual(volume.GetState(), apfs.State.ENCRYPTED)
        get_plist_from_exec_mock.assert_has_calls(
            [mock.call(['/usr/sbin/diskutil', 'apfs', 'list', '-plist'])])
Esempio n. 5
0
  def testRevertVolumeCantRevert(self, revert_exec_mock, unlock_mock):
    mock_uuid = str(uuid.uuid4())
    mock_passphrase = str(uuid.uuid4())

    volume = apfs.APFSStorage()
    self.assertRaises(storage.CouldNotRevertError,
                      volume.RevertVolume, mock_uuid, mock_passphrase)

    revert_exec_mock.assert_called_once_with(
        ('sudo', '-k', '-S', FDESETUP, 'disable'), stdin='\n')
    unlock_mock.assert_called_once_with(mock_uuid, mock_passphrase)
Esempio n. 6
0
    def testUnlockVolumeCantUnlock(self, exec_mock):
        mock_uuid = str(uuid.uuid4())
        mock_passphrase = str(uuid.uuid4())

        volume = apfs.APFSStorage()
        self.assertRaises(apfs.CouldNotUnlockError, volume.UnlockVolume,
                          mock_uuid, mock_passphrase)

        exec_mock.assert_called_once_with(
            (DISKUTIL, 'apfs', 'unlockVolume', mock_uuid, '-stdinpassphrase'),
            stdin=mock_passphrase)
Esempio n. 7
0
    def testIsBootVolumeEncryptedWhenEncrypted(self, get_plist_from_exec_mock):
        p1 = plistlib.readPlistFromString(DISKUTIL_INFO_PLIST)
        p2 = plistlib.readPlistFromString(APFS_PLIST_LIST_ENCRYPTED)
        get_plist_from_exec_mock.side_effect = [p1, p2]

        volume = apfs.APFSStorage()
        self.assertEqual(True, volume.IsBootVolumeEncrypted())

        get_plist_from_exec_mock.assert_has_calls([
            mock.call(['/usr/sbin/diskutil', 'info', '-plist', '/']),
            mock.call(['/usr/sbin/diskutil', 'apfs', 'list', '-plist'])
        ])
Esempio n. 8
0
 def _HandleResult(self, result_plist):
     """Parse the (plist) output of a FileVault tool."""
     recovery_token = result_plist.get(self.OUTPUT_PLIST_TOKEN_KEY)
     if not recovery_token:
         raise Error('Could not get recovery token!')
     hardware_uuid = result_plist.get('HardwareUUID', None)  # sanity check
     if not hardware_uuid:
         raise Error('Could not get Hardware UUID!')
     volume_uuid = apfs.APFSStorage().GetPrimaryVolumeUUID()
     if not volume_uuid:
         raise Error('Could not get Volume UUID!')
     return volume_uuid, recovery_token
Esempio n. 9
0
def GetStorage():
    """Return the module to handle this file system on this machine.

  Returns:
    APFSStorage or CoreStorage object.
  """

    fstype = GetFilesystemType()
    if fstype == 'apfs':
        return apfs.APFSStorage()
    elif fstype == 'hfs':
        return corestorage.CoreStorage()
    return corestorage.CoreStorage()  # default to core storage
Esempio n. 10
0
 def testGetVolumeUUID(self, get_plist_from_exec_mock):
   pl = plistlib.readPlistFromString(APFS_PLIST_LIST_ENCRYPTED)
   mock_uuid = 'C72D5CF6-E9D1-3FCB-A0B0-E3DE83364FD6'
   get_plist_from_exec_mock.return_value = pl
   volume = apfs.APFSStorage()
   self.assertEqual(mock_uuid, volume.GetVolumeUUID('disk'))
Esempio n. 11
0
 def testGetVolumeSize(self, get_plist_from_exec_mock):
   pl = plistlib.readPlistFromString(APFS_PLIST_LIST_ENABLED)
   mock_uuid = 'C72D5CF6-E9D1-3FCB-A0B0-E3DE83364FD6'
   get_plist_from_exec_mock.return_value = pl
   volume = apfs.APFSStorage()
   self.assertEqual('231.00 GiB', volume.GetVolumeSize(mock_uuid))
Esempio n. 12
0
 def testGetRecoveryPartitionWhenDiskutilFail(self, _):
   volume = apfs.APFSStorage()
   self.assertEqual(volume.GetRecoveryPartition(), None)
Esempio n. 13
0
 def testIsBootVolumeEncryptedWhenNotAPFSStorage(self, _):
   volume = apfs.APFSStorage()
   self.assertEqual(False, volume.IsBootVolumeEncrypted())