diff options
author | Ferdinand Thiessen <opensource@fthiessen.de> | 2025-01-18 16:28:23 +0100 |
---|---|---|
committer | Ferdinand Thiessen <opensource@fthiessen.de> | 2025-03-03 18:02:07 +0100 |
commit | 3c4feff028ab87b57a29e5771cde8ba6c5b7e4b0 (patch) | |
tree | 74b8e265ab200fa6f12fef49a0d17c9634e5f444 /tests | |
parent | 2582a55300ac83a806d79499c9bbe7db4e310aee (diff) | |
download | nextcloud-server-3c4feff028ab87b57a29e5771cde8ba6c5b7e4b0.tar.gz nextcloud-server-3c4feff028ab87b57a29e5771cde8ba6c5b7e4b0.zip |
fix: Move login via email logic to local backendfix/move-email-logic-local-user-backend
Backends can decide which names they accept for login,
e.g. with user_ldap you can configure arbitrary login fields.
This was a hacky approach to allow login via email,
so instead this is now only handled by the local user backend.
This also fixes some other related problems:
Other logic relys on `backend::get()` which was not handling email,
so e.g. password policy could not block users logged in via email
if they use out-dated passwords.
Similar for other integrations, as the user backend was not consistent with
what is a login name and what not.
Co-authored-by: Ferdinand Thiessen <opensource@fthiessen.de>
Co-authored-by: Côme Chilliet <91878298+come-nc@users.noreply.github.com>
Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/lib/Authentication/Login/EmailLoginCommandTest.php | 148 |
1 files changed, 0 insertions, 148 deletions
diff --git a/tests/lib/Authentication/Login/EmailLoginCommandTest.php b/tests/lib/Authentication/Login/EmailLoginCommandTest.php deleted file mode 100644 index b34d0d95f4f..00000000000 --- a/tests/lib/Authentication/Login/EmailLoginCommandTest.php +++ /dev/null @@ -1,148 +0,0 @@ -<?php - -/** - * SPDX-FileCopyrightText: 2019 Nextcloud GmbH and Nextcloud contributors - * SPDX-License-Identifier: AGPL-3.0-or-later - */ - -declare(strict_types=1); - -namespace Test\Authentication\Login; - -use OC\Authentication\Login\EmailLoginCommand; -use OCP\IUser; -use OCP\IUserManager; -use PHPUnit\Framework\MockObject\MockObject; - -class EmailLoginCommandTest extends ALoginCommandTest { - /** @var IUserManager|MockObject */ - private $userManager; - - protected function setUp(): void { - parent::setUp(); - - $this->userManager = $this->createMock(IUserManager::class); - - $this->cmd = new EmailLoginCommand( - $this->userManager - ); - } - - public function testProcessAlreadyLoggedIn(): void { - $data = $this->getLoggedInLoginData(); - - $result = $this->cmd->process($data); - - $this->assertTrue($result->isSuccess()); - } - - public function testProcessNotAnEmailLogin(): void { - $data = $this->getFailedLoginData(); - $this->userManager->expects($this->never()) - ->method('getByEmail') - ->with($this->username) - ->willReturn([]); - - $result = $this->cmd->process($data); - - $this->assertTrue($result->isSuccess()); - } - - public function testProcessDuplicateEmailLogin(): void { - $data = $this->getFailedLoginData(); - $data->setUsername('user@example.com'); - $this->userManager->expects($this->once()) - ->method('getByEmail') - ->with('user@example.com') - ->willReturn([ - $this->createMock(IUser::class), - $this->createMock(IUser::class), - ]); - - $result = $this->cmd->process($data); - - $this->assertTrue($result->isSuccess()); - } - - public function testProcessUidIsEmail(): void { - $email = 'user@domain.com'; - $data = $this->getFailedLoginData(); - $data->setUsername($email); - $emailUser = $this->createMock(IUser::class); - $emailUser->expects($this->any()) - ->method('getUID') - ->willReturn($email); - $this->userManager->expects($this->once()) - ->method('getByEmail') - ->with($email) - ->willReturn([ - $emailUser, - ]); - $this->userManager->expects($this->never()) - ->method('checkPassword'); - - $result = $this->cmd->process($data); - - $this->assertTrue($result->isSuccess()); - $this->assertFalse($data->getUser()); - $this->assertEquals($email, $data->getUsername()); - } - - public function testProcessWrongPassword(): void { - $email = 'user@domain.com'; - $data = $this->getFailedLoginData(); - $data->setUsername($email); - $emailUser = $this->createMock(IUser::class); - $emailUser->expects($this->any()) - ->method('getUID') - ->willReturn('user2'); - $this->userManager->expects($this->once()) - ->method('getByEmail') - ->with($email) - ->willReturn([ - $emailUser, - ]); - $this->userManager->expects($this->once()) - ->method('checkPassword') - ->with( - 'user2', - $this->password - ) - ->willReturn(false); - - $result = $this->cmd->process($data); - - $this->assertTrue($result->isSuccess()); - $this->assertFalse($data->getUser()); - $this->assertEquals($email, $data->getUsername()); - } - - public function testProcess(): void { - $email = 'user@domain.com'; - $data = $this->getFailedLoginData(); - $data->setUsername($email); - $emailUser = $this->createMock(IUser::class); - $emailUser->expects($this->any()) - ->method('getUID') - ->willReturn('user2'); - $this->userManager->expects($this->once()) - ->method('getByEmail') - ->with($email) - ->willReturn([ - $emailUser, - ]); - $this->userManager->expects($this->once()) - ->method('checkPassword') - ->with( - 'user2', - $this->password - ) - ->willReturn($emailUser); - - $result = $this->cmd->process($data); - - $this->assertTrue($result->isSuccess()); - $this->assertEquals($emailUser, $data->getUser()); - $this->assertEquals('user2', $data->getUsername()); - } -} |