diff options
author | Benjamin Gaussorgues <benjamin.gaussorgues@nextcloud.com> | 2024-05-16 14:22:30 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-05-16 14:22:30 +0200 |
commit | e630e4b98372275309916611534c237300d555bd (patch) | |
tree | 2ea424e73ff6dd220ffc1475e598236580893f3f /tests | |
parent | a6133ab48b6e55e340514099ef7d3852d6cf965b (diff) | |
parent | 7a6b1f8ae82ad9cd03673bc7f216fe8821c709ef (diff) | |
download | nextcloud-server-e630e4b98372275309916611534c237300d555bd.tar.gz nextcloud-server-e630e4b98372275309916611534c237300d555bd.zip |
Merge pull request #44763 from nextcloud/fix/group_name_length_db
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 6a59ed92be3..593fbe60bf9 100644 --- a/tests/lib/Group/DatabaseTest.php +++ b/tests/lib/Group/DatabaseTest.php @@ -18,10 +18,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; @@ -39,12 +37,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 bcf9071db5f..81fd77cc78a 100644 --- a/tests/lib/Group/ManagerTest.php +++ b/tests/lib/Group/ManagerTest.php @@ -226,6 +226,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(); |