From 76761662547f5ac945f9103e290ad0b19e3d9d10 Mon Sep 17 00:00:00 2001 From: Bjoern Schiessle Date: Mon, 18 May 2015 13:09:36 +0200 Subject: [PATCH 1/3] add l10n to constructor --- apps/encryption/appinfo/application.php | 3 ++- apps/encryption/lib/crypto/encryption.php | 10 ++++++++-- apps/encryption/tests/lib/crypto/encryptionTest.php | 9 ++++++++- 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/apps/encryption/appinfo/application.php b/apps/encryption/appinfo/application.php index 79b2ad3abaf..10ad610cd4a 100644 --- a/apps/encryption/appinfo/application.php +++ b/apps/encryption/appinfo/application.php @@ -104,7 +104,8 @@ class Application extends \OCP\AppFramework\App { $container->query('Crypt'), $container->query('KeyManager'), $container->query('Util'), - $container->getServer()->getLogger() + $container->getServer()->getLogger(), + $container->getServer()->getL10N($container->getAppName()) ); }); diff --git a/apps/encryption/lib/crypto/encryption.php b/apps/encryption/lib/crypto/encryption.php index c060bb04e53..83ed1b59c8a 100644 --- a/apps/encryption/lib/crypto/encryption.php +++ b/apps/encryption/lib/crypto/encryption.php @@ -29,6 +29,7 @@ use OCA\Encryption\Exceptions\PublicKeyMissingException; use OCA\Encryption\Util; use OCP\Encryption\IEncryptionModule; use OCA\Encryption\KeyManager; +use OCP\IL10N; use OCP\ILogger; class Encryption implements IEncryptionModule { @@ -68,25 +69,30 @@ class Encryption implements IEncryptionModule { /** @var Util */ private $util; - /** @var ILogger */ private $logger; + /** @var IL10N */ + private $l; + /** * * @param Crypt $crypt * @param KeyManager $keyManager * @param Util $util * @param ILogger $logger + * @param IL10N $il10n */ public function __construct(Crypt $crypt, KeyManager $keyManager, Util $util, - ILogger $logger) { + ILogger $logger, + IL10N $il10n) { $this->crypt = $crypt; $this->keyManager = $keyManager; $this->util = $util; $this->logger = $logger; + $this->l = $il10n; } /** diff --git a/apps/encryption/tests/lib/crypto/encryptionTest.php b/apps/encryption/tests/lib/crypto/encryptionTest.php index 960ed112488..419aed72366 100644 --- a/apps/encryption/tests/lib/crypto/encryptionTest.php +++ b/apps/encryption/tests/lib/crypto/encryptionTest.php @@ -42,6 +42,9 @@ class EncryptionTest extends TestCase { /** @var \PHPUnit_Framework_MockObject_MockObject */ private $loggerMock; + /** @var \PHPUnit_Framework_MockObject_MockObject */ + private $l10nMock; + public function setUp() { parent::setUp(); @@ -57,12 +60,16 @@ class EncryptionTest extends TestCase { $this->loggerMock = $this->getMockBuilder('OCP\ILogger') ->disableOriginalConstructor() ->getMock(); + $this->l10nMock = $this->getMockBuilder('OCP\IL10N') + ->disableOriginalConstructor() + ->getMock(); $this->instance = new Encryption( $this->cryptMock, $this->keyManagerMock, $this->utilMock, - $this->loggerMock + $this->loggerMock, + $this->l10nMock ); } From 4444db61b7accb7627c6c939e33e8af0439b167e Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Mon, 18 May 2015 13:40:08 +0200 Subject: [PATCH 2/3] Add a unit test for the decrypt method --- apps/encryption/tests/lib/crypto/encryptionTest.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/apps/encryption/tests/lib/crypto/encryptionTest.php b/apps/encryption/tests/lib/crypto/encryptionTest.php index 419aed72366..509cd9dbc40 100644 --- a/apps/encryption/tests/lib/crypto/encryptionTest.php +++ b/apps/encryption/tests/lib/crypto/encryptionTest.php @@ -63,6 +63,10 @@ class EncryptionTest extends TestCase { $this->l10nMock = $this->getMockBuilder('OCP\IL10N') ->disableOriginalConstructor() ->getMock(); + $this->l10nMock->expects($this->any()) + ->method('t') + ->with($this->anything()) + ->willReturnArgument(0); $this->instance = new Encryption( $this->cryptMock, @@ -227,7 +231,6 @@ class EncryptionTest extends TestCase { ); } - /** * by default the encryption module should encrypt regular files, files in * files_versions and files in files_trashbin * @@ -252,4 +255,11 @@ class EncryptionTest extends TestCase { ); } + /** + * @expectedException \OC\Encryption\Exceptions\DecryptionFailedException + * @expectedExceptionMessage Can not decrypt this file, probably this is a shared file. Please ask the file owner to reshare the file with you. + */ + public function testDecrypt() { + $this->instance->decrypt('abc'); + } } From 30d165ebf228f0803183bc772a988a4958356047 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Mon, 18 May 2015 13:40:23 +0200 Subject: [PATCH 3/3] Add missing import for the exception --- apps/encryption/lib/crypto/encryption.php | 2 ++ apps/encryption/tests/lib/crypto/encryptionTest.php | 1 + 2 files changed, 3 insertions(+) diff --git a/apps/encryption/lib/crypto/encryption.php b/apps/encryption/lib/crypto/encryption.php index 83ed1b59c8a..df3f9a0997e 100644 --- a/apps/encryption/lib/crypto/encryption.php +++ b/apps/encryption/lib/crypto/encryption.php @@ -25,6 +25,7 @@ namespace OCA\Encryption\Crypto; +use OC\Encryption\Exceptions\DecryptionFailedException; use OCA\Encryption\Exceptions\PublicKeyMissingException; use OCA\Encryption\Util; use OCP\Encryption\IEncryptionModule; @@ -274,6 +275,7 @@ class Encryption implements IEncryptionModule { * * @param string $data you want to decrypt * @return mixed decrypted data + * @throws DecryptionFailedException */ public function decrypt($data) { if (empty($this->fileKey)) { diff --git a/apps/encryption/tests/lib/crypto/encryptionTest.php b/apps/encryption/tests/lib/crypto/encryptionTest.php index 509cd9dbc40..d33aff877bf 100644 --- a/apps/encryption/tests/lib/crypto/encryptionTest.php +++ b/apps/encryption/tests/lib/crypto/encryptionTest.php @@ -231,6 +231,7 @@ class EncryptionTest extends TestCase { ); } + /** * by default the encryption module should encrypt regular files, files in * files_versions and files in files_trashbin *