Merge pull request #17500 from owncloud/encryption_migration_improvements
Only clean up if migration finished succesfully
This commit is contained in:
commit
d6f02eb703
|
@ -115,5 +115,7 @@ class MigrateKeys extends Command {
|
|||
}
|
||||
}
|
||||
|
||||
$migration->finalCleanUp();
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -406,19 +406,36 @@ class KeyManager {
|
|||
}
|
||||
|
||||
/**
|
||||
* @param $userId
|
||||
* check if user has a private and a public key
|
||||
*
|
||||
* @param string $userId
|
||||
* @return bool
|
||||
* @throws PrivateKeyMissingException
|
||||
* @throws PublicKeyMissingException
|
||||
*/
|
||||
public function userHasKeys($userId) {
|
||||
$privateKey = $publicKey = true;
|
||||
|
||||
try {
|
||||
$this->getPrivateKey($userId);
|
||||
$this->getPublicKey($userId);
|
||||
} catch (PrivateKeyMissingException $e) {
|
||||
return false;
|
||||
} catch (PublicKeyMissingException $e) {
|
||||
return false;
|
||||
$privateKey = false;
|
||||
$exception = $e;
|
||||
}
|
||||
try {
|
||||
$this->getPublicKey($userId);
|
||||
} catch (PublicKeyMissingException $e) {
|
||||
$publicKey = false;
|
||||
$exception = $e;
|
||||
}
|
||||
|
||||
if ($privateKey && $publicKey) {
|
||||
return true;
|
||||
} elseif (!$privateKey && !$publicKey) {
|
||||
return false;
|
||||
} else {
|
||||
throw $exception;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -50,7 +50,7 @@ class Migration {
|
|||
$this->config = $config;
|
||||
}
|
||||
|
||||
public function __destruct() {
|
||||
public function finalCleanUp() {
|
||||
$this->view->deleteAll('files_encryption/public_keys');
|
||||
$this->updateFileCache();
|
||||
$this->config->deleteAppValue('files_encryption', 'installed_version');
|
||||
|
|
|
@ -182,18 +182,62 @@ class KeyManagerTest extends TestCase {
|
|||
);
|
||||
}
|
||||
|
||||
public function testUserHasKeys() {
|
||||
/**
|
||||
* @dataProvider dataTestUserHasKeys
|
||||
*/
|
||||
public function testUserHasKeys($key, $expected) {
|
||||
$this->keyStorageMock->expects($this->exactly(2))
|
||||
->method('getUserKey')
|
||||
->with($this->equalTo($this->userId), $this->anything())
|
||||
->willReturn('key');
|
||||
->willReturn($key);
|
||||
|
||||
|
||||
$this->assertTrue(
|
||||
$this->assertSame($expected,
|
||||
$this->instance->userHasKeys($this->userId)
|
||||
);
|
||||
}
|
||||
|
||||
public function dataTestUserHasKeys() {
|
||||
return [
|
||||
['key', true],
|
||||
['', false]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \OCA\Encryption\Exceptions\PrivateKeyMissingException
|
||||
*/
|
||||
public function testUserHasKeysMissingPrivateKey() {
|
||||
$this->keyStorageMock->expects($this->exactly(2))
|
||||
->method('getUserKey')
|
||||
->willReturnCallback(function ($uid, $keyID, $encryptionModuleId) {
|
||||
if ($keyID=== 'privateKey') {
|
||||
return '';
|
||||
}
|
||||
return 'key';
|
||||
});
|
||||
|
||||
$this->instance->userHasKeys($this->userId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \OCA\Encryption\Exceptions\PublicKeyMissingException
|
||||
*/
|
||||
public function testUserHasKeysMissingPublicKey() {
|
||||
$this->keyStorageMock->expects($this->exactly(2))
|
||||
->method('getUserKey')
|
||||
->willReturnCallback(function ($uid, $keyID, $encryptionModuleId){
|
||||
if ($keyID === 'publicKey') {
|
||||
return '';
|
||||
}
|
||||
return 'key';
|
||||
});
|
||||
|
||||
$this->instance->userHasKeys($this->userId);
|
||||
|
||||
}
|
||||
|
||||
|
||||
public function testInit() {
|
||||
$this->keyStorageMock->expects($this->any())
|
||||
->method('getUserKey')
|
||||
|
|
|
@ -102,6 +102,8 @@ class EncryptionController extends Controller {
|
|||
} while (count($users) >= $limit);
|
||||
}
|
||||
|
||||
$migration->finalCleanUp();
|
||||
|
||||
} catch (\Exception $e) {
|
||||
return array(
|
||||
'data' => array(
|
||||
|
|
Loading…
Reference in New Issue