Skip to content
Snippets Groups Projects
Commit 95602d40 authored by Björn Schießle's avatar Björn Schießle
Browse files

make sure that we always read the header from the original file

parent ed3dc199
Branches
No related tags found
No related merge requests found
...@@ -349,7 +349,8 @@ class Encryption extends Wrapper { ...@@ -349,7 +349,8 @@ class Encryption extends Wrapper {
if ($this->util->isExcluded($fullPath) === false) { if ($this->util->isExcluded($fullPath) === false) {
$size = $unencryptedSize = 0; $size = $unencryptedSize = 0;
$targetExists = $this->file_exists($path); $realFile = $this->util->stripPartialFileExtension($path);
$targetExists = $this->file_exists($realFile);
$targetIsEncrypted = false; $targetIsEncrypted = false;
if ($targetExists) { if ($targetExists) {
// in case the file exists we require the explicit module as // in case the file exists we require the explicit module as
...@@ -605,8 +606,9 @@ class Encryption extends Wrapper { ...@@ -605,8 +606,9 @@ class Encryption extends Wrapper {
*/ */
protected function getHeader($path) { protected function getHeader($path) {
$header = ''; $header = '';
if ($this->storage->file_exists($path)) { $realFile = $this->util->stripPartialFileExtension($path);
$handle = $this->storage->fopen($path, 'r'); if ($this->storage->file_exists($realFile)) {
$handle = $this->storage->fopen($realFile, 'r');
$firstBlock = fread($handle, $this->util->getHeaderSize()); $firstBlock = fread($handle, $this->util->getHeaderSize());
fclose($handle); fclose($handle);
if (substr($firstBlock, 0, strlen(Util::HEADER_START)) === Util::HEADER_START) { if (substr($firstBlock, 0, strlen(Util::HEADER_START)) === Util::HEADER_START) {
......
...@@ -68,6 +68,17 @@ class Encryption extends \Test\Files\Storage\Storage { ...@@ -68,6 +68,17 @@ class Encryption extends \Test\Files\Storage\Storage {
*/ */
private $mountManager; private $mountManager;
/**
* @var \OC\Group\Manager | \PHPUnit_Framework_MockObject_MockObject
*/
private $groupManager;
/**
* @var \OCP\IConfig | \PHPUnit_Framework_MockObject_MockObject
*/
private $config;
/** @var integer dummy unencrypted size */ /** @var integer dummy unencrypted size */
private $dummySize = -1; private $dummySize = -1;
...@@ -84,14 +95,16 @@ class Encryption extends \Test\Files\Storage\Storage { ...@@ -84,14 +95,16 @@ class Encryption extends \Test\Files\Storage\Storage {
->method('getEncryptionModule') ->method('getEncryptionModule')
->willReturn($mockModule); ->willReturn($mockModule);
$config = $this->getMockBuilder('\OCP\IConfig') $this->config = $this->getMockBuilder('\OCP\IConfig')
->disableOriginalConstructor() ->disableOriginalConstructor()
->getMock(); ->getMock();
$groupManager = $this->getMockBuilder('\OC\Group\Manager') $this->groupManager = $this->getMockBuilder('\OC\Group\Manager')
->disableOriginalConstructor() ->disableOriginalConstructor()
->getMock(); ->getMock();
$this->util = $this->getMock('\OC\Encryption\Util', ['getUidAndFilename', 'isFile', 'isExcluded'], [new View(), new \OC\User\Manager(), $groupManager, $config]); $this->util = $this->getMock('\OC\Encryption\Util',
['getUidAndFilename', 'isFile', 'isExcluded'],
[new View(), new \OC\User\Manager(), $this->groupManager, $this->config]);
$this->util->expects($this->any()) $this->util->expects($this->any())
->method('getUidAndFilename') ->method('getUidAndFilename')
->willReturnCallback(function ($path) { ->willReturnCallback(function ($path) {
...@@ -365,4 +378,48 @@ class Encryption extends \Test\Files\Storage\Storage { ...@@ -365,4 +378,48 @@ class Encryption extends \Test\Files\Storage\Storage {
array(false, true), array(false, true),
); );
} }
/**
* @dataProvider dataTestGetHeader
* @param $path
* @param $strippedPath
*/
public function testGetHeader($path, $strippedPath) {
$sourceStorage = $this->getMockBuilder('\OC\Files\Storage\Storage')
->disableOriginalConstructor()->getMock();
$util = $this->getMockBuilder('\OC\Encryption\Util')
->setConstructorArgs([new View(), new \OC\User\Manager(), $this->groupManager, $this->config])
->getMock();
$instance = $this->getMockBuilder('\OC\Files\Storage\Wrapper\Encryption')
->setConstructorArgs(
[
[
'storage' => $sourceStorage,
'root' => 'foo',
'mountPoint' => '/',
'mount' => $this->mount
],
$this->encryptionManager, $util, $this->logger, $this->file, null, $this->keyStore, $this->update, $this->mountManager
]
)
->getMock();
$util->expects($this->once())->method('stripPartialFileExtension')
->with($path)->willReturn($strippedPath);
$sourceStorage->expects($this->once())->method('file_exists')
->with($strippedPath)->willReturn(false);
$this->invokePrivate($instance, 'getHeader', [$path]);
}
public function dataTestGetHeader() {
return array(
array('/foo/bar.txt', '/foo/bar.txt'),
array('/foo/bar.txt.part', '/foo/bar.txt'),
array('/foo/bar.txt.ocTransferId7437493.part', '/foo/bar.txt'),
);
}
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment