Merge pull request #23707 from owncloud/make-sure-that-encrypted-version-is-set

Make sure that the encrypted version is set
This commit is contained in:
Frank Karlitschek 2016-03-31 20:37:17 +02:00
commit 2bff34be56
2 changed files with 26 additions and 7 deletions

View File

@ -174,20 +174,25 @@ class Encryption extends Wrapper {
return null; return null;
} }
$fullPath = $this->getFullPath($path); $fullPath = $this->getFullPath($path);
$info = $this->getCache()->get($path);
if (isset($this->unencryptedSize[$fullPath])) { if (isset($this->unencryptedSize[$fullPath])) {
$data['encrypted'] = true; $data['encrypted'] = true;
$data['size'] = $this->unencryptedSize[$fullPath]; $data['size'] = $this->unencryptedSize[$fullPath];
} else { } else {
$info = $this->getCache()->get($path);
if (isset($info['fileid']) && $info['encrypted']) { if (isset($info['fileid']) && $info['encrypted']) {
$data['size'] = $this->verifyUnencryptedSize($path, $info['size']); $data['size'] = $this->verifyUnencryptedSize($path, $info['size']);
$data['encrypted'] = true; $data['encrypted'] = true;
} }
} }
if (isset($info['encryptedVersion']) && $info['encryptedVersion'] > 1) {
$data['encryptedVersion'] = $info['encryptedVersion'];
}
return $data; return $data;
} }
/** /**
* see http://php.net/manual/en/function.file_get_contents.php * see http://php.net/manual/en/function.file_get_contents.php
* *

View File

@ -260,25 +260,39 @@ class Encryption extends Storage {
$this->invokePrivate($this->instance, 'unencryptedSize', [[$path => $storedUnencryptedSize]]); $this->invokePrivate($this->instance, 'unencryptedSize', [[$path => $storedUnencryptedSize]]);
} }
$fileEntry = $this->getMockBuilder('\OC\Files\Cache\Cache')
->disableOriginalConstructor()->getMock();
$sourceStorage->expects($this->once())->method('getMetaData')->with($path) $sourceStorage->expects($this->once())->method('getMetaData')->with($path)
->willReturn($metaData); ->willReturn($metaData);
$sourceStorage->expects($this->any())
->method('getCache')
->with($path)
->willReturn($fileEntry);
$fileEntry->expects($this->any())
->method('get')
->with($metaData['fileid']);
$this->instance->expects($this->any())->method('getCache')->willReturn($cache); $this->instance->expects($this->any())->method('getCache')->willReturn($cache);
$this->instance->expects($this->any())->method('verifyUnencryptedSize') $this->instance->expects($this->any())->method('verifyUnencryptedSize')
->with($path, 0)->willReturn($expected['size']); ->with($path, 0)->willReturn($expected['size']);
$result = $this->instance->getMetaData($path); $result = $this->instance->getMetaData($path);
$this->assertSame($expected['encrypted'], $result['encrypted']); if(isset($expected['encrypted'])) {
$this->assertSame($expected['encrypted'], (bool)$result['encrypted']);
if(isset($expected['encryptedVersion'])) {
$this->assertSame($expected['encryptedVersion'], $result['encryptedVersion']);
}
}
$this->assertSame($expected['size'], $result['size']); $this->assertSame($expected['size'], $result['size']);
} }
public function dataTestGetMetaData() { public function dataTestGetMetaData() {
return [ return [
['/test.txt', ['size' => 42, 'encrypted' => false], true, true, 12, ['size' => 12, 'encrypted' => true]], ['/test.txt', ['size' => 42, 'encrypted' => 2, 'encryptedVersion' => 2, 'fileid' => 1], true, true, 12, ['size' => 12, 'encrypted' => true, 'encryptedVersion' => 2]],
['/test.txt', null, true, true, 12, null], ['/test.txt', null, true, true, 12, null],
['/test.txt', ['size' => 42, 'encrypted' => false], false, false, 12, ['size' => 42, 'encrypted' => false]], ['/test.txt', ['size' => 42, 'encrypted' => 0, 'fileid' => 1], false, false, 12, ['size' => 42, 'encrypted' => false]],
['/test.txt', ['size' => 42, 'encrypted' => false], true, false, 12, ['size' => 12, 'encrypted' => true]] ['/test.txt', ['size' => 42, 'encrypted' => false, 'fileid' => 1], true, false, 12, ['size' => 12, 'encrypted' => true]]
]; ];
} }