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
This commit is contained in:
commit
2fa929133b
23
.github/workflows/tests.yml
vendored
23
.github/workflows/tests.yml
vendored
@ -21,6 +21,17 @@ jobs:
|
||||
- 5432:5432
|
||||
env:
|
||||
POSTGRES_PASSWORD: 'password'
|
||||
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:
|
||||
@ -105,11 +116,17 @@ jobs:
|
||||
uses: shivammathur/setup-php@v2
|
||||
with:
|
||||
coverage: "none"
|
||||
extensions: "json,couchbase,memcached,mongodb,redis,rdkafka,xsl"
|
||||
extensions: "json,couchbase,memcached,mongodb,redis,rdkafka,xsl,ldap"
|
||||
ini-values: "memory_limit=-1"
|
||||
php-version: "${{ matrix.php }}"
|
||||
tools: pecl
|
||||
|
||||
- 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)"
|
||||
@ -138,7 +155,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'
|
||||
@ -147,6 +164,8 @@ jobs:
|
||||
MESSENGER_SQS_DSN: "sqs://localhost:9494/messages?sslmode=disable&poll_timeout=0.01"
|
||||
MESSENGER_SQS_FIFO_QUEUE_DSN: "sqs://localhost:9494/messages.fifo?sslmode=disable&poll_timeout=0.01"
|
||||
MEMCACHED_HOST: localhost
|
||||
LDAP_HOST: localhost
|
||||
LDAP_PORT: 3389
|
||||
MONGODB_HOST: localhost
|
||||
KAFKA_BROKER: localhost:9092
|
||||
POSTGRES_HOST: localhost
|
||||
|
14
.travis.yml
14
.travis.yml
@ -9,8 +9,6 @@ addons:
|
||||
apt_packages:
|
||||
- parallel
|
||||
- language-pack-fr-base
|
||||
- ldap-utils
|
||||
- slapd
|
||||
- zookeeperd
|
||||
- libzookeeper-mt-dev
|
||||
|
||||
@ -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"
|
||||
@ -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
|
||||
|
@ -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" />
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
public function getIterator(): \Traversable
|
||||
{
|
||||
if (!file_exists($this->prefix) || (!$this->recursive && '' === $this->pattern)) {
|
||||
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
@ -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": ', $dn).ldap_error($this->getConnectionResource()), ldap_errno($con));
|
||||
$con = $this->getConnectionResource();
|
||||
if (!@ldap_modify_batch($con, $dn, $operationsMapped)) {
|
||||
throw new UpdateOperationException(sprintf('Error executing UpdateOperation on "%s": ', $dn).ldap_error($con), ldap_errno($con));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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,
|
||||
|
@ -22,15 +22,10 @@ use Symfony\Component\Ldap\Tests\LdapTestCase;
|
||||
|
||||
/**
|
||||
* @requires extension ldap
|
||||
* @group integration
|
||||
*/
|
||||
class AdapterTest extends LdapTestCase
|
||||
{
|
||||
private const PAGINATION_REQUIRED_CONFIG = [
|
||||
'options' => [
|
||||
'protocol_version' => 3,
|
||||
],
|
||||
];
|
||||
|
||||
public function testLdapEscape()
|
||||
{
|
||||
$ldap = new Adapter();
|
||||
@ -122,7 +117,7 @@ class AdapterTest extends LdapTestCase
|
||||
|
||||
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);
|
||||
|
||||
@ -153,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.
|
||||
@ -205,7 +200,7 @@ class AdapterTest extends LdapTestCase
|
||||
|
||||
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);
|
||||
|
@ -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,11 @@ class LdapManagerTest extends LdapTestCase
|
||||
|
||||
$em = $this->adapter->getEntryManager();
|
||||
$em->add($entry);
|
||||
try {
|
||||
$em->add($entry);
|
||||
} finally {
|
||||
$em->remove($entry);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -210,11 +214,12 @@ class LdapManagerTest extends LdapTestCase
|
||||
$newEntry = $result[0];
|
||||
$originalCN = $entry->getAttribute('cn')[0];
|
||||
|
||||
$this->assertStringContainsString($originalCN, $newEntry->getAttribute('cn'));
|
||||
|
||||
try {
|
||||
$this->assertContains($originalCN, $newEntry->getAttribute('cn'));
|
||||
$this->assertContains('Kevin', $newEntry->getAttribute('cn'));
|
||||
} finally {
|
||||
$entryManager->rename($newEntry, 'cn='.$originalCN);
|
||||
|
||||
$this->executeSearchQuery(1);
|
||||
}
|
||||
}
|
||||
|
||||
public function testLdapAddRemoveAttributeValues()
|
||||
@ -372,7 +377,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 +385,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');
|
||||
}
|
||||
}
|
||||
|
@ -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
|
@ -1,4 +0,0 @@
|
||||
dn: dc=symfony,dc=com
|
||||
objectClass: dcObject
|
||||
objectClass: organizationalUnit
|
||||
ou: Organization
|
@ -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');
|
||||
|
@ -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>
|
||||
|
||||
|
Reference in New Issue
Block a user