diff options
Diffstat (limited to 'apps/encryption/tests/lib')
-rw-r--r-- | apps/encryption/tests/lib/KeyManagerTest.php | 59 | ||||
-rw-r--r-- | apps/encryption/tests/lib/RecoveryTest.php | 3 | ||||
-rw-r--r-- | apps/encryption/tests/lib/UtilTest.php | 4 |
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() { |