diff options
Diffstat (limited to 'apps/encryption/tests/lib')
-rw-r--r-- | apps/encryption/tests/lib/crypto/cryptTest.php | 2 | ||||
-rw-r--r-- | apps/encryption/tests/lib/crypto/encryptionTest.php | 63 |
2 files changed, 63 insertions, 2 deletions
diff --git a/apps/encryption/tests/lib/crypto/cryptTest.php b/apps/encryption/tests/lib/crypto/cryptTest.php index 3ea57668348..4114adb115a 100644 --- a/apps/encryption/tests/lib/crypto/cryptTest.php +++ b/apps/encryption/tests/lib/crypto/cryptTest.php @@ -20,7 +20,7 @@ */ -namespace OCA\Encryption\Tests\Crypt; +namespace OCA\Encryption\Tests\lib\Crypto; use OCA\Encryption\Crypto\Crypt; diff --git a/apps/encryption/tests/lib/crypto/encryptionTest.php b/apps/encryption/tests/lib/crypto/encryptionTest.php index cb4ca2d3a12..aa28a8b44a4 100644 --- a/apps/encryption/tests/lib/crypto/encryptionTest.php +++ b/apps/encryption/tests/lib/crypto/encryptionTest.php @@ -19,8 +19,9 @@ * */ -namespace OCA\Encryption\Tests\Crypto; +namespace OCA\Encryption\Tests\lib\Crypto; +use OCA\Encryption\Exceptions\PublicKeyMissingException; use Test\TestCase; use OCA\Encryption\Crypto\Encryption; @@ -63,6 +64,66 @@ class EncryptionTest extends TestCase { $this->utilMock, $this->loggerMock ); + + } + + /** + * test if public key from one of the recipients is missing + */ + public function testEndUser1() { + $this->instance->begin('/foo/bar', 'user1', 'r', array(), array('users' => array('user1', 'user2', 'user3'))); + $this->endTest(); + } + + /** + * test if public key from owner is missing + * + * @expectedException \OCA\Encryption\Exceptions\PublicKeyMissingException + */ + public function testEndUser2() { + $this->instance->begin('/foo/bar', 'user2', 'r', array(), array('users' => array('user1', 'user2', 'user3'))); + $this->endTest(); + } + + /** + * common part of testEndUser1 and testEndUser2 + * + * @throws PublicKeyMissingException + */ + public function endTest() { + // prepare internal variables + \Test_Helper::invokePrivate($this->instance, 'isWriteOperation', [true]); + \Test_Helper::invokePrivate($this->instance, 'writeCache', ['']); + + $this->keyManagerMock->expects($this->any()) + ->method('getPublicKey') + ->will($this->returnCallback([$this, 'getPublicKeyCallback'])); + $this->keyManagerMock->expects($this->any()) + ->method('addSystemKeys') + ->will($this->returnCallback([$this, 'addSystemKeysCallback'])); + $this->cryptMock->expects($this->any()) + ->method('multiKeyEncrypt') + ->willReturn(true); + $this->cryptMock->expects($this->any()) + ->method('setAllFileKeys') + ->willReturn(true); + + $this->instance->end('/foo/bar'); + } + + + public function getPublicKeyCallback($uid) { + if ($uid === 'user2') { + throw new PublicKeyMissingException($uid); + } + return $uid; + } + + public function addSystemKeysCallback($accessList, $publicKeys) { + $this->assertSame(2, count($publicKeys)); + $this->assertArrayHasKey('user1', $publicKeys); + $this->assertArrayHasKey('user3', $publicKeys); + return $publicKeys; } /** |