summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Müller <thomas.mueller@tmit.eu>2015-07-17 11:58:06 +0200
committerThomas Müller <thomas.mueller@tmit.eu>2015-07-17 11:58:06 +0200
commitdeeacacfae49be3496b2a67d845b28d264bf562a (patch)
treed658780a9f73f4e27fbec2a29d9778061e0d9215
parentd199fb4e8d0073ed519bfb283002c3dbb7cee909 (diff)
parentae1332e9c984f554a313f95fbcb32a227734e186 (diff)
downloadnextcloud-server-deeacacfae49be3496b2a67d845b28d264bf562a.tar.gz
nextcloud-server-deeacacfae49be3496b2a67d845b28d264bf562a.zip
Merge pull request #17678 from owncloud/backport-encryption_migration_improvements-stable8.1
Backport encryption migration improvements stable8.1
-rw-r--r--apps/encryption/command/migratekeys.php2
-rw-r--r--apps/encryption/lib/keymanager.php25
-rw-r--r--apps/encryption/lib/migration.php2
-rw-r--r--apps/encryption/tests/lib/KeyManagerTest.php50
-rw-r--r--settings/controller/encryptioncontroller.php2
5 files changed, 73 insertions, 8 deletions
diff --git a/apps/encryption/command/migratekeys.php b/apps/encryption/command/migratekeys.php
index e6e5e7b70b0..d0fc1573061 100644
--- a/apps/encryption/command/migratekeys.php
+++ b/apps/encryption/command/migratekeys.php
@@ -115,5 +115,7 @@ class MigrateKeys extends Command {
}
}
+ $migration->finalCleanUp();
+
}
}
diff --git a/apps/encryption/lib/keymanager.php b/apps/encryption/lib/keymanager.php
index 05d23873482..8c8c1f8fd78 100644
--- a/apps/encryption/lib/keymanager.php
+++ b/apps/encryption/lib/keymanager.php
@@ -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;
+ $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;
}
/**
diff --git a/apps/encryption/lib/migration.php b/apps/encryption/lib/migration.php
index b5d5dc26568..26e2a143f69 100644
--- a/apps/encryption/lib/migration.php
+++ b/apps/encryption/lib/migration.php
@@ -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');
diff --git a/apps/encryption/tests/lib/KeyManagerTest.php b/apps/encryption/tests/lib/KeyManagerTest.php
index 2561b29462f..0bac5e0341b 100644
--- a/apps/encryption/tests/lib/KeyManagerTest.php
+++ b/apps/encryption/tests/lib/KeyManagerTest.php
@@ -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')
diff --git a/settings/controller/encryptioncontroller.php b/settings/controller/encryptioncontroller.php
index 411b9e87cc1..87cbf0a4bf1 100644
--- a/settings/controller/encryptioncontroller.php
+++ b/settings/controller/encryptioncontroller.php
@@ -102,6 +102,8 @@ class EncryptionController extends Controller {
} while (count($users) >= $limit);
}
+ $migration->finalCleanUp();
+
} catch (\Exception $e) {
return array(
'data' => array(