Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorblizzz <blizzz@arthur-schiwon.de>2022-06-13 10:39:05 +0300
committerGitHub <noreply@github.com>2022-06-13 10:39:05 +0300
commitbe236efd2bc80dff914d76fd24777f4766fcb590 (patch)
treefac231e036b539aebb4856fb15a4e9b57129edf3
parent5b4341ae791242ef179c33a0bc31e379bf3fd69d (diff)
parent3189626a817241f1d31f8f37e32e54ed529e3c18 (diff)
Merge pull request #32835 from nextcloud/backport/32799/stable22
[stable22] Fix exception handling when profile data is too long
-rw-r--r--apps/provisioning_api/lib/Controller/UsersController.php6
-rw-r--r--apps/provisioning_api/tests/Controller/UsersControllerTest.php54
-rw-r--r--lib/private/Accounts/AccountManager.php2
3 files changed, 34 insertions, 28 deletions
diff --git a/apps/provisioning_api/lib/Controller/UsersController.php b/apps/provisioning_api/lib/Controller/UsersController.php
index 24768322f9d..378a8343d2e 100644
--- a/apps/provisioning_api/lib/Controller/UsersController.php
+++ b/apps/provisioning_api/lib/Controller/UsersController.php
@@ -908,7 +908,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_DISPLAYNAME . self::SCOPE_SUFFIX:
case IAccountManager::PROPERTY_EMAIL . self::SCOPE_SUFFIX:
diff --git a/apps/provisioning_api/tests/Controller/UsersControllerTest.php b/apps/provisioning_api/tests/Controller/UsersControllerTest.php
index 7ae5d0c245f..f148a069366 100644
--- a/apps/provisioning_api/tests/Controller/UsersControllerTest.php
+++ b/apps/provisioning_api/tests/Controller/UsersControllerTest.php
@@ -935,9 +935,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();
@@ -971,7 +972,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')
@@ -979,17 +980,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');
@@ -1000,10 +1001,10 @@ class UsersControllerTest extends TestCase {
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')
@@ -1122,10 +1123,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')
@@ -3563,11 +3564,12 @@ class UsersControllerTest extends TestCase {
'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());
@@ -3753,11 +3755,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);
@@ -3804,11 +3806,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);
@@ -3857,11 +3859,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());
diff --git a/lib/private/Accounts/AccountManager.php b/lib/private/Accounts/AccountManager.php
index 19faa6dabfe..0a1f7facee0 100644
--- a/lib/private/Accounts/AccountManager.php
+++ b/lib/private/Accounts/AccountManager.php
@@ -194,7 +194,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('');
}