diff options
author | Arthur Schiwon <blizzz@arthur-schiwon.de> | 2017-04-25 12:42:17 +0200 |
---|---|---|
committer | Arthur Schiwon <blizzz@arthur-schiwon.de> | 2017-04-25 12:42:17 +0200 |
commit | b1d646640accb94d962b3085d5bf38b8e6852300 (patch) | |
tree | e23d05e24bcce1400e7220f59f67a20e3a497a4e /apps/user_ldap/tests | |
parent | 133f3fdc9aec28383dba323d58569eddd160b0df (diff) | |
parent | 8db21ad8c894332b85a37bef28818604a175db23 (diff) | |
download | nextcloud-server-b1d646640accb94d962b3085d5bf38b8e6852300.tar.gz nextcloud-server-b1d646640accb94d962b3085d5bf38b8e6852300.zip |
Merge branch 'master' of https://github.com/Xuanwo/server into Xuanwo-master2
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 621a427eaac..fc13b8a35e5 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') |