2014-03-21 03:17:51 +04:00
|
|
|
<?php
|
|
|
|
/**
|
2016-07-21 17:49:16 +03:00
|
|
|
* @copyright Copyright (c) 2016, ownCloud, Inc.
|
|
|
|
*
|
2016-05-26 20:56:05 +03:00
|
|
|
* @author Arthur Schiwon <blizzz@arthur-schiwon.de>
|
2020-03-31 11:49:10 +03:00
|
|
|
* @author Christoph Wurst <christoph@winzerhof-wurst.at>
|
2016-07-21 17:49:16 +03:00
|
|
|
* @author Joas Schilling <coding@schilljs.com>
|
2015-03-26 13:44:34 +03:00
|
|
|
* @author Morris Jobke <hey@morrisjobke.de>
|
2017-11-06 17:56:42 +03:00
|
|
|
* @author Roeland Jago Douma <roeland@famdouma.nl>
|
2016-01-12 17:02:16 +03:00
|
|
|
* @author Thomas Müller <thomas.mueller@tmit.eu>
|
2017-11-06 17:56:42 +03:00
|
|
|
* @author Victor Dubiniuk <dubiniuk@owncloud.com>
|
2015-10-05 21:54:56 +03:00
|
|
|
* @author Viktor Szépe <viktor@szepe.net>
|
2015-03-26 13:44:34 +03:00
|
|
|
*
|
|
|
|
* @license AGPL-3.0
|
|
|
|
*
|
|
|
|
* This code is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License, version 3,
|
|
|
|
* as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License, version 3,
|
2019-12-03 21:57:53 +03:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
2015-03-26 13:44:34 +03:00
|
|
|
*
|
|
|
|
*/
|
2015-02-26 13:37:37 +03:00
|
|
|
|
2016-05-12 18:14:59 +03:00
|
|
|
namespace OCA\User_LDAP\Tests;
|
2014-03-21 03:17:51 +04:00
|
|
|
|
2017-11-03 19:40:05 +03:00
|
|
|
use OCA\User_LDAP\Access;
|
|
|
|
use OCA\User_LDAP\Configuration;
|
2016-09-02 12:02:12 +03:00
|
|
|
use OCA\User_LDAP\ILDAPWrapper;
|
2019-11-22 22:52:10 +03:00
|
|
|
use OCA\User_LDAP\Wizard;
|
2019-11-22 15:23:56 +03:00
|
|
|
use PHPUnit\Framework\MockObject\MockObject;
|
2017-11-03 19:40:05 +03:00
|
|
|
use Test\TestCase;
|
2014-03-21 03:17:51 +04:00
|
|
|
|
2015-11-25 18:58:54 +03:00
|
|
|
/**
|
|
|
|
* Class Test_Wizard
|
|
|
|
*
|
|
|
|
* @group DB
|
|
|
|
*
|
2016-05-12 18:14:59 +03:00
|
|
|
* @package OCA\User_LDAP\Tests
|
2015-11-25 18:58:54 +03:00
|
|
|
*/
|
2017-11-03 19:40:05 +03:00
|
|
|
class WizardTest extends TestCase {
|
2019-11-21 18:40:38 +03:00
|
|
|
protected function setUp(): void {
|
2014-11-11 00:28:12 +03:00
|
|
|
parent::setUp();
|
2014-03-21 13:08:17 +04:00
|
|
|
//we need to make sure the consts are defined, otherwise tests will fail
|
|
|
|
//on systems without php5_ldap
|
2020-03-26 11:30:18 +03:00
|
|
|
$ldapConsts = ['LDAP_OPT_PROTOCOL_VERSION',
|
2020-04-09 10:22:29 +03:00
|
|
|
'LDAP_OPT_REFERRALS', 'LDAP_OPT_NETWORK_TIMEOUT'];
|
2014-03-21 13:08:17 +04:00
|
|
|
foreach($ldapConsts as $const) {
|
|
|
|
if(!defined($const)) {
|
|
|
|
define($const, 42);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-21 03:17:51 +04:00
|
|
|
private function getWizardAndMocks() {
|
2014-08-11 18:05:43 +04:00
|
|
|
static $confMethods;
|
|
|
|
static $connMethods;
|
|
|
|
static $accMethods;
|
2014-03-21 03:17:51 +04:00
|
|
|
|
2014-08-11 18:05:43 +04:00
|
|
|
if(is_null($confMethods)) {
|
2016-05-12 17:37:49 +03:00
|
|
|
$confMethods = get_class_methods('\OCA\User_LDAP\Configuration');
|
2016-05-12 17:35:33 +03:00
|
|
|
$connMethods = get_class_methods('\OCA\User_LDAP\Connection');
|
2016-05-12 17:42:57 +03:00
|
|
|
$accMethods = get_class_methods('\OCA\User_LDAP\Access');
|
2014-03-21 03:17:51 +04:00
|
|
|
}
|
2017-11-03 19:40:05 +03:00
|
|
|
/** @var ILDAPWrapper|\PHPUnit_Framework_MockObject_MockObject $lw */
|
2016-09-02 12:02:12 +03:00
|
|
|
$lw = $this->createMock(ILDAPWrapper::class);
|
2017-11-03 19:40:05 +03:00
|
|
|
|
|
|
|
/** @var Configuration|\PHPUnit_Framework_MockObject_MockObject $conf */
|
|
|
|
$conf = $this->getMockBuilder(Configuration::class)
|
2016-09-27 23:54:37 +03:00
|
|
|
->setMethods($confMethods)
|
|
|
|
->setConstructorArgs([$lw, null, null])
|
|
|
|
->getMock();
|
|
|
|
|
2017-11-03 19:40:05 +03:00
|
|
|
/** @var Access|\PHPUnit_Framework_MockObject_MockObject $access */
|
|
|
|
$access = $this->createMock(Access::class);
|
2014-06-25 19:36:19 +04:00
|
|
|
|
2020-03-26 11:30:18 +03:00
|
|
|
return [new Wizard($conf, $lw, $access), $conf, $lw, $access];
|
2014-03-21 03:17:51 +04:00
|
|
|
}
|
|
|
|
|
2019-11-22 15:23:56 +03:00
|
|
|
private function prepareLdapWrapperForConnections(MockObject &$ldap) {
|
2014-03-21 03:17:51 +04:00
|
|
|
$ldap->expects($this->once())
|
|
|
|
->method('connect')
|
|
|
|
//dummy value, usually invalid
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn(true);
|
2014-03-21 03:17:51 +04:00
|
|
|
|
|
|
|
$ldap->expects($this->exactly(3))
|
|
|
|
->method('setOption')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn(true);
|
2014-03-21 03:17:51 +04:00
|
|
|
|
|
|
|
$ldap->expects($this->once())
|
|
|
|
->method('bind')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn(true);
|
2014-03-21 03:17:51 +04:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testCumulativeSearchOnAttributeLimited() {
|
|
|
|
list($wizard, $configuration, $ldap) = $this->getWizardAndMocks();
|
|
|
|
|
|
|
|
$configuration->expects($this->any())
|
|
|
|
->method('__get')
|
2020-04-09 14:53:40 +03:00
|
|
|
->willReturnCallback(function ($name) {
|
2014-03-21 03:17:51 +04:00
|
|
|
if($name === 'ldapBase') {
|
2020-03-26 11:30:18 +03:00
|
|
|
return ['base'];
|
2014-03-21 03:17:51 +04:00
|
|
|
}
|
|
|
|
return null;
|
2020-03-26 00:21:27 +03:00
|
|
|
});
|
2014-03-21 03:17:51 +04:00
|
|
|
|
|
|
|
$this->prepareLdapWrapperForConnections($ldap);
|
|
|
|
|
|
|
|
$ldap->expects($this->any())
|
|
|
|
->method('isResource')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn(true);
|
2014-03-21 03:17:51 +04:00
|
|
|
|
|
|
|
$ldap->expects($this->exactly(2))
|
|
|
|
->method('search')
|
|
|
|
//dummy value, usually invalid
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn(true);
|
2014-03-21 03:17:51 +04:00
|
|
|
|
|
|
|
$ldap->expects($this->exactly(2))
|
|
|
|
->method('countEntries')
|
|
|
|
//an is_resource check will follow, so we need to return a dummy resource
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn(23);
|
2014-03-21 03:17:51 +04:00
|
|
|
|
|
|
|
//5 DNs per filter means 2x firstEntry and 8x nextEntry
|
|
|
|
$ldap->expects($this->exactly(2))
|
|
|
|
->method('firstEntry')
|
|
|
|
//dummy value, usually invalid
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn(true);
|
2014-03-21 03:17:51 +04:00
|
|
|
|
|
|
|
$ldap->expects($this->exactly(8))
|
|
|
|
->method('nextEntry')
|
|
|
|
//dummy value, usually invalid
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn(true);
|
2014-03-21 03:17:51 +04:00
|
|
|
|
|
|
|
$ldap->expects($this->exactly(10))
|
|
|
|
->method('getAttributes')
|
|
|
|
//dummy value, usually invalid
|
2020-03-26 11:30:18 +03:00
|
|
|
->willReturn(['cn' => ['foo'], 'count' => 1]);
|
2014-03-21 03:17:51 +04:00
|
|
|
|
|
|
|
global $uidnumber;
|
|
|
|
$uidnumber = 1;
|
|
|
|
$ldap->expects($this->exactly(10))
|
|
|
|
->method('getDN')
|
|
|
|
//dummy value, usually invalid
|
2020-04-09 14:53:40 +03:00
|
|
|
->willReturnCallback(function ($a, $b) {
|
2014-03-21 03:17:51 +04:00
|
|
|
global $uidnumber;
|
|
|
|
return $uidnumber++;
|
2020-03-26 00:21:27 +03:00
|
|
|
});
|
2014-03-21 03:17:51 +04:00
|
|
|
|
2015-07-21 23:19:53 +03:00
|
|
|
// The following expectations are the real test
|
2020-03-26 11:30:18 +03:00
|
|
|
$filters = ['f1', 'f2', '*'];
|
2014-06-11 15:35:35 +04:00
|
|
|
$wizard->cumulativeSearchOnAttribute($filters, 'cn', 5);
|
2014-03-21 03:17:51 +04:00
|
|
|
unset($uidnumber);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testCumulativeSearchOnAttributeUnlimited() {
|
|
|
|
list($wizard, $configuration, $ldap) = $this->getWizardAndMocks();
|
|
|
|
|
|
|
|
$configuration->expects($this->any())
|
|
|
|
->method('__get')
|
2020-04-09 14:53:40 +03:00
|
|
|
->willReturnCallback(function ($name) {
|
2014-03-21 03:17:51 +04:00
|
|
|
if($name === 'ldapBase') {
|
2020-03-26 11:30:18 +03:00
|
|
|
return ['base'];
|
2014-03-21 03:17:51 +04:00
|
|
|
}
|
|
|
|
return null;
|
2020-03-26 00:21:27 +03:00
|
|
|
});
|
2014-03-21 03:17:51 +04:00
|
|
|
|
|
|
|
$this->prepareLdapWrapperForConnections($ldap);
|
|
|
|
|
|
|
|
$ldap->expects($this->any())
|
|
|
|
->method('isResource')
|
2020-04-09 14:53:40 +03:00
|
|
|
->willReturnCallback(function ($r) {
|
2014-03-21 03:17:51 +04:00
|
|
|
if($r === true) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if($r % 24 === 0) {
|
|
|
|
global $uidnumber;
|
|
|
|
$uidnumber++;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
2020-03-26 00:21:27 +03:00
|
|
|
});
|
2014-03-21 03:17:51 +04:00
|
|
|
|
|
|
|
$ldap->expects($this->exactly(2))
|
|
|
|
->method('search')
|
|
|
|
//dummy value, usually invalid
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn(true);
|
2014-03-21 03:17:51 +04:00
|
|
|
|
|
|
|
$ldap->expects($this->exactly(2))
|
|
|
|
->method('countEntries')
|
|
|
|
//an is_resource check will follow, so we need to return a dummy resource
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn(23);
|
2014-03-21 03:17:51 +04:00
|
|
|
|
|
|
|
//5 DNs per filter means 2x firstEntry and 8x nextEntry
|
|
|
|
$ldap->expects($this->exactly(2))
|
|
|
|
->method('firstEntry')
|
|
|
|
//dummy value, usually invalid
|
2020-04-09 14:53:40 +03:00
|
|
|
->willReturnCallback(function ($r) {
|
2014-03-21 03:17:51 +04:00
|
|
|
global $uidnumber;
|
|
|
|
return $uidnumber;
|
2020-03-26 00:21:27 +03:00
|
|
|
});
|
2014-03-21 03:17:51 +04:00
|
|
|
|
|
|
|
$ldap->expects($this->exactly(46))
|
|
|
|
->method('nextEntry')
|
|
|
|
//dummy value, usually invalid
|
2020-04-09 14:53:40 +03:00
|
|
|
->willReturnCallback(function ($r) {
|
2014-03-21 03:17:51 +04:00
|
|
|
global $uidnumber;
|
|
|
|
return $uidnumber;
|
2020-03-26 00:21:27 +03:00
|
|
|
});
|
2014-03-21 03:17:51 +04:00
|
|
|
|
|
|
|
$ldap->expects($this->exactly(46))
|
|
|
|
->method('getAttributes')
|
|
|
|
//dummy value, usually invalid
|
2020-03-26 11:30:18 +03:00
|
|
|
->willReturn(['cn' => ['foo'], 'count' => 1]);
|
2014-03-21 03:17:51 +04:00
|
|
|
|
|
|
|
global $uidnumber;
|
|
|
|
$uidnumber = 1;
|
|
|
|
$ldap->expects($this->exactly(46))
|
|
|
|
->method('getDN')
|
|
|
|
//dummy value, usually invalid
|
2020-04-09 14:53:40 +03:00
|
|
|
->willReturnCallback(function ($a, $b) {
|
2014-03-21 03:17:51 +04:00
|
|
|
global $uidnumber;
|
|
|
|
return $uidnumber++;
|
2020-03-26 00:21:27 +03:00
|
|
|
});
|
2014-03-21 03:17:51 +04:00
|
|
|
|
2015-07-21 23:19:53 +03:00
|
|
|
// The following expectations are the real test
|
2020-03-26 11:30:18 +03:00
|
|
|
$filters = ['f1', 'f2', '*'];
|
2014-06-11 15:35:35 +04:00
|
|
|
$wizard->cumulativeSearchOnAttribute($filters, 'cn', 0);
|
2014-03-21 03:17:51 +04:00
|
|
|
unset($uidnumber);
|
|
|
|
}
|
|
|
|
|
2014-06-25 20:01:04 +04:00
|
|
|
public function testDetectEmailAttributeAlreadySet() {
|
|
|
|
list($wizard, $configuration, $ldap, $access)
|
|
|
|
= $this->getWizardAndMocks();
|
|
|
|
|
|
|
|
$configuration->expects($this->any())
|
|
|
|
->method('__get')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturnCallback(function ($name) {
|
2014-06-25 20:01:04 +04:00
|
|
|
if($name === 'ldapEmailAttribute') {
|
|
|
|
return 'myEmailAttribute';
|
|
|
|
} else {
|
|
|
|
//for requirement checks
|
|
|
|
return 'let me pass';
|
|
|
|
}
|
2020-03-26 00:21:27 +03:00
|
|
|
});
|
2014-06-25 20:01:04 +04:00
|
|
|
|
|
|
|
$access->expects($this->once())
|
|
|
|
->method('countUsers')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn(42);
|
2014-06-25 20:01:04 +04:00
|
|
|
|
|
|
|
$wizard->detectEmailAttribute();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testDetectEmailAttributeOverrideSet() {
|
|
|
|
list($wizard, $configuration, $ldap, $access)
|
|
|
|
= $this->getWizardAndMocks();
|
|
|
|
|
|
|
|
$configuration->expects($this->any())
|
|
|
|
->method('__get')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturnCallback(function ($name) {
|
2014-06-25 20:01:04 +04:00
|
|
|
if($name === 'ldapEmailAttribute') {
|
|
|
|
return 'myEmailAttribute';
|
|
|
|
} else {
|
|
|
|
//for requirement checks
|
|
|
|
return 'let me pass';
|
|
|
|
}
|
2020-03-26 00:21:27 +03:00
|
|
|
});
|
2014-06-25 20:01:04 +04:00
|
|
|
|
|
|
|
$access->expects($this->exactly(3))
|
|
|
|
->method('combineFilterWithAnd')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturnCallback(function ($filterParts) {
|
2014-06-25 20:01:04 +04:00
|
|
|
return str_replace('=*', '', array_pop($filterParts));
|
2020-03-26 00:21:27 +03:00
|
|
|
});
|
2014-06-25 20:01:04 +04:00
|
|
|
|
|
|
|
$access->expects($this->exactly(3))
|
|
|
|
->method('countUsers')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturnCallback(function ($filter) {
|
2014-06-25 20:01:04 +04:00
|
|
|
if($filter === 'myEmailAttribute') {
|
|
|
|
return 0;
|
2020-04-10 11:35:09 +03:00
|
|
|
} elseif($filter === 'mail') {
|
2014-06-25 20:01:04 +04:00
|
|
|
return 3;
|
2020-04-10 11:35:09 +03:00
|
|
|
} elseif($filter === 'mailPrimaryAddress') {
|
2014-06-25 20:01:04 +04:00
|
|
|
return 17;
|
|
|
|
}
|
2015-04-18 16:09:15 +03:00
|
|
|
throw new \Exception('Untested filter: ' . $filter);
|
2020-03-26 00:21:27 +03:00
|
|
|
});
|
2014-06-25 20:01:04 +04:00
|
|
|
|
2014-06-25 21:38:54 +04:00
|
|
|
$result = $wizard->detectEmailAttribute()->getResultArray();
|
|
|
|
$this->assertSame('mailPrimaryAddress',
|
|
|
|
$result['changes']['ldap_email_attr']);
|
2014-06-25 20:01:04 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testDetectEmailAttributeFind() {
|
|
|
|
list($wizard, $configuration, $ldap, $access)
|
|
|
|
= $this->getWizardAndMocks();
|
|
|
|
|
|
|
|
$configuration->expects($this->any())
|
|
|
|
->method('__get')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturnCallback(function ($name) {
|
2014-06-25 20:01:04 +04:00
|
|
|
if($name === 'ldapEmailAttribute') {
|
|
|
|
return '';
|
|
|
|
} else {
|
|
|
|
//for requirement checks
|
|
|
|
return 'let me pass';
|
|
|
|
}
|
2020-03-26 00:21:27 +03:00
|
|
|
});
|
2014-06-25 20:01:04 +04:00
|
|
|
|
|
|
|
$access->expects($this->exactly(2))
|
|
|
|
->method('combineFilterWithAnd')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturnCallback(function ($filterParts) {
|
2014-06-25 20:01:04 +04:00
|
|
|
return str_replace('=*', '', array_pop($filterParts));
|
2020-03-26 00:21:27 +03:00
|
|
|
});
|
2014-06-25 20:01:04 +04:00
|
|
|
|
|
|
|
$access->expects($this->exactly(2))
|
|
|
|
->method('countUsers')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturnCallback(function ($filter) {
|
2014-06-25 20:01:04 +04:00
|
|
|
if($filter === 'myEmailAttribute') {
|
|
|
|
return 0;
|
2020-04-10 11:35:09 +03:00
|
|
|
} elseif($filter === 'mail') {
|
2014-06-25 20:01:04 +04:00
|
|
|
return 3;
|
2020-04-10 11:35:09 +03:00
|
|
|
} elseif($filter === 'mailPrimaryAddress') {
|
2014-06-25 20:01:04 +04:00
|
|
|
return 17;
|
|
|
|
}
|
2015-04-18 16:09:15 +03:00
|
|
|
throw new \Exception('Untested filter: ' . $filter);
|
2020-03-26 00:21:27 +03:00
|
|
|
});
|
2014-06-25 20:01:04 +04:00
|
|
|
|
2014-06-25 21:38:54 +04:00
|
|
|
$result = $wizard->detectEmailAttribute()->getResultArray();
|
|
|
|
$this->assertSame('mailPrimaryAddress',
|
|
|
|
$result['changes']['ldap_email_attr']);
|
2014-06-25 20:01:04 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testDetectEmailAttributeFindNothing() {
|
|
|
|
list($wizard, $configuration, $ldap, $access)
|
|
|
|
= $this->getWizardAndMocks();
|
|
|
|
|
|
|
|
$configuration->expects($this->any())
|
|
|
|
->method('__get')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturnCallback(function ($name) {
|
2014-06-25 20:01:04 +04:00
|
|
|
if($name === 'ldapEmailAttribute') {
|
|
|
|
return 'myEmailAttribute';
|
|
|
|
} else {
|
|
|
|
//for requirement checks
|
|
|
|
return 'let me pass';
|
|
|
|
}
|
2020-03-26 00:21:27 +03:00
|
|
|
});
|
2014-06-25 20:01:04 +04:00
|
|
|
|
|
|
|
$access->expects($this->exactly(3))
|
|
|
|
->method('combineFilterWithAnd')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturnCallback(function ($filterParts) {
|
2014-06-25 20:01:04 +04:00
|
|
|
return str_replace('=*', '', array_pop($filterParts));
|
2020-03-26 00:21:27 +03:00
|
|
|
});
|
2014-06-25 20:01:04 +04:00
|
|
|
|
|
|
|
$access->expects($this->exactly(3))
|
|
|
|
->method('countUsers')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturnCallback(function ($filter) {
|
2014-06-25 20:01:04 +04:00
|
|
|
if($filter === 'myEmailAttribute') {
|
|
|
|
return 0;
|
2020-04-10 11:35:09 +03:00
|
|
|
} elseif($filter === 'mail') {
|
2014-06-25 20:01:04 +04:00
|
|
|
return 0;
|
2020-04-10 11:35:09 +03:00
|
|
|
} elseif($filter === 'mailPrimaryAddress') {
|
2014-06-25 20:01:04 +04:00
|
|
|
return 0;
|
|
|
|
}
|
2015-04-18 16:09:15 +03:00
|
|
|
throw new \Exception('Untested filter: ' . $filter);
|
2020-03-26 00:21:27 +03:00
|
|
|
});
|
2014-06-25 20:01:04 +04:00
|
|
|
|
2014-06-25 21:38:54 +04:00
|
|
|
$result = $wizard->detectEmailAttribute();
|
|
|
|
$this->assertSame(false, $result->hasChanges());
|
2014-06-25 20:01:04 +04:00
|
|
|
}
|
|
|
|
|
2014-05-16 20:03:15 +04:00
|
|
|
public function testCumulativeSearchOnAttributeSkipReadDN() {
|
|
|
|
// tests that there is no infinite loop, when skipping already processed
|
|
|
|
// DNs (they can be returned multiple times for multiple filters )
|
|
|
|
list($wizard, $configuration, $ldap) = $this->getWizardAndMocks();
|
|
|
|
|
|
|
|
$configuration->expects($this->any())
|
|
|
|
->method('__get')
|
2020-04-09 14:53:40 +03:00
|
|
|
->willReturnCallback(function ($name) {
|
2014-05-16 20:03:15 +04:00
|
|
|
if($name === 'ldapBase') {
|
2020-03-26 11:30:18 +03:00
|
|
|
return ['base'];
|
2014-05-16 20:03:15 +04:00
|
|
|
}
|
|
|
|
return null;
|
2020-03-26 00:21:27 +03:00
|
|
|
});
|
2014-05-16 20:03:15 +04:00
|
|
|
|
|
|
|
$this->prepareLdapWrapperForConnections($ldap);
|
|
|
|
|
|
|
|
$ldap->expects($this->any())
|
|
|
|
->method('isResource')
|
2020-04-09 14:53:40 +03:00
|
|
|
->willReturnCallback(function ($res) {
|
2014-05-16 20:03:15 +04:00
|
|
|
return (bool)$res;
|
2020-03-26 00:21:27 +03:00
|
|
|
});
|
2014-05-16 20:03:15 +04:00
|
|
|
|
|
|
|
$ldap->expects($this->any())
|
|
|
|
->method('search')
|
|
|
|
//dummy value, usually invalid
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn(true);
|
2014-05-16 20:03:15 +04:00
|
|
|
|
|
|
|
$ldap->expects($this->any())
|
|
|
|
->method('countEntries')
|
|
|
|
//an is_resource check will follow, so we need to return a dummy resource
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn(7);
|
2014-05-16 20:03:15 +04:00
|
|
|
|
|
|
|
//5 DNs per filter means 2x firstEntry and 8x nextEntry
|
|
|
|
$ldap->expects($this->any())
|
|
|
|
->method('firstEntry')
|
|
|
|
//dummy value, usually invalid
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn(1);
|
2014-05-16 20:03:15 +04:00
|
|
|
|
|
|
|
global $mark;
|
|
|
|
$mark = false;
|
|
|
|
// entries return order: 1, 2, 3, 4, 4, 5, 6
|
|
|
|
$ldap->expects($this->any())
|
|
|
|
->method('nextEntry')
|
|
|
|
//dummy value, usually invalid
|
2020-04-09 14:53:40 +03:00
|
|
|
->willReturnCallback(function ($a, $prev) {
|
2014-05-16 20:03:15 +04:00
|
|
|
$current = $prev + 1;
|
|
|
|
if($current === 7) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
global $mark;
|
|
|
|
if($prev === 4 && !$mark) {
|
|
|
|
$mark = true;
|
|
|
|
return 4;
|
|
|
|
}
|
|
|
|
return $current;
|
2020-03-26 00:21:27 +03:00
|
|
|
});
|
2014-05-16 20:03:15 +04:00
|
|
|
|
|
|
|
$ldap->expects($this->any())
|
|
|
|
->method('getAttributes')
|
|
|
|
//dummy value, usually invalid
|
2020-04-09 14:53:40 +03:00
|
|
|
->willReturnCallback(function ($a, $entry) {
|
2020-03-26 11:30:18 +03:00
|
|
|
return ['cn' => [$entry], 'count' => 1];
|
2020-03-26 00:21:27 +03:00
|
|
|
});
|
2014-05-16 20:03:15 +04:00
|
|
|
|
|
|
|
$ldap->expects($this->any())
|
|
|
|
->method('getDN')
|
|
|
|
//dummy value, usually invalid
|
2020-04-09 14:53:40 +03:00
|
|
|
->willReturnCallback(function ($a, $b) {
|
2014-05-16 20:03:15 +04:00
|
|
|
return $b;
|
2020-03-26 00:21:27 +03:00
|
|
|
});
|
2014-05-16 20:03:15 +04:00
|
|
|
|
2015-07-21 23:19:53 +03:00
|
|
|
// The following expectations are the real test
|
2020-03-26 11:30:18 +03:00
|
|
|
$filters = ['f1', 'f2', '*'];
|
2014-08-26 12:50:00 +04:00
|
|
|
$resultArray = $wizard->cumulativeSearchOnAttribute($filters, 'cn', 0);
|
2014-05-16 20:03:15 +04:00
|
|
|
$this->assertSame(6, count($resultArray));
|
|
|
|
unset($mark);
|
|
|
|
}
|
|
|
|
|
2014-06-11 15:35:35 +04:00
|
|
|
}
|