]> source.dussan.org Git - nextcloud-server.git/commitdiff
Fix exception handling when profile data is too long 32799/head
authorJoas Schilling <coding@schilljs.com>
Thu, 9 Jun 2022 20:07:46 +0000 (22:07 +0200)
committerJoas Schilling <coding@schilljs.com>
Thu, 9 Jun 2022 20:07:46 +0000 (22:07 +0200)
Signed-off-by: Joas Schilling <coding@schilljs.com>
apps/provisioning_api/lib/Controller/UsersController.php
apps/provisioning_api/tests/Controller/UsersControllerTest.php
lib/private/Accounts/AccountManager.php

index 38d51857ffc91b9b6d2c0b2f85145422552a5bf3..a26479ba0a8f2e3d21400fe5ea7446d97fed2462 100644 (file)
@@ -958,7 +958,11 @@ class UsersController extends AUserData {
                                } 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_PROFILE_ENABLED:
                                $userAccount = $this->accountManager->getAccount($targetUser);
index 2ce5cadb57d2275218334d54655daf3747f3a14b..6162be54a041cb87ddb446171853ce6bcf6d83da 100644 (file)
@@ -939,9 +939,10 @@ class UsersControllerTest extends TestCase {
        }
 
        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();
@@ -975,7 +976,7 @@ class UsersControllerTest extends TestCase {
                $this->groupManager
                        ->expects($this->any())
                        ->method('getUserGroups')
-                       ->willReturn([$group, $group, $group]);
+                       ->willReturn([$group0, $group1, $group2]);
                $this->groupManager
                        ->expects($this->once())
                        ->method('getSubAdmin')
@@ -983,17 +984,17 @@ class UsersControllerTest extends TestCase {
                $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');
 
@@ -1009,10 +1010,10 @@ class UsersControllerTest extends TestCase {
                        IAccountManager::PROPERTY_PROFILE_ENABLED => ['value' => '1'],
                ]);
                $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')
@@ -1136,10 +1137,10 @@ class UsersControllerTest extends TestCase {
                        ->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')
@@ -3622,11 +3623,12 @@ class UsersControllerTest extends TestCase {
                        'profile_enabled' => '1'
                ];
 
-               $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());
@@ -3812,11 +3814,11 @@ class UsersControllerTest extends TestCase {
                        ->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);
 
@@ -3863,11 +3865,11 @@ class UsersControllerTest extends TestCase {
                        ->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);
 
@@ -3916,11 +3918,11 @@ class UsersControllerTest extends TestCase {
                        ->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());
index b80c7887591891dedc5bed81ffba0e50688520e6..bdf33d73c291bebac7d75cf724a16d05ee038246 100644 (file)
@@ -220,7 +220,7 @@ class AccountManager implements IAccountManager {
                foreach ($properties as $property) {
                        if (strlen($property->getValue()) > 2048) {
                                if ($throwOnData) {
-                                       throw new InvalidArgumentException();
+                                       throw new InvalidArgumentException($property->getName());
                                } else {
                                        $property->setValue('');
                                }