diff options
m--------- | 3rdparty | 0 | ||||
-rw-r--r-- | core/command/app/checkcode.php | 23 | ||||
-rw-r--r-- | lib/private/app/codechecker.php | 2 | ||||
-rw-r--r-- | lib/private/encryption/update.php | 24 | ||||
-rw-r--r-- | lib/private/files/storage/wrapper/encryption.php | 57 | ||||
-rw-r--r-- | settings/templates/admin.php | 14 | ||||
-rw-r--r-- | tests/lib/files/storage/wrapper/encryption.php | 125 |
7 files changed, 161 insertions, 84 deletions
diff --git a/3rdparty b/3rdparty -Subproject 0f862d433ad146ebca97e356c703369777c2a30 +Subproject a79a7ee86b70db60fee8caa7caaad11be9fd004 diff --git a/core/command/app/checkcode.php b/core/command/app/checkcode.php index 18d8f0d5311..6d10714d410 100644 --- a/core/command/app/checkcode.php +++ b/core/command/app/checkcode.php @@ -43,16 +43,27 @@ class CheckCode extends Command { $appId = $input->getArgument('app-id'); $codeChecker = new \OC\App\CodeChecker(); $codeChecker->listen('CodeChecker', 'analyseFileBegin', function($params) use ($output) { - $output->writeln("<info>Analysing {$params}</info>"); + if(OutputInterface::VERBOSITY_VERBOSE <= $output->getVerbosity()) { + $output->writeln("<info>Analysing {$params}</info>"); + } }); - $codeChecker->listen('CodeChecker', 'analyseFileFinished', function($params) use ($output) { - $count = count($params); - $output->writeln(" {$count} errors"); - usort($params, function($a, $b) { + $codeChecker->listen('CodeChecker', 'analyseFileFinished', function($filename, $errors) use ($output) { + $count = count($errors); + + // show filename if the verbosity is low, but there are errors in a file + if($count > 0 && OutputInterface::VERBOSITY_VERBOSE > $output->getVerbosity()) { + $output->writeln("<info>Analysing {$filename}</info>"); + } + + // show error count if there are errros present or the verbosity is high + if($count > 0 || OutputInterface::VERBOSITY_VERBOSE <= $output->getVerbosity()) { + $output->writeln(" {$count} errors"); + } + usort($errors, function($a, $b) { return $a['line'] >$b['line']; }); - foreach($params as $p) { + foreach($errors as $p) { $line = sprintf("%' 4d", $p['line']); $output->writeln(" <error>line $line: {$p['disallowedToken']} - {$p['reason']}</error>"); } diff --git a/lib/private/app/codechecker.php b/lib/private/app/codechecker.php index 918d04a0bd6..8c2f3405fb9 100644 --- a/lib/private/app/codechecker.php +++ b/lib/private/app/codechecker.php @@ -119,7 +119,7 @@ class CodeChecker extends BasicEmitter { /** @var SplFileInfo $file */ $this->emit('CodeChecker', 'analyseFileBegin', [$file->getPathname()]); $fileErrors = $this->analyseFile($file); - $this->emit('CodeChecker', 'analyseFileFinished', [$fileErrors]); + $this->emit('CodeChecker', 'analyseFileFinished', [$file->getPathname(), $fileErrors]); $errors = array_merge($fileErrors, $errors); } diff --git a/lib/private/encryption/update.php b/lib/private/encryption/update.php index a0b0af968c6..ddcee3bae93 100644 --- a/lib/private/encryption/update.php +++ b/lib/private/encryption/update.php @@ -81,11 +81,13 @@ class Update { * @param array $params */ public function postShared($params) { - if ($params['itemType'] === 'file' || $params['itemType'] === 'folder') { - $path = Filesystem::getPath($params['fileSource']); - list($owner, $ownerPath) = $this->getOwnerPath($path); - $absPath = '/' . $owner . '/files/' . $ownerPath; - $this->update($absPath); + if ($this->encryptionManager->isEnabled()) { + if ($params['itemType'] === 'file' || $params['itemType'] === 'folder') { + $path = Filesystem::getPath($params['fileSource']); + list($owner, $ownerPath) = $this->getOwnerPath($path); + $absPath = '/' . $owner . '/files/' . $ownerPath; + $this->update($absPath); + } } } @@ -95,11 +97,13 @@ class Update { * @param array $params */ public function postUnshared($params) { - if ($params['itemType'] === 'file' || $params['itemType'] === 'folder') { - $path = Filesystem::getPath($params['fileSource']); - list($owner, $ownerPath) = $this->getOwnerPath($path); - $absPath = '/' . $owner . '/files/' . $ownerPath; - $this->update($absPath); + if ($this->encryptionManager->isEnabled()) { + if ($params['itemType'] === 'file' || $params['itemType'] === 'folder') { + $path = Filesystem::getPath($params['fileSource']); + list($owner, $ownerPath) = $this->getOwnerPath($path); + $absPath = '/' . $owner . '/files/' . $ownerPath; + $this->update($absPath); + } } } diff --git a/lib/private/files/storage/wrapper/encryption.php b/lib/private/files/storage/wrapper/encryption.php index 41a7f9e9242..24bbef9b93c 100644 --- a/lib/private/files/storage/wrapper/encryption.php +++ b/lib/private/files/storage/wrapper/encryption.php @@ -220,23 +220,23 @@ class Encryption extends Wrapper { * @return bool */ public function rename($path1, $path2) { - $source = $this->getFullPath($path1); - if ($this->util->isExcluded($source)) { - return $this->storage->rename($path1, $path2); - } $result = $this->storage->rename($path1, $path2); - if ($result) { - $target = $this->getFullPath($path2); - if (isset($this->unencryptedSize[$source])) { - $this->unencryptedSize[$target] = $this->unencryptedSize[$source]; - } - $keysRenamed = $this->keyStorage->renameKeys($source, $target); - if ($keysRenamed && - dirname($source) !== dirname($target) && - $this->util->isFile($target) - ) { - $this->update->update($target); + + if ($result && $this->encryptionManager->isEnabled()) { + $source = $this->getFullPath($path1); + if (!$this->util->isExcluded($source)) { + $target = $this->getFullPath($path2); + if (isset($this->unencryptedSize[$source])) { + $this->unencryptedSize[$target] = $this->unencryptedSize[$source]; + } + $keysRenamed = $this->keyStorage->renameKeys($source, $target); + if ($keysRenamed && + dirname($source) !== dirname($target) && + $this->util->isFile($target) + ) { + $this->update->update($target); + } } } @@ -251,22 +251,31 @@ class Encryption extends Wrapper { * @return bool */ public function copy($path1, $path2) { + $fullPath1 = $this->getFullPath($path1); + $fullPath2 = $this->getFullPath($path2); + if ($this->util->isExcluded($fullPath1)) { return $this->storage->copy($path1, $path2); } - $source = $this->getFullPath($path1); $result = $this->storage->copy($path1, $path2); - if ($result) { - $target = $this->getFullPath($path2); - $keysCopied = $this->keyStorage->copyKeys($source, $target); - if ($keysCopied && - dirname($source) !== dirname($target) && - $this->util->isFile($target) - ) { - $this->update->update($target); + + if ($result && $this->encryptionManager->isEnabled()) { + $source = $this->getFullPath($path1); + if (!$this->util->isExcluded($source)) { + $target = $this->getFullPath($path2); + $keysCopied = $this->keyStorage->copyKeys($source, $target); + if ($keysCopied && + dirname($source) !== dirname($target) && + $this->util->isFile($target) + ) { + $this->update->update($target); + } } + $data = $this->getMetaData($path1); + $this->getCache()->put($path2, ['encrypted' => $data['encrypted']]); + $this->updateUnencryptedSize($fullPath2, $data['size']); } return $result; diff --git a/settings/templates/admin.php b/settings/templates/admin.php index 638c3d7bff5..f5a3a40662a 100644 --- a/settings/templates/admin.php +++ b/settings/templates/admin.php @@ -327,10 +327,7 @@ if ($_['cronErrors']) { </p> <div id="EncryptionWarning" class="warning hidden"> - <?php p($l->t('Encryption is a one way process. Once encryption is enabled, - all files from that point forward will be encrypted on the server and it - will not be possible to disable encryption at a later date. This is the final warning: - Do you really want to enable encryption?')) ?> + <?php p($l->t('Encryption is a one way process. Once encryption is enabled, all files from that point forward will be encrypted on the server and it will not be possible to disable encryption at a later date. This is the final warning: Do you really want to enable encryption?')) ?> <input type="button" id="reallyEnableEncryption" value="<?php p($l->t("Enable encryption")); ?>" /> @@ -340,9 +337,9 @@ if ($_['cronErrors']) { <div id='selectEncryptionModules' class="<?php if (!$_['encryptionReady']) p('hidden'); ?>"> <?php if (empty($_['encryptionModules'])) { - p('No encryption module loaded, please load a encryption module in the app menu'); + p($l->t('No encryption module loaded, please load a encryption module in the app menu')); } else { ?> - <h3>Select default encryption module:</h3> + <h3><?php p($l->t('Select default encryption module:')) ?></h3> <fieldset id='encryptionModules'> <?php foreach ($_['encryptionModules'] as $id => $module): ?> <input type="radio" id="<?php p($id) ?>" @@ -361,10 +358,9 @@ if ($_['cronErrors']) { <div id="migrationWarning" class="<?php if ($_['encryptionReady']) p('hidden'); ?>"> <?php if ($_['encryptionReady'] === false && $_['externalBackendsEnabled'] === true) { - p('You need to migrate your encryption keys from the old encryption (ownCloud <= 8.0) to the new one. ' - . 'Please enable the "ownCloud Default Encryption Module" and run \'occ encryption:migrate\''); + p($l->t('You need to migrate your encryption keys from the old encryption (ownCloud <= 8.0) to the new one. Please enable the "ownCloud Default Encryption Module" and run \'occ encryption:migrate\'')); } elseif ($_['encryptionReady'] === false && $_['externalBackendsEnabled'] === false) { - p('You need to migrate your encryption keys from the old encryption (ownCloud <= 8.0) to the new one.'); ?> + p($l->t('You need to migrate your encryption keys from the old encryption (ownCloud <= 8.0) to the new one.')); ?> <input type="submit" name="startmigration" id="startmigration" value="<?php p($l->t('Start migration')); ?>"/> <?php } ?> diff --git a/tests/lib/files/storage/wrapper/encryption.php b/tests/lib/files/storage/wrapper/encryption.php index 6fc9b17fad0..6c593bb7749 100644 --- a/tests/lib/files/storage/wrapper/encryption.php +++ b/tests/lib/files/storage/wrapper/encryption.php @@ -13,7 +13,7 @@ class Encryption extends \Test\Files\Storage\Storage { private $sourceStorage; /** - * @var \OC\Files\Storage\Wrapper\Encryption + * @var \OC\Files\Storage\Wrapper\Encryption | \PHPUnit_Framework_MockObject_MockObject */ protected $instance; @@ -27,7 +27,6 @@ class Encryption extends \Test\Files\Storage\Storage { */ private $util; - /** * @var \OC\Encryption\Manager | \PHPUnit_Framework_MockObject_MockObject */ @@ -38,12 +37,19 @@ class Encryption extends \Test\Files\Storage\Storage { */ private $encryptionModule; - /** * @var \OC\Encryption\Update | \PHPUnit_Framework_MockObject_MockObject */ private $update; + /** + * @var \OC\Files\Cache\Cache | \PHPUnit_Framework_MockObject_MockObject + */ + private $cache; + + /** @var integer dummy unencrypted size */ + private $dummySize = -1; + protected function setUp() { parent::setUp(); @@ -56,9 +62,6 @@ class Encryption extends \Test\Files\Storage\Storage { $this->encryptionManager->expects($this->any()) ->method('getEncryptionModule') ->willReturn($mockModule); - $this->encryptionManager->expects($this->any()) - ->method('isEnabled') - ->willReturn(true); $config = $this->getMockBuilder('\OCP\IConfig') ->disableOriginalConstructor() @@ -83,23 +86,46 @@ class Encryption extends \Test\Files\Storage\Storage { $logger = $this->getMock('\OC\Log'); $this->sourceStorage = new Temporary(array()); + $this->keyStore = $this->getMockBuilder('\OC\Encryption\Keys\Storage') ->disableOriginalConstructor()->getMock(); + $this->update = $this->getMockBuilder('\OC\Encryption\Update') ->disableOriginalConstructor()->getMock(); + $mount = $this->getMockBuilder('\OC\Files\Mount\MountPoint') ->disableOriginalConstructor() ->setMethods(['getOption']) ->getMock(); $mount->expects($this->any())->method('getOption')->willReturn(true); - $this->instance = new \OC\Files\Storage\Wrapper\Encryption([ - 'storage' => $this->sourceStorage, - 'root' => 'foo', - 'mountPoint' => '/', - 'mount' => $mount - ], - $this->encryptionManager, $this->util, $logger, $file, null, $this->keyStore, $this->update - ); + + $this->cache = $this->getMockBuilder('\OC\Files\Cache\Cache') + ->disableOriginalConstructor()->getMock(); + $this->cache->expects($this->any()) + ->method('get') + ->willReturn(['encrypted' => false]); + + $this->instance = $this->getMockBuilder('\OC\Files\Storage\Wrapper\Encryption') + ->setConstructorArgs([ + [ + 'storage' => $this->sourceStorage, + 'root' => 'foo', + 'mountPoint' => '/', + 'mount' => $mount + ], + $this->encryptionManager, $this->util, $logger, $file, null, $this->keyStore, $this->update + ]) + ->setMethods(['getMetaData', 'getCache']) + ->getMock(); + + $this->instance->expects($this->any()) + ->method('getMetaData') + ->willReturn(['encrypted' => true, 'size' => $this->dummySize]); + + $this->instance->expects($this->any()) + ->method('getCache') + ->willReturn($this->cache); + } /** @@ -128,16 +154,28 @@ class Encryption extends \Test\Files\Storage\Storage { * * @param string $source * @param string $target + * @param $encryptionEnabled * @param boolean $renameKeysReturn * @param boolean $shouldUpdate */ - public function testRename($source, $target, $renameKeysReturn, $shouldUpdate) { - $this->keyStore - ->expects($this->once()) - ->method('renameKeys') - ->willReturn($renameKeysReturn); + public function testRename($source, + $target, + $encryptionEnabled, + $renameKeysReturn, + $shouldUpdate) { + if ($encryptionEnabled) { + $this->keyStore + ->expects($this->once()) + ->method('renameKeys') + ->willReturn($renameKeysReturn); + } else { + $this->keyStore + ->expects($this->never())->method('renameKeys'); + } $this->util->expects($this->any()) ->method('isFile')->willReturn(true); + $this->encryptionManager->expects($this->once()) + ->method('isEnabled')->willReturn($encryptionEnabled); if ($shouldUpdate) { $this->update->expects($this->once()) ->method('update'); @@ -156,16 +194,33 @@ class Encryption extends \Test\Files\Storage\Storage { * * @param string $source * @param string $target + * @param $encryptionEnabled * @param boolean $copyKeysReturn * @param boolean $shouldUpdate */ - public function testCopyTesting($source, $target, $copyKeysReturn, $shouldUpdate) { - $this->keyStore - ->expects($this->once()) - ->method('copyKeys') - ->willReturn($copyKeysReturn); + public function testCopy($source, + $target, + $encryptionEnabled, + $copyKeysReturn, + $shouldUpdate) { + + if ($encryptionEnabled) { + $this->keyStore + ->expects($this->once()) + ->method('copyKeys') + ->willReturn($copyKeysReturn); + $this->cache->expects($this->once()) + ->method('put') + ->with($this->anything(), ['encrypted' => true]) + ->willReturn(true); + } else { + $this->cache->expects($this->never())->method('put'); + $this->keyStore->expects($this->never())->method('copyKeys'); + } $this->util->expects($this->any()) ->method('isFile')->willReturn(true); + $this->encryptionManager->expects($this->once()) + ->method('isEnabled')->willReturn($encryptionEnabled); if ($shouldUpdate) { $this->update->expects($this->once()) ->method('update'); @@ -177,13 +232,12 @@ class Encryption extends \Test\Files\Storage\Storage { $this->instance->mkdir($source); $this->instance->mkdir(dirname($target)); $this->instance->copy($source, $target); - } - /** - * @dataProvider copyAndMoveProvider - */ - public function testCopy($source, $target) { - $this->assertTrue(true, 'Replaced by testCopyTesting()'); + if ($encryptionEnabled) { + $this->assertSame($this->dummySize, + $this->instance->filesize($target) + ); + } } /** @@ -193,14 +247,17 @@ class Encryption extends \Test\Files\Storage\Storage { */ public function dataTestCopyAndRename() { return array( - array('source', 'target', false, false), - array('source', 'target', true, false), - array('source', '/subFolder/target', false, false), - array('source', '/subFolder/target', true, true), + array('source', 'target', true, false, false), + array('source', 'target', true, true, false), + array('source', '/subFolder/target', true, false, false), + array('source', '/subFolder/target', true, true, true), + array('source', '/subFolder/target', false, true, false), ); } public function testIsLocal() { + $this->encryptionManager->expects($this->once()) + ->method('isEnabled')->willReturn(true); $this->assertFalse($this->instance->isLocal()); } } |