diff --git a/core/Controller/LostController.php b/core/Controller/LostController.php index 5ac0557e5d6bf..24ce1f620486a 100644 --- a/core/Controller/LostController.php +++ b/core/Controller/LostController.php @@ -186,8 +186,12 @@ protected function checkPasswordResetToken($token, $userId) { throw new \Exception($this->l10n->t('Couldn\'t reset password because the token is invalid')); } + $encryptedToken = $this->config->getUserValue($userId, 'core', 'lostpassword', null); + if ($encryptedToken === null) { + throw new \Exception($this->l10n->t('Couldn\'t reset password because the token is invalid')); + } + try { - $encryptedToken = $this->config->getUserValue($userId, 'core', 'lostpassword', null); $mailAddress = !is_null($user->getEMailAddress()) ? $user->getEMailAddress() : ''; $decryptedToken = $this->crypto->decrypt($encryptedToken, $mailAddress.$this->config->getSystemValue('secret')); } catch (\Exception $e) { diff --git a/tests/Core/Controller/LostControllerTest.php b/tests/Core/Controller/LostControllerTest.php index 8500819a9cae8..02683a543cc9f 100644 --- a/tests/Core/Controller/LostControllerTest.php +++ b/tests/Core/Controller/LostControllerTest.php @@ -687,6 +687,22 @@ public function testIsSetPasswordWithoutTokenFailing() { $this->assertSame($expectedResponse, $response); } + public function testIsSetPasswordTokenNullFailing() { + $this->config->method('getUserValue') + ->with('ValidTokenUser', 'core', 'lostpassword', null) + ->willReturn(null); + $this->userManager->method('get') + ->with('ValidTokenUser') + ->willReturn($this->existingUser); + + $response = $this->lostController->setPassword('', 'ValidTokenUser', 'NewPassword', true); + $expectedResponse = [ + 'status' => 'error', + 'msg' => 'Couldn\'t reset password because the token is invalid' + ]; + $this->assertSame($expectedResponse, $response); + } + public function testSetPasswordForDisabledUser() { $user = $this->createMock(IUser::class); $user->expects($this->any()) @@ -700,7 +716,7 @@ public function testSetPasswordForDisabledUser() { ->willReturn('encryptedData'); $this->userManager->method('get') ->with('DisabledUser') - ->willReturn($this->existingUser); + ->willReturn($user); $response = $this->lostController->setPassword('TheOnlyAndOnlyOneTokenToResetThePassword', 'DisabledUser', 'NewPassword', true); $expectedResponse = [