Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[stable22] Fix exception handling when profile data is too long #32835

Merged
merged 1 commit into from
Jun 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion apps/provisioning_api/lib/Controller/UsersController.php
Original file line number Diff line number Diff line change
Expand Up @@ -908,7 +908,11 @@ public function editUser(string $userId, string $key, string $value): DataRespon
} catch (PropertyDoesNotExistException $e) {
$userAccount->setProperty($key, $value, IAccountManager::SCOPE_PRIVATE, IAccountManager::NOT_VERIFIED);
}
$this->accountManager->updateAccount($userAccount);
try {
$this->accountManager->updateAccount($userAccount);
} catch (InvalidArgumentException $e) {
throw new OCSException('Invalid ' . $e->getMessage(), 102);
}
break;
case IAccountManager::PROPERTY_DISPLAYNAME . self::SCOPE_SUFFIX:
case IAccountManager::PROPERTY_EMAIL . self::SCOPE_SUFFIX:
Expand Down
54 changes: 28 additions & 26 deletions apps/provisioning_api/tests/Controller/UsersControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -935,9 +935,10 @@ public function testGetUserTargetDoesNotExist() {
}

public function testGetUserDataAsAdmin() {
$group = $this->getMockBuilder(IGroup::class)
->disableOriginalConstructor()
->getMock();
$group0 = $this->createMock(IGroup::class);
$group1 = $this->createMock(IGroup::class);
$group2 = $this->createMock(IGroup::class);
$group3 = $this->createMock(IGroup::class);
$loggedInUser = $this->getMockBuilder(IUser::class)
->disableOriginalConstructor()
->getMock();
Expand Down Expand Up @@ -971,25 +972,25 @@ public function testGetUserDataAsAdmin() {
$this->groupManager
->expects($this->any())
->method('getUserGroups')
->willReturn([$group, $group, $group]);
->willReturn([$group0, $group1, $group2]);
$this->groupManager
->expects($this->once())
->method('getSubAdmin')
->willReturn($subAdminManager);
$subAdminManager
->expects($this->once())
->method('getSubAdminsGroups')
->willReturn([$group]);
$group->expects($this->at(0))
->willReturn([$group3]);
$group0->expects($this->once())
->method('getGID')
->willReturn('group0');
$group->expects($this->at(1))
$group1->expects($this->once())
->method('getGID')
->willReturn('group1');
$group->expects($this->at(2))
$group2->expects($this->once())
->method('getGID')
->willReturn('group2');
$group->expects($this->at(3))
$group3->expects($this->once())
->method('getGID')
->willReturn('group3');

Expand All @@ -1000,10 +1001,10 @@ public function testGetUserDataAsAdmin() {
IAccountManager::PROPERTY_WEBSITE => ['value' => 'website'],
]);
$this->config
->expects($this->at(0))
->method('getUserValue')
->with('UID', 'core', 'enabled', 'true')
->willReturn('true');
->willReturnMap([
['UID', 'core', 'enabled', 'true', 'true'],
]);
$this->api
->expects($this->once())
->method('fillStorageInfo')
Expand Down Expand Up @@ -1122,10 +1123,10 @@ public function testGetUserDataAsSubAdminAndUserIsAccessible() {
->method('getSubAdmin')
->willReturn($subAdminManager);
$this->config
->expects($this->at(0))
->method('getUserValue')
->with('UID', 'core', 'enabled', 'true')
->willReturn('true');
->willReturnMap([
['UID', 'core', 'enabled', 'true', 'true'],
]);
$this->api
->expects($this->once())
->method('fillStorageInfo')
Expand Down Expand Up @@ -3563,11 +3564,12 @@ public function testGetUser() {
'displayname' => 'Demo User'
];

$api->expects($this->at(0))->method('getUserData')
->with('uid', false)
->willReturn($expected);
$api->expects($this->at(1))->method('getUserData')
->with('currentuser', true)
$api->expects($this->exactly(2))
->method('getUserData')
->withConsecutive(
['uid', false],
['currentuser', true],
)
->willReturn($expected);

$this->assertSame($expected, $api->getUser('uid')->getData());
Expand Down Expand Up @@ -3753,11 +3755,11 @@ public function testResendWelcomeMessageSuccess() {
->willReturn('abc@example.org');
$emailTemplate = $this->createMock(IEMailTemplate::class);
$this->newUserMailHelper
->expects($this->at(0))
->expects($this->once())
->method('generateTemplate')
->willReturn($emailTemplate);
$this->newUserMailHelper
->expects($this->at(1))
->expects($this->once())
->method('sendMail')
->with($targetUser, $emailTemplate);

Expand Down Expand Up @@ -3804,11 +3806,11 @@ public function testResendWelcomeMessageSuccessWithFallbackLanguage() {
->getMock();
$emailTemplate = $this->createMock(IEMailTemplate::class);
$this->newUserMailHelper
->expects($this->at(0))
->expects($this->once())
->method('generateTemplate')
->willReturn($emailTemplate);
$this->newUserMailHelper
->expects($this->at(1))
->expects($this->once())
->method('sendMail')
->with($targetUser, $emailTemplate);

Expand Down Expand Up @@ -3857,11 +3859,11 @@ public function testResendWelcomeMessageFailed() {
->willReturn('abc@example.org');
$emailTemplate = $this->createMock(IEMailTemplate::class);
$this->newUserMailHelper
->expects($this->at(0))
->expects($this->once())
->method('generateTemplate')
->willReturn($emailTemplate);
$this->newUserMailHelper
->expects($this->at(1))
->expects($this->once())
->method('sendMail')
->with($targetUser, $emailTemplate)
->willThrowException(new \Exception());
Expand Down
2 changes: 1 addition & 1 deletion lib/private/Accounts/AccountManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ protected function testValueLengths(array $properties, bool $throwOnData = false
foreach ($properties as $property) {
if (strlen($property->getValue()) > 2048) {
if ($throwOnData) {
throw new InvalidArgumentException();
throw new InvalidArgumentException($property->getName());
} else {
$property->setValue('');
}
Expand Down