diff options
author | Bjoern Schiessle <schiessle@owncloud.com> | 2016-03-30 23:20:37 +0200 |
---|---|---|
committer | Bjoern Schiessle <schiessle@owncloud.com> | 2016-03-31 19:24:47 +0200 |
commit | 93ed965cbb1952faafc1ca5e09ee0de84d122c05 (patch) | |
tree | 2631e5302305b9b59b25b006edca19650ca2a1bc /tests/lib/files | |
parent | 8ef6c6c7bcf0b58561aee6ec1a18ea7a8643a773 (diff) | |
download | nextcloud-server-93ed965cbb1952faafc1ca5e09ee0de84d122c05.tar.gz nextcloud-server-93ed965cbb1952faafc1ca5e09ee0de84d122c05.zip |
fix creation of versions of encrypted files on external storages
in order to create a 1:1 copy of a file if a version gets created
we need to store this information on copyBetweenStorage(). This
allows us to by-pass the encryption wrapper if we read the source file.
Diffstat (limited to 'tests/lib/files')
-rw-r--r-- | tests/lib/files/storage/wrapper/encryption.php | 44 | ||||
-rw-r--r-- | tests/lib/files/stream/encryption.php | 7 |
2 files changed, 37 insertions, 14 deletions
diff --git a/tests/lib/files/storage/wrapper/encryption.php b/tests/lib/files/storage/wrapper/encryption.php index bde920e440e..9d68f3b14b2 100644 --- a/tests/lib/files/storage/wrapper/encryption.php +++ b/tests/lib/files/storage/wrapper/encryption.php @@ -87,6 +87,9 @@ class Encryption extends Storage { */ private $config; + /** @var \OC\Memcache\ArrayCache | \PHPUnit_Framework_MockObject_MockObject */ + private $arrayCache; + /** @var integer dummy unencrypted size */ private $dummySize = -1; @@ -104,6 +107,7 @@ class Encryption extends Storage { ->method('getEncryptionModule') ->willReturn($mockModule); + $this->arrayCache = $this->getMock('OC\Memcache\ArrayCache'); $this->config = $this->getMockBuilder('\OCP\IConfig') ->disableOriginalConstructor() ->getMock(); @@ -111,9 +115,10 @@ class Encryption extends Storage { ->disableOriginalConstructor() ->getMock(); - $this->util = $this->getMock('\OC\Encryption\Util', + $this->util = $this->getMock( + '\OC\Encryption\Util', ['getUidAndFilename', 'isFile', 'isExcluded'], - [new View(), new \OC\User\Manager(), $this->groupManager, $this->config]); + [new View(), new \OC\User\Manager(), $this->groupManager, $this->config, $this->arrayCache]); $this->util->expects($this->any()) ->method('getUidAndFilename') ->willReturnCallback(function ($path) { @@ -168,7 +173,7 @@ class Encryption extends Storage { 'mountPoint' => '/', 'mount' => $this->mount ], - $this->encryptionManager, $this->util, $this->logger, $this->file, null, $this->keyStore, $this->update, $this->mountManager + $this->encryptionManager, $this->util, $this->logger, $this->file, null, $this->keyStore, $this->update, $this->mountManager, $this->arrayCache ] ) ->setMethods(['getMetaData', 'getCache', 'getEncryptionModule']) @@ -245,7 +250,7 @@ class Encryption extends Storage { 'mountPoint' => '/', 'mount' => $this->mount ], - $this->encryptionManager, $this->util, $this->logger, $this->file, null, $this->keyStore, $this->update, $this->mountManager + $this->encryptionManager, $this->util, $this->logger, $this->file, null, $this->keyStore, $this->update, $this->mountManager, $this->arrayCache ] ) ->setMethods(['getCache', 'verifyUnencryptedSize']) @@ -293,7 +298,7 @@ class Encryption extends Storage { 'mountPoint' => '/', 'mount' => $this->mount ], - $this->encryptionManager, $this->util, $this->logger, $this->file, null, $this->keyStore, $this->update, $this->mountManager + $this->encryptionManager, $this->util, $this->logger, $this->file, null, $this->keyStore, $this->update, $this->mountManager, $this->arrayCache ] ) ->setMethods(['getCache', 'verifyUnencryptedSize']) @@ -331,7 +336,7 @@ class Encryption extends Storage { 'mountPoint' => '/', 'mount' => $this->mount ], - $this->encryptionManager, $this->util, $this->logger, $this->file, null, $this->keyStore, $this->update, $this->mountManager + $this->encryptionManager, $this->util, $this->logger, $this->file, null, $this->keyStore, $this->update, $this->mountManager, $this->arrayCache ] ) ->setMethods(['fixUnencryptedSize']) @@ -521,8 +526,15 @@ class Encryption extends Storage { ->disableOriginalConstructor()->getMock(); $util = $this->getMockBuilder('\OC\Encryption\Util') - ->setConstructorArgs([new View(), new \OC\User\Manager(), $this->groupManager, $this->config]) - ->getMock(); + ->setConstructorArgs( + [ + new View(), + new \OC\User\Manager(), + $this->groupManager, + $this->config, + $this->arrayCache + ] + )->getMock(); $instance = $this->getMockBuilder('\OC\Files\Storage\Wrapper\Encryption') ->setConstructorArgs( @@ -533,7 +545,7 @@ class Encryption extends Storage { 'mountPoint' => '/', 'mount' => $this->mount ], - $this->encryptionManager, $util, $this->logger, $this->file, null, $this->keyStore, $this->update, $this->mountManager + $this->encryptionManager, $util, $this->logger, $this->file, null, $this->keyStore, $this->update, $this->mountManager, $this->arrayCache ] ) ->setMethods(['readFirstBlock', 'parseRawHeader']) @@ -582,7 +594,7 @@ class Encryption extends Storage { ->disableOriginalConstructor()->getMock(); $util = $this->getMockBuilder('\OC\Encryption\Util') - ->setConstructorArgs([new View(), new \OC\User\Manager(), $this->groupManager, $this->config]) + ->setConstructorArgs([new View(), new \OC\User\Manager(), $this->groupManager, $this->config, $this->arrayCache]) ->getMock(); $cache = $this->getMockBuilder('\OC\Files\Cache\Cache') @@ -600,7 +612,7 @@ class Encryption extends Storage { 'mountPoint' => '/', 'mount' => $this->mount ], - $this->encryptionManager, $util, $this->logger, $this->file, null, $this->keyStore, $this->update, $this->mountManager + $this->encryptionManager, $util, $this->logger, $this->file, null, $this->keyStore, $this->update, $this->mountManager, $this->arrayCache ] ) ->setMethods(['readFirstBlock', 'parseRawHeader', 'getCache']) @@ -636,7 +648,7 @@ class Encryption extends Storage { 'mountPoint' => '/', 'mount' => $this->mount ], - $this->encryptionManager, $this->util, $this->logger, $this->file, null, $this->keyStore, $this->update, $this->mountManager + $this->encryptionManager, $this->util, $this->logger, $this->file, null, $this->keyStore, $this->update, $this->mountManager, $this->arrayCache ); @@ -763,6 +775,8 @@ class Encryption extends Storage { $expectedCachePut['encryptedVersion'] = 12345; } + $this->arrayCache->expects($this->never())->method('set'); + $this->cache->expects($this->once()) ->method('put') ->with($sourceInternalPath, $expectedCachePut); @@ -812,7 +826,8 @@ class Encryption extends Storage { null, $this->keyStore, $this->update, - $this->mountManager + $this->mountManager, + $this->arrayCache ] ) ->setMethods(['updateUnencryptedSize', 'getCache']) @@ -825,6 +840,9 @@ class Encryption extends Storage { $instance->expects($this->any())->method('getCache') ->willReturn($cache); + $this->arrayCache->expects($this->once())->method('set') + ->with('encryption_copy_version_' . $sourceInternalPath, true); + if ($copyResult) { $cache->expects($this->once())->method('get') ->with($sourceInternalPath) diff --git a/tests/lib/files/stream/encryption.php b/tests/lib/files/stream/encryption.php index f67dd09bc4d..afb31f2822d 100644 --- a/tests/lib/files/stream/encryption.php +++ b/tests/lib/files/stream/encryption.php @@ -31,6 +31,7 @@ class Encryption extends \Test\TestCase { $config = $this->getMockBuilder('\OCP\IConfig') ->disableOriginalConstructor() ->getMock(); + $arrayCache = $this->getMock('OC\Memcache\ArrayCache'); $groupManager = $this->getMockBuilder('\OC\Group\Manager') ->disableOriginalConstructor() ->getMock(); @@ -39,7 +40,11 @@ class Encryption extends \Test\TestCase { ->setMethods(['getAccessList']) ->getMock(); $file->expects($this->any())->method('getAccessList')->willReturn([]); - $util = $this->getMock('\OC\Encryption\Util', ['getUidAndFilename'], [new View(), new \OC\User\Manager(), $groupManager, $config]); + $util = $this->getMock( + '\OC\Encryption\Util', + ['getUidAndFilename'], + [new View(), new \OC\User\Manager(), $groupManager, $config, $arrayCache] + ); $util->expects($this->any()) ->method('getUidAndFilename') ->willReturn(['user1', $internalPath]); |