8000 Merge branch '4.4' into 5.1 · symfony/symfony@3372b3e · GitHub
[go: up one dir, main page]

Skip to content

Commit 3372b3e

Browse files
committed
Merge branch '4.4' into 5.1
* 4.4: 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 a71bce8 + 55707fb commit 3372b3e

File tree

12 files changed

+71
-63
lines changed

12 files changed

+71
-63
lines changed

.github/workflows/tests.yml

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,17 @@ jobs:
1515
php: ['7.2', '7.4']
1616

1717
services:
18+
ldap:
19+
image: bitnami/openldap
20+
ports:
21+
- 3389:3389
22+
env:
23+
LDAP_ADMIN_USERNAME: admin
24+
LDAP_ADMIN_PASSWORD: symfony
25+
LDAP_ROOT: dc=symfony,dc=com
26+
LDAP_PORT_NUMBER: 3389
27+
LDAP_USERS: a
28+
LDAP_PASSWORDS: a
1829
redis:
1930
image: redis:6.0.0
2031
ports:
@@ -99,11 +110,17 @@ jobs:
99110
uses: shivammathur/setup-php@v2
100111
with:
101112
coverage: "none"
102-
extensions: "json,couchbase,memcached,mongodb,redis,rdkafka,xsl"
113+
extensions: "json,couchbase,memcached,mongodb,redis,rdkafka,xsl,ldap"
103114
ini-values: "memory_limit=-1"
104115
php-version: "${{ matrix.php }}"
105116
tools: pecl
106117

118+
- name: Load fixtures
119+
uses: docker://bitnami/openldap
120+
with:
121+
entrypoint: /bin/bash
122+
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"
123+
107124
- name: Configure composer
108125
run: |
109126
COMPOSER_HOME="$(composer config home)"
@@ -132,7 +149,7 @@ jobs:
132149
echo "::endgroup::"
133150
134151
- name: Run tests
135-
run: ./phpunit --group integration
152+
run: ./phpunit --group integration -v
136153
env:
137154
REDIS_HOST: localhost
138155
REDIS_CLUSTER_HOSTS: 'localhost:7000 localhost:7001 localhost:7002 localhost:7003 localhost:7004 localhost:7005'
@@ -141,6 +158,8 @@ jobs:
141158
MESSENGER_SQS_DSN: "sqs://localhost:9494/messages?sslmode=disable&poll_timeout=0.01"
142159
MESSENGER_SQS_FIFO_QUEUE_DSN: "sqs://localhost:9494/messages.fifo?sslmode=disable&poll_timeout=0.01"
143160
MEMCACHED_HOST: localhost
161+
LDAP_HOST: localhost
162+
LDAP_PORT: 3389
144163
MONGODB_HOST: localhost
145164
KAFKA_BROKER: localhost:9092
146165

.travis.yml

Lines 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

Lines 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

Lines 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

Lines 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/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< 179B /span>,

src/Symfony/Component/Ldap/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);

src/Symfony/Component/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
}

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

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

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

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

src/Symfony/Component/Ldap/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');

src/Symfony/Component/Ldap/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)
0