summaryrefslogtreecommitdiffstats
path: root/tests/Core/Controller
diff options
context:
space:
mode:
authorblizzz <blizzz@arthur-schiwon.de>2018-09-13 10:48:30 +0200
committerGitHub <noreply@github.com>2018-09-13 10:48:30 +0200
commitef97ef72f6a505430b2e71dc44f3433167b5500c (patch)
treee5490ac2740d4afa8b6d6092560499721f732501 /tests/Core/Controller
parentd1cb83424feb5bd96f49e657d20b912cddfdd3d3 (diff)
parent031fdfb1fc3b99c7a7dd93ee20fe000e9cf7fda6 (diff)
downloadnextcloud-server-ef97ef72f6a505430b2e71dc44f3433167b5500c.tar.gz
nextcloud-server-ef97ef72f6a505430b2e71dc44f3433167b5500c.zip
Merge pull request #10743 from danielkesselberg/bugfix/noid/allow-password-reset-for-duplicate-email
Enable password reset for user with same email address when only one is active
Diffstat (limited to 'tests/Core/Controller')
-rw-r--r--tests/Core/Controller/LostControllerTest.php84
1 files changed, 84 insertions, 0 deletions
diff --git a/tests/Core/Controller/LostControllerTest.php b/tests/Core/Controller/LostControllerTest.php
index cfaa8e712fa..91b52fc8efa 100644
--- a/tests/Core/Controller/LostControllerTest.php
+++ b/tests/Core/Controller/LostControllerTest.php
@@ -759,4 +759,88 @@ class LostControllerTest extends \Test\TestCase {
$this->assertSame($expectedResponse, $response);
}
+ public function testTwoUsersWithSameEmail() {
+ $user1 = $this->createMock(IUser::class);
+ $user1->expects($this->any())
+ ->method('getEMailAddress')
+ ->willReturn('test@example.com');
+ $user1->expects($this->any())
+ ->method('getUID')
+ ->willReturn('User1');
+ $user1->expects($this->any())
+ ->method('isEnabled')
+ ->willReturn(true);
+
+ $user2 = $this->createMock(IUser::class);
+ $user2->expects($this->any())
+ ->method('getEMailAddress')
+ ->willReturn('test@example.com');
+ $user2->expects($this->any())
+ ->method('getUID')
+ ->willReturn('User2');
+ $user2->expects($this->any())
+ ->method('isEnabled')
+ ->willReturn(true);
+
+ $this->userManager
+ ->method('get')
+ ->willReturn(null);
+
+ $this->userManager
+ ->method('getByEmail')
+ ->willReturn([$user1, $user2]);
+
+ // request password reset for test@example.com
+ $response = $this->lostController->email('test@example.com');
+
+ $expectedResponse = new JSONResponse([
+ 'status' => 'error',
+ 'msg' => 'Couldn\'t send reset email. Please make sure your username is correct.'
+ ]);
+ $expectedResponse->throttle();
+
+ $this->assertEquals($expectedResponse, $response);
+ }
+
+ public function testTwoUsersWithSameEmailOneDisabled() {
+ $user1 = $this->createMock(IUser::class);
+ $user1->expects($this->any())
+ ->method('getEMailAddress')
+ ->willReturn('test@example.com');
+ $user1->expects($this->any())
+ ->method('getUID')
+ ->willReturn('User1');
+ $user1->expects($this->any())
+ ->method('isEnabled')
+ ->willReturn(true);
+
+ $user2 = $this->createMock(IUser::class);
+ $user2->expects($this->any())
+ ->method('getEMailAddress')
+ ->willReturn('test@example.com');
+ $user2->expects($this->any())
+ ->method('getUID')
+ ->willReturn('User2');
+ $user2->expects($this->any())
+ ->method('isEnabled')
+ ->willReturn(false);
+
+ $this->userManager
+ ->method('get')
+ ->willReturn(null);
+
+ $this->userManager
+ ->method('getByEmail')
+ ->willReturn([$user1, $user2]);
+
+ // request password reset for test@example.com
+ $response = $this->lostController->email('test@example.com');
+
+ $expectedResponse = new JSONResponse([
+ 'status' => 'success'
+ ]);
+ $expectedResponse->throttle();
+
+ $this->assertEquals($expectedResponse, $response);
+ }
}