diff options
author | Arthur Schiwon <blizzz@owncloud.com> | 2014-08-11 16:40:41 +0200 |
---|---|---|
committer | Arthur Schiwon <blizzz@owncloud.com> | 2014-08-11 16:40:41 +0200 |
commit | fc6793f2ae778448d1c797625149c17ed77bfcc0 (patch) | |
tree | c0078933f3b50ab7cba331e0bfb48ebe781820cd /apps/user_ldap/tests | |
parent | 13d44f8f7f09b3fa641f2ea8e835d0be9bd00c49 (diff) | |
download | nextcloud-server-fc6793f2ae778448d1c797625149c17ed77bfcc0.tar.gz nextcloud-server-fc6793f2ae778448d1c797625149c17ed77bfcc0.zip |
better check whether string resembles a DN, fixes #9887
Diffstat (limited to 'apps/user_ldap/tests')
-rw-r--r-- | apps/user_ldap/tests/access.php | 76 | ||||
-rw-r--r-- | apps/user_ldap/tests/user/manager.php | 47 |
2 files changed, 123 insertions, 0 deletions
diff --git a/apps/user_ldap/tests/access.php b/apps/user_ldap/tests/access.php index e77aad769d4..72b9780c018 100644 --- a/apps/user_ldap/tests/access.php +++ b/apps/user_ldap/tests/access.php @@ -156,4 +156,80 @@ class Test_Access extends \PHPUnit_Framework_TestCase { $this->assertSame($expected, $access->getDomainDNFromDN($inputDN)); } + + public function stringResemblesDNYes() { + list($lw, $con, $um) = $this->getConnecterAndLdapMock(); + $access = new Access($con, $lw, $um); + + $input = 'foo=bar,bar=foo,dc=foobar'; + $interResult = array( + 'count' => 3, + 0 => 'foo=bar', + 1 => 'bar=foo', + 2 => 'dc=foobar' + ); + + $lw->expects($this->once()) + ->method('explodeDN') + ->will($this->returnValue($interResult)); + + $this->assertTrue($access->stringResemblesDN($input)); + } + + public function stringResemblesDNYesLDAPmod() { + list($lw, $con, $um) = $this->getConnecterAndLdapMock(); + $lw = new \OCA\user_ldap\lib\LDAP(); + $access = new Access($con, $lw, $um); + + if(!function_exists('ldap_explode_dn')) { + $this->markTestSkipped('LDAP Module not available'); + } + + $input = 'foo=bar,bar=foo,dc=foobar'; + $interResult = array( + 'count' => 3, + 0 => 'foo=bar', + 1 => 'bar=foo', + 2 => 'dc=foobar' + ); + + $lw->expects($this->once()) + ->method('explodeDN') + ->will($this->returnValue($interResult)); + + $this->assertTrue($access->stringResemblesDN($input)); + } + + public function stringResemblesDNNo() { + list($lw, $con, $um) = $this->getConnecterAndLdapMock(); + $access = new Access($con, $lw, $um); + + $input = 'foobarbarfoodcfoobar'; + $interResult = false; + + $lw->expects($this->once()) + ->method('explodeDN') + ->will($this->returnValue($interResult)); + + $this->assertFalse($access->stringResemblesDN($input)); + } + + public function stringResemblesDNNoLDAPMod() { + list($lw, $con, $um) = $this->getConnecterAndLdapMock(); + $lw = new \OCA\user_ldap\lib\LDAP(); + $access = new Access($con, $lw, $um); + + if(!function_exists('ldap_explode_dn')) { + $this->markTestSkipped('LDAP Module not available'); + } + + $input = 'foobarbarfoodcfoobar'; + $interResult = false; + + $lw->expects($this->once()) + ->method('explodeDN') + ->will($this->returnValue($interResult)); + + $this->assertFalse($access->stringResemblesDN($input)); + } } diff --git a/apps/user_ldap/tests/user/manager.php b/apps/user_ldap/tests/user/manager.php index 7599980ff9a..7d687867213 100644 --- a/apps/user_ldap/tests/user/manager.php +++ b/apps/user_ldap/tests/user/manager.php @@ -44,6 +44,11 @@ class Test_User_Manager extends \PHPUnit_Framework_TestCase { $inputDN = 'cn=foo,dc=foobar,dc=bar'; $uid = '563418fc-423b-1033-8d1c-ad5f418ee02e'; + $access->expects($this->once()) + ->method('stringResemblesDN') + ->with($this->equalTo($inputDN)) + ->will($this->returnValue(true)); + $access->expects($this->once()) ->method('dn2username') ->with($this->equalTo($inputDN)) @@ -66,6 +71,38 @@ class Test_User_Manager extends \PHPUnit_Framework_TestCase { $inputDN = 'uid=foo,o=foobar,c=bar'; $uid = '563418fc-423b-1033-8d1c-ad5f418ee02e'; + $access->expects($this->once()) + ->method('stringResemblesDN') + ->with($this->equalTo($inputDN)) + ->will($this->returnValue(true)); + + $access->expects($this->once()) + ->method('dn2username') + ->with($this->equalTo($inputDN)) + ->will($this->returnValue($uid)); + + $access->expects($this->never()) + ->method('username2dn'); + + $manager = new Manager($config, $filesys, $log, $avaMgr, $image); + $manager->setLdapAccess($access); + $user = $manager->get($inputDN); + + $this->assertInstanceOf('\OCA\user_ldap\lib\user\User', $user); + } + + public function testGetByExoticDN() { + list($access, $config, $filesys, $image, $log, $avaMgr) = + $this->getTestInstances(); + + $inputDN = 'ab=cde,f=ghei,mno=pq'; + $uid = '563418fc-423b-1033-8d1c-ad5f418ee02e'; + + $access->expects($this->once()) + ->method('stringResemblesDN') + ->with($this->equalTo($inputDN)) + ->will($this->returnValue(true)); + $access->expects($this->once()) ->method('dn2username') ->with($this->equalTo($inputDN)) @@ -87,6 +124,11 @@ class Test_User_Manager extends \PHPUnit_Framework_TestCase { $inputDN = 'cn=gone,dc=foobar,dc=bar'; + $access->expects($this->once()) + ->method('stringResemblesDN') + ->with($this->equalTo($inputDN)) + ->will($this->returnValue(true)); + $access->expects($this->once()) ->method('dn2username') ->with($this->equalTo($inputDN)) @@ -119,6 +161,11 @@ class Test_User_Manager extends \PHPUnit_Framework_TestCase { ->with($this->equalTo($uid)) ->will($this->returnValue($dn)); + $access->expects($this->once()) + ->method('stringResemblesDN') + ->with($this->equalTo($uid)) + ->will($this->returnValue(false)); + $manager = new Manager($config, $filesys, $log, $avaMgr, $image); $manager->setLdapAccess($access); $user = $manager->get($uid); |