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.
This commit is contained in:
Bjoern Schiessle 2016-03-30 23:20:37 +02:00
parent 8ef6c6c7bc
commit 93ed965cbb
12 changed files with 310 additions and 130 deletions

View File

@ -722,7 +722,8 @@ class OC {
} }
private static function registerEncryptionWrapper() { private static function registerEncryptionWrapper() {
\OCP\Util::connectHook('OC_Filesystem', 'preSetup', 'OC\Encryption\Manager', 'setupStorage'); $manager = self::$server->getEncryptionManager();
\OCP\Util::connectHook('OC_Filesystem', 'preSetup', $manager, 'setupStorage');
} }
private static function registerEncryptionHooks() { private static function registerEncryptionHooks() {

View File

@ -59,6 +59,7 @@ use OC\Lock\DBLockingProvider;
use OC\Lock\MemcacheLockingProvider; use OC\Lock\MemcacheLockingProvider;
use OC\Lock\NoopLockingProvider; use OC\Lock\NoopLockingProvider;
use OC\Mail\Mailer; use OC\Mail\Mailer;
use OC\Memcache\ArrayCache;
use OC\Notification\Manager; use OC\Notification\Manager;
use OC\Security\CertificateManager; use OC\Security\CertificateManager;
use OC\Security\CSP\ContentSecurityPolicyManager; use OC\Security\CSP\ContentSecurityPolicyManager;
@ -117,7 +118,8 @@ class Server extends ServerContainer implements IServerContainer {
$c->getLogger(), $c->getLogger(),
$c->getL10N('core'), $c->getL10N('core'),
new View(), new View(),
$util $util,
new ArrayCache()
); );
}); });

View File

@ -0,0 +1,124 @@
<?php
/**
* @author Björn Schießle <schiessle@owncloud.com>
*
* @copyright Copyright (c) 2016, ownCloud, Inc.
* @license AGPL-3.0
*
* This code is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License, version 3,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License, version 3,
* along with this program. If not, see <http://www.gnu.org/licenses/>
*
*/
namespace OC\Encryption;
use OC\Memcache\ArrayCache;
use OC\Files\Filesystem;
use OC\Files\Storage\Wrapper\Encryption;
use OCP\Files\Mount\IMountPoint;
use OC\Files\View;
use OCP\Files\Storage;
use OCP\ILogger;
/**
* Class EncryptionWrapper
*
* applies the encryption storage wrapper
*
* @package OC\Encryption
*/
class EncryptionWrapper {
/** @var ArrayCache */
private $arrayCache;
/** @var Manager */
private $manager;
/** @var ILogger */
private $logger;
/**
* EncryptionWrapper constructor.
*
* @param ArrayCache $arrayCache
* @param Manager $manager
* @param ILogger $logger
*/
public function __construct(ArrayCache $arrayCache,
Manager $manager,
ILogger $logger
) {
$this->arrayCache = $arrayCache;
$this->manager = $manager;
$this->logger = $logger;
}
/**
* Wraps the given storage when it is not a shared storage
*
* @param string $mountPoint
* @param Storage $storage
* @param IMountPoint $mount
* @return Encryption|Storage
*/
public function wrapStorage($mountPoint, Storage $storage, IMountPoint $mount) {
$parameters = [
'storage' => $storage,
'mountPoint' => $mountPoint,
'mount' => $mount
];
if (!$storage->instanceOfStorage('OC\Files\Storage\Shared')
&& !$storage->instanceOfStorage('OCA\Files_Sharing\External\Storage')
&& !$storage->instanceOfStorage('OC\Files\Storage\OwnCloud')) {
$user = \OC::$server->getUserSession()->getUser();
$mountManager = Filesystem::getMountManager();
$uid = $user ? $user->getUID() : null;
$fileHelper = \OC::$server->getEncryptionFilesHelper();
$keyStorage = \OC::$server->getEncryptionKeyStorage();
$util = new Util(
new View(),
\OC::$server->getUserManager(),
\OC::$server->getGroupManager(),
\OC::$server->getConfig()
);
$update = new Update(
new View(),
$util,
Filesystem::getMountManager(),
$this->manager,
$fileHelper,
$uid
);
return new Encryption(
$parameters,
$this->manager,
$util,
$this->logger,
$fileHelper,
$uid,
$keyStorage,
$update,
$mountManager,
$this->arrayCache
);
} else {
return $storage;
}
}
}

View File

@ -27,6 +27,7 @@ namespace OC\Encryption;
use OC\Encryption\Keys\Storage; use OC\Encryption\Keys\Storage;
use OC\Files\Filesystem; use OC\Files\Filesystem;
use OC\Files\View; use OC\Files\View;
use OC\Memcache\ArrayCache;
use OC\ServiceUnavailableException; use OC\ServiceUnavailableException;
use OCP\Encryption\IEncryptionModule; use OCP\Encryption\IEncryptionModule;
use OCP\Encryption\IManager; use OCP\Encryption\IManager;
@ -54,20 +55,25 @@ class Manager implements IManager {
/** @var Util */ /** @var Util */
protected $util; protected $util;
/** @var ArrayCache */
protected $arrayCache;
/** /**
* @param IConfig $config * @param IConfig $config
* @param ILogger $logger * @param ILogger $logger
* @param IL10N $l10n * @param IL10N $l10n
* @param View $rootView * @param View $rootView
* @param Util $util * @param Util $util
* @param ArrayCache $arrayCache
*/ */
public function __construct(IConfig $config, ILogger $logger, IL10N $l10n, View $rootView, Util $util) { public function __construct(IConfig $config, ILogger $logger, IL10N $l10n, View $rootView, Util $util, ArrayCache $arrayCache) {
$this->encryptionModules = array(); $this->encryptionModules = array();
$this->config = $config; $this->config = $config;
$this->logger = $logger; $this->logger = $logger;
$this->l = $l10n; $this->l = $l10n;
$this->rootView = $rootView; $this->rootView = $rootView;
$this->util = $util; $this->util = $util;
$this->arrayCache = $arrayCache;
} }
/** /**
@ -227,14 +233,9 @@ class Manager implements IManager {
/** /**
* Add storage wrapper * Add storage wrapper
*/ */
public static function setupStorage() { public function setupStorage() {
$util = new Util( $encryptionWrapper = new EncryptionWrapper($this->arrayCache, $this, $this->logger);
new View(), Filesystem::addStorageWrapper('oc_encryption', array($encryptionWrapper, 'wrapStorage'), 2);
\OC::$server->getUserManager(),
\OC::$server->getGroupManager(),
\OC::$server->getConfig()
);
Filesystem::addStorageWrapper('oc_encryption', array($util, 'wrapStorage'), 2);
} }

View File

@ -28,10 +28,8 @@ use OC\Encryption\Exceptions\EncryptionHeaderKeyExistsException;
use OC\Encryption\Exceptions\EncryptionHeaderToLargeException; use OC\Encryption\Exceptions\EncryptionHeaderToLargeException;
use OC\Encryption\Exceptions\ModuleDoesNotExistsException; use OC\Encryption\Exceptions\ModuleDoesNotExistsException;
use OC\Files\Filesystem; use OC\Files\Filesystem;
use OC\Files\Storage\Wrapper\Encryption;
use OC\Files\View; use OC\Files\View;
use OCP\Encryption\IEncryptionModule; use OCP\Encryption\IEncryptionModule;
use OCP\Files\Mount\IMountPoint;
use OCP\Files\Storage; use OCP\Files\Storage;
use OCP\IConfig; use OCP\IConfig;
@ -392,52 +390,4 @@ class Util {
return $this->config->getAppValue('core', 'encryption_key_storage_root', ''); return $this->config->getAppValue('core', 'encryption_key_storage_root', '');
} }
/**
* Wraps the given storage when it is not a shared storage
*
* @param string $mountPoint
* @param Storage $storage
* @param IMountPoint $mount
* @return Encryption|Storage
*/
public function wrapStorage($mountPoint, Storage $storage, IMountPoint $mount) {
$parameters = [
'storage' => $storage,
'mountPoint' => $mountPoint,
'mount' => $mount];
if (!$storage->instanceOfStorage('OC\Files\Storage\Shared')
&& !$storage->instanceOfStorage('OCA\Files_Sharing\External\Storage')
&& !$storage->instanceOfStorage('OC\Files\Storage\OwnCloud')) {
$manager = \OC::$server->getEncryptionManager();
$user = \OC::$server->getUserSession()->getUser();
$logger = \OC::$server->getLogger();
$mountManager = Filesystem::getMountManager();
$uid = $user ? $user->getUID() : null;
$fileHelper = \OC::$server->getEncryptionFilesHelper();
$keyStorage = \OC::$server->getEncryptionKeyStorage();
$update = new Update(
new View(),
$this,
Filesystem::getMountManager(),
$manager,
$fileHelper,
$uid
);
return new Encryption(
$parameters,
$manager,
$this,
$logger,
$fileHelper,
$uid,
$keyStorage,
$update,
$mountManager
);
} else {
return $storage;
}
}
} }

View File

@ -33,6 +33,7 @@ use OC\Files\Cache\CacheEntry;
use OC\Files\Filesystem; use OC\Files\Filesystem;
use OC\Files\Mount\Manager; use OC\Files\Mount\Manager;
use OC\Files\Storage\LocalTempFileTrait; use OC\Files\Storage\LocalTempFileTrait;
use OC\Memcache\ArrayCache;
use OCP\Encryption\Exceptions\GenericEncryptionException; use OCP\Encryption\Exceptions\GenericEncryptionException;
use OCP\Encryption\IFile; use OCP\Encryption\IFile;
use OCP\Encryption\IManager; use OCP\Encryption\IManager;
@ -82,6 +83,9 @@ class Encryption extends Wrapper {
/** @var array remember for which path we execute the repair step to avoid recursions */ /** @var array remember for which path we execute the repair step to avoid recursions */
private $fixUnencryptedSizeOf = array(); private $fixUnencryptedSizeOf = array();
/** @var ArrayCache */
private $arrayCache;
/** /**
* @param array $parameters * @param array $parameters
* @param IManager $encryptionManager * @param IManager $encryptionManager
@ -92,6 +96,7 @@ class Encryption extends Wrapper {
* @param IStorage $keyStorage * @param IStorage $keyStorage
* @param Update $update * @param Update $update
* @param Manager $mountManager * @param Manager $mountManager
* @param ArrayCache $arrayCache
*/ */
public function __construct( public function __construct(
$parameters, $parameters,
@ -102,7 +107,8 @@ class Encryption extends Wrapper {
$uid = null, $uid = null,
IStorage $keyStorage = null, IStorage $keyStorage = null,
Update $update = null, Update $update = null,
Manager $mountManager = null Manager $mountManager = null,
ArrayCache $arrayCache = null
) { ) {
$this->mountPoint = $parameters['mountPoint']; $this->mountPoint = $parameters['mountPoint'];
@ -116,6 +122,7 @@ class Encryption extends Wrapper {
$this->unencryptedSize = array(); $this->unencryptedSize = array();
$this->update = $update; $this->update = $update;
$this->mountManager = $mountManager; $this->mountManager = $mountManager;
$this->arrayCache = $arrayCache;
parent::__construct($parameters); parent::__construct($parameters);
} }
@ -352,6 +359,14 @@ class Encryption extends Wrapper {
*/ */
public function fopen($path, $mode) { public function fopen($path, $mode) {
// check if the file is stored in the array cache, this means that we
// copy a file over to the versions folder, in this case we don't want to
// decrypt it
if ($this->arrayCache->hasKey('encryption_copy_version_' . $path)) {
$this->arrayCache->remove('encryption_copy_version_' . $path);
return $this->storage->fopen($path, $mode);
}
$encryptionEnabled = $this->encryptionManager->isEnabled(); $encryptionEnabled = $this->encryptionManager->isEnabled();
$shouldEncrypt = false; $shouldEncrypt = false;
$encryptionModule = null; $encryptionModule = null;
@ -674,6 +689,10 @@ class Encryption extends Wrapper {
// key from the original file. Just create a 1:1 copy and done // key from the original file. Just create a 1:1 copy and done
if ($this->isVersion($targetInternalPath) || if ($this->isVersion($targetInternalPath) ||
$this->isVersion($sourceInternalPath)) { $this->isVersion($sourceInternalPath)) {
// remember that we try to create a version so that we can detect it during
// fopen($sourceInternalPath) and by-pass the encryption in order to
// create a 1:1 copy of the file
$this->arrayCache->set('encryption_copy_version_' . $sourceInternalPath, true);
$result = $this->storage->copyFromStorage($sourceStorage, $sourceInternalPath, $targetInternalPath); $result = $this->storage->copyFromStorage($sourceStorage, $sourceInternalPath, $targetInternalPath);
if ($result) { if ($result) {
$info = $this->getCache('', $sourceStorage)->get($sourceInternalPath); $info = $this->getCache('', $sourceStorage)->get($sourceInternalPath);

View File

@ -0,0 +1,101 @@
<?php
/**
* @author Björn Schießle <schiessle@owncloud.com>
*
* @copyright Copyright (c) 2016, ownCloud, Inc.
* @license AGPL-3.0
*
* This code is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License, version 3,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License, version 3,
* along with this program. If not, see <http://www.gnu.org/licenses/>
*
*/
namespace Test\Encryption;
use OC\Encryption\EncryptionWrapper;
use Test\TestCase;
class EncryptionWrapperTest extends TestCase {
/** @var EncryptionWrapper */
private $instance;
/** @var \PHPUnit_Framework_MockObject_MockObject | \OCP\ILogger */
private $logger;
/** @var \PHPUnit_Framework_MockObject_MockObject | \OC\Encryption\Manager */
private $manager;
/** @var \PHPUnit_Framework_MockObject_MockObject | \OC\Memcache\ArrayCache */
private $arrayCache;
public function setUp() {
parent::setUp();
$this->arrayCache = $this->getMock('OC\Memcache\ArrayCache');
$this->manager = $this->getMockBuilder('OC\Encryption\Manager')
->disableOriginalConstructor()->getMock();
$this->logger = $this->getMock('OCP\ILogger');
$this->instance = new EncryptionWrapper($this->arrayCache, $this->manager, $this->logger);
}
/**
* @dataProvider provideWrapStorage
*/
public function testWrapStorage($expectedWrapped, $wrappedStorages) {
$storage = $this->getMockBuilder('OC\Files\Storage\Storage')
->disableOriginalConstructor()
->getMock();
foreach ($wrappedStorages as $wrapper) {
$storage->expects($this->any())
->method('instanceOfStorage')
->willReturnMap([
[$wrapper, true],
]);
}
$mount = $this->getMockBuilder('OCP\Files\Mount\IMountPoint')
->disableOriginalConstructor()
->getMock();
$returnedStorage = $this->instance->wrapStorage('mountPoint', $storage, $mount);
$this->assertEquals(
$expectedWrapped,
$returnedStorage->instanceOfStorage('OC\Files\Storage\Wrapper\Encryption'),
'Asserted that the storage is (not) wrapped with encryption'
);
}
public function provideWrapStorage() {
return [
// Wrap when not wrapped or not wrapped with storage
[true, []],
[true, ['OCA\Files_Trashbin\Storage']],
// Do not wrap shared storages
[false, ['OC\Files\Storage\Shared']],
[false, ['OCA\Files_Sharing\External\Storage']],
[false, ['OC\Files\Storage\OwnCloud']],
[false, ['OC\Files\Storage\Shared', 'OCA\Files_Sharing\External\Storage']],
[false, ['OC\Files\Storage\Shared', 'OC\Files\Storage\OwnCloud']],
[false, ['OCA\Files_Sharing\External\Storage', 'OC\Files\Storage\OwnCloud']],
[false, ['OC\Files\Storage\Shared', 'OCA\Files_Sharing\External\Storage', 'OC\Files\Storage\OwnCloud']],
];
}
}

View File

@ -25,6 +25,9 @@ class ManagerTest extends TestCase {
/** @var \PHPUnit_Framework_MockObject_MockObject */ /** @var \PHPUnit_Framework_MockObject_MockObject */
private $util; private $util;
/** @var \PHPUnit_Framework_MockObject_MockObject | \OC\Memcache\ArrayCache */
private $arrayCache;
public function setUp() { public function setUp() {
parent::setUp(); parent::setUp();
$this->config = $this->getMock('\OCP\IConfig'); $this->config = $this->getMock('\OCP\IConfig');
@ -32,7 +35,8 @@ class ManagerTest extends TestCase {
$this->l10n = $this->getMock('\OCP\Il10n'); $this->l10n = $this->getMock('\OCP\Il10n');
$this->view = $this->getMock('\OC\Files\View'); $this->view = $this->getMock('\OC\Files\View');
$this->util = $this->getMockBuilder('\OC\Encryption\Util')->disableOriginalConstructor()->getMock(); $this->util = $this->getMockBuilder('\OC\Encryption\Util')->disableOriginalConstructor()->getMock();
$this->manager = new Manager($this->config, $this->logger, $this->l10n, $this->view, $this->util); $this->arrayCache = $this->getMock('OC\Memcache\ArrayCache');
$this->manager = new Manager($this->config, $this->logger, $this->l10n, $this->view, $this->util, $this->arrayCache);
} }
public function testManagerIsDisabled() { public function testManagerIsDisabled() {

View File

@ -188,49 +188,4 @@ class UtilTest extends TestCase {
); );
} }
/**
* @dataProvider provideWrapStorage
*/
public function testWrapStorage($expectedWrapped, $wrappedStorages) {
$storage = $this->getMockBuilder('OC\Files\Storage\Storage')
->disableOriginalConstructor()
->getMock();
foreach ($wrappedStorages as $wrapper) {
$storage->expects($this->any())
->method('instanceOfStorage')
->willReturnMap([
[$wrapper, true],
]);
}
$mount = $this->getMockBuilder('OCP\Files\Mount\IMountPoint')
->disableOriginalConstructor()
->getMock();
$returnedStorage = $this->util->wrapStorage('mountPoint', $storage, $mount);
$this->assertEquals(
$expectedWrapped,
$returnedStorage->instanceOfStorage('OC\Files\Storage\Wrapper\Encryption'),
'Asserted that the storage is (not) wrapped with encryption'
);
}
public function provideWrapStorage() {
return [
// Wrap when not wrapped or not wrapped with storage
[true, []],
[true, ['OCA\Files_Trashbin\Storage']],
// Do not wrap shared storages
[false, ['OC\Files\Storage\Shared']],
[false, ['OCA\Files_Sharing\External\Storage']],
[false, ['OC\Files\Storage\OwnCloud']],
[false, ['OC\Files\Storage\Shared', 'OCA\Files_Sharing\External\Storage']],
[false, ['OC\Files\Storage\Shared', 'OC\Files\Storage\OwnCloud']],
[false, ['OCA\Files_Sharing\External\Storage', 'OC\Files\Storage\OwnCloud']],
[false, ['OC\Files\Storage\Shared', 'OCA\Files_Sharing\External\Storage', 'OC\Files\Storage\OwnCloud']],
];
}
} }

View File

@ -87,6 +87,9 @@ class Encryption extends Storage {
*/ */
private $config; private $config;
/** @var \OC\Memcache\ArrayCache | \PHPUnit_Framework_MockObject_MockObject */
private $arrayCache;
/** @var integer dummy unencrypted size */ /** @var integer dummy unencrypted size */
private $dummySize = -1; private $dummySize = -1;
@ -104,6 +107,7 @@ class Encryption extends Storage {
->method('getEncryptionModule') ->method('getEncryptionModule')
->willReturn($mockModule); ->willReturn($mockModule);
$this->arrayCache = $this->getMock('OC\Memcache\ArrayCache');
$this->config = $this->getMockBuilder('\OCP\IConfig') $this->config = $this->getMockBuilder('\OCP\IConfig')
->disableOriginalConstructor() ->disableOriginalConstructor()
->getMock(); ->getMock();
@ -111,9 +115,10 @@ class Encryption extends Storage {
->disableOriginalConstructor() ->disableOriginalConstructor()
->getMock(); ->getMock();
$this->util = $this->getMock('\OC\Encryption\Util', $this->util = $this->getMock(
'\OC\Encryption\Util',
['getUidAndFilename', 'isFile', 'isExcluded'], ['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()) $this->util->expects($this->any())
->method('getUidAndFilename') ->method('getUidAndFilename')
->willReturnCallback(function ($path) { ->willReturnCallback(function ($path) {
@ -168,7 +173,7 @@ class Encryption extends Storage {
'mountPoint' => '/', 'mountPoint' => '/',
'mount' => $this->mount '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']) ->setMethods(['getMetaData', 'getCache', 'getEncryptionModule'])
@ -245,7 +250,7 @@ class Encryption extends Storage {
'mountPoint' => '/', 'mountPoint' => '/',
'mount' => $this->mount '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']) ->setMethods(['getCache', 'verifyUnencryptedSize'])
@ -293,7 +298,7 @@ class Encryption extends Storage {
'mountPoint' => '/', 'mountPoint' => '/',
'mount' => $this->mount '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']) ->setMethods(['getCache', 'verifyUnencryptedSize'])
@ -331,7 +336,7 @@ class Encryption extends Storage {
'mountPoint' => '/', 'mountPoint' => '/',
'mount' => $this->mount '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']) ->setMethods(['fixUnencryptedSize'])
@ -521,8 +526,15 @@ class Encryption extends Storage {
->disableOriginalConstructor()->getMock(); ->disableOriginalConstructor()->getMock();
$util = $this->getMockBuilder('\OC\Encryption\Util') $util = $this->getMockBuilder('\OC\Encryption\Util')
->setConstructorArgs([new View(), new \OC\User\Manager(), $this->groupManager, $this->config]) ->setConstructorArgs(
->getMock(); [
new View(),
new \OC\User\Manager(),
$this->groupManager,
$this->config,
$this->arrayCache
]
)->getMock();
$instance = $this->getMockBuilder('\OC\Files\Storage\Wrapper\Encryption') $instance = $this->getMockBuilder('\OC\Files\Storage\Wrapper\Encryption')
->setConstructorArgs( ->setConstructorArgs(
@ -533,7 +545,7 @@ class Encryption extends Storage {
'mountPoint' => '/', 'mountPoint' => '/',
'mount' => $this->mount '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']) ->setMethods(['readFirstBlock', 'parseRawHeader'])
@ -582,7 +594,7 @@ class Encryption extends Storage {
->disableOriginalConstructor()->getMock(); ->disableOriginalConstructor()->getMock();
$util = $this->getMockBuilder('\OC\Encryption\Util') $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(); ->getMock();
$cache = $this->getMockBuilder('\OC\Files\Cache\Cache') $cache = $this->getMockBuilder('\OC\Files\Cache\Cache')
@ -600,7 +612,7 @@ class Encryption extends Storage {
'mountPoint' => '/', 'mountPoint' => '/',
'mount' => $this->mount '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']) ->setMethods(['readFirstBlock', 'parseRawHeader', 'getCache'])
@ -636,7 +648,7 @@ class Encryption extends Storage {
'mountPoint' => '/', 'mountPoint' => '/',
'mount' => $this->mount '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; $expectedCachePut['encryptedVersion'] = 12345;
} }
$this->arrayCache->expects($this->never())->method('set');
$this->cache->expects($this->once()) $this->cache->expects($this->once())
->method('put') ->method('put')
->with($sourceInternalPath, $expectedCachePut); ->with($sourceInternalPath, $expectedCachePut);
@ -812,7 +826,8 @@ class Encryption extends Storage {
null, null,
$this->keyStore, $this->keyStore,
$this->update, $this->update,
$this->mountManager $this->mountManager,
$this->arrayCache
] ]
) )
->setMethods(['updateUnencryptedSize', 'getCache']) ->setMethods(['updateUnencryptedSize', 'getCache'])
@ -825,6 +840,9 @@ class Encryption extends Storage {
$instance->expects($this->any())->method('getCache') $instance->expects($this->any())->method('getCache')
->willReturn($cache); ->willReturn($cache);
$this->arrayCache->expects($this->once())->method('set')
->with('encryption_copy_version_' . $sourceInternalPath, true);
if ($copyResult) { if ($copyResult) {
$cache->expects($this->once())->method('get') $cache->expects($this->once())->method('get')
->with($sourceInternalPath) ->with($sourceInternalPath)

View File

@ -31,6 +31,7 @@ class Encryption extends \Test\TestCase {
$config = $this->getMockBuilder('\OCP\IConfig') $config = $this->getMockBuilder('\OCP\IConfig')
->disableOriginalConstructor() ->disableOriginalConstructor()
->getMock(); ->getMock();
$arrayCache = $this->getMock('OC\Memcache\ArrayCache');
$groupManager = $this->getMockBuilder('\OC\Group\Manager') $groupManager = $this->getMockBuilder('\OC\Group\Manager')
->disableOriginalConstructor() ->disableOriginalConstructor()
->getMock(); ->getMock();
@ -39,7 +40,11 @@ class Encryption extends \Test\TestCase {
->setMethods(['getAccessList']) ->setMethods(['getAccessList'])
->getMock(); ->getMock();
$file->expects($this->any())->method('getAccessList')->willReturn([]); $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()) $util->expects($this->any())
->method('getUidAndFilename') ->method('getUidAndFilename')
->willReturn(['user1', $internalPath]); ->willReturn(['user1', $internalPath]);

View File

@ -8,8 +8,8 @@
namespace Test\Traits; namespace Test\Traits;
use OC\Encryption\Util; use OC\Encryption\EncryptionWrapper;
use OC\Files\View; use OC\Memcache\ArrayCache;
use OCA\Encryption\AppInfo\Application; use OCA\Encryption\AppInfo\Application;
use OCA\Encryption\KeyManager; use OCA\Encryption\KeyManager;
use OCA\Encryption\Users\Setup; use OCA\Encryption\Users\Setup;
@ -68,13 +68,13 @@ trait EncryptionTrait {
} }
protected function postLogin() { protected function postLogin() {
$util = new Util( $encryptionWrapper = new EncryptionWrapper(
new View(), new ArrayCache(),
\OC::$server->getUserManager(), \OC::$server->getEncryptionManager(),
\OC::$server->getGroupManager(), \OC::$server->getLogger()
\OC::$server->getConfig()
); );
$this->registerStorageWrapper('oc_encryption', array($util, 'wrapStorage'));
$this->registerStorageWrapper('oc_encryption', array($encryptionWrapper, 'wrapStorage'));
} }
protected function setUpEncryptionTrait() { protected function setUpEncryptionTrait() {