diff options
author | Vincent Petry <pvince81@owncloud.com> | 2016-05-25 11:08:46 +0200 |
---|---|---|
committer | Vincent Petry <pvince81@owncloud.com> | 2016-05-25 11:08:46 +0200 |
commit | 25e6026fa6f4c696fce13642ab57ff9c4f2f00d6 (patch) | |
tree | 82d36a95c5467cb6f26b260925da133f2e6ca272 /tests | |
parent | b5f455f5ac31ea3a35b8adc70ae82d8e4d31920f (diff) | |
parent | d06598081471896dde67a15bb02cae49d1548480 (diff) | |
download | nextcloud-server-25e6026fa6f4c696fce13642ab57ff9c4f2f00d6.tar.gz nextcloud-server-25e6026fa6f4c696fce13642ab57ff9c4f2f00d6.zip |
Merge pull request #24735 from juliushaertl/passwordreset-invalid
Show error messages if a password reset link is invalid or expired
Diffstat (limited to 'tests')
-rw-r--r-- | tests/Core/Controller/LostControllerTest.php | 107 |
1 files changed, 104 insertions, 3 deletions
diff --git a/tests/Core/Controller/LostControllerTest.php b/tests/Core/Controller/LostControllerTest.php index ca63c3404eb..492a04bcfde 100644 --- a/tests/Core/Controller/LostControllerTest.php +++ b/tests/Core/Controller/LostControllerTest.php @@ -114,14 +114,115 @@ class LostControllerTest extends \PHPUnit_Framework_TestCase { ); } - public function testResetFormUnsuccessful() { + public function testResetFormInvalidToken() { $userId = 'admin'; $token = 'MySecretToken'; + $response = $this->lostController->resetform($token, $userId); + $expectedResponse = new TemplateResponse('core', + 'error', + [ + 'errors' => [ + ['error' => 'Couldn\'t reset password because the token is invalid'], + ] + ], + 'guest'); + $this->assertEquals($expectedResponse, $response); + } + + public function testResetFormInvalidTokenMatch() { + $this->config + ->expects($this->once()) + ->method('getUserValue') + ->with('ValidTokenUser', 'owncloud', 'lostpassword', null) + ->will($this->returnValue('12345:TheOnlyAndOnlyOneTokenToResetThePassword')); + $user = $this->getMockBuilder('\OCP\IUser') + ->disableOriginalConstructor()->getMock(); + $user + ->expects($this->once()) + ->method('getLastLogin') + ->will($this->returnValue(12344)); + $this->userManager + ->expects($this->once()) + ->method('get') + ->with('ValidTokenUser') + ->will($this->returnValue($user)); + $userId = 'ValidTokenUser'; + $token = '12345:MySecretToken'; + $response = $this->lostController->resetform($token, $userId); + $expectedResponse = new TemplateResponse('core', + 'error', + [ + 'errors' => [ + ['error' => 'Couldn\'t reset password because the token is invalid'], + ] + ], + 'guest'); + $this->assertEquals($expectedResponse, $response); + } + + + public function testResetFormExpiredToken() { + $userId = 'ValidTokenUser'; + $token = '12345:TheOnlyAndOnlyOneTokenToResetThePassword'; + $user = $this->getMockBuilder('\OCP\IUser') + ->disableOriginalConstructor()->getMock(); + $this->userManager + ->expects($this->once()) + ->method('get') + ->with('ValidTokenUser') + ->will($this->returnValue($user)); + $this->timeFactory + ->expects($this->once()) + ->method('getTime') + ->will($this->returnValue(12345*60*60*12)); + $userId = 'ValidTokenUser'; + $token = 'TheOnlyAndOnlyOneTokenToResetThePassword'; + $this->config + ->expects($this->once()) + ->method('getUserValue') + ->with('ValidTokenUser', 'owncloud', 'lostpassword', null) + ->will($this->returnValue('12345:TheOnlyAndOnlyOneTokenToResetThePassword')); + $response = $this->lostController->resetform($token, $userId); + $expectedResponse = new TemplateResponse('core', + 'error', + [ + 'errors' => [ + ['error' => 'Couldn\'t reset password because the token is expired'], + ] + ], + 'guest'); + $this->assertEquals($expectedResponse, $response); + } + public function testResetFormValidToken() { + $userId = 'ValidTokenUser'; + $token = '12345:TheOnlyAndOnlyOneTokenToResetThePassword'; + $user = $this->getMockBuilder('\OCP\IUser') + ->disableOriginalConstructor()->getMock(); + $user + ->expects($this->once()) + ->method('getLastLogin') + ->will($this->returnValue(12344)); + $this->userManager + ->expects($this->once()) + ->method('get') + ->with('ValidTokenUser') + ->will($this->returnValue($user)); + $this->timeFactory + ->expects($this->once()) + ->method('getTime') + ->will($this->returnValue(12348)); + $userId = 'ValidTokenUser'; + $token = 'TheOnlyAndOnlyOneTokenToResetThePassword'; + $this->config + ->expects($this->once()) + ->method('getUserValue') + ->with('ValidTokenUser', 'owncloud', 'lostpassword', null) + ->will($this->returnValue('12345:TheOnlyAndOnlyOneTokenToResetThePassword')); $this->urlGenerator ->expects($this->once()) ->method('linkToRouteAbsolute') - ->with('core.lost.setPassword', array('userId' => 'admin', 'token' => 'MySecretToken')) + ->with('core.lost.setPassword', array('userId' => 'ValidTokenUser', 'token' => 'TheOnlyAndOnlyOneTokenToResetThePassword')) ->will($this->returnValue('https://ownCloud.com/index.php/lostpassword/')); $response = $this->lostController->resetform($token, $userId); @@ -329,7 +430,7 @@ class LostControllerTest extends \PHPUnit_Framework_TestCase { ->with('NewPassword') ->will($this->returnValue(true)); $this->userManager - ->expects($this->once()) + ->expects($this->exactly(2)) ->method('get') ->with('ValidTokenUser') ->will($this->returnValue($user)); |