Skip to content

Commit a1d570b

Browse files
authored
Merge pull request #32833 from nextcloud/backport/32799/stable24
[stable24] Fix exception handling when profile data is too long
2 parents b146d8d + d328e3c commit a1d570b

File tree

3 files changed

+34
-28
lines changed

3 files changed

+34
-28
lines changed

apps/provisioning_api/lib/Controller/UsersController.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -958,7 +958,11 @@ public function editUser(string $userId, string $key, string $value): DataRespon
958958
} catch (PropertyDoesNotExistException $e) {
959959
$userAccount->setProperty($key, $value, IAccountManager::SCOPE_PRIVATE, IAccountManager::NOT_VERIFIED);
960960
}
961-
$this->accountManager->updateAccount($userAccount);
961+
try {
962+
$this->accountManager->updateAccount($userAccount);
963+
} catch (InvalidArgumentException $e) {
964+
throw new OCSException('Invalid ' . $e->getMessage(), 102);
965+
}
962966
break;
963967
case IAccountManager::PROPERTY_PROFILE_ENABLED:
964968
$userAccount = $this->accountManager->getAccount($targetUser);

apps/provisioning_api/tests/Controller/UsersControllerTest.php

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -939,9 +939,10 @@ public function testGetUserTargetDoesNotExist() {
939939
}
940940

941941
public function testGetUserDataAsAdmin() {
942-
$group = $this->getMockBuilder(IGroup::class)
943-
->disableOriginalConstructor()
944-
->getMock();
942+
$group0 = $this->createMock(IGroup::class);
943+
$group1 = $this->createMock(IGroup::class);
944+
$group2 = $this->createMock(IGroup::class);
945+
$group3 = $this->createMock(IGroup::class);
945946
$loggedInUser = $this->getMockBuilder(IUser::class)
946947
->disableOriginalConstructor()
947948
->getMock();
@@ -975,25 +976,25 @@ public function testGetUserDataAsAdmin() {
975976
$this->groupManager
976977
->expects($this->any())
977978
->method('getUserGroups')
978-
->willReturn([$group, $group, $group]);
979+
->willReturn([$group0, $group1, $group2]);
979980
$this->groupManager
980981
->expects($this->once())
981982
->method('getSubAdmin')
982983
->willReturn($subAdminManager);
983984
$subAdminManager
984985
->expects($this->once())
985986
->method('getSubAdminsGroups')
986-
->willReturn([$group]);
987-
$group->expects($this->at(0))
987+
->willReturn([$group3]);
988+
$group0->expects($this->once())
988989
->method('getGID')
989990
->willReturn('group0');
990-
$group->expects($this->at(1))
991+
$group1->expects($this->once())
991992
->method('getGID')
992993
->willReturn('group1');
993-
$group->expects($this->at(2))
994+
$group2->expects($this->once())
994995
->method('getGID')
995996
->willReturn('group2');
996-
$group->expects($this->at(3))
997+
$group3->expects($this->once())
997998
->method('getGID')
998999
->willReturn('group3');
9991000

@@ -1009,10 +1010,10 @@ public function testGetUserDataAsAdmin() {
10091010
IAccountManager::PROPERTY_PROFILE_ENABLED => ['value' => '1'],
10101011
]);
10111012
$this->config
1012-
->expects($this->at(0))
10131013
->method('getUserValue')
1014-
->with('UID', 'core', 'enabled', 'true')
1015-
->willReturn('true');
1014+
->willReturnMap([
1015+
['UID', 'core', 'enabled', 'true', 'true'],
1016+
]);
10161017
$this->api
10171018
->expects($this->once())
10181019
->method('fillStorageInfo')
@@ -1136,10 +1137,10 @@ public function testGetUserDataAsSubAdminAndUserIsAccessible() {
11361137
->method('getSubAdmin')
11371138
->willReturn($subAdminManager);
11381139
$this->config
1139-
->expects($this->at(0))
11401140
->method('getUserValue')
1141-
->with('UID', 'core', 'enabled', 'true')
1142-
->willReturn('true');
1141+
->willReturnMap([
1142+
['UID', 'core', 'enabled', 'true', 'true'],
1143+
]);
11431144
$this->api
11441145
->expects($this->once())
11451146
->method('fillStorageInfo')
@@ -3622,11 +3623,12 @@ public function testGetUser() {
36223623
'profile_enabled' => '1'
36233624
];
36243625

3625-
$api->expects($this->at(0))->method('getUserData')
3626-
->with('uid', false)
3627-
->willReturn($expected);
3628-
$api->expects($this->at(1))->method('getUserData')
3629-
->with('currentuser', true)
3626+
$api->expects($this->exactly(2))
3627+
->method('getUserData')
3628+
->withConsecutive(
3629+
['uid', false],
3630+
['currentuser', true],
3631+
)
36303632
->willReturn($expected);
36313633

36323634
$this->assertSame($expected, $api->getUser('uid')->getData());
@@ -3812,11 +3814,11 @@ public function testResendWelcomeMessageSuccess() {
38123814
->willReturn('abc@example.org');
38133815
$emailTemplate = $this->createMock(IEMailTemplate::class);
38143816
$this->newUserMailHelper
3815-
->expects($this->at(0))
3817+
->expects($this->once())
38163818
->method('generateTemplate')
38173819
->willReturn($emailTemplate);
38183820
$this->newUserMailHelper
3819-
->expects($this->at(1))
3821+
->expects($this->once())
38203822
->method('sendMail')
38213823
->with($targetUser, $emailTemplate);
38223824

@@ -3863,11 +3865,11 @@ public function testResendWelcomeMessageSuccessWithFallbackLanguage() {
38633865
->getMock();
38643866
$emailTemplate = $this->createMock(IEMailTemplate::class);
38653867
$this->newUserMailHelper
3866-
->expects($this->at(0))
3868+
->expects($this->once())
38673869
->method('generateTemplate')
38683870
->willReturn($emailTemplate);
38693871
$this->newUserMailHelper
3870-
->expects($this->at(1))
3872+
->expects($this->once())
38713873
->method('sendMail')
38723874
->with($targetUser, $emailTemplate);
38733875

@@ -3916,11 +3918,11 @@ public function testResendWelcomeMessageFailed() {
39163918
->willReturn('abc@example.org');
39173919
$emailTemplate = $this->createMock(IEMailTemplate::class);
39183920
$this->newUserMailHelper
3919-
->expects($this->at(0))
3921+
->expects($this->once())
39203922
->method('generateTemplate')
39213923
->willReturn($emailTemplate);
39223924
$this->newUserMailHelper
3923-
->expects($this->at(1))
3925+
->expects($this->once())
39243926
->method('sendMail')
39253927
->with($targetUser, $emailTemplate)
39263928
->willThrowException(new \Exception());

lib/private/Accounts/AccountManager.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ protected function testValueLengths(array $properties, bool $throwOnData = false
202202
foreach ($properties as $property) {
203203
if (strlen($property->getValue()) > 2048) {
204204
if ($throwOnData) {
205-
throw new InvalidArgumentException();
205+
throw new InvalidArgumentException($property->getName());
206206
} else {
207207
$property->setValue('');
208208
}

0 commit comments

Comments
 (0)