Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit af9562b

Browse files
lucasabajderusse
authored andcommitted
Adds LDAP Adapter test in integration group
Adds ext-ldap on github-actions
1 parent beeafb1 commit af9562b

File tree

9 files changed

+67
-19
lines changed

9 files changed

+67
-19
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
FROM osixia/openldap
2+
LABEL maintainer="[email protected]"
3+
ENV LDAP_ORGANISATION="Symfony"
4+
ENV LDAP_DOMAIN="symfony.com"
5+
ENV LDAP_ADMIN_PASSWORD="symfony"
6+
ENV LDAP_BASE_DN="dc=symfony,dc=com"
7+
ENV LDAP_SEED_INTERNAL_LDIF_PATH="/ldif-data"
8+
RUN mkdir /ldif-data
9+
COPY ./fixtures.ldif /ldif-data/50-fixtures.ldif
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
name: 'LDAP Populate'
2+
description: 'Create a pre-populated LDAP server with symfony test data'
3+
branding:
4+
icon: 'database'
5+
color: 'blue'
6+
7+
runs:
8+
using: 'docker'
9+
image: 'Dockerfile'
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
dn: cn=Fabien Potencier,dc=symfony,dc=com
2+
objectClass: inetOrgPerson
3+
objectClass: organizationalPerson
4+
objectClass: person
5+
objectClass: top
6+
cn: Fabien Potencier
7+
sn: fabpot
8+
9+
10+
ou: People
11+
ou: Maintainers
12+
ou: Founder
13+
givenName: Fabien Potencier
14+
description: Founder and project lead @Symfony
15+
16+
dn: ou=Components,dc=symfony,dc=com
17+
objectclass: organizationalunit
18+
ou: Components
19+
20+
dn: ou=Ldap,ou=Components,dc=symfony,dc=com
21+
objectclass: organizationalunit
22+
ou: Ldap
23+
24+
dn: ou=Ldap scoping,ou=Ldap,ou=Components,dc=symfony,dc=com
25+
objectclass: organizationalunit
26+
ou: Ldap scoping

.github/workflows/tests.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ jobs:
4545
- name: Checkout
4646
uses: actions/checkout@v2
4747

48+
- name: Populate LDAP
49+
uses: ./.github/actions/populate-ldap
50+
4851
- name: Setup PHP
4952
uses: shivammathur/setup-php@v2
5053
with:
@@ -87,6 +90,8 @@ jobs:
8790
MESSENGER_REDIS_DSN: redis://127.0.0.1:7006/messages
8891
MESSENGER_AMQP_DSN: amqp://localhost/%2f/messages
8992
MEMCACHED_HOST: localhost
93+
LDAP_HOST: localhost
94+
LDAP_PORT: 3389
9095

9196
- name: Run HTTP push tests
9297
if: matrix.php == '7.4'

.travis.yml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,6 @@ before_install:
5555
# General configuration
5656
set -e
5757
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 &
6358
cp .github/composer-config.json "$(composer config home)/config.json"
6459
export PHPUNIT=$(readlink -f ./phpunit)
6560
export PHPUNIT_X="$PHPUNIT --exclude-group tty,benchmark,intl-data"

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/Ldap/Tests/Adapter/ExtLdap/AdapterTest.php

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,6 @@
2525
*/
2626
class AdapterTest extends LdapTestCase
2727
{
28-
private const PAGINATION_REQUIRED_CONFIG = [
29-
'options' => [
30-
'protocol_version' => 3,
31-
],
32-
];
33-
3428
public function testLdapEscape()
3529
{
3630
$ldap = new Adapter();
@@ -122,7 +116,7 @@ public function testLdapQueryScopeOneLevel()
122116

123117
public function testLdapPagination()
124118
{
125-
$ldap = new Adapter(array_merge($this->getLdapConfig(), static::PAGINATION_REQUIRED_CONFIG));
119+
$ldap = new Adapter(array_merge($this->getLdapConfig()));
126120
$ldap->getConnection()->bind('cn=admin,dc=symfony,dc=com', 'symfony');
127121
$entries = $this->setupTestUsers($ldap);
128122

@@ -205,7 +199,7 @@ private function destroyEntries($ldap, $entries)
205199

206200
public function testLdapPaginationLimits()
207201
{
208-
$ldap = new Adapter(array_merge($this->getLdapConfig(), static::PAGINATION_REQUIRED_CONFIG));
202+
$ldap = new Adapter(array_merge($this->getLdapConfig()));
209203
$ldap->getConnection()->bind('cn=admin,dc=symfony,dc=com', 'symfony');
210204

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

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

Lines changed: 14 additions & 5 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,12 @@ public function testLdapAddDouble()
9494

9595
$em = $this->adapter->getEntryManager();
9696
$em->add($entry);
97-
$em->add($entry);
97+
try {
98+
$em->add($entry);
99+
} catch (LdapException $e) {
100+
$em->remove($entry);
101+
throw $e;
102+
}
98103
}
99104

100105
/**
@@ -210,7 +215,8 @@ public function testLdapRenameWithoutRemovingOldRdn()
210215
$newEntry = $result[0];
211216
$originalCN = $entry->getAttribute('cn')[0];
212217

213-
$this->assertStringContainsString($originalCN, $newEntry->getAttribute('cn'));
218+
$this->assertContains($originalCN, $newEntry->getAttribute('cn'));
219+
$this->assertContains('Kevin', $newEntry->getAttribute('cn'));
214220

215221
$entryManager->rename($newEntry, 'cn='.$originalCN);
216222

@@ -372,13 +378,16 @@ public function testLdapMove()
372378
$result = $this->executeSearchQuery(1);
373379

374380
$entry = $result[0];
375-
$this->assertNotContains('ou=Ldap', $entry->getDn());
381+
$this->assertStringNotContainsString('ou=Ldap', $entry->getDn());
376382

377383
$entryManager = $this->adapter->getEntryManager();
378384
$entryManager->move($entry, 'ou=Ldap,ou=Components,dc=symfony,dc=com');
379385

380386
$result = $this->executeSearchQuery(1);
381387
$movedEntry = $result[0];
382388
$this->assertStringContainsString('ou=Ldap', $movedEntry->getDn());
389+
390+
// Move back entry
391+
$entryManager->move($movedEntry, 'dc=symfony,dc=com');
383392
}
384393
}

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');

0 commit comments

Comments
 (0)