From 1fbf50368ed996e6bc8dde121018689277af8496 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Pablo=20Villaf=C3=A1=C3=B1ez?= Date: Tue, 21 Apr 2026 14:54:59 +0200 Subject: [PATCH 1/2] fix: use the right user id when changing the email --- settings/Controller/UsersController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/settings/Controller/UsersController.php b/settings/Controller/UsersController.php index 955c9e5ec07e..b688e0fd554b 100644 --- a/settings/Controller/UsersController.php +++ b/settings/Controller/UsersController.php @@ -972,7 +972,7 @@ public function setMailAddress($id, $mailAddress) { // admins can set email without verification if ($mailAddress === '' || $this->isAdmin) { - $this->setEmailAddress($userId, $mailAddress); + $this->setEmailAddress($id, $mailAddress); return new DataResponse( [ 'status' => 'success', From 5e57b95cf1bc2c003f7289ac27e113e628046564 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Pablo=20Villaf=C3=A1=C3=B1ez?= Date: Wed, 22 Apr 2026 11:26:22 +0200 Subject: [PATCH 2/2] test: adjust unit test to ensure the mail is set for the user2 Previously, the test only used one user, so it was difficult to verify that the mail was changed for the user2 instead of user1 --- .../Controller/UsersControllerTest.php | 49 ++++++++++++------- 1 file changed, 30 insertions(+), 19 deletions(-) diff --git a/tests/Settings/Controller/UsersControllerTest.php b/tests/Settings/Controller/UsersControllerTest.php index 11c378045625..ed87c42d4e24 100644 --- a/tests/Settings/Controller/UsersControllerTest.php +++ b/tests/Settings/Controller/UsersControllerTest.php @@ -2183,10 +2183,10 @@ public function setEmailAddressData(): array { * @param string $mailAddress * @param bool $isValid * @param bool $expectsUpdate - * @param bool $chanChangeMailAddress + * @param bool $canChangeMailAddress * @param bool $responseCode */ - public function testSetEmailAddress($mailAddress, $isValid, $expectsUpdate, $chanChangeMailAddress, $responseCode): void { + public function testSetEmailAddress($mailAddress, $isValid, $expectsUpdate, $canChangeMailAddress, $responseCode): void { $this->container['IsAdmin'] = true; $user = $this->getMockBuilder(User::class) @@ -2199,12 +2199,21 @@ public function testSetEmailAddress($mailAddress, $isValid, $expectsUpdate, $cha ->willReturn('foo@local'); $user ->method('canChangeMailAddress') - ->willReturn($chanChangeMailAddress); - $user - ->method('setEMailAddress') - ->with( - $this->equalTo($mailAddress) - ); + ->willReturn($canChangeMailAddress); + + $user2 = $this->createMock(User::class); + $user2->method('getUID')->willReturn('anotherUserId'); + $user2->method('getEMailAddress')->willReturn('another@local'); + $user2->method('canChangeMailAddress')->willReturn($canChangeMailAddress); + + if ($isValid && $canChangeMailAddress) { + $user2 + ->expects($this->once()) + ->method('setEMailAddress') + ->with( + $this->equalTo($mailAddress) + ); + } $this->container['UserSession'] ->expects($this->atLeastOnce()) @@ -2215,24 +2224,26 @@ public function testSetEmailAddress($mailAddress, $isValid, $expectsUpdate, $cha ->with($mailAddress) ->willReturn($isValid); - if ($isValid) { - $user->expects($this->atLeastOnce()) - ->method('canChangeMailAddress') - ->willReturn(true); - } - $this->container['Config'] ->method('getUserValue') - ->with('foo', 'owncloud', 'changeMail') - ->willReturn('12000:AVerySecretToken'); + ->willReturnMap([ + ['foo', 'owncloud', 'changeMail', '12000:AVerySecretToken'], + ['anotherUserId', 'owncloud', 'changeMail', '120:ASecretToken'], + ]); $this->container['TimeFactory'] ->method('getTime') ->willReturnOnConsecutiveCalls(12301, 12348); $this->container['UserManager'] ->expects($this->atLeastOnce()) ->method('get') - ->with('foo') - ->willReturn($user); + ->willReturnCallback(function ($id) use ($user, $user2) { + switch($id) { + case "foo": + return $user; + case "anotherUserId": + return $user2; + } + }); $this->container['SecureRandom'] ->method('generate') ->with('21') @@ -2265,7 +2276,7 @@ public function testSetEmailAddress($mailAddress, $isValid, $expectsUpdate, $cha ->method('send') ->with($message); - $response = $this->container['UsersController']->setMailAddress($user->getUID(), $mailAddress); + $response = $this->container['UsersController']->setMailAddress("anotherUserId", $mailAddress); $this->assertSame($responseCode, $response->getStatus()); }