From d9534779cf838b3db2edaf3c81984808e7ff161d Mon Sep 17 00:00:00 2001 From: Wouter de Jong Date: Mon, 16 Nov 2020 12:15:53 +0100 Subject: [PATCH 1/5] Reinitialize globBrace after unserialization --- .../Component/Config/Resource/GlobResource.php | 8 ++++++++ .../Config/Tests/Resource/GlobResourceTest.php | 13 +++++++++++++ 2 files changed, 21 insertions(+) diff --git a/src/Symfony/Component/Config/Resource/GlobResource.php b/src/Symfony/Component/Config/Resource/GlobResource.php index 041b663f3e..f825a92911 100644 --- a/src/Symfony/Component/Config/Resource/GlobResource.php +++ b/src/Symfony/Component/Config/Resource/GlobResource.php @@ -94,6 +94,14 @@ class GlobResource implements \IteratorAggregate, SelfCheckingResourceInterface return ['prefix', 'pattern', 'recursive', 'hash', 'forExclusion', 'excludedPrefixes']; } + /** + * @internal + */ + public function __wakeup(): void + { + $this->globBrace = \defined('GLOB_BRACE') ? \GLOB_BRACE : 0; + } + /** * @return \Traversable */ diff --git a/src/Symfony/Component/Config/Tests/Resource/GlobResourceTest.php b/src/Symfony/Component/Config/Tests/Resource/GlobResourceTest.php index 2b6609d740..a30fbe8c43 100644 --- a/src/Symfony/Component/Config/Tests/Resource/GlobResourceTest.php +++ b/src/Symfony/Component/Config/Tests/Resource/GlobResourceTest.php @@ -194,4 +194,17 @@ class GlobResourceTest extends TestCase $this->assertSame([], array_keys(iterator_to_array($resource))); } + + public function testSerializeUnserialize() + { + $dir = \dirname(__DIR__).\DIRECTORY_SEPARATOR.'Fixtures'; + $resource = new GlobResource($dir, '/Resource', true); + + $newResource = unserialize(serialize($resource)); + + $p = new \ReflectionProperty($resource, 'globBrace'); + $p->setAccessible(true); + + $this->assertEquals($p->getValue($resource), $p->getValue($newResource)); + } } From a2b74762a61b99700981590c80d50409971fea98 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Deruss=C3=A9?= Date: Mon, 16 Nov 2020 12:44:36 +0100 Subject: [PATCH 2/5] Fix critical extension when reseting paged control --- src/Symfony/Component/Ldap/Adapter/ExtLdap/Query.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Symfony/Component/Ldap/Adapter/ExtLdap/Query.php b/src/Symfony/Component/Ldap/Adapter/ExtLdap/Query.php index 6bb798319c..4fa933a319 100644 --- a/src/Symfony/Component/Ldap/Adapter/ExtLdap/Query.php +++ b/src/Symfony/Component/Ldap/Adapter/ExtLdap/Query.php @@ -100,7 +100,7 @@ class Query extends AbstractQuery $cookie = ''; do { if ($pageControl) { - $this->controlPagedResult($con, $pageSize, $cookie); + $this->controlPagedResult($con, $pageSize, true, $cookie); } $sizeLimit = $itemsLeft; if ($pageSize > 0 && $sizeLimit >= $pageSize) { @@ -174,7 +174,7 @@ class Query extends AbstractQuery private function resetPagination() { $con = $this->connection->getResource(); - $this->controlPagedResult($con, 0, ''); + $this->controlPagedResult($con, 0, false, ''); $this->serverctrls = []; // This is a workaround for a bit of a bug in the above invocation @@ -204,15 +204,15 @@ class Query extends AbstractQuery * * @param resource $con */ - private function controlPagedResult($con, int $pageSize, string $cookie): bool + private function controlPagedResult($con, int $pageSize, bool $critical, string $cookie): bool { if (\PHP_VERSION_ID < 70300) { - return ldap_control_paged_result($con, $pageSize, true, $cookie); + return ldap_control_paged_result($con, $pageSize, $critical, $cookie); } $this->serverctrls = [ [ 'oid' => \LDAP_CONTROL_PAGEDRESULTS, - 'isCritical' => true, + 'isCritical' => $critical, 'value' => [ 'size' => $pageSize, 'cookie' => $cookie, From af9562b12c1590fb546e9fc4272a022fff46e9f4 Mon Sep 17 00:00:00 2001 From: Luca Saba Date: Mon, 2 Nov 2020 20:20:43 +0100 Subject: [PATCH 3/5] Adds LDAP Adapter test in integration group Adds ext-ldap on github-actions --- .../actions/populate-ldap/Dockerfile | 9 +++++++ .../actions/populate-ldap/action.yml | 9 +++++++ .../actions/populate-ldap/fixtures.ldif | 26 +++++++++++++++++++ .github/workflows/tests.yml | 5 ++++ .travis.yml | 5 ---- phpunit.xml.dist | 2 +- .../Tests/Adapter/ExtLdap/AdapterTest.php | 10 ++----- .../Tests/Adapter/ExtLdap/LdapManagerTest.php | 19 ++++++++++---- .../Component/Ldap/Tests/LdapTestCase.php | 1 + 9 files changed, 67 insertions(+), 19 deletions(-) create mode 100644 .github/workflows/actions/populate-ldap/Dockerfile create mode 100644 .github/workflows/actions/populate-ldap/action.yml create mode 100644 .github/workflows/actions/populate-ldap/fixtures.ldif diff --git a/.github/workflows/actions/populate-ldap/Dockerfile b/.github/workflows/actions/populate-ldap/Dockerfile new file mode 100644 index 0000000000..c256b27bf6 --- /dev/null +++ b/.github/workflows/actions/populate-ldap/Dockerfile @@ -0,0 +1,9 @@ +FROM osixia/openldap +LABEL maintainer="wshihadeh.devx@gmail.com" +ENV LDAP_ORGANISATION="Symfony" +ENV LDAP_DOMAIN="symfony.com" +ENV LDAP_ADMIN_PASSWORD="symfony" +ENV LDAP_BASE_DN="dc=symfony,dc=com" +ENV LDAP_SEED_INTERNAL_LDIF_PATH="/ldif-data" +RUN mkdir /ldif-data +COPY ./fixtures.ldif /ldif-data/50-fixtures.ldif diff --git a/.github/workflows/actions/populate-ldap/action.yml b/.github/workflows/actions/populate-ldap/action.yml new file mode 100644 index 0000000000..971d98a0fd --- /dev/null +++ b/.github/workflows/actions/populate-ldap/action.yml @@ -0,0 +1,9 @@ +name: 'LDAP Populate' +description: 'Create a pre-populated LDAP server with symfony test data' +branding: + icon: 'database' + color: 'blue' + +runs: + using: 'docker' + image: 'Dockerfile' diff --git a/.github/workflows/actions/populate-ldap/fixtures.ldif b/.github/workflows/actions/populate-ldap/fixtures.ldif new file mode 100644 index 0000000000..43842146b2 --- /dev/null +++ b/.github/workflows/actions/populate-ldap/fixtures.ldif @@ -0,0 +1,26 @@ +dn: cn=Fabien Potencier,dc=symfony,dc=com +objectClass: inetOrgPerson +objectClass: organizationalPerson +objectClass: person +objectClass: top +cn: Fabien Potencier +sn: fabpot +mail: fabpot@symfony.com +mail: fabien@potencier.com +ou: People +ou: Maintainers +ou: Founder +givenName: Fabien Potencier +description: Founder and project lead @Symfony + +dn: ou=Components,dc=symfony,dc=com +objectclass: organizationalunit +ou: Components + +dn: ou=Ldap,ou=Components,dc=symfony,dc=com +objectclass: organizationalunit +ou: Ldap + +dn: ou=Ldap scoping,ou=Ldap,ou=Components,dc=symfony,dc=com +objectclass: organizationalunit +ou: Ldap scoping diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index a5d6ea0e9a..c12a7339bb 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -45,6 +45,9 @@ jobs: - name: Checkout uses: actions/checkout@v2 + - name: Populate LDAP + uses: ./.github/actions/populate-ldap + - name: Setup PHP uses: shivammathur/setup-php@v2 with: @@ -87,6 +90,8 @@ jobs: MESSENGER_REDIS_DSN: redis://127.0.0.1:7006/messages MESSENGER_AMQP_DSN: amqp://localhost/%2f/messages MEMCACHED_HOST: localhost + LDAP_HOST: localhost + LDAP_PORT: 3389 - name: Run HTTP push tests if: matrix.php == '7.4' diff --git a/.travis.yml b/.travis.yml index b69c4567dd..cbb8984c88 100644 --- a/.travis.yml +++ b/.travis.yml @@ -55,11 +55,6 @@ before_install: # General configuration set -e stty cols 120 - mkdir /tmp/slapd - if [ ! -e /tmp/slapd-modules ]; then - [ -d /usr/lib/openldap ] && ln -s /usr/lib/openldap /tmp/slapd-modules || ln -s /usr/lib/ldap /tmp/slapd-modules - fi - slapd -f src/Symfony/Component/Ldap/Tests/Fixtures/conf/slapd.conf -h ldap://localhost:3389 & cp .github/composer-config.json "$(composer config home)/config.json" export PHPUNIT=$(readlink -f ./phpunit) export PHPUNIT_X="$PHPUNIT --exclude-group tty,benchmark,intl-data" diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 7313d16d25..d7f495fac7 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -15,7 +15,7 @@ - + diff --git a/src/Symfony/Component/Ldap/Tests/Adapter/ExtLdap/AdapterTest.php b/src/Symfony/Component/Ldap/Tests/Adapter/ExtLdap/AdapterTest.php index 11ad46544e..3447cdda96 100644 --- a/src/Symfony/Component/Ldap/Tests/Adapter/ExtLdap/AdapterTest.php +++ b/src/Symfony/Component/Ldap/Tests/Adapter/ExtLdap/AdapterTest.php @@ -25,12 +25,6 @@ use Symfony\Component\Ldap\Tests\LdapTestCase; */ class AdapterTest extends LdapTestCase { - private const PAGINATION_REQUIRED_CONFIG = [ - 'options' => [ - 'protocol_version' => 3, - ], - ]; - public function testLdapEscape() { $ldap = new Adapter(); @@ -122,7 +116,7 @@ class AdapterTest extends LdapTestCase public function testLdapPagination() { - $ldap = new Adapter(array_merge($this->getLdapConfig(), static::PAGINATION_REQUIRED_CONFIG)); + $ldap = new Adapter(array_merge($this->getLdapConfig())); $ldap->getConnection()->bind('cn=admin,dc=symfony,dc=com', 'symfony'); $entries = $this->setupTestUsers($ldap); @@ -205,7 +199,7 @@ class AdapterTest extends LdapTestCase public function testLdapPaginationLimits() { - $ldap = new Adapter(array_merge($this->getLdapConfig(), static::PAGINATION_REQUIRED_CONFIG)); + $ldap = new Adapter(array_merge($this->getLdapConfig())); $ldap->getConnection()->bind('cn=admin,dc=symfony,dc=com', 'symfony'); $entries = $this->setupTestUsers($ldap); diff --git a/src/Symfony/Component/Ldap/Tests/Adapter/ExtLdap/LdapManagerTest.php b/src/Symfony/Component/Ldap/Tests/Adapter/ExtLdap/LdapManagerTest.php index e23e801854..0fcbbfadec 100644 --- a/src/Symfony/Component/Ldap/Tests/Adapter/ExtLdap/LdapManagerTest.php +++ b/src/Symfony/Component/Ldap/Tests/Adapter/ExtLdap/LdapManagerTest.php @@ -15,7 +15,6 @@ use Symfony\Component\Ldap\Adapter\ExtLdap\Adapter; use Symfony\Component\Ldap\Adapter\ExtLdap\Collection; use Symfony\Component\Ldap\Adapter\ExtLdap\UpdateOperation; use Symfony\Component\Ldap\Entry; -use Symfony\Component\Ldap\Exception\AlreadyExistsException; use Symfony\Component\Ldap\Exception\LdapException; use Symfony\Component\Ldap\Exception\NotBoundException; use Symfony\Component\Ldap\Exception\UpdateOperationException; @@ -23,6 +22,7 @@ use Symfony\Component\Ldap\Tests\LdapTestCase; /** * @requires extension ldap + * @group integration */ class LdapManagerTest extends LdapTestCase { @@ -82,7 +82,7 @@ class LdapManagerTest extends LdapTestCase */ public function testLdapAddDouble() { - $this->expectException(AlreadyExistsException::class); + $this->expectException(LdapException::class); $this->executeSearchQuery(1); $entry = new Entry('cn=Elsa Amrouche,dc=symfony,dc=com', [ @@ -94,7 +94,12 @@ class LdapManagerTest extends LdapTestCase $em = $this->adapter->getEntryManager(); $em->add($entry); - $em->add($entry); + try { + $em->add($entry); + } catch (LdapException $e) { + $em->remove($entry); + throw $e; + } } /** @@ -210,7 +215,8 @@ class LdapManagerTest extends LdapTestCase $newEntry = $result[0]; $originalCN = $entry->getAttribute('cn')[0]; - $this->assertStringContainsString($originalCN, $newEntry->getAttribute('cn')); + $this->assertContains($originalCN, $newEntry->getAttribute('cn')); + $this->assertContains('Kevin', $newEntry->getAttribute('cn')); $entryManager->rename($newEntry, 'cn='.$originalCN); @@ -372,7 +378,7 @@ class LdapManagerTest extends LdapTestCase $result = $this->executeSearchQuery(1); $entry = $result[0]; - $this->assertNotContains('ou=Ldap', $entry->getDn()); + $this->assertStringNotContainsString('ou=Ldap', $entry->getDn()); $entryManager = $this->adapter->getEntryManager(); $entryManager->move($entry, 'ou=Ldap,ou=Components,dc=symfony,dc=com'); @@ -380,5 +386,8 @@ class LdapManagerTest extends LdapTestCase $result = $this->executeSearchQuery(1); $movedEntry = $result[0]; $this->assertStringContainsString('ou=Ldap', $movedEntry->getDn()); + + // Move back entry + $entryManager->move($movedEntry, 'dc=symfony,dc=com'); } } diff --git a/src/Symfony/Component/Ldap/Tests/LdapTestCase.php b/src/Symfony/Component/Ldap/Tests/LdapTestCase.php index 9a1424a62e..6caf659e09 100644 --- a/src/Symfony/Component/Ldap/Tests/LdapTestCase.php +++ b/src/Symfony/Component/Ldap/Tests/LdapTestCase.php @@ -9,6 +9,7 @@ class LdapTestCase extends TestCase protected function getLdapConfig() { $h = @ldap_connect(getenv('LDAP_HOST'), getenv('LDAP_PORT')); + ldap_set_option($h, LDAP_OPT_PROTOCOL_VERSION, 3); if (!$h || !@ldap_bind($h)) { $this->markTestSkipped('No server is listening on LDAP_HOST:LDAP_PORT'); From ea78f728b153fccc37f732c5f25c897b8dd3123c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Deruss=C3=A9?= Date: Mon, 16 Nov 2020 09:41:36 +0100 Subject: [PATCH 4/5] Use GithubAction to run ldap tests --- .../actions/populate-ldap/Dockerfile | 9 ------- .../actions/populate-ldap/action.yml | 9 ------- .../actions/populate-ldap/fixtures.ldif | 26 ------------------- .github/workflows/tests.yml | 24 +++++++++++++---- .travis.yml | 9 ------- .../Tests/Adapter/ExtLdap/AdapterTest.php | 7 ++--- .../Tests/Adapter/ExtLdap/LdapManagerTest.php | 15 +++++------ .../Ldap/Tests/Fixtures/conf/slapd.conf | 18 ------------- .../Ldap/Tests/Fixtures/data/base.ldif | 4 --- .../Component/Ldap/Tests/LdapTestCase.php | 2 +- src/Symfony/Component/Ldap/phpunit.xml.dist | 2 +- 11 files changed, 32 insertions(+), 93 deletions(-) delete mode 100644 .github/workflows/actions/populate-ldap/Dockerfile delete mode 100644 .github/workflows/actions/populate-ldap/action.yml delete mode 100644 .github/workflows/actions/populate-ldap/fixtures.ldif delete mode 100644 src/Symfony/Component/Ldap/Tests/Fixtures/conf/slapd.conf delete mode 100644 src/Symfony/Component/Ldap/Tests/Fixtures/data/base.ldif diff --git a/.github/workflows/actions/populate-ldap/Dockerfile b/.github/workflows/actions/populate-ldap/Dockerfile deleted file mode 100644 index c256b27bf6..0000000000 --- a/.github/workflows/actions/populate-ldap/Dockerfile +++ /dev/null @@ -1,9 +0,0 @@ -FROM osixia/openldap -LABEL maintainer="wshihadeh.devx@gmail.com" -ENV LDAP_ORGANISATION="Symfony" -ENV LDAP_DOMAIN="symfony.com" -ENV LDAP_ADMIN_PASSWORD="symfony" -ENV LDAP_BASE_DN="dc=symfony,dc=com" -ENV LDAP_SEED_INTERNAL_LDIF_PATH="/ldif-data" -RUN mkdir /ldif-data -COPY ./fixtures.ldif /ldif-data/50-fixtures.ldif diff --git a/.github/workflows/actions/populate-ldap/action.yml b/.github/workflows/actions/populate-ldap/action.yml deleted file mode 100644 index 971d98a0fd..0000000000 --- a/.github/workflows/actions/populate-ldap/action.yml +++ /dev/null @@ -1,9 +0,0 @@ -name: 'LDAP Populate' -description: 'Create a pre-populated LDAP server with symfony test data' -branding: - icon: 'database' - color: 'blue' - -runs: - using: 'docker' - image: 'Dockerfile' diff --git a/.github/workflows/actions/populate-ldap/fixtures.ldif b/.github/workflows/actions/populate-ldap/fixtures.ldif deleted file mode 100644 index 43842146b2..0000000000 --- a/.github/workflows/actions/populate-ldap/fixtures.ldif +++ /dev/null @@ -1,26 +0,0 @@ -dn: cn=Fabien Potencier,dc=symfony,dc=com -objectClass: inetOrgPerson -objectClass: organizationalPerson -objectClass: person -objectClass: top -cn: Fabien Potencier -sn: fabpot -mail: fabpot@symfony.com -mail: fabien@potencier.com -ou: People -ou: Maintainers -ou: Founder -givenName: Fabien Potencier -description: Founder and project lead @Symfony - -dn: ou=Components,dc=symfony,dc=com -objectclass: organizationalunit -ou: Components - -dn: ou=Ldap,ou=Components,dc=symfony,dc=com -objectclass: organizationalunit -ou: Ldap - -dn: ou=Ldap scoping,ou=Ldap,ou=Components,dc=symfony,dc=com -objectclass: organizationalunit -ou: Ldap scoping diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index c12a7339bb..efb905e996 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -15,6 +15,17 @@ jobs: php: ['7.1', '7.4'] services: + ldap: + image: bitnami/openldap + ports: + - 3389:3389 + env: + LDAP_ADMIN_USERNAME: admin + LDAP_ADMIN_PASSWORD: symfony + LDAP_ROOT: dc=symfony,dc=com + LDAP_PORT_NUMBER: 3389 + LDAP_USERS: a + LDAP_PASSWORDS: a redis: image: redis:6.0.0 ports: @@ -45,17 +56,20 @@ jobs: - name: Checkout uses: actions/checkout@v2 - - name: Populate LDAP - uses: ./.github/actions/populate-ldap - - name: Setup PHP uses: shivammathur/setup-php@v2 with: coverage: "none" - extensions: "memcached,redis,xsl" + extensions: "memcached,redis,xsl,ldap" ini-values: "memory_limit=-1" php-version: "${{ matrix.php }}" + - name: Load fixtures + uses: docker://bitnami/openldap + with: + entrypoint: /bin/bash + 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" + - name: Configure composer run: | COMPOSER_HOME="$(composer config home)" @@ -83,7 +97,7 @@ jobs: echo "::endgroup::" - name: Run tests - run: ./phpunit --group integration + run: ./phpunit --group integration -v env: REDIS_HOST: localhost REDIS_CLUSTER_HOSTS: 'localhost:7000 localhost:7001 localhost:7002 localhost:7003 localhost:7004 localhost:7005' diff --git a/.travis.yml b/.travis.yml index cbb8984c88..582625f988 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,8 +9,6 @@ addons: apt_packages: - parallel - language-pack-fr-base - - ldap-utils - - slapd - zookeeperd - libzookeeper-mt-dev @@ -164,13 +162,6 @@ before_install: tfold ext.redis tpecl redis-5.2.3 redis.so $INI "no" done - - | - # Load fixtures - if [[ ! $skip ]]; then - ldapadd -h localhost:3389 -D cn=admin,dc=symfony,dc=com -w symfony -f src/Symfony/Component/Ldap/Tests/Fixtures/data/base.ldif && - ldapadd -h localhost:3389 -D cn=admin,dc=symfony,dc=com -w symfony -f src/Symfony/Component/Ldap/Tests/Fixtures/data/fixtures.ldif - fi - install: - | # Install the phpunit-bridge from a PR if required diff --git a/src/Symfony/Component/Ldap/Tests/Adapter/ExtLdap/AdapterTest.php b/src/Symfony/Component/Ldap/Tests/Adapter/ExtLdap/AdapterTest.php index 3447cdda96..d7b06c6b35 100644 --- a/src/Symfony/Component/Ldap/Tests/Adapter/ExtLdap/AdapterTest.php +++ b/src/Symfony/Component/Ldap/Tests/Adapter/ExtLdap/AdapterTest.php @@ -22,6 +22,7 @@ use Symfony\Component\Ldap\Tests\LdapTestCase; /** * @requires extension ldap + * @group integration */ class AdapterTest extends LdapTestCase { @@ -116,7 +117,7 @@ class AdapterTest extends LdapTestCase public function testLdapPagination() { - $ldap = new Adapter(array_merge($this->getLdapConfig())); + $ldap = new Adapter($this->getLdapConfig()); $ldap->getConnection()->bind('cn=admin,dc=symfony,dc=com', 'symfony'); $entries = $this->setupTestUsers($ldap); @@ -147,7 +148,7 @@ class AdapterTest extends LdapTestCase $this->assertEquals(\count($fully_paged_query->getResources()), 1); $this->assertEquals(\count($paged_query->getResources()), 5); - if (\PHP_MAJOR_VERSION > 7 || (\PHP_MAJOR_VERSION == 7 && \PHP_MINOR_VERSION >= 2)) { + if (\PHP_VERSION_ID >= 70200) { // This last query is to ensure that we haven't botched the state of our connection // by not resetting pagination properly. extldap <= PHP 7.1 do not implement the necessary // bits to work around an implementation flaw, so we simply can't guarantee this to work there. @@ -199,7 +200,7 @@ class AdapterTest extends LdapTestCase public function testLdapPaginationLimits() { - $ldap = new Adapter(array_merge($this->getLdapConfig())); + $ldap = new Adapter($this->getLdapConfig()); $ldap->getConnection()->bind('cn=admin,dc=symfony,dc=com', 'symfony'); $entries = $this->setupTestUsers($ldap); diff --git a/src/Symfony/Component/Ldap/Tests/Adapter/ExtLdap/LdapManagerTest.php b/src/Symfony/Component/Ldap/Tests/Adapter/ExtLdap/LdapManagerTest.php index 0fcbbfadec..bfdd7d5342 100644 --- a/src/Symfony/Component/Ldap/Tests/Adapter/ExtLdap/LdapManagerTest.php +++ b/src/Symfony/Component/Ldap/Tests/Adapter/ExtLdap/LdapManagerTest.php @@ -96,9 +96,8 @@ class LdapManagerTest extends LdapTestCase $em->add($entry); try { $em->add($entry); - } catch (LdapException $e) { + } finally { $em->remove($entry); - throw $e; } } @@ -215,12 +214,12 @@ class LdapManagerTest extends LdapTestCase $newEntry = $result[0]; $originalCN = $entry->getAttribute('cn')[0]; - $this->assertContains($originalCN, $newEntry->getAttribute('cn')); - $this->assertContains('Kevin', $newEntry->getAttribute('cn')); - - $entryManager->rename($newEntry, 'cn='.$originalCN); - - $this->executeSearchQuery(1); + try { + $this->assertContains($originalCN, $newEntry->getAttribute('cn')); + $this->assertContains('Kevin', $newEntry->getAttribute('cn')); + } finally { + $entryManager->rename($newEntry, 'cn='.$originalCN); + } } public function testLdapAddRemoveAttributeValues() diff --git a/src/Symfony/Component/Ldap/Tests/Fixtures/conf/slapd.conf b/src/Symfony/Component/Ldap/Tests/Fixtures/conf/slapd.conf deleted file mode 100644 index 24eebcb2db..0000000000 --- a/src/Symfony/Component/Ldap/Tests/Fixtures/conf/slapd.conf +++ /dev/null @@ -1,18 +0,0 @@ -# See slapd.conf(5) for details on configuration options. -include /etc/ldap/schema/core.schema -include /etc/ldap/schema/cosine.schema -include /etc/ldap/schema/inetorgperson.schema -include /etc/ldap/schema/nis.schema - -pidfile /tmp/slapd/slapd.pid -argsfile /tmp/slapd/slapd.args - -modulepath /tmp/slapd-modules -moduleload back_hdb - -database hdb -directory /tmp/slapd - -suffix "dc=symfony,dc=com" -rootdn "cn=admin,dc=symfony,dc=com" -rootpw {SSHA}btWUi971ytYpVMbZLkaQ2A6ETh3VA0lL diff --git a/src/Symfony/Component/Ldap/Tests/Fixtures/data/base.ldif b/src/Symfony/Component/Ldap/Tests/Fixtures/data/base.ldif deleted file mode 100644 index 25abb296c9..0000000000 --- a/src/Symfony/Component/Ldap/Tests/Fixtures/data/base.ldif +++ /dev/null @@ -1,4 +0,0 @@ -dn: dc=symfony,dc=com -objectClass: dcObject -objectClass: organizationalUnit -ou: Organization diff --git a/src/Symfony/Component/Ldap/Tests/LdapTestCase.php b/src/Symfony/Component/Ldap/Tests/LdapTestCase.php index 6caf659e09..606065e491 100644 --- a/src/Symfony/Component/Ldap/Tests/LdapTestCase.php +++ b/src/Symfony/Component/Ldap/Tests/LdapTestCase.php @@ -9,7 +9,7 @@ class LdapTestCase extends TestCase protected function getLdapConfig() { $h = @ldap_connect(getenv('LDAP_HOST'), getenv('LDAP_PORT')); - ldap_set_option($h, LDAP_OPT_PROTOCOL_VERSION, 3); + @ldap_set_option($h, LDAP_OPT_PROTOCOL_VERSION, 3); if (!$h || !@ldap_bind($h)) { $this->markTestSkipped('No server is listening on LDAP_HOST:LDAP_PORT'); diff --git a/src/Symfony/Component/Ldap/phpunit.xml.dist b/src/Symfony/Component/Ldap/phpunit.xml.dist index e9861f8221..a679848078 100644 --- a/src/Symfony/Component/Ldap/phpunit.xml.dist +++ b/src/Symfony/Component/Ldap/phpunit.xml.dist @@ -10,7 +10,7 @@ > - + From 15da31686a5c095c0b06b876aec9a2a4bf55e2f8 Mon Sep 17 00:00:00 2001 From: "Alexander M. Turek" Date: Mon, 16 Nov 2020 18:05:55 +0100 Subject: [PATCH 5/5] [Ldap] Fix undefined variable $con. --- src/Symfony/Component/Ldap/Adapter/ExtLdap/EntryManager.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Component/Ldap/Adapter/ExtLdap/EntryManager.php b/src/Symfony/Component/Ldap/Adapter/ExtLdap/EntryManager.php index f34a559761..8ed1b7d668 100644 --- a/src/Symfony/Component/Ldap/Adapter/ExtLdap/EntryManager.php +++ b/src/Symfony/Component/Ldap/Adapter/ExtLdap/EntryManager.php @@ -151,8 +151,9 @@ class EntryManager implements EntryManagerInterface $operationsMapped[] = $modification->toArray(); } - if (!@ldap_modify_batch($this->getConnectionResource(), $dn, $operationsMapped)) { - throw new UpdateOperationException(sprintf('Error executing UpdateOperation on "%s": "%s".', $dn, ldap_error($this->getConnectionResource()))); + $con = $this->getConnectionResource(); + if (!@ldap_modify_batch($con, $dn, $operationsMapped)) { + throw new UpdateOperationException(sprintf('Error executing UpdateOperation on "%s": "%s".', $dn, ldap_error($con))); } }