summaryrefslogtreecommitdiffstats
path: root/apps/encryption/tests
diff options
context:
space:
mode:
authorBjoern Schiessle <schiessle@owncloud.com>2015-04-29 17:18:41 +0200
committerBjoern Schiessle <schiessle@owncloud.com>2015-04-30 11:38:53 +0200
commit70a44621beac44e258b46ff17e1d68d86e18d00d (patch)
tree17eeb5660f7e74e683cff60cf6b86f8b13ad7446 /apps/encryption/tests
parentd308ec4f0ea54e8cb0c99228a480da8cb7cf30a8 (diff)
downloadnextcloud-server-70a44621beac44e258b46ff17e1d68d86e18d00d.tar.gz
nextcloud-server-70a44621beac44e258b46ff17e1d68d86e18d00d.zip
check recovery setting for the right user
Diffstat (limited to 'apps/encryption/tests')
-rw-r--r--apps/encryption/tests/lib/KeyManagerTest.php59
-rw-r--r--apps/encryption/tests/lib/RecoveryTest.php3
-rw-r--r--apps/encryption/tests/lib/UtilTest.php4
3 files changed, 63 insertions, 3 deletions
diff --git a/apps/encryption/tests/lib/KeyManagerTest.php b/apps/encryption/tests/lib/KeyManagerTest.php
index 251628d99f2..6e9c6d15818 100644
--- a/apps/encryption/tests/lib/KeyManagerTest.php
+++ b/apps/encryption/tests/lib/KeyManagerTest.php
@@ -297,4 +297,63 @@ class KeyManagerTest extends TestCase {
$this->assertTrue($this->instance->deleteAllFileKeys('/'));
}
+
+ /**
+ * test add public share key and or recovery key to the list of public keys
+ *
+ * @dataProvider dataTestAddSystemKeys
+ *
+ * @param array $accessList
+ * @param array $publicKeys
+ * @param string $uid
+ * @param array $expectedKeys
+ */
+ public function testAddSystemKeys($accessList, $publicKeys, $uid, $expectedKeys) {
+
+ $publicShareKeyId = 'publicShareKey';
+ $recoveryKeyId = 'recoveryKey';
+
+ $this->keyStorageMock->expects($this->any())
+ ->method('getSystemUserKey')
+ ->willReturnCallback(function($keyId, $encryptionModuleId) {
+ return $keyId;
+ });
+
+ $this->utilMock->expects($this->any())
+ ->method('isRecoveryEnabledForUser')
+ ->willReturnCallback(function($uid) {
+ if ($uid === 'user1') {
+ return true;
+ }
+ return false;
+ });
+
+ // set key IDs
+ \Test_Helper::invokePrivate($this->instance, 'publicShareKeyId', [$publicShareKeyId]);
+ \Test_Helper::invokePrivate($this->instance, 'recoveryKeyId', [$recoveryKeyId]);
+
+ $result = $this->instance->addSystemKeys($accessList, $publicKeys, $uid);
+
+ foreach ($expectedKeys as $expected) {
+ $this->assertArrayHasKey($expected, $result);
+ }
+
+ $this->assertSameSize($expectedKeys, $result);
+ }
+
+ /**
+ * data provider for testAddSystemKeys()
+ *
+ * @return array
+ */
+ public function dataTestAddSystemKeys() {
+ return array(
+ array(['public' => true],[], 'user1', ['publicShareKey', 'recoveryKey']),
+ array(['public' => false], [], 'user1', ['recoveryKey']),
+ array(['public' => true],[], 'user2', ['publicShareKey']),
+ array(['public' => false], [], 'user2', []),
+ );
+ }
+
+
}
diff --git a/apps/encryption/tests/lib/RecoveryTest.php b/apps/encryption/tests/lib/RecoveryTest.php
index b3fd403949c..5bfafa3a98e 100644
--- a/apps/encryption/tests/lib/RecoveryTest.php
+++ b/apps/encryption/tests/lib/RecoveryTest.php
@@ -170,6 +170,7 @@ class RecoveryTest extends TestCase {
$this->keyManagerMock->expects($this->once())
->method('addSystemKeys')
+ ->with($this->anything(), $this->anything(), $this->equalTo('admin'))
->willReturn(['admin' => 'publicKey']);
@@ -181,7 +182,7 @@ class RecoveryTest extends TestCase {
$this->assertNull(\Test_Helper::invokePrivate($this->instance,
'recoverFile',
- ['/', 'testkey']));
+ ['/', 'testkey', 'admin']));
}
protected function setUp() {
diff --git a/apps/encryption/tests/lib/UtilTest.php b/apps/encryption/tests/lib/UtilTest.php
index 5f086a8e475..eab912b82d4 100644
--- a/apps/encryption/tests/lib/UtilTest.php
+++ b/apps/encryption/tests/lib/UtilTest.php
@@ -44,11 +44,11 @@ class UtilTest extends TestCase {
*
*/
public function testIsRecoveryEnabledForUser() {
- $this->assertTrue($this->instance->isRecoveryEnabledForUser());
+ $this->assertTrue($this->instance->isRecoveryEnabledForUser('admin'));
// Assert recovery will return default value if not set
unset(self::$tempStorage['recoveryEnabled']);
- $this->assertEquals(0, $this->instance->isRecoveryEnabledForUser());
+ $this->assertEquals(0, $this->instance->isRecoveryEnabledForUser('admin'));
}
public function testUserHasFiles() {