Skip to content

[LDAP] Add ldap tests to github CI #39030

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -49,10 +60,16 @@ jobs:
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)"
Expand Down Expand Up @@ -80,13 +97,15 @@ 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'
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'
Expand Down
14 changes: 0 additions & 14 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ addons:
apt_packages:
- parallel
- language-pack-fr-base
- ldap-utils
- slapd
- zookeeperd
- libzookeeper-mt-dev

Expand Down Expand Up @@ -55,11 +53,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"
Expand Down Expand Up @@ -169,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
Expand Down
2 changes: 1 addition & 1 deletion phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<ini name="memory_limit" value="-1" />
<env name="DUMP_LIGHT_ARRAY" value="" />
<env name="DUMP_STRING_LENGTH" value="" />
<env name="LDAP_HOST" value="127.0.0.1" />
<env name="LDAP_HOST" value="localhost" />
<env name="LDAP_PORT" value="3389" />
<env name="REDIS_HOST" value="localhost" />
<env name="MEMCACHED_HOST" value="localhost" />
Expand Down
13 changes: 4 additions & 9 deletions src/Symfony/Component/Ldap/Tests/Adapter/ExtLdap/AdapterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,10 @@

/**
* @requires extension ldap
* @group integration
*/
class AdapterTest extends LdapTestCase
{
private const PAGINATION_REQUIRED_CONFIG = [
'options' => [
'protocol_version' => 3,
],
];

public function testLdapEscape()
{
$ldap = new Adapter();
Expand Down Expand Up @@ -122,7 +117,7 @@ public function testLdapQueryScopeOneLevel()

public function testLdapPagination()
{
$ldap = new Adapter(array_merge($this->getLdapConfig(), static::PAGINATION_REQUIRED_CONFIG));
$ldap = new Adapter($this->getLdapConfig());
$ldap->getConnection()->bind('cn=admin,dc=symfony,dc=com', 'symfony');
$entries = $this->setupTestUsers($ldap);

Expand Down Expand Up @@ -153,7 +148,7 @@ public function testLdapPagination()
$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.
Expand Down Expand Up @@ -205,7 +200,7 @@ private function destroyEntries($ldap, $entries)

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

$entries = $this->setupTestUsers($ldap);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@
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;
use Symfony\Component\Ldap\Tests\LdapTestCase;

/**
* @requires extension ldap
* @group integration
*/
class LdapManagerTest extends LdapTestCase
{
Expand Down Expand Up @@ -82,7 +82,7 @@ public function testLdapAddInvalidEntry()
*/
public function testLdapAddDouble()
{
$this->expectException(AlreadyExistsException::class);
$this->expectException(LdapException::class);
$this->executeSearchQuery(1);

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

$em = $this->adapter->getEntryManager();
$em->add($entry);
$em->add($entry);
try {
$em->add($entry);
} finally {
$em->remove($entry);
}
}

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

$this->assertStringContainsString($originalCN, $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()
Expand Down Expand Up @@ -372,13 +377,16 @@ public function testLdapMove()
$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');

$result = $this->executeSearchQuery(1);
$movedEntry = $result[0];
$this->assertStringContainsString('ou=Ldap', $movedEntry->getDn());

// Move back entry
$entryManager->move($movedEntry, 'dc=symfony,dc=com');
}
}
18 changes: 0 additions & 18 deletions src/Symfony/Component/Ldap/Tests/Fixtures/conf/slapd.conf

This file was deleted.

4 changes: 0 additions & 4 deletions src/Symfony/Component/Ldap/Tests/Fixtures/data/base.ldif

This file was deleted.

1 change: 1 addition & 0 deletions src/Symfony/Component/Ldap/Tests/LdapTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/Ldap/phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
>
<php>
<ini name="error_reporting" value="-1" />
<env name="LDAP_HOST" value="127.0.0.1" />
<env name="LDAP_HOST" value="localhost" />
<env name="LDAP_PORT" value="3389" />
</php>

Expand Down