diff options
author | Thomas Müller <thomas.mueller@tmit.eu> | 2015-04-02 14:44:58 +0200 |
---|---|---|
committer | Thomas Müller <thomas.mueller@tmit.eu> | 2015-04-07 13:30:30 +0200 |
commit | 104d11ec4c5d359c54985e01c171ba1845537632 (patch) | |
tree | 2cd51e73fab86bef8a4cd86af08d615643f402aa /tests/lib | |
parent | d9c41b00ab4271b401ed838ccc0b19a9a0f67a76 (diff) | |
download | nextcloud-server-104d11ec4c5d359c54985e01c171ba1845537632.tar.gz nextcloud-server-104d11ec4c5d359c54985e01c171ba1845537632.zip |
Fixing encryption storage wrapper tests
Diffstat (limited to 'tests/lib')
-rw-r--r-- | tests/lib/files/storage/storage.php | 2 | ||||
-rw-r--r-- | tests/lib/files/storage/wrapper/encryption.php | 69 |
2 files changed, 66 insertions, 5 deletions
diff --git a/tests/lib/files/storage/storage.php b/tests/lib/files/storage/storage.php index ad7522f1ea8..938fecb5bf3 100644 --- a/tests/lib/files/storage/storage.php +++ b/tests/lib/files/storage/storage.php @@ -253,7 +253,7 @@ abstract class Storage extends \Test\TestCase { $this->instance->file_put_contents('/lorem.txt', file_get_contents($textFile)); $localFile = $this->instance->getLocalFile('/lorem.txt'); $this->assertTrue(file_exists($localFile)); - $this->assertEquals(file_get_contents($localFile), file_get_contents($textFile)); + $this->assertEquals(file_get_contents($textFile), file_get_contents($localFile)); $this->instance->mkdir('/folder'); $this->instance->file_put_contents('/folder/lorem.txt', file_get_contents($textFile)); diff --git a/tests/lib/files/storage/wrapper/encryption.php b/tests/lib/files/storage/wrapper/encryption.php index eea6a53e043..9f681a34298 100644 --- a/tests/lib/files/storage/wrapper/encryption.php +++ b/tests/lib/files/storage/wrapper/encryption.php @@ -16,6 +16,7 @@ class Encryption extends \Test\Files\Storage\Storage { parent::setUp(); + $mockModule = $this->buildMockModule(); $encryptionManager = $this->getMockBuilder('\OC\Encryption\Manager') ->disableOriginalConstructor() ->setMethods(['getDefaultEncryptionModule', 'getEncryptionModule']) @@ -25,22 +26,57 @@ class Encryption extends \Test\Files\Storage\Storage { ->getMock(); $encryptionManager->expects($this->any()) ->method('getDefaultEncryptionModule') - ->willReturn(new DummyModule()); + ->willReturn($mockModule); + $encryptionManager->expects($this->any()) + ->method('getEncryptionModule') + ->willReturn($mockModule); - $util = new \OC\Encryption\Util(new View(), new \OC\User\Manager(), $config); + $util = $this->getMock('\OC\Encryption\Util', ['getUidAndFilename'], [new View(), new \OC\User\Manager(), $config]); + $util->expects($this->any()) + ->method('getUidAndFilename') + ->willReturnCallback(function ($path) { + return ['user1', $path]; + }); + $file = $this->getMockBuilder('\OC\Encryption\File') + ->disableOriginalConstructor() + ->getMock(); $logger = $this->getMock('\OC\Log'); $this->sourceStorage = new \OC\Files\Storage\Temporary(array()); - $this->instance = new \OC\Files\Storage\Wrapper\Encryption([ + $keyStore = $this->getMockBuilder('\OC\Encryption\Keys\Storage') + ->disableOriginalConstructor()->getMock(); + $this->instance = new EncryptionWrapper([ 'storage' => $this->sourceStorage, 'root' => 'foo', 'mountPoint' => '/' ], - $encryptionManager, $util, $logger + $encryptionManager, $util, $logger, $file, null, $keyStore ); } + /** + * @return \PHPUnit_Framework_MockObject_MockObject + */ + protected function buildMockModule() { + $encryptionModule = $this->getMockBuilder('\OCP\Encryption\IEncryptionModule') + ->disableOriginalConstructor() + ->setMethods(['getId', 'getDisplayName', 'begin', 'end', 'encrypt', 'decrypt', 'update', 'shouldEncrypt', 'calculateUnencryptedSize', 'getUnencryptedBlockSize']) + ->getMock(); + + $encryptionModule->expects($this->any())->method('getId')->willReturn('UNIT_TEST_MODULE'); + $encryptionModule->expects($this->any())->method('getDisplayName')->willReturn('Unit test module'); + $encryptionModule->expects($this->any())->method('begin')->willReturn([]); + $encryptionModule->expects($this->any())->method('end')->willReturn(''); + $encryptionModule->expects($this->any())->method('encrypt')->willReturnArgument(0); + $encryptionModule->expects($this->any())->method('decrypt')->willReturnArgument(0); + $encryptionModule->expects($this->any())->method('update')->willReturn(true); + $encryptionModule->expects($this->any())->method('shouldEncrypt')->willReturn(true); + $encryptionModule->expects($this->any())->method('calculateUnencryptedSize')->willReturn(42); + $encryptionModule->expects($this->any())->method('getUnencryptedBlockSize')->willReturn(6126); + return $encryptionModule; + } + // public function testMkDirRooted() { // $this->instance->mkdir('bar'); // $this->assertTrue($this->sourceStorage->is_dir('foo/bar')); @@ -51,3 +87,28 @@ class Encryption extends \Test\Files\Storage\Storage { // $this->assertEquals('asd', $this->sourceStorage->file_get_contents('foo/bar')); // } } + +// +// FIXME: this is too bad and needs adjustment +// +class EncryptionWrapper extends \OC\Files\Storage\Wrapper\Encryption { + private $keyStore; + + public function __construct( + $parameters, + \OC\Encryption\Manager $encryptionManager = null, + \OC\Encryption\Util $util = null, + \OC\Log $logger = null, + \OC\Encryption\File $fileHelper = null, + $uid = null, + $keyStore = null + ) { + $this->keyStore = $keyStore; + parent::__construct($parameters, $encryptionManager, $util, $logger, $fileHelper, $uid); + } + + protected function getKeyStorage($encryptionModuleId) { + return $this->keyStore; + } + +} |