From d2e90b6050d1c26cb365c81e987ccc1577ae56d0 Mon Sep 17 00:00:00 2001 From: Bjoern Schiessle Date: Mon, 21 Sep 2015 13:13:38 +0200 Subject: [PATCH] improved error message if user doesn't exists --- lib/private/encryption/decryptall.php | 5 +++++ tests/lib/encryption/decryptalltest.php | 15 +++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/lib/private/encryption/decryptall.php b/lib/private/encryption/decryptall.php index e59be17886..1ff9c74ef8 100644 --- a/lib/private/encryption/decryptall.php +++ b/lib/private/encryption/decryptall.php @@ -80,6 +80,11 @@ class DecryptAll { $this->input = $input; $this->output = $output; + if ($user !== '' && $this->userManager->userExists($user) === false) { + $this->output->writeln('User "' . $user . '" does not exist. Please check the username and try again'); + return false; + } + $this->output->writeln('prepare encryption modules...'); if ($this->prepareEncryptionModules($user) === false) { return false; diff --git a/tests/lib/encryption/decryptalltest.php b/tests/lib/encryption/decryptalltest.php index eb3bc721f8..c2a0711c0a 100644 --- a/tests/lib/encryption/decryptalltest.php +++ b/tests/lib/encryption/decryptalltest.php @@ -80,11 +80,13 @@ class DecryptAllTest extends TestCase { /** * @dataProvider dataTrueFalse + * @param bool $prepareResult */ public function testDecryptAll($prepareResult) { $user = 'user1'; + $this->userManager->expects($this->once())->method('userExists')->willReturn(true); /** @var DecryptAll | \PHPUnit_Framework_MockObject_MockObject | $instance */ $instance = $this->getMockBuilder('OC\Encryption\DecryptAll') ->setConstructorArgs( @@ -120,6 +122,19 @@ class DecryptAllTest extends TestCase { ]; } + /** + * test decrypt all call with a user who doesn't exists + */ + public function testDecryptAllWrongUser() { + $this->userManager->expects($this->once())->method('userExists')->willReturn(false); + $this->outputInterface->expects($this->once())->method('writeln') + ->with('User "user1" does not exist. Please check the username and try again'); + + $this->assertFalse( + $this->instance->decryptAll($this->inputInterface, $this->outputInterface, 'user1') + ); + } + /** * @dataProvider dataTrueFalse */