From 6175c68317f6cf8a92564c39f9ef8ee3326b3c23 Mon Sep 17 00:00:00 2001 From: Sujith H Date: Mon, 14 Jan 2019 15:56:51 +0530 Subject: [PATCH 1/2] [stable10] Backport of Fix password reset confirmation email from occ Fix password reset confirmation email from occ. This was missing when user:resetpassword command was used with options "--send-email --password-from-env". With this change set the issue is resolved. Signed-off-by: Sujith H --- core/Command/User/ResetPassword.php | 14 ++++ tests/Core/Command/User/ResetPasswordTest.php | 68 +++++++++++++++++++ 2 files changed, 82 insertions(+) diff --git a/core/Command/User/ResetPassword.php b/core/Command/User/ResetPassword.php index 5902c8b65909..c7b4c53836d4 100644 --- a/core/Command/User/ResetPassword.php +++ b/core/Command/User/ResetPassword.php @@ -175,6 +175,20 @@ protected function execute(InputInterface $input, OutputInterface $output) { return 1; } + if ($emailLink) { + $userId = $user->getUID(); + list(, $token) = $this->lostController->generateTokenAndLink($userId); + $this->config->setUserValue($userId, 'owncloud', 'lostpassword', $this->timeFactory->getTime() . ':' . $token); + $success = $this->lostController->setPassword($token, $userId, $password, false); + if (\is_array($success) && isset($success['status']) && $success['status'] === 'success') { + $output->writeln("Successfully reset password for {$username}."); + return 0; + } else { + $output->writeln("Error while resetting password!"); + return 1; + } + } + $success = $user->setPassword($password); if ($success) { $output->writeln("Successfully reset password for " . $username . ""); diff --git a/tests/Core/Command/User/ResetPasswordTest.php b/tests/Core/Command/User/ResetPasswordTest.php index 7a1c2f4fa749..690087f1f50b 100644 --- a/tests/Core/Command/User/ResetPasswordTest.php +++ b/tests/Core/Command/User/ResetPasswordTest.php @@ -240,4 +240,72 @@ public function testEmailLinkFailure($emailAddress) { ->with('Email address is not set for the user foo'); $this->invokePrivate($this->resetPassword, 'execute', [$input, $output]); } + + public function providesStatusOfPasswordFromEnvWithEmailConfirmation() { + return [ + [true], + [false] + ]; + } + + /** + * @dataProvider providesStatusOfPasswordFromEnvWithEmailConfirmation + * @param $expectedResult + */ + public function testPasswordFromEnvAndPasswordConfirmationEmail($expectedResult) { + $input = $this->createMock(InputInterface::class); + $output = $this->createMock(OutputInterface::class); + + $input->expects($this->once()) + ->method('getArgument') + ->willReturn('foo'); + + $input->expects($this->exactly(3)) + ->method('getOption') + ->willReturnMap([ + ['send-email', true], + ['output-link', false], + ['password-from-env', true] + ]); + + $user = $this->createMock(IUser::class); + + $user->method('getUID') + ->willReturn('foo'); + + $this->userManager->expects($this->once()) + ->method('get') + ->willReturn($user); + + $this->environmentHelper->expects($this->once()) + ->method('getEnvVar') + ->willReturn('fooPass'); + + $this->lostController->method('generateTokenAndLink') + ->with('foo') + ->willReturn(['http://localhost/foo/bar/123AbcFooBar/foo', '123AbcFooBar']); + + if ($expectedResult === true) { + $this->lostController->method('setPassword') + ->willReturn(['status' => 'success']); + + $output->expects($this->once()) + ->method('writeln') + ->with("Successfully reset password for foo."); + } else { + $this->lostController->method('setPassword') + ->willReturn("failed"); + + $output->expects($this->once()) + ->method('writeln') + ->with("Error while resetting password!"); + } + + $result = $this->invokePrivate($this->resetPassword, 'execute', [$input, $output]); + if ($expectedResult === true) { + $this->assertEquals(0, $result); + } else { + $this->assertEquals(1, $result); + } + } } From 67ce367a3c4680be8b8b9ca0265efb7b33169b32 Mon Sep 17 00:00:00 2001 From: Phil Davis Date: Mon, 14 Jan 2019 17:52:57 +0545 Subject: [PATCH 2/2] [stable10] Backport of Adjust acceptance test for issue 33384 --- tests/Core/Command/User/ResetPasswordTest.php | 9 ++++++--- .../features/cliProvisioning/resetUserPassword.feature | 10 ++++------ 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/tests/Core/Command/User/ResetPasswordTest.php b/tests/Core/Command/User/ResetPasswordTest.php index 690087f1f50b..902fcbd00315 100644 --- a/tests/Core/Command/User/ResetPasswordTest.php +++ b/tests/Core/Command/User/ResetPasswordTest.php @@ -281,19 +281,22 @@ public function testPasswordFromEnvAndPasswordConfirmationEmail($expectedResult) ->method('getEnvVar') ->willReturn('fooPass'); - $this->lostController->method('generateTokenAndLink') + $this->lostController->expects($this->once()) + ->method('generateTokenAndLink') ->with('foo') ->willReturn(['http://localhost/foo/bar/123AbcFooBar/foo', '123AbcFooBar']); if ($expectedResult === true) { - $this->lostController->method('setPassword') + $this->lostController->expects($this->once()) + ->method('setPassword') ->willReturn(['status' => 'success']); $output->expects($this->once()) ->method('writeln') ->with("Successfully reset password for foo."); } else { - $this->lostController->method('setPassword') + $this->lostController->expects($this->once()) + ->method('setPassword') ->willReturn("failed"); $output->expects($this->once()) diff --git a/tests/acceptance/features/cliProvisioning/resetUserPassword.feature b/tests/acceptance/features/cliProvisioning/resetUserPassword.feature index 2beb3cdde5dc..74383dd5ed44 100644 --- a/tests/acceptance/features/cliProvisioning/resetUserPassword.feature +++ b/tests/acceptance/features/cliProvisioning/resetUserPassword.feature @@ -26,7 +26,6 @@ Feature: reset user password Use the following link to reset your password: