diff options
author | Lukas Reschke <lukas@owncloud.com> | 2015-02-02 11:41:14 +0100 |
---|---|---|
committer | Lukas Reschke <lukas@owncloud.com> | 2015-02-02 11:41:14 +0100 |
commit | 2426bd1b9dd0a79249329c6f51781d16136fad9d (patch) | |
tree | 68521de1316e19f00cc159e5efe08cee4a26add1 | |
parent | 359abca50c09f17ab0c1f872990a66ca48eab74d (diff) | |
parent | 944dc127b82105acb8c28ffb28439b245c020f43 (diff) | |
download | nextcloud-server-2426bd1b9dd0a79249329c6f51781d16136fad9d.tar.gz nextcloud-server-2426bd1b9dd0a79249329c6f51781d16136fad9d.zip |
Merge pull request #13811 from owncloud/default-to-null
Default to `null` for lostpassword
-rw-r--r-- | core/lostpassword/controller/lostcontroller.php | 4 | ||||
-rw-r--r-- | tests/core/lostpassword/controller/lostcontrollertest.php | 64 |
2 files changed, 39 insertions, 29 deletions
diff --git a/core/lostpassword/controller/lostcontroller.php b/core/lostpassword/controller/lostcontroller.php index aee4001ed37..c039c578b59 100644 --- a/core/lostpassword/controller/lostcontroller.php +++ b/core/lostpassword/controller/lostcontroller.php @@ -141,14 +141,14 @@ class LostController extends Controller { * @return array */ public function setPassword($token, $userId, $password, $proceed) { - if ($this->isDataEncrypted && !$proceed){ + if ($this->isDataEncrypted && !$proceed) { return $this->error('', array('encryption' => true)); } try { $user = $this->userManager->get($userId); - if (!StringUtils::equals($this->config->getUserValue($userId, 'owncloud', 'lostpassword'), $token)) { + if (!StringUtils::equals($this->config->getUserValue($userId, 'owncloud', 'lostpassword', null), $token)) { throw new \Exception($this->l10n->t('Couldn\'t reset password because the token is invalid')); } diff --git a/tests/core/lostpassword/controller/lostcontrollertest.php b/tests/core/lostpassword/controller/lostcontrollertest.php index 2ed7692a32f..b03cbd7c42f 100644 --- a/tests/core/lostpassword/controller/lostcontrollertest.php +++ b/tests/core/lostpassword/controller/lostcontrollertest.php @@ -29,6 +29,12 @@ class LostControllerTest extends \PHPUnit_Framework_TestCase { ->disableOriginalConstructor()->getMock(); $this->container['L10N'] = $this->getMockBuilder('\OCP\IL10N') ->disableOriginalConstructor()->getMock(); + $this->container['L10N'] + ->expects($this->any()) + ->method('t') + ->will($this->returnCallback(function($text, $parameters = array()) { + return vsprintf($text, $parameters); + })); $this->container['Defaults'] = $this->getMockBuilder('\OC_Defaults') ->disableOriginalConstructor()->getMock(); $this->container['UserManager'] = $this->getMockBuilder('\OCP\IUserManager') @@ -73,21 +79,13 @@ class LostControllerTest extends \PHPUnit_Framework_TestCase { array(true, $existingUser), array(false, $nonExistingUser) ))); - $this->container['L10N'] - ->expects($this->any()) - ->method('t') - ->will( - $this->returnValueMap( - array( - array('Couldn\'t send reset email. Please make sure your username is correct.', array(), - 'Couldn\'t send reset email. Please make sure your username is correct.'), - - ) - )); // With a non existing user $response = $this->lostController->email($nonExistingUser); - $expectedResponse = array('status' => 'error', 'msg' => 'Couldn\'t send reset email. Please make sure your username is correct.'); + $expectedResponse = [ + 'status' => 'error', + 'msg' => 'Couldn\'t send reset email. Please make sure your username is correct.' + ]; $this->assertSame($expectedResponse, $response); // With no mail address @@ -97,7 +95,10 @@ class LostControllerTest extends \PHPUnit_Framework_TestCase { ->with($existingUser, 'settings', 'email') ->will($this->returnValue(null)); $response = $this->lostController->email($existingUser); - $expectedResponse = array('status' => 'error', 'msg' => 'Couldn\'t send reset email. Please make sure your username is correct.'); + $expectedResponse = [ + 'status' => 'error', + 'msg' => 'Couldn\'t send reset email. Please make sure your username is correct.' + ]; $this->assertSame($expectedResponse, $response); } @@ -146,31 +147,24 @@ class LostControllerTest extends \PHPUnit_Framework_TestCase { } public function testSetPasswordUnsuccessful() { - $this->container['L10N'] - ->expects($this->any()) - ->method('t') - ->will( - $this->returnValueMap( - array( - array('Couldn\'t reset password because the token is invalid', array(), - 'Couldn\'t reset password because the token is invalid'), - ) - )); $this->container['Config'] ->expects($this->once()) ->method('getUserValue') - ->with('InvalidTokenUser', 'owncloud', 'lostpassword') + ->with('InvalidTokenUser', 'owncloud', 'lostpassword', null) ->will($this->returnValue('TheOnlyAndOnlyOneTokenToResetThePassword')); // With an invalid token $userName = 'InvalidTokenUser'; $response = $this->lostController->setPassword('wrongToken', $userName, 'NewPassword', true); - $expectedResponse = array('status' => 'error', 'msg' => 'Couldn\'t reset password because the token is invalid'); + $expectedResponse = [ + 'status' => 'error', + 'msg' => 'Couldn\'t reset password because the token is invalid' + ]; $this->assertSame($expectedResponse, $response); // With a valid token and no proceed $response = $this->lostController->setPassword('TheOnlyAndOnlyOneTokenToResetThePassword!', $userName, 'NewPassword', false); - $expectedResponse = array('status' => 'error', 'msg' => '', 'encryption' => true); + $expectedResponse = ['status' => 'error', 'msg' => '', 'encryption' => true]; $this->assertSame($expectedResponse, $response); } @@ -178,7 +172,7 @@ class LostControllerTest extends \PHPUnit_Framework_TestCase { $this->container['Config'] ->expects($this->once()) ->method('getUserValue') - ->with('ValidTokenUser', 'owncloud', 'lostpassword') + ->with('ValidTokenUser', 'owncloud', 'lostpassword', null) ->will($this->returnValue('TheOnlyAndOnlyOneTokenToResetThePassword')); $user = $this->getMockBuilder('\OCP\IUser') ->disableOriginalConstructor()->getMock(); @@ -200,4 +194,20 @@ class LostControllerTest extends \PHPUnit_Framework_TestCase { $expectedResponse = array('status' => 'success'); $this->assertSame($expectedResponse, $response); } + + public function testIsSetPasswordWithoutTokenFailing() { + $this->container['Config'] + ->expects($this->once()) + ->method('getUserValue') + ->with('ValidTokenUser', 'owncloud', 'lostpassword', null) + ->will($this->returnValue(null)); + + $response = $this->lostController->setPassword('', 'ValidTokenUser', 'NewPassword', true); + $expectedResponse = [ + 'status' => 'error', + 'msg' => 'Couldn\'t reset password because the token is invalid' + ]; + $this->assertSame($expectedResponse, $response); + } + } |