diff options
author | Bjoern Schiessle <schiessle@owncloud.com> | 2015-05-21 14:07:42 +0200 |
---|---|---|
committer | Bjoern Schiessle <schiessle@owncloud.com> | 2015-05-22 15:41:28 +0200 |
commit | c63f2286c06e94926a8af738397c18c3bb1ff4ea (patch) | |
tree | 5fa2de556e6d7a7a3c4fc97f5f66317b01fcb845 /tests | |
parent | 38bceb0d744357fc25cf0353989aa59f1bdcf11c (diff) | |
download | nextcloud-server-c63f2286c06e94926a8af738397c18c3bb1ff4ea.tar.gz nextcloud-server-c63f2286c06e94926a8af738397c18c3bb1ff4ea.zip |
copy keys before we move a file between storages to make sure that the new target file reuses the old file key, otherwise versions will break
Diffstat (limited to 'tests')
-rw-r--r-- | tests/lib/files/storage/wrapper/encryption.php | 49 |
1 files changed, 45 insertions, 4 deletions
diff --git a/tests/lib/files/storage/wrapper/encryption.php b/tests/lib/files/storage/wrapper/encryption.php index 39af648cb75..d286978d926 100644 --- a/tests/lib/files/storage/wrapper/encryption.php +++ b/tests/lib/files/storage/wrapper/encryption.php @@ -63,6 +63,11 @@ class Encryption extends \Test\Files\Storage\Storage { */ private $mount; + /** + * @var \OC\Files\Mount\Manager | \PHPUnit_Framework_MockObject_MockObject + */ + private $mountManager; + /** @var integer dummy unencrypted size */ private $dummySize = -1; @@ -86,7 +91,7 @@ class Encryption extends \Test\Files\Storage\Storage { ->disableOriginalConstructor() ->getMock(); - $this->util = $this->getMock('\OC\Encryption\Util', ['getUidAndFilename', 'isFile'], [new View(), new \OC\User\Manager(), $groupManager, $config]); + $this->util = $this->getMock('\OC\Encryption\Util', ['getUidAndFilename', 'isFile', 'isExcluded'], [new View(), new \OC\User\Manager(), $groupManager, $config]); $this->util->expects($this->any()) ->method('getUidAndFilename') ->willReturnCallback(function ($path) { @@ -119,7 +124,10 @@ class Encryption extends \Test\Files\Storage\Storage { ->disableOriginalConstructor()->getMock(); $this->cache->expects($this->any()) ->method('get') - ->willReturn(['encrypted' => false]); + ->willReturnCallback(function($path) {return ['encrypted' => false, 'path' => $path];}); + + $this->mountManager = $this->getMockBuilder('\OC\Files\Mount\Manager') + ->disableOriginalConstructor()->getMock(); $this->instance = $this->getMockBuilder('\OC\Files\Storage\Wrapper\Encryption') ->setConstructorArgs( @@ -130,7 +138,7 @@ class Encryption extends \Test\Files\Storage\Storage { 'mountPoint' => '/', 'mount' => $this->mount ], - $this->encryptionManager, $this->util, $this->logger, $this->file, null, $this->keyStore, $this->update + $this->encryptionManager, $this->util, $this->logger, $this->file, null, $this->keyStore, $this->update, $this->mountManager ] ) ->setMethods(['getMetaData', 'getCache', 'getEncryptionModule']) @@ -138,7 +146,9 @@ class Encryption extends \Test\Files\Storage\Storage { $this->instance->expects($this->any()) ->method('getMetaData') - ->willReturn(['encrypted' => true, 'size' => $this->dummySize]); + ->willReturnCallback(function ($path) { + return ['encrypted' => true, 'size' => $this->dummySize, 'path' => $path]; + }); $this->instance->expects($this->any()) ->method('getCache') @@ -232,6 +242,8 @@ class Encryption extends \Test\Files\Storage\Storage { } $this->util->expects($this->any()) ->method('isFile')->willReturn(true); + $this->util->expects($this->any()) + ->method('isExcluded')->willReturn(false); $this->encryptionManager->expects($this->once()) ->method('isEnabled')->willReturn($encryptionEnabled); if ($shouldUpdate) { @@ -324,4 +336,33 @@ class Encryption extends \Test\Files\Storage\Storage { array('/file.txt', false, false, false), ); } + + /** + * @dataProvider dataTestCopyKeys + * + * @param boolean $excluded + * @param boolean $expected + */ + public function testCopyKeys($excluded, $expected) { + $this->util->expects($this->once()) + ->method('isExcluded') + ->willReturn($excluded); + + if ($excluded) { + $this->keyStore->expects($this->never())->method('copyKeys'); + } else { + $this->keyStore->expects($this->once())->method('copyKeys')->willReturn(true); + } + + $this->assertSame($expected, + \Test_Helper::invokePrivate($this->instance, 'copyKeys', ['/source', '/target']) + ); + } + + public function dataTestCopyKeys() { + return array( + array(true, false), + array(false, true), + ); + } } |