diff options
author | Xuanwo <xuanwo@yunify.com> | 2017-03-18 14:56:24 +0800 |
---|---|---|
committer | Xuanwo <xuanwo@yunify.com> | 2017-04-25 10:06:47 +0800 |
commit | 8db21ad8c894332b85a37bef28818604a175db23 (patch) | |
tree | 7c0634b90346f92e0dcde7f276168db73d06f50b /apps/user_ldap/tests | |
parent | 9e1e7dac479f63f194b595e45c05d7bf833622dd (diff) | |
download | nextcloud-server-8db21ad8c894332b85a37bef28818604a175db23.tar.gz nextcloud-server-8db21ad8c894332b85a37bef28818604a175db23.zip |
user_ldap: Add support for gidNumber
This patch is based on the work of @dleeuw (https://github.com/dleeuw)
(See https://github.com/nextcloud/server/issues/2640#issuecomment-269615883 for more details).
The difference is user & group data will be written into cache to have
better performance, and functions splited from primaryGroupID series to
make them more readable.
Fixed https://github.com/nextcloud/server/issues/2640
Signed-off-by: Xuanwo <xuanwo@yunify.com>
Diffstat (limited to 'apps/user_ldap/tests')
-rw-r--r-- | apps/user_ldap/tests/Group_LDAPTest.php | 105 |
1 files changed, 105 insertions, 0 deletions
diff --git a/apps/user_ldap/tests/Group_LDAPTest.php b/apps/user_ldap/tests/Group_LDAPTest.php index 906db6bb17b..80989b63463 100644 --- a/apps/user_ldap/tests/Group_LDAPTest.php +++ b/apps/user_ldap/tests/Group_LDAPTest.php @@ -9,6 +9,7 @@ * @author Morris Jobke <hey@morrisjobke.de> * @author Thomas Müller <thomas.mueller@tmit.eu> * @author Vincent Petry <pvince81@owncloud.com> + * @author Xuanwo <xuanwo@yunify.com> * * @license AGPL-3.0 * @@ -142,6 +143,107 @@ class Group_LDAPTest extends \Test\TestCase { $this->assertSame(2, $users); } + public function testGidNumber2NameSuccess() { + $access = $this->getAccessMock(); + $this->enableGroups($access); + + $userDN = 'cn=alice,cn=foo,dc=barfoo,dc=bar'; + + $access->expects($this->once()) + ->method('searchGroups') + ->will($this->returnValue([['dn' => ['cn=foo,dc=barfoo,dc=bar']]])); + + $access->expects($this->once()) + ->method('dn2groupname') + ->with('cn=foo,dc=barfoo,dc=bar') + ->will($this->returnValue('MyGroup')); + + $groupBackend = new GroupLDAP($access); + + $group = $groupBackend->gidNumber2Name('3117', $userDN); + + $this->assertSame('MyGroup', $group); + } + + public function testGidNumberID2NameNoGroup() { + $access = $this->getAccessMock(); + $this->enableGroups($access); + + $userDN = 'cn=alice,cn=foo,dc=barfoo,dc=bar'; + + $access->expects($this->once()) + ->method('searchGroups') + ->will($this->returnValue(array())); + + $access->expects($this->never()) + ->method('dn2groupname'); + + $groupBackend = new GroupLDAP($access); + + $group = $groupBackend->gidNumber2Name('3117', $userDN); + + $this->assertSame(false, $group); + } + + public function testGidNumberID2NameNoName() { + $access = $this->getAccessMock(); + $this->enableGroups($access); + + $userDN = 'cn=alice,cn=foo,dc=barfoo,dc=bar'; + + $access->expects($this->once()) + ->method('searchGroups') + ->will($this->returnValue([['dn' => ['cn=foo,dc=barfoo,dc=bar']]])); + + $access->expects($this->once()) + ->method('dn2groupname') + ->will($this->returnValue(false)); + + $groupBackend = new GroupLDAP($access); + + $group = $groupBackend->gidNumber2Name('3117', $userDN); + + $this->assertSame(false, $group); + } + + public function testGetEntryGidNumberValue() { + $access = $this->getAccessMock(); + $this->enableGroups($access); + + $dn = 'cn=foobar,cn=foo,dc=barfoo,dc=bar'; + $attr = 'gidNumber'; + + $access->expects($this->once()) + ->method('readAttribute') + ->with($dn, $attr) + ->will($this->returnValue(array('3117'))); + + $groupBackend = new GroupLDAP($access); + + $gid = $groupBackend->getGroupGidNumber($dn); + + $this->assertSame('3117', $gid); + } + + public function testGetEntryGidNumberNoValue() { + $access = $this->getAccessMock(); + $this->enableGroups($access); + + $dn = 'cn=foobar,cn=foo,dc=barfoo,dc=bar'; + $attr = 'gidNumber'; + + $access->expects($this->once()) + ->method('readAttribute') + ->with($dn, $attr) + ->will($this->returnValue(false)); + + $groupBackend = new GroupLDAP($access); + + $gid = $groupBackend->getGroupGidNumber($dn); + + $this->assertSame(false, $gid); + } + public function testPrimaryGroupID2NameSuccess() { $access = $this->getAccessMock(); $this->enableGroups($access); @@ -401,6 +503,7 @@ class Group_LDAPTest extends \Test\TestCase { $dn = 'cn=userX,dc=foobar'; $access->connection->hasPrimaryGroups = false; + $access->connection->hasGidNumber = false; $access->expects($this->any()) ->method('username2dn') @@ -441,6 +544,7 @@ class Group_LDAPTest extends \Test\TestCase { $dn = 'cn=userX,dc=foobar'; $access->connection->hasPrimaryGroups = false; + $access->connection->hasGidNumber = false; $access->expects($this->once()) ->method('username2dn') @@ -477,6 +581,7 @@ class Group_LDAPTest extends \Test\TestCase { $dn = 'cn=userX,dc=foobar'; $access->connection->hasPrimaryGroups = false; + $access->connection->hasGidNumber = false; $access->expects($this->exactly(2)) ->method('username2dn') |