diff options
author | Lukas Reschke <lukas@statuscode.ch> | 2016-08-28 14:22:29 +0200 |
---|---|---|
committer | Roeland Jago Douma <roeland@famdouma.nl> | 2016-11-03 14:27:26 +0100 |
commit | 6d686c213be0b07107d9329a4058c5d11421a498 (patch) | |
tree | 35d0bcef1a779be9eedff27b28f518e29a9d7ace /tests/Core/Controller | |
parent | b129adfb58eb98a37278dbd5a2f30b52c90cb4fc (diff) | |
download | nextcloud-server-6d686c213be0b07107d9329a4058c5d11421a498.tar.gz nextcloud-server-6d686c213be0b07107d9329a4058c5d11421a498.zip |
[WIP] Use mail for encrypting the password reset token as well
Diffstat (limited to 'tests/Core/Controller')
-rw-r--r-- | tests/Core/Controller/LostControllerTest.php | 48 |
1 files changed, 42 insertions, 6 deletions
diff --git a/tests/Core/Controller/LostControllerTest.php b/tests/Core/Controller/LostControllerTest.php index 2c9b078908a..7860e597e30 100644 --- a/tests/Core/Controller/LostControllerTest.php +++ b/tests/Core/Controller/LostControllerTest.php @@ -32,6 +32,7 @@ use OCP\IURLGenerator; use OCP\IUser; use OCP\IUserManager; use OCP\Mail\IMailer; +use OCP\Security\ICrypto; use OCP\Security\ISecureRandom; use PHPUnit_Framework_MockObject_MockObject; @@ -66,6 +67,8 @@ class LostControllerTest extends \Test\TestCase { private $timeFactory; /** @var IRequest */ private $request; + /** @var ICrypto */ + private $crypto; protected function setUp() { parent::setUp(); @@ -107,6 +110,7 @@ class LostControllerTest extends \Test\TestCase { $this->encryptionManager->expects($this->any()) ->method('isEnabled') ->willReturn(true); + $this->crypto = $this->createMock(ICrypto::class); $this->lostController = new LostController( 'Core', $this->request, @@ -119,23 +123,55 @@ class LostControllerTest extends \Test\TestCase { 'lostpassword-noreply@localhost', $this->encryptionManager, $this->mailer, - $this->timeFactory + $this->timeFactory, + $this->crypto ); } - public function testResetFormInvalidToken() { + public function testResetFormWithNotExistingUser() { + $userId = 'NotExistingUser'; + $token = 'MySecretToken'; + $this->userManager + ->expects($this->once()) + ->method('get') + ->with('NotExistingUser') + ->willReturn(null); + + $expectedResponse = new TemplateResponse( + 'core', + 'error', + [ + 'errors' => [ + ['error' => 'Couldn\'t reset password because the token is invalid'], + ] + ], + 'guest' + ); + $this->assertEquals($expectedResponse, $this->lostController->resetform($token, $userId)); + } + + public function testResetFormInvalidTokenFormatting() { $userId = 'admin'; $token = 'MySecretToken'; - $response = $this->lostController->resetform($token, $userId); - $expectedResponse = new TemplateResponse('core', + $user = $this->getMockBuilder('\OCP\IUser')->getMock(); + + $this->userManager + ->expects($this->once()) + ->method('get') + ->with('admin') + ->willReturn($user); + + $expectedResponse = new TemplateResponse( + 'core', 'error', [ 'errors' => [ ['error' => 'Couldn\'t reset password because the token is invalid'], ] ], - 'guest'); - $this->assertEquals($expectedResponse, $response); + 'guest' + ); + $this->assertEquals($expectedResponse, $this->lostController->resetform($token, $userId)); } public function testResetFormInvalidTokenMatch() { |