Skip to content
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
use the loginname to verify the old password in user password changes
Signed-off-by: Arthur Schiwon <[email protected]>
  • Loading branch information
blizzz authored and backportbot[bot] committed May 26, 2020
commit 292d8c3d9c6c1d9055bbe0178418fa06c031e276
3 changes: 2 additions & 1 deletion apps/settings/lib/Controller/ChangePasswordController.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,9 @@ public function __construct(string $appName,
* @BruteForceProtection(action=changePersonalPassword)
*/
public function changePersonalPassword(string $oldpassword = '', string $newpassword = null): JSONResponse {
$loginName = $this->userSession->getLoginName();
/** @var IUser $user */
$user = $this->userManager->checkPassword($this->userId, $oldpassword);
$user = $this->userManager->checkPassword($loginName, $oldpassword);
if ($user === false) {
$response = new JSONResponse([
'status' => 'error',
Expand Down
32 changes: 27 additions & 5 deletions tests/Core/Controller/ChangePasswordControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
class ChangePasswordControllerTest extends \Test\TestCase {
/** @var string */
private $userId = 'currentUser';
/** @var string */
private $loginName = 'ua1337';
/** @var IUserManager|\PHPUnit_Framework_MockObject_MockObject */
private $userManager;
/** @var Session|\PHPUnit_Framework_MockObject_MockObject */
Expand Down Expand Up @@ -75,9 +77,13 @@ protected function setUp(): void {
}

public function testChangePersonalPasswordWrongPassword() {
$this->userSession->expects($this->once())
->method('getLoginName')
->willReturn($this->loginName);

$this->userManager->expects($this->once())
->method('checkPassword')
->with($this->userId, 'old')
->with($this->loginName, 'old')
->willReturn(false);

$expects = new JSONResponse([
Expand All @@ -93,10 +99,14 @@ public function testChangePersonalPasswordWrongPassword() {
}

public function testChangePersonalPasswordCommonPassword() {
$this->userSession->expects($this->once())
->method('getLoginName')
->willReturn($this->loginName);

$user = $this->getMockBuilder(IUser::class)->getMock();
$this->userManager->expects($this->once())
->method('checkPassword')
->with($this->userId, 'old')
->with($this->loginName, 'old')
->willReturn($user);

$user->expects($this->once())
Expand All @@ -116,10 +126,14 @@ public function testChangePersonalPasswordCommonPassword() {
}

public function testChangePersonalPasswordNoNewPassword() {
$this->userSession->expects($this->once())
->method('getLoginName')
->willReturn($this->loginName);

$user = $this->getMockBuilder(IUser::class)->getMock();
$this->userManager->expects($this->once())
->method('checkPassword')
->with($this->userId, 'old')
->with($this->loginName, 'old')
->willReturn($user);

$expects = [
Expand All @@ -132,10 +146,14 @@ public function testChangePersonalPasswordNoNewPassword() {
}

public function testChangePersonalPasswordCantSetPassword() {
$this->userSession->expects($this->once())
->method('getLoginName')
->willReturn($this->loginName);

$user = $this->getMockBuilder(IUser::class)->getMock();
$this->userManager->expects($this->once())
->method('checkPassword')
->with($this->userId, 'old')
->with($this->loginName, 'old')
->willReturn($user);

$user->expects($this->once())
Expand All @@ -152,10 +170,14 @@ public function testChangePersonalPasswordCantSetPassword() {
}

public function testChangePersonalPassword() {
$this->userSession->expects($this->once())
->method('getLoginName')
->willReturn($this->loginName);

$user = $this->getMockBuilder(IUser::class)->getMock();
$this->userManager->expects($this->once())
->method('checkPassword')
->with($this->userId, 'old')
->with($this->loginName, 'old')
->willReturn($user);

$user->expects($this->once())
Expand Down