Skip to content

Commit

Permalink
Fix issue 36925 user:resetpassword with --send-email and --password-f…
Browse files Browse the repository at this point in the history
…rom-env
  • Loading branch information
phil-davis committed Feb 10, 2020
1 parent 3344a31 commit 268440d
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 7 deletions.
13 changes: 13 additions & 0 deletions changelog/unreleased/36925
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Bugfix: user:resetpassword with --send-email --password-from-env

When trying to do command:
occ user:resetpassword Anne --send-email --password-from-env

If Anne does not have an email address setup then an error was logged in the
ownCloud log.

This has been corrected. Now the administrator is shown the correct error
"Email address is not set for the user Anne"

https://github.com/owncloud/core/issues/36925
https://github.com/owncloud/core/pull/36926
4 changes: 4 additions & 0 deletions core/Command/User/ResetPassword.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,10 @@ protected function execute(InputInterface $input, OutputInterface $output) {
if ($emailLink) {
$userId = $user->getUID();
list(, $token) = $this->lostController->generateTokenAndLink($userId);
if (!$this->hasValidEmailAddress($user->getEMailAddress())) {
$output->writeln('<error>Email address is not set for the user ' . $user->getUID() . '</error>');
return 1;
}
$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') {
Expand Down
13 changes: 9 additions & 4 deletions tests/Core/Command/User/ResetPasswordTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -286,17 +286,22 @@ public function testPasswordFromEnvAndPasswordConfirmationEmail($expectedResult)
->method('setPassword')
->willReturn(['status' => 'success']);

$user->method('getEMailAddress')
->willReturn('[email protected]');

$output->expects($this->once())
->method('writeln')
->with("<info>Successfully reset password for foo.</info>");
} else {
$this->lostController->expects($this->once())
->method('setPassword')
->willReturn("failed");
$this->lostController->expects($this->never())
->method('setPassword');

$user->method('getEMailAddress')
->willReturn('');

$output->expects($this->once())
->method('writeln')
->with("<error>Error while resetting password!</error>");
->with("<error>Email address is not set for the user foo</error>");
}

$result = $this->invokePrivate($this->resetPassword, 'execute', [$input, $output]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,14 @@ Feature: reset user password
Then the command should have failed with exit code 1
And the command output should contain the text "Email address is not set for the user brand-new-user"

@issue-36925
@skipOnOcV10.3
Scenario: administrator gets error message while trying to reset specifying user password with send email when the email address of the user is not setup
Given these users have been created with skeleton files:
| username | password | displayname |
| brand-new-user | %regular% | New user |
When the administrator resets the password of user "brand-new-user" to "%alt1%" sending email using the occ command
Then the command should have failed with exit code 1
And the command output should contain the text "Error while resetting password!"
#And the command output should contain the text "Email address is not set for the user brand-new-user"
And the command output should contain the text "Email address is not set for the user brand-new-user"

Scenario: user should not get an email when the smtpmode value points to an invalid or missing mail program
Given these users have been created with skeleton files:
Expand Down

0 comments on commit 268440d

Please sign in to comment.