diff options
author | Arthur Schiwon <blizzz@arthur-schiwon.de> | 2021-01-12 20:52:52 +0100 |
---|---|---|
committer | Arthur Schiwon <blizzz@arthur-schiwon.de> | 2021-01-12 20:52:52 +0100 |
commit | 02b703193a9575b3ee742d9b1b851924bc617319 (patch) | |
tree | 6dedd94d86a60f717fe2b3f6359305b9796b0ffa /apps/user_ldap/tests | |
parent | 3447ea4955fa4aae6d5f150c3c15923cba0d575f (diff) | |
download | nextcloud-server-02b703193a9575b3ee742d9b1b851924bc617319.tar.gz nextcloud-server-02b703193a9575b3ee742d9b1b851924bc617319.zip |
really use known groups
Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
Diffstat (limited to 'apps/user_ldap/tests')
-rw-r--r-- | apps/user_ldap/tests/AccessTest.php | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/apps/user_ldap/tests/AccessTest.php b/apps/user_ldap/tests/AccessTest.php index cc62a2a19ce..a532bd6fd7a 100644 --- a/apps/user_ldap/tests/AccessTest.php +++ b/apps/user_ldap/tests/AccessTest.php @@ -42,6 +42,7 @@ use OCA\User_LDAP\Helper; use OCA\User_LDAP\ILDAPWrapper; use OCA\User_LDAP\LDAP; use OCA\User_LDAP\LogWrapper; +use OCA\User_LDAP\Mapping\GroupMapping; use OCA\User_LDAP\Mapping\UserMapping; use OCA\User_LDAP\User\Manager; use OCA\User_LDAP\User\OfflineUser; @@ -66,6 +67,8 @@ class AccessTest extends TestCase { protected $userMapper; /** @var IManager|\PHPUnit\Framework\MockObject\MockObject */ protected $shareManager; + /** @var GroupMapping|\PHPUnit\Framework\MockObject\MockObject */ + protected $groupMapper; /** @var Connection|\PHPUnit\Framework\MockObject\MockObject */ private $connection; /** @var LDAP|\PHPUnit\Framework\MockObject\MockObject */ @@ -88,6 +91,7 @@ class AccessTest extends TestCase { $this->helper = $this->createMock(Helper::class); $this->config = $this->createMock(IConfig::class); $this->userMapper = $this->createMock(UserMapping::class); + $this->groupMapper = $this->createMock(GroupMapping::class); $this->ncUserManager = $this->createMock(IUserManager::class); $this->shareManager = $this->createMock(IManager::class); @@ -100,6 +104,7 @@ class AccessTest extends TestCase { $this->ncUserManager ); $this->access->setUserMapper($this->userMapper); + $this->access->setGroupMapper($this->groupMapper); } private function getConnectorAndLdapMock() { @@ -641,6 +646,45 @@ class AccessTest extends TestCase { $this->assertSame($expected, $list); } + public function testFetchListOfGroupsKnown() { + $filter = 'objectClass=nextcloudGroup'; + $attributes = ['cn', 'gidNumber', 'dn']; + $base = 'ou=SomeGroups,dc=my,dc=directory'; + + $fakeConnection = ldap_connect(); + $fakeSearchResultResource = ldap_connect(); + $fakeLdapEntries = [ + 'count' => 2, + [ + 'dn' => 'cn=Good Team,' . $base, + 'cn' => ['Good Team'], + ], + [ + 'dn' => 'cn=Another Good Team,' . $base, + 'cn' => ['Another Good Team'], + ] + ]; + + $this->prepareMocksForSearchTests($base, $fakeConnection, $fakeSearchResultResource, $fakeLdapEntries); + + $this->groupMapper->expects($this->any()) + ->method('getListOfIdsByDn') + ->willReturn([ + 'cn=Good Team,' . $base => 'Good_Team', + 'cn=Another Good Team,' . $base => 'Another_Good_Team', + ]); + $this->groupMapper->expects($this->never()) + ->method('getNameByDN'); + + $this->connection->expects($this->exactly(2)) + ->method('writeToCache'); + + $groups = $this->access->fetchListOfGroups($filter, $attributes); + $this->assertSame(2, count($groups)); + $this->assertSame('Good Team', $groups[0]['cn'][0]); + $this->assertSame('Another Good Team', $groups[1]['cn'][0]); + } + public function intUsernameProvider() { // system dependent :-/ $translitExpected = @iconv('UTF-8', 'ASCII//TRANSLIT', 'fränk') ? 'frank' : 'frnk'; |