diff options
author | Benjamin Gaussorgues <benjamin.gaussorgues@nextcloud.com> | 2024-04-10 11:00:51 +0200 |
---|---|---|
committer | Benjamin Gaussorgues <benjamin.gaussorgues@nextcloud.com> | 2024-04-22 15:26:55 +0200 |
commit | 7a6b1f8ae82ad9cd03673bc7f216fe8821c709ef (patch) | |
tree | fda4e34e3954e62feb6cdbb355132c118e716a6b /tests | |
parent | 5fffbcfe8650eab75b00e8d188fbc95b0e43f3a8 (diff) | |
download | nextcloud-server-7a6b1f8ae82ad9cd03673bc7f216fe8821c709ef.tar.gz nextcloud-server-7a6b1f8ae82ad9cd03673bc7f216fe8821c709ef.zip |
fix(groups): allows to save group names with more than 64 characters
Mimic behaviour from LDAP users and add a hard limit to 255 characters
Signed-off-by: Benjamin Gaussorgues <benjamin.gaussorgues@nextcloud.com>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/lib/Group/DatabaseTest.php | 18 | ||||
-rw-r--r-- | tests/lib/Group/ManagerTest.php | 24 |
2 files changed, 37 insertions, 5 deletions
diff --git a/tests/lib/Group/DatabaseTest.php b/tests/lib/Group/DatabaseTest.php index 586d77e0ec0..9d3b4d8b9fd 100644 --- a/tests/lib/Group/DatabaseTest.php +++ b/tests/lib/Group/DatabaseTest.php @@ -36,10 +36,8 @@ class DatabaseTest extends Backend { /** * get a new unique group name * test cases can override this in order to clean up created groups - * - * @return string */ - public function getGroupName($name = null) { + public function getGroupName($name = null): string { $name = parent::getGroupName($name); $this->groups[] = $name; return $name; @@ -57,12 +55,22 @@ class DatabaseTest extends Backend { parent::tearDown(); } - public function testAddDoubleNoCache() { + public function testAddDoubleNoCache(): void { $group = $this->getGroupName(); $this->backend->createGroup($group); $backend = new \OC\Group\Database(); - $this->assertFalse($backend->createGroup($group)); + $this->assertNull($backend->createGroup($group)); + } + + public function testAddLongGroupName(): void { + $groupName = $this->getUniqueID('test_', 100); + + $gidCreated = $this->backend->createGroup($groupName); + $this->assertEquals(64, strlen($gidCreated)); + + $group = $this->backend->getGroupDetails($gidCreated); + $this->assertEquals(['displayName' => $groupName], $group); } } diff --git a/tests/lib/Group/ManagerTest.php b/tests/lib/Group/ManagerTest.php index 142532a5f4f..9a53bc8326c 100644 --- a/tests/lib/Group/ManagerTest.php +++ b/tests/lib/Group/ManagerTest.php @@ -241,6 +241,30 @@ class ManagerTest extends TestCase { $this->assertEquals(null, $group); } + public function testCreateTooLong() { + /**@var \PHPUnit\Framework\MockObject\MockObject|\OC\Group\Backend $backend */ + $backendGroupCreated = false; + $backend = $this->getTestBackend( + GroupInterface::ADD_TO_GROUP | + GroupInterface::REMOVE_FROM_GOUP | + GroupInterface::COUNT_USERS | + GroupInterface::CREATE_GROUP | + GroupInterface::DELETE_GROUP | + GroupInterface::GROUP_DETAILS + ); + $groupName = str_repeat('x', 256); + $backend->expects($this->any()) + ->method('groupExists') + ->with($groupName) + ->willReturn(false); + + $manager = new \OC\Group\Manager($this->userManager, $this->dispatcher, $this->logger, $this->cache); + $manager->addBackend($backend); + + $this->expectException(\Exception::class); + $group = $manager->createGroup($groupName); + } + public function testCreateExists() { /** @var \PHPUnit\Framework\MockObject\MockObject|\OC\Group\Backend $backend */ $backend = $this->getTestBackend(); |