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

Skip to content

Commit 72765b9

Browse files
committed
Use GithubAction to run ldap tests
1 parent 8c4b310 commit 72765b9

File tree

9 files changed

+38
-66
lines changed

9 files changed

+38
-66
lines changed

.github/workflows/actions/populate-ldap/Dockerfile

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

.github/workflows/actions/populate-ldap/action.yml

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

.github/workflows/actions/populate-ldap/fixtures.ldif

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

.github/workflows/tests.yml

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,17 @@ jobs:
1515
php: ['7.1', '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:
@@ -40,21 +51,26 @@ jobs:
4051
image: rabbitmq:3.8.3
4152
ports:
4253
- 5672:5672
54+
55+
4356
steps:
4457
- name: Checkout
4558
uses: actions/checkout@v2
4659

47-
- name: Populate LDAP
48-
uses: ./.github/actions/populate-ldap
49-
5060
- name: Setup PHP
5161
uses: shivammathur/setup-php@v2
5262
with:
5363
coverage: "none"
54-
extensions: "memcached,redis,xsl"
64+
extensions: "memcached,redis,xsl,ldap"
5565
ini-values: "memory_limit=-1"
5666
php-version: "${{ matrix.php }}"
5767

68+
- name: Load fixtures
69+
uses: docker://bitnami/openldap
70+
with:
71+
entrypoint: /bin/bash
72+
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"
73+
5874
- name: Configure composer
5975
run: |
6076
COMPOSER_HOME="$(composer config home)"

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,

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
/**
2424
* @requires extension ldap
25+
* @group integration
2526
*/
2627
class AdapterTest extends LdapTestCase
2728
{
@@ -116,7 +117,7 @@ public function testLdapQueryScopeOneLevel()
116117

117118
public function testLdapPagination()
118119
{
119-
$ldap = new Adapter(array_merge($this->getLdapConfig()));
120+
$ldap = new Adapter($this->getLdapConfig());
120121
$ldap->getConnection()->bind('cn=admin,dc=symfony,dc=com', 'symfony');
121122
$entries = $this->setupTestUsers($ldap);
122123

@@ -147,7 +148,7 @@ public function testLdapPagination()
147148
$this->assertEquals(\count($fully_paged_query->getResources()), 1);
148149
$this->assertEquals(\count($paged_query->getResources()), 5);
149150

150-
if (\PHP_MAJOR_VERSION > 7 || (\PHP_MAJOR_VERSION == 7 && \PHP_MINOR_VERSION >= 2)) {
151+
if (\PHP_VERSION_ID >= 70200) {
151152
// This last query is to ensure that we haven't botched the state of our connection
152153
// by not resetting pagination properly. extldap <= PHP 7.1 do not implement the necessary
153154
// bits to work around an implementation flaw, so we simply can't guarantee this to work there.
@@ -199,7 +200,7 @@ private function destroyEntries($ldap, $entries)
199200

200201
public function testLdapPaginationLimits()
201202
{
202-
$ldap = new Adapter(array_merge($this->getLdapConfig()));
203+
$ldap = new Adapter($this->getLdapConfig());
203204
$ldap->getConnection()->bind('cn=admin,dc=symfony,dc=com', 'symfony');
204205

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

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

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,8 @@ public function testLdapAddDouble()
9696
$em->add($entry);
9797
try {
9898
$em->add($entry);
99-
} catch (LdapException $e) {
99+
} finally {
100100
$em->remove($entry);
101-
throw $e;
102101
}
103102
}
104103

@@ -215,12 +214,12 @@ public function testLdapRenameWithoutRemovingOldRdn()
215214
$newEntry = $result[0];
216215
$originalCN = $entry->getAttribute('cn')[0];
217216

218-
$this->assertContains($originalCN, $newEntry->getAttribute('cn'));
219-
$this->assertContains('Kevin', $newEntry->getAttribute('cn'));
220-
221-
$entryManager->rename($newEntry, 'cn='.$originalCN);
222-
223-
$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+
}
224223
}
225224

226225
public function testLdapAddRemoveAttributeValues()

src/Symfony/Component/Ldap/Tests/LdapTestCase.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +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);
12+
@ldap_set_option($h, LDAP_OPT_PROTOCOL_VERSION, 3);
1313

1414
if (!$h || !@ldap_bind($h)) {
1515
$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)