]> source.dussan.org Git - nextcloud-server.git/commitdiff
use the loginname to verify the old password in user password changes 21115/head
authorArthur Schiwon <blizzz@arthur-schiwon.de>
Mon, 25 May 2020 21:00:00 +0000 (23:00 +0200)
committerbackportbot[bot] <backportbot[bot]@users.noreply.github.com>
Tue, 26 May 2020 19:22:33 +0000 (19:22 +0000)
Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
apps/settings/lib/Controller/ChangePasswordController.php
tests/Core/Controller/ChangePasswordControllerTest.php

index c374b3ff8bf5e6e048db977755b75bcdd24a4445..63238771de59b06b47f29ebff49677d91ff7b377 100644 (file)
@@ -113,8 +113,9 @@ class ChangePasswordController extends Controller {
         * @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',
index a55b0bc232e0c0bd76d5daf89fba6d4f3ebc898b..3e0cd1b64b11d3027f281df772d37655d2458301 100644 (file)
@@ -36,6 +36,8 @@ use OCP\IUserManager;
 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 */
@@ -75,9 +77,13 @@ class ChangePasswordControllerTest extends \Test\TestCase {
        }
 
        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([
@@ -93,10 +99,14 @@ class ChangePasswordControllerTest extends \Test\TestCase {
        }
 
        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())
@@ -116,10 +126,14 @@ class ChangePasswordControllerTest extends \Test\TestCase {
        }
 
        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 = [
@@ -132,10 +146,14 @@ class ChangePasswordControllerTest extends \Test\TestCase {
        }
 
        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())
@@ -152,10 +170,14 @@ class ChangePasswordControllerTest extends \Test\TestCase {
        }
 
        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())