Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix reset confirmation mail from occ stable10 #34154

Merged
merged 2 commits into from
Feb 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions core/Command/User/ResetPassword.php
Original file line number Diff line number Diff line change
Expand Up @@ -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("<info>Successfully reset password for {$username}.</info>");
return 0;
} else {
$output->writeln("<error>Error while resetting password!</error>");
return 1;
}
}

$success = $user->setPassword($password);
if ($success) {
$output->writeln("<info>Successfully reset password for " . $username . "</info>");
Expand Down
71 changes: 71 additions & 0 deletions tests/Core/Command/User/ResetPasswordTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -240,4 +240,75 @@ public function testEmailLinkFailure($emailAddress) {
->with('<error>Email address is not set for the user foo</error>');
$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->expects($this->once())
->method('generateTokenAndLink')
->with('foo')
->willReturn(['http://localhost/foo/bar/123AbcFooBar/foo', '123AbcFooBar']);

if ($expectedResult === true) {
$this->lostController->expects($this->once())
->method('setPassword')
->willReturn(['status' => 'success']);

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

$output->expects($this->once())
->method('writeln')
->with("<error>Error while resetting password!</error>");
}

$result = $this->invokePrivate($this->resetPassword, 'execute', [$input, $output]);
if ($expectedResult === true) {
$this->assertEquals(0, $result);
} else {
$this->assertEquals(1, $result);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,17 @@ Feature: reset user password
Use the following link to reset your password: <a href=
"""

@issue-33384
Scenario: user should get email when the administrator changes their password and specifies to also send email
Given these users have been created:
| username | password | displayname | email |
| brand-new-user | %regular% | New user | brand.new.user@oc.com.np |
When the administrator resets the password of user "brand-new-user" to "%alt1%" sending email using the occ command
Then the command should have been successful
And the command output should contain the text "Successfully reset password for brand-new-user"
And the email address "brand.new.user@oc.com.np" should not have received an email
#And the email address "brand.new.user@oc.com.np" should have received an email with the body containing
#"""
#Password changed successfully
#"""
And the email address "brand.new.user@oc.com.np" should have received an email with the body containing
"""
Password changed successfully
"""
And the content of file "textfile0.txt" for user "brand-new-user" using password "%alt1%" should be "ownCloud test text file 0" plus end-of-line
But user "brand-new-user" using password "%regular%" should not be able to download file "textfile0.txt"

Expand Down