summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--core/command/encryption/decryptall.php15
-rw-r--r--lib/private/encryption/decryptall.php18
-rw-r--r--tests/lib/encryption/decryptalltest.php42
3 files changed, 51 insertions, 24 deletions
diff --git a/core/command/encryption/decryptall.php b/core/command/encryption/decryptall.php
index 0a126db5b17..83c6c1dc168 100644
--- a/core/command/encryption/decryptall.php
+++ b/core/command/encryption/decryptall.php
@@ -1,6 +1,6 @@
<?php
/**
- * @author Björn Schießle <schiessle@owncloud.com>
+ * @author Björn Schießle <bjoern@schiessle.org>
* @author Joas Schilling <nickvergessen@owncloud.com>
*
* @copyright Copyright (c) 2016, ownCloud, Inc.
@@ -111,7 +111,8 @@ class DecryptAll extends Command {
$this->addArgument(
'user',
InputArgument::OPTIONAL,
- 'user for which you want to decrypt all files (optional)'
+ 'user for which you want to decrypt all files (optional)',
+ ''
);
}
@@ -127,8 +128,15 @@ class DecryptAll extends Command {
return;
}
+ $uid = $input->getArgument('user');
+ if ($uid === '') {
+ $message = 'your ownCloud';
+ } else {
+ $message = "$uid's account";
+ }
+
$output->writeln("\n");
- $output->writeln('You are about to start to decrypt all files stored in your ownCloud.');
+ $output->writeln("You are about to start to decrypt all files stored in $message.");
$output->writeln('It will depend on the encryption module and your setup if this is possible.');
$output->writeln('Depending on the number and size of your files this can take some time');
$output->writeln('Please make sure that no user access his files during this process!');
@@ -140,6 +148,7 @@ class DecryptAll extends Command {
$result = $this->decryptAll->decryptAll($input, $output, $user);
if ($result === false) {
$output->writeln(' aborted.');
+ $output->writeln('Server side encryption remains enabled');
$this->config->setAppValue('core', 'encryption_enabled', 'yes');
}
$this->resetSingleUserAndTrashbin();
diff --git a/lib/private/encryption/decryptall.php b/lib/private/encryption/decryptall.php
index 7a965a5f227..34a3e1bff91 100644
--- a/lib/private/encryption/decryptall.php
+++ b/lib/private/encryption/decryptall.php
@@ -1,6 +1,6 @@
<?php
/**
- * @author Björn Schießle <schiessle@owncloud.com>
+ * @author Björn Schießle <bjoern@schiessle.org>
*
* @copyright Copyright (c) 2016, ownCloud, Inc.
* @license AGPL-3.0
@@ -80,7 +80,7 @@ class DecryptAll {
$this->input = $input;
$this->output = $output;
- if (!empty($user) && $this->userManager->userExists($user) === false) {
+ if ($user !== '' && $this->userManager->userExists($user) === false) {
$this->output->writeln('User "' . $user . '" does not exist. Please check the username and try again');
return false;
}
@@ -133,6 +133,7 @@ class DecryptAll {
/**
* iterate over all user and encrypt their files
+ *
* @param string $user which users files should be decrypted, default = all users
*/
protected function decryptAllUsersFiles($user = '') {
@@ -140,7 +141,7 @@ class DecryptAll {
$this->output->writeln("\n");
$userList = [];
- if (empty($user)) {
+ if ($user === '') {
$fetchUsersProgress = new ProgressBar($this->output);
$fetchUsersProgress->setFormat(" %message% \n [%bar%]");
@@ -200,9 +201,9 @@ class DecryptAll {
$this->setupUserFS($uid);
$directories = array();
- $directories[] = '/' . $uid . '/files';
+ $directories[] = '/' . $uid . '/files';
- while($root = array_pop($directories)) {
+ while ($root = array_pop($directories)) {
$content = $this->rootView->getDirectoryContent($root);
foreach ($content as $file) {
$path = $root . '/' . $file['name'];
@@ -213,9 +214,14 @@ class DecryptAll {
try {
$progress->setMessage("decrypt files for user $userCount: $path");
$progress->advance();
- if ($this->decryptFile($path) === false) {
+ if ($file->isEncrypted() === false) {
$progress->setMessage("decrypt files for user $userCount: $path (already decrypted)");
$progress->advance();
+ } else {
+ if ($this->decryptFile($path) === false) {
+ $progress->setMessage("decrypt files for user $userCount: $path (already decrypted)");
+ $progress->advance();
+ }
}
} catch (\Exception $e) {
if (isset($this->failed[$uid])) {
diff --git a/tests/lib/encryption/decryptalltest.php b/tests/lib/encryption/decryptalltest.php
index 85fbe3e0ed9..d7cf2fb7baf 100644
--- a/tests/lib/encryption/decryptalltest.php
+++ b/tests/lib/encryption/decryptalltest.php
@@ -26,6 +26,7 @@ namespace Test\Encryption;
use OC\Encryption\DecryptAll;
use OC\Encryption\Exceptions\DecryptionFailedException;
use OC\Encryption\Manager;
+use OC\Files\FileInfo;
use OC\Files\View;
use OCP\IUserManager;
use Test\TestCase;
@@ -85,13 +86,25 @@ class DecryptAllTest extends TestCase {
$this->invokePrivate($this->instance, 'output', [$this->outputInterface]);
}
+ public function dataDecryptAll() {
+ return [
+ [true, 'user1', true],
+ [false, 'user1', true],
+ [true, '0', true],
+ [false, '0', true],
+ [true, '', false],
+ ];
+ }
+
/**
- * @dataProvider dataTrueFalse
+ * @dataProvider dataDecryptAll
* @param bool $prepareResult
+ * @param string $user
+ * @param bool $userExistsChecked
*/
- public function testDecryptAll($prepareResult, $user) {
+ public function testDecryptAll($prepareResult, $user, $userExistsChecked) {
- if (!empty($user)) {
+ if ($userExistsChecked) {
$this->userManager->expects($this->once())->method('userExists')->willReturn(true);
} else {
$this->userManager->expects($this->never())->method('userExists');
@@ -124,15 +137,6 @@ class DecryptAllTest extends TestCase {
$instance->decryptAll($this->inputInterface, $this->outputInterface, $user);
}
- public function dataTrueFalse() {
- return [
- [true, 'user1'],
- [false, 'user1'],
- [true, ''],
- [true, null]
- ];
- }
-
/**
* test decrypt all call with a user who doesn't exists
*/
@@ -146,8 +150,16 @@ class DecryptAllTest extends TestCase {
);
}
+ public function dataTrueFalse() {
+ return [
+ [true],
+ [false],
+ ];
+ }
+
/**
* @dataProvider dataTrueFalse
+ * @param bool $success
*/
public function testPrepareEncryptionModules($success) {
@@ -242,15 +254,15 @@ class DecryptAllTest extends TestCase {
$this->view->expects($this->at(0))->method('getDirectoryContent')
->with('/user1/files')->willReturn(
[
- ['name' => 'foo', 'type'=>'dir'],
- ['name' => 'bar', 'type'=>'file'],
+ new FileInfo('path', null, 'intPath', ['name' => 'foo', 'type'=>'dir'], null),
+ new FileInfo('path', null, 'intPath', ['name' => 'bar', 'type'=>'file', 'encrypted'=>true], null)
]
);
$this->view->expects($this->at(3))->method('getDirectoryContent')
->with('/user1/files/foo')->willReturn(
[
- ['name' => 'subfile', 'type'=>'file']
+ new FileInfo('path', null, 'intPath', ['name' => 'subfile', 'type'=>'file', 'encrypted'=>true], null)
]
);