diff options
author | Lukas Reschke <lukas@owncloud.com> | 2016-03-02 20:37:13 +0100 |
---|---|---|
committer | Lukas Reschke <lukas@owncloud.com> | 2016-03-03 14:41:53 +0100 |
commit | 98f79173ed01e8fa2a25fbb0ab3a01523a3c15e1 (patch) | |
tree | 8674fb57e74737ecda1a57021d5e6117ca309fc0 /tests/lib/files | |
parent | 445957a0e2061b8f0b26ea6c859ca72abead3fa5 (diff) | |
download | nextcloud-server-98f79173ed01e8fa2a25fbb0ab3a01523a3c15e1.tar.gz nextcloud-server-98f79173ed01e8fa2a25fbb0ab3a01523a3c15e1.zip |
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.
Diffstat (limited to 'tests/lib/files')
-rw-r--r-- | tests/lib/files/storage/wrapper/encryption.php | 27 |
1 files changed, 21 insertions, 6 deletions
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]); |