diff options
author | skjnldsv <skjnldsv@protonmail.com> | 2025-07-09 19:43:02 +0200 |
---|---|---|
committer | skjnldsv <skjnldsv@protonmail.com> | 2025-07-11 09:05:27 +0200 |
commit | 9cbf2edf9700e0573a2c0a4768a5c37a9399de06 (patch) | |
tree | f9fbea40a063236686a8937e4f27f074e9e03275 | |
parent | 8ff1b8fd0e6430ab9873a1ab38ed04e06d50ddee (diff) | |
download | nextcloud-server-backport/53887/stable30.tar.gz nextcloud-server-backport/53887/stable30.zip |
fix: force lowercase emailsbackport/53887/stable30
Signed-off-by: skjnldsv <skjnldsv@protonmail.com>
-rw-r--r-- | apps/provisioning_api/lib/Controller/AUserData.php | 3 | ||||
-rw-r--r-- | apps/provisioning_api/lib/Controller/UsersController.php | 8 | ||||
-rw-r--r-- | apps/provisioning_api/tests/Controller/UsersControllerTest.php | 49 | ||||
-rw-r--r-- | core/Command/User/Setting.php | 3 | ||||
-rw-r--r-- | lib/private/User/User.php | 8 |
5 files changed, 63 insertions, 8 deletions
diff --git a/apps/provisioning_api/lib/Controller/AUserData.php b/apps/provisioning_api/lib/Controller/AUserData.php index e891a71ff6d..c316a008e9e 100644 --- a/apps/provisioning_api/lib/Controller/AUserData.php +++ b/apps/provisioning_api/lib/Controller/AUserData.php @@ -136,7 +136,8 @@ abstract class AUserData extends OCSController { $additionalEmails = $additionalEmailScopes = []; $emailCollection = $userAccount->getPropertyCollection(IAccountManager::COLLECTION_EMAIL); foreach ($emailCollection->getProperties() as $property) { - $additionalEmails[] = $property->getValue(); + $email = mb_strtolower(trim($property->getValue())); + $additionalEmails[] = $email; if ($includeScopes) { $additionalEmailScopes[] = $property->getScope(); } diff --git a/apps/provisioning_api/lib/Controller/UsersController.php b/apps/provisioning_api/lib/Controller/UsersController.php index a866090dce8..ba9c260224c 100644 --- a/apps/provisioning_api/lib/Controller/UsersController.php +++ b/apps/provisioning_api/lib/Controller/UsersController.php @@ -531,6 +531,7 @@ class UsersController extends AUserData { $generatePasswordResetToken = true; } + $email = mb_strtolower(trim($email)); if ($email === '' && $this->config->getAppValue('core', 'newUser.requireEmail', 'no') === 'yes') { throw new OCSException($this->l10n->t('Required email address was not provided'), 110); } @@ -577,7 +578,7 @@ class UsersController extends AUserData { // Send new user mail only if a mail is set if ($email !== '') { - $newUser->setEMailAddress($email); + $newUser->setSystemEMailAddress($email); if ($this->config->getAppValue('core', 'newUser.sendEmail', 'yes') === 'yes') { try { $emailTemplate = $this->newUserMailHelper->generateTemplate($newUser, $generatePasswordResetToken); @@ -837,6 +838,7 @@ class UsersController extends AUserData { $mailCollection = $userAccount->getPropertyCollection(IAccountManager::COLLECTION_EMAIL); $mailCollection->removePropertyByValue($key); if ($value !== '') { + $value = mb_strtolower(trim($value)); $mailCollection->addPropertyWithDefaults($value); $property = $mailCollection->getPropertyByValue($key); if ($isAdminOrSubadmin && $property) { @@ -1119,13 +1121,15 @@ class UsersController extends AUserData { } break; case IAccountManager::PROPERTY_EMAIL: + $value = mb_strtolower(trim($value)); if (filter_var($value, FILTER_VALIDATE_EMAIL) || $value === '') { - $targetUser->setEMailAddress($value); + $targetUser->setSystemEMailAddress($value); } else { throw new OCSException('', 101); } break; case IAccountManager::COLLECTION_EMAIL: + $value = mb_strtolower(trim($value)); if (filter_var($value, FILTER_VALIDATE_EMAIL) && $value !== $targetUser->getSystemEMailAddress()) { $userAccount = $this->accountManager->getAccount($targetUser); $mailCollection = $userAccount->getPropertyCollection(IAccountManager::COLLECTION_EMAIL); diff --git a/apps/provisioning_api/tests/Controller/UsersControllerTest.php b/apps/provisioning_api/tests/Controller/UsersControllerTest.php index c4e24842a5a..8240e968abb 100644 --- a/apps/provisioning_api/tests/Controller/UsersControllerTest.php +++ b/apps/provisioning_api/tests/Controller/UsersControllerTest.php @@ -621,7 +621,7 @@ class UsersControllerTest extends TestCase { ->willReturn(false); $newUser = $this->createMock(IUser::class); $newUser->expects($this->once()) - ->method('setEMailAddress'); + ->method('setSystemEMailAddress'); $this->userManager ->expects($this->once()) ->method('createUser') @@ -657,6 +657,51 @@ class UsersControllerTest extends TestCase { )); } + public function testAddUserSuccessfulLowercaseEmail(): void { + $this->userManager + ->expects($this->once()) + ->method('userExists') + ->with('NewUser') + ->willReturn(false); + $newUser = $this->createMock(IUser::class); + $newUser->expects($this->once()) + ->method('setSystemEMailAddress') + ->with('foo@bar.com'); + $this->userManager + ->expects($this->once()) + ->method('createUser') + ->willReturn($newUser); + $this->logger + ->expects($this->once()) + ->method('info') + ->with('Successful addUser call with userid: NewUser', ['app' => 'ocs_api']); + $loggedInUser = $this->getMockBuilder(IUser::class) + ->disableOriginalConstructor() + ->getMock(); + $loggedInUser + ->expects($this->exactly(2)) + ->method('getUID') + ->willReturn('adminUser'); + $this->userSession + ->expects($this->once()) + ->method('getUser') + ->willReturn($loggedInUser); + $this->groupManager + ->expects($this->once()) + ->method('isAdmin') + ->with('adminUser') + ->willReturn(true); + $this->eventDispatcher + ->expects($this->once()) + ->method('dispatchTyped') + ->with(new GenerateSecurePasswordEvent()); + + $this->assertTrue(key_exists( + 'id', + $this->api->addUser('NewUser', '', '', 'fOo@BaR.CoM')->getData() + )); + } + public function testAddUserFailedToGenerateUserID() { $this->expectException(\OCP\AppFramework\OCS\OCSException::class); @@ -1627,7 +1672,7 @@ class UsersControllerTest extends TestCase { ->willReturn($targetUser); $targetUser ->expects($this->once()) - ->method('setEMailAddress') + ->method('setSystemEMailAddress') ->with('demo@nextcloud.com'); $targetUser ->expects($this->any()) diff --git a/core/Command/User/Setting.php b/core/Command/User/Setting.php index 16e851d8252..7fc5aab1dc7 100644 --- a/core/Command/User/Setting.php +++ b/core/Command/User/Setting.php @@ -155,7 +155,8 @@ class Setting extends Base { $user = $this->userManager->get($uid); if ($user instanceof IUser) { if ($key === 'email') { - $user->setEMailAddress($input->getArgument('value')); + $email = $input->getArgument('value'); + $user->setSystemEMailAddress(mb_strtolower(trim($email))); } elseif ($key === 'display_name') { if (!$user->setDisplayName($input->getArgument('value'))) { if ($user->getDisplayName() === $input->getArgument('value')) { diff --git a/lib/private/User/User.php b/lib/private/User/User.php index ee42191fdae..722ce0df5c1 100644 --- a/lib/private/User/User.php +++ b/lib/private/User/User.php @@ -155,6 +155,7 @@ class User implements IUser { */ public function setSystemEMailAddress(string $mailAddress): void { $oldMailAddress = $this->getSystemEMailAddress(); + $mailAddress = mb_strtolower(trim($mailAddress)); if ($mailAddress === '') { $this->config->deleteUserValue($this->uid, 'settings', 'email'); @@ -177,6 +178,7 @@ class User implements IUser { * @inheritDoc */ public function setPrimaryEMailAddress(string $mailAddress): void { + $mailAddress = mb_strtolower(trim($mailAddress)); if ($mailAddress === '') { $this->config->deleteUserValue($this->uid, 'settings', 'primary_email'); return; @@ -496,14 +498,16 @@ class User implements IUser { * @inheritDoc */ public function getSystemEMailAddress(): ?string { - return $this->config->getUserValue($this->uid, 'settings', 'email', null); + $email = $this->config->getUserValue($this->uid, 'settings', 'email', null); + return $email ? mb_strtolower(trim($email)) : null; } /** * @inheritDoc */ public function getPrimaryEMailAddress(): ?string { - return $this->config->getUserValue($this->uid, 'settings', 'primary_email', null); + $email = $this->config->getUserValue($this->uid, 'settings', 'primary_email', null); + return $email ? mb_strtolower(trim($email)) : null; } /** |