From 72c8187cbb24b460edf7d1c5c2cbfaee12c22fd6 Mon Sep 17 00:00:00 2001 From: Lukas Reschke Date: Wed, 2 Mar 2016 20:37:13 +0100 Subject: Keep "encryptedVersion" when calling `\OC\Files\View::copy` When calling `\OC\Files\View::copy` we should also keep the version to ensure that the file will always have the correct version attached and can be successfully decrypted. To test this the following steps are necessary (from https://github.com/owncloud/core/issues/22781#issuecomment-191328982): 1. setup a new ownCloud 9.0 beta2 2. enable encryption 2. upload a docx (5.7MB large) 3. upload the same file again and overwrite the existing file 4. I can download the original file and the first version 5. I restore the first version 6. restored version can no longer be downloaded with the error described above The manual cache operation in `\OCA\Files_Versions\Storage` is unfortunately necessary since `\OCA\Files_Versions\Storage::copyFileContents` is not using `\OCP\Files\Storage::moveFromStorage` in the case when an object storage is used. Due to the workaround added in https://github.com/owncloud/core/commit/54cea05271b887f1c8062c034741df869bc0f055 the stream is directly copied and thus bypassing the FS. --- tests/lib/files/storage/wrapper/encryption.php | 27 ++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) (limited to 'tests') diff --git a/tests/lib/files/storage/wrapper/encryption.php b/tests/lib/files/storage/wrapper/encryption.php index c18e518fe6d..b5ec15b12bf 100644 --- a/tests/lib/files/storage/wrapper/encryption.php +++ b/tests/lib/files/storage/wrapper/encryption.php @@ -693,11 +693,19 @@ class Encryption extends Storage { $temp = \OC::$server->getTempManager(); return fopen($temp->getTemporaryFile(), $mode); }); - + if($expectedEncrypted) { + $cache = $this->getMock('\OCP\Files\Cache\ICache'); + $cache->expects($this->once()) + ->method('get') + ->with($sourceInternalPath) + ->willReturn(['encryptedVersion' => 12345]); + $storage2->expects($this->once()) + ->method('getCache') + ->willReturn($cache); + } $this->encryptionManager->expects($this->any()) ->method('isEnabled') ->willReturn($encryptionEnabled); - // FIXME can not overwrite the return after definition // $this->mount->expects($this->at(0)) // ->method('getOption') @@ -706,9 +714,16 @@ class Encryption extends Storage { global $mockedMountPointEncryptionEnabled; $mockedMountPointEncryptionEnabled = $mountPointEncryptionEnabled; + $expectedCachePut = [ + 'encrypted' => $expectedEncrypted, + ]; + if($expectedEncrypted === true) { + $expectedCachePut['encryptedVersion'] = 12345; + } + $this->cache->expects($this->once()) ->method('put') - ->with($sourceInternalPath, ['encrypted' => $expectedEncrypted]); + ->with($sourceInternalPath, $expectedCachePut); $this->invokePrivate($this->instance, 'copyBetweenStorage', [$storage2, $sourceInternalPath, $targetInternalPath, $preserveMtime, $isRename]); @@ -765,10 +780,10 @@ class Encryption extends Storage { ->with($sourceStorage, $sourceInternalPath, $targetInternalPath) ->willReturn($copyResult); + $instance->expects($this->any())->method('getCache') + ->willReturn($cache); + if ($copyResult) { - $instance->expects($this->once())->method('getCache') - ->with('', $sourceStorage) - ->willReturn($cache); $cache->expects($this->once())->method('get') ->with($sourceInternalPath) ->willReturn(['encrypted' => $encrypted, 'size' => 42]); -- cgit v1.2.3