2014-03-20 19:17:51 -04:00
|
|
|
<?php
|
2024-05-29 05:32:54 -04:00
|
|
|
|
2025-05-28 03:50:46 -04:00
|
|
|
declare(strict_types=1);
|
2014-03-20 19:17:51 -04:00
|
|
|
/**
|
2024-05-29 05:32:54 -04:00
|
|
|
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
|
|
|
|
|
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
|
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
2015-03-26 06:44:34 -04:00
|
|
|
*/
|
2016-05-12 11:14:59 -04:00
|
|
|
namespace OCA\User_LDAP\Tests;
|
2014-03-20 19:17:51 -04:00
|
|
|
|
2017-11-03 12:40:05 -04:00
|
|
|
use OCA\User_LDAP\Access;
|
|
|
|
|
use OCA\User_LDAP\Configuration;
|
2016-09-02 05:02:12 -04:00
|
|
|
use OCA\User_LDAP\ILDAPWrapper;
|
2019-11-22 14:52:10 -05:00
|
|
|
use OCA\User_LDAP\Wizard;
|
2019-11-22 07:23:56 -05:00
|
|
|
use PHPUnit\Framework\MockObject\MockObject;
|
2017-11-03 12:40:05 -04:00
|
|
|
use Test\TestCase;
|
2014-03-20 19:17:51 -04:00
|
|
|
|
2015-11-25 10:58:54 -05:00
|
|
|
/**
|
|
|
|
|
* Class Test_Wizard
|
|
|
|
|
*
|
|
|
|
|
* @group DB
|
|
|
|
|
*
|
2016-05-12 11:14:59 -04:00
|
|
|
* @package OCA\User_LDAP\Tests
|
2015-11-25 10:58:54 -05:00
|
|
|
*/
|
2017-11-03 12:40:05 -04:00
|
|
|
class WizardTest extends TestCase {
|
2019-11-21 10:40:38 -05:00
|
|
|
protected function setUp(): void {
|
2014-11-10 16:28:12 -05:00
|
|
|
parent::setUp();
|
2014-03-21 05: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 04:30:18 -04:00
|
|
|
$ldapConsts = ['LDAP_OPT_PROTOCOL_VERSION',
|
2020-04-09 03:22:29 -04:00
|
|
|
'LDAP_OPT_REFERRALS', 'LDAP_OPT_NETWORK_TIMEOUT'];
|
2014-03-21 05:08:17 -04:00
|
|
|
foreach ($ldapConsts as $const) {
|
|
|
|
|
if (!defined($const)) {
|
|
|
|
|
define($const, 42);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-05-28 03:50:46 -04:00
|
|
|
private function getWizardAndMocks(): array {
|
2014-08-11 10:05:43 -04:00
|
|
|
static $confMethods;
|
2014-03-20 19:17:51 -04:00
|
|
|
|
2014-08-11 10:05:43 -04:00
|
|
|
if (is_null($confMethods)) {
|
2016-05-12 10:37:49 -04:00
|
|
|
$confMethods = get_class_methods('\OCA\User_LDAP\Configuration');
|
2014-03-20 19:17:51 -04:00
|
|
|
}
|
2025-05-28 03:50:46 -04:00
|
|
|
/** @var ILDAPWrapper&MockObject $lw */
|
2020-10-05 09:12:57 -04:00
|
|
|
$lw = $this->createMock(ILDAPWrapper::class);
|
2017-11-03 12:40:05 -04:00
|
|
|
|
2025-05-28 03:50:46 -04:00
|
|
|
/** @var Configuration&MockObject $conf */
|
2017-11-03 12:40:05 -04:00
|
|
|
$conf = $this->getMockBuilder(Configuration::class)
|
2025-05-28 03:50:46 -04:00
|
|
|
->onlyMethods($confMethods)
|
2022-03-03 10:35:06 -05:00
|
|
|
->setConstructorArgs(['', true])
|
2016-09-27 16:54:37 -04:00
|
|
|
->getMock();
|
|
|
|
|
|
2025-05-28 03:50:46 -04:00
|
|
|
/** @var Access&MockObject $access */
|
2017-11-03 12:40:05 -04:00
|
|
|
$access = $this->createMock(Access::class);
|
2014-06-25 11:36:19 -04:00
|
|
|
|
2020-03-26 04:30:18 -04:00
|
|
|
return [new Wizard($conf, $lw, $access), $conf, $lw, $access];
|
2014-03-20 19:17:51 -04:00
|
|
|
}
|
|
|
|
|
|
2025-05-28 03:50:46 -04:00
|
|
|
private function prepareLdapWrapperForConnections(MockObject $ldap) {
|
2014-03-20 19:17:51 -04:00
|
|
|
$ldap->expects($this->once())
|
|
|
|
|
->method('connect')
|
2024-04-04 11:37:19 -04:00
|
|
|
//dummy value
|
|
|
|
|
->willReturn(ldap_connect('ldap://example.com'));
|
2014-03-20 19:17:51 -04:00
|
|
|
|
|
|
|
|
$ldap->expects($this->exactly(3))
|
|
|
|
|
->method('setOption')
|
2020-03-25 17:21:27 -04:00
|
|
|
->willReturn(true);
|
2014-03-20 19:17:51 -04:00
|
|
|
|
|
|
|
|
$ldap->expects($this->once())
|
|
|
|
|
->method('bind')
|
2020-03-25 17:21:27 -04:00
|
|
|
->willReturn(true);
|
2014-03-20 19:17:51 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testCumulativeSearchOnAttributeLimited(): void {
|
2021-01-12 04:15:48 -05:00
|
|
|
[$wizard, $configuration, $ldap] = $this->getWizardAndMocks();
|
2014-03-20 19:17:51 -04:00
|
|
|
|
|
|
|
|
$configuration->expects($this->any())
|
|
|
|
|
->method('__get')
|
2020-04-09 07:53:40 -04:00
|
|
|
->willReturnCallback(function ($name) {
|
2014-03-20 19:17:51 -04:00
|
|
|
if ($name === 'ldapBase') {
|
2020-03-26 04:30:18 -04:00
|
|
|
return ['base'];
|
2014-03-20 19:17:51 -04:00
|
|
|
}
|
|
|
|
|
return null;
|
2020-03-25 17:21:27 -04:00
|
|
|
});
|
2014-03-20 19:17:51 -04:00
|
|
|
|
|
|
|
|
$this->prepareLdapWrapperForConnections($ldap);
|
|
|
|
|
|
|
|
|
|
$ldap->expects($this->any())
|
|
|
|
|
->method('isResource')
|
2020-03-25 17:21:27 -04:00
|
|
|
->willReturn(true);
|
2014-03-20 19:17:51 -04:00
|
|
|
|
|
|
|
|
$ldap->expects($this->exactly(2))
|
|
|
|
|
->method('search')
|
|
|
|
|
//dummy value, usually invalid
|
2020-03-25 17:21:27 -04:00
|
|
|
->willReturn(true);
|
2014-03-20 19: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-25 17:21:27 -04:00
|
|
|
->willReturn(23);
|
2014-03-20 19: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-25 17:21:27 -04:00
|
|
|
->willReturn(true);
|
2014-03-20 19:17:51 -04:00
|
|
|
|
|
|
|
|
$ldap->expects($this->exactly(8))
|
|
|
|
|
->method('nextEntry')
|
|
|
|
|
//dummy value, usually invalid
|
2020-03-25 17:21:27 -04:00
|
|
|
->willReturn(true);
|
2014-03-20 19:17:51 -04:00
|
|
|
|
|
|
|
|
$ldap->expects($this->exactly(10))
|
|
|
|
|
->method('getAttributes')
|
|
|
|
|
//dummy value, usually invalid
|
2020-03-26 04:30:18 -04:00
|
|
|
->willReturn(['cn' => ['foo'], 'count' => 1]);
|
2014-03-20 19:17:51 -04:00
|
|
|
|
|
|
|
|
global $uidnumber;
|
|
|
|
|
$uidnumber = 1;
|
|
|
|
|
$ldap->expects($this->exactly(10))
|
|
|
|
|
->method('getDN')
|
|
|
|
|
//dummy value, usually invalid
|
2020-04-09 07:53:40 -04:00
|
|
|
->willReturnCallback(function ($a, $b) {
|
2014-03-20 19:17:51 -04:00
|
|
|
global $uidnumber;
|
|
|
|
|
return $uidnumber++;
|
2020-03-25 17:21:27 -04:00
|
|
|
});
|
2014-03-20 19:17:51 -04:00
|
|
|
|
2015-07-21 16:19:53 -04:00
|
|
|
// The following expectations are the real test
|
2020-03-26 04:30:18 -04:00
|
|
|
$filters = ['f1', 'f2', '*'];
|
2014-06-11 07:35:35 -04:00
|
|
|
$wizard->cumulativeSearchOnAttribute($filters, 'cn', 5);
|
2014-03-20 19:17:51 -04:00
|
|
|
unset($uidnumber);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testCumulativeSearchOnAttributeUnlimited(): void {
|
2021-01-12 04:15:48 -05:00
|
|
|
[$wizard, $configuration, $ldap] = $this->getWizardAndMocks();
|
2014-03-20 19:17:51 -04:00
|
|
|
|
|
|
|
|
$configuration->expects($this->any())
|
|
|
|
|
->method('__get')
|
2020-04-09 07:53:40 -04:00
|
|
|
->willReturnCallback(function ($name) {
|
2014-03-20 19:17:51 -04:00
|
|
|
if ($name === 'ldapBase') {
|
2020-03-26 04:30:18 -04:00
|
|
|
return ['base'];
|
2014-03-20 19:17:51 -04:00
|
|
|
}
|
|
|
|
|
return null;
|
2020-03-25 17:21:27 -04:00
|
|
|
});
|
2014-03-20 19:17:51 -04:00
|
|
|
|
|
|
|
|
$this->prepareLdapWrapperForConnections($ldap);
|
|
|
|
|
|
|
|
|
|
$ldap->expects($this->any())
|
|
|
|
|
->method('isResource')
|
2020-04-09 07:53:40 -04:00
|
|
|
->willReturnCallback(function ($r) {
|
2024-04-04 11:37:19 -04:00
|
|
|
if ($r instanceof \LDAP\Connection) {
|
2014-03-20 19:17:51 -04:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
if ($r % 24 === 0) {
|
|
|
|
|
global $uidnumber;
|
|
|
|
|
$uidnumber++;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
2020-03-25 17:21:27 -04:00
|
|
|
});
|
2014-03-20 19:17:51 -04:00
|
|
|
|
|
|
|
|
$ldap->expects($this->exactly(2))
|
|
|
|
|
->method('search')
|
|
|
|
|
//dummy value, usually invalid
|
2020-03-25 17:21:27 -04:00
|
|
|
->willReturn(true);
|
2014-03-20 19: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-25 17:21:27 -04:00
|
|
|
->willReturn(23);
|
2014-03-20 19: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 07:53:40 -04:00
|
|
|
->willReturnCallback(function ($r) {
|
2014-03-20 19:17:51 -04:00
|
|
|
global $uidnumber;
|
|
|
|
|
return $uidnumber;
|
2020-03-25 17:21:27 -04:00
|
|
|
});
|
2014-03-20 19:17:51 -04:00
|
|
|
|
|
|
|
|
$ldap->expects($this->exactly(46))
|
|
|
|
|
->method('nextEntry')
|
|
|
|
|
//dummy value, usually invalid
|
2020-04-09 07:53:40 -04:00
|
|
|
->willReturnCallback(function ($r) {
|
2014-03-20 19:17:51 -04:00
|
|
|
global $uidnumber;
|
|
|
|
|
return $uidnumber;
|
2020-03-25 17:21:27 -04:00
|
|
|
});
|
2014-03-20 19:17:51 -04:00
|
|
|
|
|
|
|
|
$ldap->expects($this->exactly(46))
|
|
|
|
|
->method('getAttributes')
|
|
|
|
|
//dummy value, usually invalid
|
2020-03-26 04:30:18 -04:00
|
|
|
->willReturn(['cn' => ['foo'], 'count' => 1]);
|
2014-03-20 19:17:51 -04:00
|
|
|
|
|
|
|
|
global $uidnumber;
|
|
|
|
|
$uidnumber = 1;
|
|
|
|
|
$ldap->expects($this->exactly(46))
|
|
|
|
|
->method('getDN')
|
|
|
|
|
//dummy value, usually invalid
|
2020-04-09 07:53:40 -04:00
|
|
|
->willReturnCallback(function ($a, $b) {
|
2014-03-20 19:17:51 -04:00
|
|
|
global $uidnumber;
|
|
|
|
|
return $uidnumber++;
|
2020-03-25 17:21:27 -04:00
|
|
|
});
|
2014-03-20 19:17:51 -04:00
|
|
|
|
2015-07-21 16:19:53 -04:00
|
|
|
// The following expectations are the real test
|
2020-03-26 04:30:18 -04:00
|
|
|
$filters = ['f1', 'f2', '*'];
|
2014-06-11 07:35:35 -04:00
|
|
|
$wizard->cumulativeSearchOnAttribute($filters, 'cn', 0);
|
2014-03-20 19:17:51 -04:00
|
|
|
unset($uidnumber);
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-25 12:01:04 -04:00
|
|
|
public function testDetectEmailAttributeAlreadySet(): void {
|
2021-01-12 04:15:48 -05:00
|
|
|
[$wizard, $configuration, $ldap, $access]
|
2014-06-25 12:01:04 -04:00
|
|
|
= $this->getWizardAndMocks();
|
|
|
|
|
|
|
|
|
|
$configuration->expects($this->any())
|
|
|
|
|
->method('__get')
|
2020-03-25 17:21:27 -04:00
|
|
|
->willReturnCallback(function ($name) {
|
2014-06-25 12:01:04 -04:00
|
|
|
if ($name === 'ldapEmailAttribute') {
|
|
|
|
|
return 'myEmailAttribute';
|
|
|
|
|
} else {
|
|
|
|
|
//for requirement checks
|
|
|
|
|
return 'let me pass';
|
|
|
|
|
}
|
2020-03-25 17:21:27 -04:00
|
|
|
});
|
2014-06-25 12:01:04 -04:00
|
|
|
|
|
|
|
|
$access->expects($this->once())
|
|
|
|
|
->method('countUsers')
|
2020-03-25 17:21:27 -04:00
|
|
|
->willReturn(42);
|
2014-06-25 12:01:04 -04:00
|
|
|
|
|
|
|
|
$wizard->detectEmailAttribute();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testDetectEmailAttributeOverrideSet(): void {
|
2021-01-12 04:15:48 -05:00
|
|
|
[$wizard, $configuration, $ldap, $access]
|
2014-06-25 12:01:04 -04:00
|
|
|
= $this->getWizardAndMocks();
|
|
|
|
|
|
|
|
|
|
$configuration->expects($this->any())
|
|
|
|
|
->method('__get')
|
2020-03-25 17:21:27 -04:00
|
|
|
->willReturnCallback(function ($name) {
|
2014-06-25 12:01:04 -04:00
|
|
|
if ($name === 'ldapEmailAttribute') {
|
|
|
|
|
return 'myEmailAttribute';
|
|
|
|
|
} else {
|
|
|
|
|
//for requirement checks
|
|
|
|
|
return 'let me pass';
|
|
|
|
|
}
|
2020-03-25 17:21:27 -04:00
|
|
|
});
|
2014-06-25 12:01:04 -04:00
|
|
|
|
|
|
|
|
$access->expects($this->exactly(3))
|
|
|
|
|
->method('combineFilterWithAnd')
|
2020-03-25 17:21:27 -04:00
|
|
|
->willReturnCallback(function ($filterParts) {
|
2014-06-25 12:01:04 -04:00
|
|
|
return str_replace('=*', '', array_pop($filterParts));
|
2020-03-25 17:21:27 -04:00
|
|
|
});
|
2014-06-25 12:01:04 -04:00
|
|
|
|
|
|
|
|
$access->expects($this->exactly(3))
|
|
|
|
|
->method('countUsers')
|
2020-03-25 17:21:27 -04:00
|
|
|
->willReturnCallback(function ($filter) {
|
2014-06-25 12:01:04 -04:00
|
|
|
if ($filter === 'myEmailAttribute') {
|
|
|
|
|
return 0;
|
2020-04-10 04:35:09 -04:00
|
|
|
} elseif ($filter === 'mail') {
|
2014-06-25 12:01:04 -04:00
|
|
|
return 3;
|
2020-04-10 04:35:09 -04:00
|
|
|
} elseif ($filter === 'mailPrimaryAddress') {
|
2014-06-25 12:01:04 -04:00
|
|
|
return 17;
|
|
|
|
|
}
|
2015-04-18 09:09:15 -04:00
|
|
|
throw new \Exception('Untested filter: ' . $filter);
|
2020-03-25 17:21:27 -04:00
|
|
|
});
|
2014-06-25 12:01:04 -04:00
|
|
|
|
2014-06-25 13:38:54 -04:00
|
|
|
$result = $wizard->detectEmailAttribute()->getResultArray();
|
|
|
|
|
$this->assertSame('mailPrimaryAddress',
|
|
|
|
|
$result['changes']['ldap_email_attr']);
|
2014-06-25 12:01:04 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testDetectEmailAttributeFind(): void {
|
2021-01-12 04:15:48 -05:00
|
|
|
[$wizard, $configuration, $ldap, $access]
|
2014-06-25 12:01:04 -04:00
|
|
|
= $this->getWizardAndMocks();
|
|
|
|
|
|
|
|
|
|
$configuration->expects($this->any())
|
|
|
|
|
->method('__get')
|
2020-03-25 17:21:27 -04:00
|
|
|
->willReturnCallback(function ($name) {
|
2014-06-25 12:01:04 -04:00
|
|
|
if ($name === 'ldapEmailAttribute') {
|
|
|
|
|
return '';
|
|
|
|
|
} else {
|
|
|
|
|
//for requirement checks
|
|
|
|
|
return 'let me pass';
|
|
|
|
|
}
|
2020-03-25 17:21:27 -04:00
|
|
|
});
|
2014-06-25 12:01:04 -04:00
|
|
|
|
|
|
|
|
$access->expects($this->exactly(2))
|
|
|
|
|
->method('combineFilterWithAnd')
|
2020-03-25 17:21:27 -04:00
|
|
|
->willReturnCallback(function ($filterParts) {
|
2014-06-25 12:01:04 -04:00
|
|
|
return str_replace('=*', '', array_pop($filterParts));
|
2020-03-25 17:21:27 -04:00
|
|
|
});
|
2014-06-25 12:01:04 -04:00
|
|
|
|
|
|
|
|
$access->expects($this->exactly(2))
|
|
|
|
|
->method('countUsers')
|
2020-03-25 17:21:27 -04:00
|
|
|
->willReturnCallback(function ($filter) {
|
2014-06-25 12:01:04 -04:00
|
|
|
if ($filter === 'myEmailAttribute') {
|
|
|
|
|
return 0;
|
2020-04-10 04:35:09 -04:00
|
|
|
} elseif ($filter === 'mail') {
|
2014-06-25 12:01:04 -04:00
|
|
|
return 3;
|
2020-04-10 04:35:09 -04:00
|
|
|
} elseif ($filter === 'mailPrimaryAddress') {
|
2014-06-25 12:01:04 -04:00
|
|
|
return 17;
|
|
|
|
|
}
|
2015-04-18 09:09:15 -04:00
|
|
|
throw new \Exception('Untested filter: ' . $filter);
|
2020-03-25 17:21:27 -04:00
|
|
|
});
|
2014-06-25 12:01:04 -04:00
|
|
|
|
2014-06-25 13:38:54 -04:00
|
|
|
$result = $wizard->detectEmailAttribute()->getResultArray();
|
|
|
|
|
$this->assertSame('mailPrimaryAddress',
|
|
|
|
|
$result['changes']['ldap_email_attr']);
|
2014-06-25 12:01:04 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testDetectEmailAttributeFindNothing(): void {
|
2021-01-12 04:15:48 -05:00
|
|
|
[$wizard, $configuration, $ldap, $access]
|
2014-06-25 12:01:04 -04:00
|
|
|
= $this->getWizardAndMocks();
|
|
|
|
|
|
|
|
|
|
$configuration->expects($this->any())
|
|
|
|
|
->method('__get')
|
2020-03-25 17:21:27 -04:00
|
|
|
->willReturnCallback(function ($name) {
|
2014-06-25 12:01:04 -04:00
|
|
|
if ($name === 'ldapEmailAttribute') {
|
|
|
|
|
return 'myEmailAttribute';
|
|
|
|
|
} else {
|
|
|
|
|
//for requirement checks
|
|
|
|
|
return 'let me pass';
|
|
|
|
|
}
|
2020-03-25 17:21:27 -04:00
|
|
|
});
|
2014-06-25 12:01:04 -04:00
|
|
|
|
|
|
|
|
$access->expects($this->exactly(3))
|
|
|
|
|
->method('combineFilterWithAnd')
|
2020-03-25 17:21:27 -04:00
|
|
|
->willReturnCallback(function ($filterParts) {
|
2014-06-25 12:01:04 -04:00
|
|
|
return str_replace('=*', '', array_pop($filterParts));
|
2020-03-25 17:21:27 -04:00
|
|
|
});
|
2014-06-25 12:01:04 -04:00
|
|
|
|
|
|
|
|
$access->expects($this->exactly(3))
|
|
|
|
|
->method('countUsers')
|
2020-03-25 17:21:27 -04:00
|
|
|
->willReturnCallback(function ($filter) {
|
2014-06-25 12:01:04 -04:00
|
|
|
if ($filter === 'myEmailAttribute') {
|
|
|
|
|
return 0;
|
2020-04-10 04:35:09 -04:00
|
|
|
} elseif ($filter === 'mail') {
|
2014-06-25 12:01:04 -04:00
|
|
|
return 0;
|
2020-04-10 04:35:09 -04:00
|
|
|
} elseif ($filter === 'mailPrimaryAddress') {
|
2014-06-25 12:01:04 -04:00
|
|
|
return 0;
|
|
|
|
|
}
|
2015-04-18 09:09:15 -04:00
|
|
|
throw new \Exception('Untested filter: ' . $filter);
|
2020-03-25 17:21:27 -04:00
|
|
|
});
|
2014-06-25 12:01:04 -04:00
|
|
|
|
2014-06-25 13:38:54 -04:00
|
|
|
$result = $wizard->detectEmailAttribute();
|
2025-05-28 03:50:46 -04:00
|
|
|
$this->assertFalse($result->hasChanges());
|
2014-06-25 12:01:04 -04:00
|
|
|
}
|
|
|
|
|
|
2014-05-16 12:03:15 -04:00
|
|
|
public function testCumulativeSearchOnAttributeSkipReadDN(): void {
|
|
|
|
|
// tests that there is no infinite loop, when skipping already processed
|
|
|
|
|
// DNs (they can be returned multiple times for multiple filters )
|
2021-01-12 04:15:48 -05:00
|
|
|
[$wizard, $configuration, $ldap] = $this->getWizardAndMocks();
|
2014-05-16 12:03:15 -04:00
|
|
|
|
|
|
|
|
$configuration->expects($this->any())
|
|
|
|
|
->method('__get')
|
2020-04-09 07:53:40 -04:00
|
|
|
->willReturnCallback(function ($name) {
|
2014-05-16 12:03:15 -04:00
|
|
|
if ($name === 'ldapBase') {
|
2020-03-26 04:30:18 -04:00
|
|
|
return ['base'];
|
2014-05-16 12:03:15 -04:00
|
|
|
}
|
|
|
|
|
return null;
|
2020-03-25 17:21:27 -04:00
|
|
|
});
|
2014-05-16 12:03:15 -04:00
|
|
|
|
|
|
|
|
$this->prepareLdapWrapperForConnections($ldap);
|
|
|
|
|
|
|
|
|
|
$ldap->expects($this->any())
|
|
|
|
|
->method('isResource')
|
2020-04-09 07:53:40 -04:00
|
|
|
->willReturnCallback(function ($res) {
|
2014-05-16 12:03:15 -04:00
|
|
|
return (bool)$res;
|
2020-03-25 17:21:27 -04:00
|
|
|
});
|
2014-05-16 12:03:15 -04:00
|
|
|
|
|
|
|
|
$ldap->expects($this->any())
|
|
|
|
|
->method('search')
|
|
|
|
|
//dummy value, usually invalid
|
2020-03-25 17:21:27 -04:00
|
|
|
->willReturn(true);
|
2014-05-16 12: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-25 17:21:27 -04:00
|
|
|
->willReturn(7);
|
2014-05-16 12: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-25 17:21:27 -04:00
|
|
|
->willReturn(1);
|
2014-05-16 12: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 07:53:40 -04:00
|
|
|
->willReturnCallback(function ($a, $prev) {
|
2014-05-16 12: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-25 17:21:27 -04:00
|
|
|
});
|
2014-05-16 12:03:15 -04:00
|
|
|
|
|
|
|
|
$ldap->expects($this->any())
|
|
|
|
|
->method('getAttributes')
|
|
|
|
|
//dummy value, usually invalid
|
2020-04-09 07:53:40 -04:00
|
|
|
->willReturnCallback(function ($a, $entry) {
|
2020-03-26 04:30:18 -04:00
|
|
|
return ['cn' => [$entry], 'count' => 1];
|
2020-03-25 17:21:27 -04:00
|
|
|
});
|
2014-05-16 12:03:15 -04:00
|
|
|
|
|
|
|
|
$ldap->expects($this->any())
|
|
|
|
|
->method('getDN')
|
|
|
|
|
//dummy value, usually invalid
|
2020-04-09 07:53:40 -04:00
|
|
|
->willReturnCallback(function ($a, $b) {
|
2014-05-16 12:03:15 -04:00
|
|
|
return $b;
|
2020-03-25 17:21:27 -04:00
|
|
|
});
|
2014-05-16 12:03:15 -04:00
|
|
|
|
2015-07-21 16:19:53 -04:00
|
|
|
// The following expectations are the real test
|
2020-03-26 04:30:18 -04:00
|
|
|
$filters = ['f1', 'f2', '*'];
|
2014-08-26 04:50:00 -04:00
|
|
|
$resultArray = $wizard->cumulativeSearchOnAttribute($filters, 'cn', 0);
|
2025-05-28 03:50:46 -04:00
|
|
|
$this->assertCount(6, $resultArray);
|
2014-05-16 12:03:15 -04:00
|
|
|
unset($mark);
|
|
|
|
|
}
|
2014-06-11 07:35:35 -04:00
|
|
|
}
|