def testGetCoreStorageStateNone(self): self.mox.StubOutWithMock(util, 'GetPlistFromExec') pl = plistlib.readPlistFromString(CORE_STORAGE_PLIST_LIST_EMPTY) util.GetPlistFromExec(mox.In(DISKUTIL)).AndReturn(pl) self.mox.ReplayAll() self.assertEquals(corestorage.GetState(), corestorage.State.NONE) self.mox.VerifyAll()
def testGetCoreStorageStateFailed(self, get_plist_from_exec_mock): pl = plistlib.readPlistFromString(CORE_STORAGE_PLIST_LIST_ENABLED) pl2 = plistlib.readPlistFromString(CORE_STORAGE_PLIST_LVF_INFO_ENABLED) pl3 = plistlib.readPlistFromString(CORE_STORAGE_PLIST_LV_INFO) pl3['CoreStorageLogicalVolumeConversionState'] = 'Failed' get_plist_from_exec_mock.side_effect = [pl, pl2, pl3] self.assertEquals(corestorage.GetState(), corestorage.State.FAILED)
def testGetCoreStorageStateEnabled(self, get_plist_from_exec_mock): pl = plistlib.readPlistFromString(CORE_STORAGE_PLIST_LIST_ENABLED) pl2 = plistlib.readPlistFromString(CORE_STORAGE_PLIST_LVF_INFO_ENABLED) pl3 = plistlib.readPlistFromString(CORE_STORAGE_PLIST_LV_INFO) get_plist_from_exec_mock.side_effect = [pl, pl2, pl3] self.assertEquals(corestorage.GetState(), corestorage.State.ENABLED)
def testGetCoreStorageStateNone(self, get_plist_from_exec_mock): pl = plistlib.readPlistFromString(CORE_STORAGE_PLIST_LIST_EMPTY) get_plist_from_exec_mock.return_value = pl self.assertEquals(corestorage.GetState(), corestorage.State.NONE) get_plist_from_exec_mock.assert_called_once_with( ['/usr/sbin/diskutil', 'corestorage', 'list', '-plist'])
def testGetCoreStorageStateEnabled(self): self.mox.StubOutWithMock(util, 'GetPlistFromExec') pl = plistlib.readPlistFromString(CORE_STORAGE_PLIST_LIST_ENABLED) pl2 = plistlib.readPlistFromString(CORE_STORAGE_PLIST_LVF_INFO_ENABLED) pl3 = plistlib.readPlistFromString(CORE_STORAGE_PLIST_LV_INFO) util.GetPlistFromExec(mox.In(DISKUTIL)).AndReturn(pl) util.GetPlistFromExec(mox.In(DISKUTIL)).AndReturn(pl2) util.GetPlistFromExec(mox.In(DISKUTIL)).AndReturn(pl3) self.mox.ReplayAll() self.assertEquals(corestorage.GetState(), corestorage.State.ENABLED) self.mox.VerifyAll()
def CheckEncryptionPreconditions(): # As far as our current understanding, we can't apply encryption if no # recovery partition is on the disk. If we attempt to do so csfde fails # inside Apple's code when it calls -[DADisk description] on a null pointer, # presumably the recovery partition it expected to find. if not corestorage.GetRecoveryPartition(): raise OptionError('Recovery partition must exist.') # We can't apply encryption if core storage is already in place. if corestorage.GetState() != corestorage.State.NONE: raise OptionError( 'Core storage must be disabled. If you just reverted, please reboot.' ) # We can't get a recovery passphrase if a keychain is in place. if os.path.exists('/Library/Keychains/FileVaultMaster.keychain'): raise OptionError( 'This tool cannot operate with a FileVaultMaster keychain in place.' )
def testGetCoreStorageStateEncrypted(self, get_plist_from_exec_mock): pl = plistlib.readPlistFromString(CORE_STORAGE_PLIST_LIST_ENABLED) pl2 = plistlib.readPlistFromString( CORE_STORAGE_PLIST_LVF_INFO_ENCRYPTED) pl3 = plistlib.readPlistFromString(CORE_STORAGE_PLIST_LV_INFO) get_plist_from_exec_mock.side_effect = [pl, pl2, pl3] self.assertEquals(corestorage.GetState(), corestorage.State.ENCRYPTED) get_plist_from_exec_mock.assert_has_calls([ mock.call(['/usr/sbin/diskutil', 'corestorage', 'list', '-plist']), mock.call([ '/usr/sbin/diskutil', 'corestorage', 'info', '-plist', 'F550F600-D0C3-40C2-AE18-BBEB5197283F' ]), mock.call([ '/usr/sbin/diskutil', 'corestorage', 'info', '-plist', 'F93A24E9-C8DB-4E83-8EB0-FDEC3C029B9D' ]) ])