Skip to content

Commit 0024df7

Browse files
committed
Merge branch '5.1' into 5.2
* 5.1: [Ldap] Fix undefined variable $con. Use GithubAction to run ldap tests Adds LDAP Adapter test in integration group Fix critical extension when reseting paged control Reinitialize globBrace after unserialization
2 parents bb9dca4 + 3b55ed7 commit 0024df7

File tree

8 files changed

+31
-48
lines changed

8 files changed

+31
-48
lines changed

Adapter/ExtLdap/EntryManager.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,9 @@ public function applyOperations(string $dn, iterable $operations): void
151151
$operationsMapped[] = $modification->toArray();
152152
}
153153

154-
if (!@ldap_modify_batch($this->getConnectionResource(), $dn, $operationsMapped)) {
155-
throw new UpdateOperationException(sprintf('Error executing UpdateOperation on "%s": ', $dn).ldap_error($this->getConnectionResource()), ldap_errno($con));
154+
$con = $this->getConnectionResource();
155+
if (!@ldap_modify_batch($con, $dn, $operationsMapped)) {
156+
throw new UpdateOperationException(sprintf('Error executing UpdateOperation on "%s": ', $dn).ldap_error($con), ldap_errno($con));
156157
}
157158
}
158159

Adapter/ExtLdap/Query.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ public function execute()
100100
$cookie = '';
101101
do {
102102
if ($pageControl) {
103-
$this->controlPagedResult($con, $pageSize, $cookie);
103+
$this->controlPagedResult($con, $pageSize, true, $cookie);
104104
}
105105
$sizeLimit = $itemsLeft;
106106
if ($pageSize > 0 && $sizeLimit >= $pageSize) {
@@ -174,7 +174,7 @@ public function getResources(): array
174174
private function resetPagination()
175175
{
176176
$con = $this->connection->getResource();
177-
$this->controlPagedResult($con, 0, '');
177+
$this->controlPagedResult($con, 0, false, '');
178178
$this->serverctrls = [];
179179

180180
// This is a workaround for a bit of a bug in the above invocation
@@ -204,15 +204,15 @@ private function resetPagination()
204204
*
205205
* @param resource $con
206206
*/
207-
private function controlPagedResult($con, int $pageSize, string $cookie): bool
207+
private function controlPagedResult($con, int $pageSize, bool $critical, string $cookie): bool
208208
{
209209
if (\PHP_VERSION_ID < 70300) {
210-
return ldap_control_paged_result($con, $pageSize, true, $cookie);
210+
return ldap_control_paged_result($con, $pageSize, $critical, $cookie);
211211
}
212212
$this->serverctrls = [
213213
[
214214
'oid' => \LDAP_CONTROL_PAGEDRESULTS,
215-
'isCritical' => true,
215+
'isCritical' => $critical,
216216
'value' => [
217217
'size' => $pageSize,
218218
'cookie' => $cookie,

Tests/Adapter/ExtLdap/AdapterTest.php

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,10 @@
2222

2323
/**
2424
* @requires extension ldap
25+
* @group integration
2526
*/
2627
class AdapterTest extends LdapTestCase
2728
{
28-
private const PAGINATION_REQUIRED_CONFIG = [
29-
'options' => [
30-
'protocol_version' => 3,
31-
],
32-
];
33-
3429
public function testLdapEscape()
3530
{
3631
$ldap = new Adapter();
@@ -122,7 +117,7 @@ public function testLdapQueryScopeOneLevel()
122117

123118
public function testLdapPagination()
124119
{
125-
$ldap = new Adapter(array_merge($this->getLdapConfig(), static::PAGINATION_REQUIRED_CONFIG));
120+
$ldap = new Adapter($this->getLdapConfig());
126121
$ldap->getConnection()->bind('cn=admin,dc=symfony,dc=com', 'symfony');
127122
$entries = $this->setupTestUsers($ldap);
128123

@@ -153,7 +148,7 @@ public function testLdapPagination()
153148
$this->assertEquals(\count($fully_paged_query->getResources()), 1);
154149
$this->assertEquals(\count($paged_query->getResources()), 5);
155150

156-
if (\PHP_MAJOR_VERSION > 7 || (\PHP_MAJOR_VERSION == 7 && \PHP_MINOR_VERSION >= 2)) {
151+
if (\PHP_VERSION_ID >= 70200) {
157152
// This last query is to ensure that we haven't botched the state of our connection
158153
// by not resetting pagination properly. extldap <= PHP 7.1 do not implement the necessary
159154
// bits to work around an implementation flaw, so we simply can't guarantee this to work there.
@@ -205,7 +200,7 @@ private function destroyEntries($ldap, $entries)
205200

206201
public function testLdapPaginationLimits()
207202
{
208-
$ldap = new Adapter(array_merge($this->getLdapConfig(), static::PAGINATION_REQUIRED_CONFIG));
203+
$ldap = new Adapter($this->getLdapConfig());
209204
$ldap->getConnection()->bind('cn=admin,dc=symfony,dc=com', 'symfony');
210205

211206
$entries = $this->setupTestUsers($ldap);

Tests/Adapter/ExtLdap/LdapManagerTest.php

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@
1515
use Symfony\Component\Ldap\Adapter\ExtLdap\Collection;
1616
use Symfony\Component\Ldap\Adapter\ExtLdap\UpdateOperation;
1717
use Symfony\Component\Ldap\Entry;
18-
use Symfony\Component\Ldap\Exception\AlreadyExistsException;
1918
use Symfony\Component\Ldap\Exception\LdapException;
2019
use Symfony\Component\Ldap\Exception\NotBoundException;
2120
use Symfony\Component\Ldap\Exception\UpdateOperationException;
2221
use Symfony\Component\Ldap\Tests\LdapTestCase;
2322

2423
/**
2524
* @requires extension ldap
25+
* @group integration
2626
*/
2727
class LdapManagerTest extends LdapTestCase
2828
{
@@ -82,7 +82,7 @@ public function testLdapAddInvalidEntry()
8282
*/
8383
public function testLdapAddDouble()
8484
{
85-
$this->expectException(AlreadyExistsException::class);
85+
$this->expectException(LdapException::class);
8686
$this->executeSearchQuery(1);
8787

8888
$entry = new Entry('cn=Elsa Amrouche,dc=symfony,dc=com', [
@@ -94,7 +94,11 @@ public function testLdapAddDouble()
9494

9595
$em = $this->adapter->getEntryManager();
9696
$em->add($entry);
97-
$em->add($entry);
97+
try {
98+
$em->add($entry);
99+
} finally {
100+
$em->remove($entry);
101+
}
98102
}
99103

100104
/**
@@ -210,11 +214,12 @@ public function testLdapRenameWithoutRemovingOldRdn()
210214
$newEntry = $result[0];
211215
$originalCN = $entry->getAttribute('cn')[0];
212216

213-
$this->assertStringContainsString($originalCN, $newEntry->getAttribute('cn'));
214-
215-
$entryManager->rename($newEntry, 'cn='.$originalCN);
216-
217-
$this->executeSearchQuery(1);
217+
try {
218+
$this->assertContains($originalCN, $newEntry->getAttribute('cn'));
219+
$this->assertContains('Kevin', $newEntry->getAttribute('cn'));
220+
} finally {
221+
$entryManager->rename($newEntry, 'cn='.$originalCN);
222+
}
218223
}
219224

220225
public function testLdapAddRemoveAttributeValues()
@@ -372,13 +377,16 @@ public function testLdapMove()
372377
$result = $this->executeSearchQuery(1);
373378

374379
$entry = $result[0];
375-
$this->assertNotContains('ou=Ldap', $entry->getDn());
380+
$this->assertStringNotContainsString('ou=Ldap', $entry->getDn());
376381

377382
$entryManager = $this->adapter->getEntryManager();
378383
$entryManager->move($entry, 'ou=Ldap,ou=Components,dc=symfony,dc=com');
379384

380385
$result = $this->executeSearchQuery(1);
381386
$movedEntry = $result[0];
382387
$this->assertStringContainsString('ou=Ldap', $movedEntry->getDn());
388+
389+
// Move back entry
390+
$entryManager->move($movedEntry, 'dc=symfony,dc=com');
383391
}
384392
}

Tests/Fixtures/conf/slapd.conf

Lines changed: 0 additions & 18 deletions
This file was deleted.

Tests/Fixtures/data/base.ldif

Lines changed: 0 additions & 4 deletions
This file was deleted.

Tests/LdapTestCase.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ class LdapTestCase extends TestCase
99
protected function getLdapConfig()
1010
{
1111
$h = @ldap_connect(getenv('LDAP_HOST'), getenv('LDAP_PORT'));
12+
@ldap_set_option($h, LDAP_OPT_PROTOCOL_VERSION, 3);
1213

1314
if (!$h || !@ldap_bind($h)) {
1415
$this->markTestSkipped('No server is listening on LDAP_HOST:LDAP_PORT');

phpunit.xml.dist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
>
1111
<php>
1212
<ini name="error_reporting" value="-1" />
13-
<env name="LDAP_HOST" value="127.0.0.1" />
13+
<env name="LDAP_HOST" value="localhost" />
1414
<env name="LDAP_PORT" value="3389" />
1515
</php>
1616

0 commit comments

Comments
 (0)