From a4032a38007a888c62ba9f72ac3037bc9a26031c Mon Sep 17 00:00:00 2001 From: Joshua Trees Date: Wed, 5 Apr 2023 12:12:50 +0200 Subject: [PATCH] Add some tests for input trimming in LostController.php Signed-off-by: Joshua Trees --- tests/Core/Controller/LostControllerTest.php | 36 ++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/tests/Core/Controller/LostControllerTest.php b/tests/Core/Controller/LostControllerTest.php index e95c3fa1c51..1481a1e46d4 100644 --- a/tests/Core/Controller/LostControllerTest.php +++ b/tests/Core/Controller/LostControllerTest.php @@ -1,8 +1,10 @@ + * @author Joshua Trees * * @copyright Copyright (c) 2015, ownCloud, Inc. + * @copyright Copyright (c) 2023, Joshua Trees * @license AGPL-3.0 * * This code is free software: you can redistribute it and/or modify @@ -721,4 +723,38 @@ class LostControllerTest extends TestCase { $result = self::invokePrivate($this->lostController, 'findUserByIdOrMail', ['test@example.com']); $this->assertInstanceOf(IUser::class, $result); } + + public function testTrimEmailInput() { + $this->userManager + ->expects($this->once()) + ->method('getByEmail') + ->with('test@example.com') + ->willReturn([$this->existingUser]); + + $this->mailer + ->expects($this->once()) + ->method('send'); + + $response = $this->lostController->email(' test@example.com '); + $expectedResponse = new JSONResponse(['status' => 'success']); + $expectedResponse->throttle(); + $this->assertEquals($expectedResponse, $response); + } + + public function testUsernameInput() { + $this->userManager + ->expects($this->once()) + ->method('get') + ->with('ExistingUser') + ->willReturn($this->existingUser); + + $this->mailer + ->expects($this->once()) + ->method('send'); + + $response = $this->lostController->email(' ExistingUser '); + $expectedResponse = new JSONResponse(['status' => 'success']); + $expectedResponse->throttle(); + $this->assertEquals($expectedResponse, $response); + } } -- 2.39.5