Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 2fa9291

Browse filesBrowse files
committed
Merge branch '5.2' into 5.x
* 5.2: [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 2a453c2 + fb52afa commit 2fa9291
Copy full SHA for 2fa9291

File tree

Expand file treeCollapse file tree

13 files changed

+74
-65
lines changed
Filter options
Expand file treeCollapse file tree

13 files changed

+74
-65
lines changed

‎.github/workflows/tests.yml

Copy file name to clipboardExpand all lines: .github/workflows/tests.yml
+21-2Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,17 @@ jobs:
2121
- 5432:5432
2222
env:
2323
POSTGRES_PASSWORD: 'password'
24+
ldap:
25+
image: bitnami/openldap
26+
ports:
27+
- 3389:3389
28+
env:
29+
LDAP_ADMIN_USERNAME: admin
30+
LDAP_ADMIN_PASSWORD: symfony
31+
LDAP_ROOT: dc=symfony,dc=com
32+
LDAP_PORT_NUMBER: 3389
33+
LDAP_USERS: a
34+
LDAP_PASSWORDS: a
2435
redis:
2536
image: redis:6.0.0
2637
ports:
@@ -105,11 +116,17 @@ jobs:
105116
uses: shivammathur/setup-php@v2
106117
with:
107118
coverage: "none"
108-
extensions: "json,couchbase,memcached,mongodb,redis,rdkafka,xsl"
119+
extensions: "json,couchbase,memcached,mongodb,redis,rdkafka,xsl,ldap"
109120
ini-values: "memory_limit=-1"
110121
php-version: "${{ matrix.php }}"
111122
tools: pecl
112123

124+
- name: Load fixtures
125+
uses: docker://bitnami/openldap
126+
with:
127+
entrypoint: /bin/bash
128+
args: -c "(ldapwhoami -h localhost:3389 -D cn=admin,dc=symfony,dc=com -w symfony||sleep 5) && ldapadd -h ldap:3389 -D cn=admin,dc=symfony,dc=com -w symfony -f src/Symfony/Component/Ldap/Tests/Fixtures/data/fixtures.ldif && ldapdelete -h ldap:3389 -D cn=admin,dc=symfony,dc=com -w symfony cn=a,ou=users,dc=symfony,dc=com"
129+
113130
- name: Configure composer
114131
run: |
115132
COMPOSER_HOME="$(composer config home)"
@@ -138,7 +155,7 @@ jobs:
138155
echo "::endgroup::"
139156
140157
- name: Run tests
141-
run: ./phpunit --group integration
158+
run: ./phpunit --group integration -v
142159
env:
143160
REDIS_HOST: localhost
144161
REDIS_CLUSTER_HOSTS: 'localhost:7000 localhost:7001 localhost:7002 localhost:7003 localhost:7004 localhost:7005'
@@ -147,6 +164,8 @@ jobs:
147164
MESSENGER_SQS_DSN: "sqs://localhost:9494/messages?sslmode=disable&poll_timeout=0.01"
148165
MESSENGER_SQS_FIFO_QUEUE_DSN: "sqs://localhost:9494/messages.fifo?sslmode=disable&poll_timeout=0.01"
149166
MEMCACHED_HOST: localhost
167+
LDAP_HOST: localhost
168+
LDAP_PORT: 3389
150169
MONGODB_HOST: localhost
151170
KAFKA_BROKER: localhost:9092
152171
POSTGRES_HOST: localhost

‎.travis.yml

Copy file name to clipboardExpand all lines: .travis.yml
-14Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ addons:
99
apt_packages:
1010
- parallel
1111
- language-pack-fr-base
12-
- ldap-utils
13-
- slapd
1412
- zookeeperd
1513
- libzookeeper-mt-dev
1614

@@ -55,11 +53,6 @@ before_install:
5553
# General configuration
5654
set -e
5755
stty cols 120
58-
mkdir /tmp/slapd
59-
if [ ! -e /tmp/slapd-modules ]; then
60-
[ -d /usr/lib/openldap ] && ln -s /usr/lib/openldap /tmp/slapd-modules || ln -s /usr/lib/ldap /tmp/slapd-modules
61-
fi
62-
slapd -f src/Symfony/Component/Ldap/Tests/Fixtures/conf/slapd.conf -h ldap://localhost:3389 &
6356
cp .github/composer-config.json "$(composer config home)/config.json"
6457
export PHPUNIT=$(readlink -f ./phpunit)
6558
export PHPUNIT_X="$PHPUNIT --exclude-group tty,benchmark,intl-data"
@@ -169,13 +162,6 @@ before_install:
169162
tfold ext.redis tpecl redis-5.2.3 redis.so $INI "no"
170163
done
171164
172-
- |
173-
# Load fixtures
174-
if [[ ! $skip ]]; then
175-
ldapadd -h localhost:3389 -D cn=admin,dc=symfony,dc=com -w symfony -f src/Symfony/Component/Ldap/Tests/Fixtures/data/base.ldif &&
176-
ldapadd -h localhost:3389 -D cn=admin,dc=symfony,dc=com -w symfony -f src/Symfony/Component/Ldap/Tests/Fixtures/data/fixtures.ldif
177-
fi
178-
179165
install:
180166
- |
181167
# Install the phpunit-bridge from a PR if required

‎phpunit.xml.dist

Copy file name to clipboardExpand all lines: phpunit.xml.dist
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<ini name="memory_limit" value="-1" />
1616
<env name="DUMP_LIGHT_ARRAY" value="" />
1717
<env name="DUMP_STRING_LENGTH" value="" />
18-
<env name="LDAP_HOST" value="127.0.0.1" />
18+
<env name="LDAP_HOST" value="localhost" />
1919
<env name="LDAP_PORT" value="3389" />
2020
<env name="REDIS_HOST" value="localhost" />
2121
<env name="MEMCACHED_HOST" value="localhost" />

‎src/Symfony/Component/Config/Resource/GlobResource.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Config/Resource/GlobResource.php
+8Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,14 @@ public function __sleep(): array
9494
return ['prefix', 'pattern', 'recursive', 'hash', 'forExclusion', 'excludedPrefixes'];
9595
}
9696

97+
/**
98+
* @internal
99+
*/
100+
public function __wakeup(): void
101+
{
102+
$this->globBrace = \defined('GLOB_BRACE') ? \GLOB_BRACE : 0;
103+
}
104+
97105
public function getIterator(): \Traversable
98106
{
99107
if (!file_exists($this->prefix) || (!$this->recursive && '' === $this->pattern)) {

‎src/Symfony/Component/Config/Tests/Resource/GlobResourceTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Config/Tests/Resource/GlobResourceTest.php
+13Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,4 +194,17 @@ public function testUnbalancedBraceFallback()
194194

195195
$this->assertSame([], array_keys(iterator_to_array($resource)));
196196
}
197+
198+
public function testSerializeUnserialize()
199+
{
200+
$dir = \dirname(__DIR__).\DIRECTORY_SEPARATOR.'Fixtures';
201+
$resource = new GlobResource($dir, '/Resource', true);
202+
203+
$newResource = unserialize(serialize($resource));
204+
205+
$p = new \ReflectionProperty($resource, 'globBrace');
206+
$p->setAccessible(true);
207+
208+
$this->assertEquals($p->getValue($resource), $p->getValue($newResource));
209+
}
197210
}

‎src/Symfony/Component/Ldap/Adapter/ExtLdap/EntryManager.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Ldap/Adapter/ExtLdap/EntryManager.php
+3-2Lines 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

‎src/Symfony/Component/Ldap/Adapter/ExtLdap/Query.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Ldap/Adapter/ExtLdap/Query.php
+5-5Lines 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,

‎src/Symfony/Component/Ldap/Tests/Adapter/ExtLdap/AdapterTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Ldap/Tests/Adapter/ExtLdap/AdapterTest.php
+4-9Lines 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);

‎src/Symfony/Component/Ldap/Tests/Adapter/ExtLdap/LdapManagerTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Ldap/Tests/Adapter/ExtLdap/LdapManagerTest.php
+17-9Lines 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
}

‎src/Symfony/Component/Ldap/Tests/Fixtures/conf/slapd.conf

Copy file name to clipboardExpand all lines: src/Symfony/Component/Ldap/Tests/Fixtures/conf/slapd.conf
-18Lines changed: 0 additions & 18 deletions
This file was deleted.

‎src/Symfony/Component/Ldap/Tests/Fixtures/data/base.ldif

Copy file name to clipboardExpand all lines: src/Symfony/Component/Ldap/Tests/Fixtures/data/base.ldif
-4Lines changed: 0 additions & 4 deletions
This file was deleted.

‎src/Symfony/Component/Ldap/Tests/LdapTestCase.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Ldap/Tests/LdapTestCase.php
+1Lines 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');

‎src/Symfony/Component/Ldap/phpunit.xml.dist

Copy file name to clipboardExpand all lines: src/Symfony/Component/Ldap/phpunit.xml.dist
+1-1Lines 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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.