]> source.dussan.org Git - nextcloud-server.git/commitdiff
Add some tests for input trimming in LostController.php 37595/head
authorJoshua Trees <me@jtrees.io>
Wed, 5 Apr 2023 10:12:50 +0000 (12:12 +0200)
committerJoshua Trees <me@jtrees.io>
Wed, 5 Apr 2023 10:15:38 +0000 (12:15 +0200)
Signed-off-by: Joshua Trees <me@jtrees.io>
tests/Core/Controller/LostControllerTest.php

index e95c3fa1c51c0f6ac5c335a8608c91b8b23f4247..1481a1e46d4698a5c4bea4153135cc0e1e5a4c9f 100644 (file)
@@ -1,8 +1,10 @@
 <?php
 /**
  * @author Lukas Reschke <lukas@owncloud.com>
+ * @author Joshua Trees <me@jtrees.io>
  *
  * @copyright Copyright (c) 2015, ownCloud, Inc.
+ * @copyright Copyright (c) 2023, Joshua Trees <me@jtrees.io>
  * @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);
+       }
 }