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

Skip to content
Closed
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
12 changes: 9 additions & 3 deletions src/Symfony/Component/Ldap/Adapter/ExtLdap/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,6 @@ private function resetPagination()
{
$con = $this->connection->getResource();
$this->controlPagedResultResponse($con, 0, '');
Copy link
Member

@jderusse jderusse Oct 30, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at the original PR : https://github.com/symfony/symfony/pull/38392/files#diff-24b79f3ac1a99938f5acb158a450e38d30c1984a5d333b5b20f2c38a73d10e31L183-R177

I think the fix, should be to change this line to:

Suggested change
$this->controlPagedResultResponse($con, 0, '');
$this->controlPagedResult($con, 0, '');

and keep the rest of the code.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/cc @lucasaba

Copy link
Contributor

@lucasaba lucasaba Oct 30, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure. The original error is on #38874 is Warning: ldap_parse_result() expects parameter 2 to be resource, int given.

The only place where ldap_parse_result receive an in is when it is called from
$this->controlPagedResultResponse($con, 0, '');

I think the correct solutions is to call it with $this->controlPagedResultResponse($con, null, '');

But your proposal should work as well... I need to test it. I'll check with a working LDAP env.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lucasaba I think error on #38874 is a result of mistake on #38392
Why ldap_control_paged_result was replaced by controlPagedResultResponse, not controlPagedResult?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

my point is, when. you replaced ldap_parse_result() by controlPagedResult in #38392, in that line you replaced it by controlPagedResultResponse.

This explain why the second argument is 0 and not a ressources.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've created a new repository with a test openldap server with the configuration needed by symony's tests.
You can find it here: https://github.com/lucasaba/symfony-ldap-test-server

Just docker-compose up it and launch test suite.

@jderusse suggestion fixes the problem. But I need some more time to make other checks. I'm unable to delete entries and I'm not sure if the problem is the LDAP server or the code.

Copy link
Contributor

@lucasaba lucasaba Oct 31, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By the way: I had to modify AdapterTest and remove

const PAGINATION_REQUIRED_CONFIG = [
        'options' => [
            'protocol_version' => 3,
        ],
    ];

And I had to add, in LdapTestCase, after ldap_connect, the following:

ldap_set_option($h, LDAP_OPT_PROTOCOL_VERSION, 3);

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jderusse You're completly right! Its all my bad.
@Nek- I could launch locally the tests and they all pass. I should've done it earlier. I'm not able to add the ldap server on github actions because I still don't have enough knowledge.

To launch the tests, just clone https://github.com/lucasaba/symfony-ldap-test-server, build it and launch it. Then you can run phpunit against the LDAP tests.

Just some more notes (since you're working on it):

  • remove definition of the PAGINATION_REQUIRED_CONFIG constant from src/Symfony/Component/Ldap/Tests/Adapter/ExtLdap.php and all its reference from the same file (it doesn't work)
  • add ldap_set_option($h, LDAP_OPT_PROTOCOL_VERSION, 3); on src/Symfony/Component/Ldap/Tests/LdapTestCase.php just after the connection
  • at row 85, in src/Symfony/Component/Ldap/Tests/Adapter/ExtLdap/LdapManagerTest.php, modify the test. The exception is a LdapException. AlreadyExistsException is used for an already existing connection.
  • after the testLdapAddDouble there is a new entry ('cn=Elsa Amrouche,dc=symfony,dc=com'). This will break all successive tests.... you should find a way to remove the entry just after the test....
  • at row 213, in src/Symfony/Component/Ldap/Tests/Adapter/ExtLdap/LdapManagerTest.php substitute the line with:
// $newEntry->getAttribute('cn') returns an array not a string
$this->assertContains($originalCN, $newEntry->getAttribute('cn'));
$this->assertContains('Kevin', $newEntry->getAttribute('cn'));

Copy link
Contributor Author

@Nek- Nek- Nov 1, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Idk if it's related to be being under WSL ^^' but even with the docker it's not working (even with rebinding ports).

Since I can't run the whole test suite I think cleaning the test suite is not a super good idea since it's out of the scope of this PR.

$this->serverctrls = [];

// This is a workaround for a bit of a bug in the above invocation
// of ldap_control_paged_result. Instead of indicating to extldap that
Expand Down Expand Up @@ -226,16 +225,23 @@ private function controlPagedResult($con, int $pageSize, string $cookie): bool
/**
* Retrieve LDAP pagination cookie.
*
* @param resource $con
* @param resource $result
* @param resource $con
* @param resource|0 $result
*/
private function controlPagedResultResponse($con, $result, string $cookie = ''): string
{
$this->serverctrls = [];

if (\PHP_VERSION_ID < 70300) {
ldap_control_paged_result_response($con, $result, $cookie);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the point of calling this function when $result === null? Is that legal for its API?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hum. Not sure. It will probably return an empty string. I have to admit that I never paginated LDAP result so IDK. At least I should send 0 to keep compatibility.


return $cookie;
}

if (0 === $result) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to really be compatible and seamless, this should be an elseif - otherwise, we're affecting the behavior on php <=7.3.

a test case would really help if you can have a look

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a return in the previous if content, how can this impact the previous statements? 🤔

I was not able to run the test entire test suite on my computer :( . I'll give another try, but if you have any insights about running slapd that'd be great ^^' .

return '';
}

ldap_parse_result($con, $result, $errcode, $matcheddn, $errmsg, $referrals, $controls);

return $controls[\LDAP_CONTROL_PAGEDRESULTS]['value']['cookie'] ?? '';
Expand Down