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

Conversation

lucasaba
Copy link
Contributor

@lucasaba lucasaba commented Nov 7, 2020

Q A
Branch? 4.4
Bug fix? yes
New feature? no
Deprecations? no
Tickets Fix #39028
License MIT
Doc PR

Adds LDAP test on github actions pipeline and corrects sum bugs in the LDAP Component test

It also adds a bug resolution from @Nek- made in #38875

@wouterj
Copy link
Member

wouterj commented Nov 7, 2020

Thank you for starting this PR! Adding LDAP integration tests to the already complex CI set-up of Symfony is a really brave task :)

Let's start with a big disclaimer: I've never used LDAP before, so my knowledge about it is very weak.

Can you maybe share why a custom docker image was used (instead of semi-official ones like bitnami/openldap)?
I think it would be good to explore how we can remove this "dependency" on a custom image, in order to reduce maintenance work (and depending on images maintained by a single author is a bit more "risky" than depending on an image maintained by a community or company).

@jderusse jderusse mentioned this pull request Nov 7, 2020
@lucasaba
Copy link
Contributor Author

lucasaba commented Nov 7, 2020

Well, honestly I'm not into LDAP too. I've just used it for authentication. But I've made a PR which led to a bug that would have been avoided if I had been more accurate with tests. So... this is my way to ask forgiveness..

You're absolutely right: introducing a dependency on a custom image would absolutely be risky. I needed to do it because I needed to push some initial data to the LDAP server, namely, those in the test env. And it is precisely what I do in my custom Dockerfile: I create a folder where I store the data and copy it there. Then, with the env, I tell the image to load it.

I think, the best aproach would be to use the standard image and then, add a step in the action, that pushes the data to the server. In order to do that I should use some command line program like ldapadd. And thats where I'm stuck...

Another way would be to create a custom action, which would lead to tha same problem as having a custom docker image.

@derrabus
Copy link
Member

derrabus commented Nov 7, 2020

If we really need a custom image (which I'd like to avoid), we should move its maintenance this this repository or at least a repository within the Symfony organization.

@jderusse
Copy link
Member

jderusse commented Nov 7, 2020

If we really need a custom image (which I'd like to avoid), we should move its maintenance this this repository or at least a repository within the Symfony organization.

we even don't need a docker image. Github Action can run Dockerfile directly (https://docs.github.com/en/free-pro-team@latest/actions/creating-actions/creating-a-docker-container-action)

@wouterj
Copy link
Member

wouterj commented Nov 7, 2020

We can do this without a custom image I think. The following docker compose config (docker compose isn't needed here, it's just more readable than a docker run command imho) sets up the openldap image with our fixture data (as far as I can see):

version: '3.0'

services:
    ldap:
        image: osixia/openldap:1.4.0
        ports:
            - 3389:389
        volumes:
            - ./src/Symfony/Component/Ldap/Tests/Fixtures/data/fixtures.ldif:/container/service/slapd/assets/config/bootstrap/ldif/50-bootstrap.ldif
        command: --copy-service --loglevel debug
        environment:
            LDAP_DOMAIN: symfony.com
            LDAP_BASE_DN: dc=symfony,dc=com
            LDAP_ADMIN_PASSWORD: 'symfony'

Please note that I can't make the tests pass with this config, so something isn't quite right. But it at least is a start to get custom data in the openldap image without using a custom image.

@lucasaba
Copy link
Contributor Author

lucasaba commented Nov 7, 2020

@wouterj I've tryed your suggestion. seemd promising! I've mounted a volume with the GHA:

openldap:
    image: osixia/openldap:1.4.0
    options: -v ${{ github.workspace }}/src/Symfony/Component/Ldap/Tests/Fixtures/data/fixtures.ldif:/ldif-data
    ports:
        - 3389:389
    env:
        LDAP_DOMAIN: "symfony.com"
        LDAP_ADMIN_PASSWORD: symfony
        LDAP_BASE_DN: "dc=symfony,dc=com"
        LDAP_SEED_INTERNAL_LDIF_PATH: "/ldif-data"

But in the Checkout phase, GHA tryes to clean-up the workspace and, beeing the volume tied to the image, breaks the pipeline.

I'll try some alternatives and read the article pointed from @jderusse

@lucasaba
Copy link
Contributor Author

lucasaba commented Nov 8, 2020

we even don't need a docker image. Github Action can run Dockerfile directly (https://docs.github.com/en/free-pro-team@latest/actions/creating-actions/creating-a-docker-container-action)

At a first impression, that would move the problem. In the sense that, instead of maintaing a docker image, there should be a GHA to maintain.

@wouterj
Copy link
Member

wouterj commented Nov 8, 2020

Hmm, according to actions/checkout#211 (comment) the solution would be to run this command before the checkout action:

sudo chown -R $USER:$USER /home/runner/work/symfony/symfony/src/Symfony/Component/Ldap/Tests/Fixtures/data/fixtures.ldif

@lucasaba
Copy link
Contributor Author

lucasaba commented Nov 8, 2020

we even don't need a docker image. Github Action can run Dockerfile directly (https://docs.github.com/en/free-pro-team@latest/actions/creating-actions/creating-a-docker-container-action)

My bad @jderusse ! Indeed, we can use a local action and not depenend on an external one.

@lucasaba lucasaba changed the title Add ldap tests [LDAP] Add ldap tests to github CI Nov 10, 2020
@jderusse
Copy link
Member

I squashed your commits @lucasaba rebased, and puh a commit that fix the CI.
Please, pull --rebase before pushing another commit

PR is ready for review @derrabus @wouterj

@jderusse jderusse marked this pull request as ready for review November 16, 2020 12:53
@chalasr
Copy link
Member

chalasr commented Nov 16, 2020

Rebase went wrong? It seems that an unrelated commit landed in this PR 3510b67

@lucasaba
Copy link
Contributor Author

lucasaba commented Nov 16, 2020

Thanks @jderusse ! I didn't think about using actions in that way! Thank you very much!
The erros on Travis and appveyour seems unrelated.

@chalasr seems ok now. I had some error too. Maybe some cache on github....

@derrabus
Copy link
Member

@chalasr is right, that does not look right. The content of that commit looks okay, but message and author are from a different PR.

@jderusse
Copy link
Member

Rebase went wrong? It seems that an unrelated commit landed in this PR 3510b67

Yeah, the commit was there in the original PR (lucasaba@9de6771) I can reword it or squash it if you want @derrabus

@derrabus
Copy link
Member

Right now, the commit message is misleading and I'm the author of that commit. I think, squashing it into the second commit and removing me as author would be good. 😃

Adds ext-ldap on github-actions
Copy link
Member

@wouterj wouterj left a comment

Choose a reason for hiding this comment

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

I don't really understand anything about what's happening here, but it seems to make the LDAP tests run successfully 👍

Should this also remove the - now unused - src/Symfony/Component/Ldap/Tests/Fixtures/conf/slapd.conf and src/Symfony/Component/Ldap/Tests/Fixtures/data/base.ldif files?

(unrelated, but I'm a bit scared by amount of integration tests that are skipped on our CI)

@jderusse
Copy link
Member

derstand anything about what's happening here, but it seems to make the LDAP

For the record. This PR update the CI to:

  • starts an openldap server as a service (like redis/memcache/...)
  • load fixtures
  • deletes the user created by the bitnami/openldap (I didn't found a way to start with basic root setup, BUT WITHOUT demo users generated by LDAP_USERS env variable)
  • remove LDAP calls from travis

Then it fixes tests:

  • restore states of database after successful/failed tests (otherwise, you can't run tests twice)
  • fix SSL bug in connection to LDAP
  • fix wrong exception expected

unrelated, but I'm a bit scared by amount of integration tests that are skipped on our CI

So do I.. Shall we run tests with option -vv to see the reason of skipped tests?

@derrabus
Copy link
Member

So do I.. Shall we run tests with option -vv to see the reason of skipped tests?

Yes, that would be good. Integration tests are often skipped if an external system is not available. If we have a CI run dedicated to integration tests, skipped tests are likely an accident.

@jderusse
Copy link
Member

So do I.. Shall we run tests with option -vv to see the reason of skipped tests?

Yes, that would be good. Integration tests are often skipped if an external system is not available. If we have a CI run dedicated to integration tests, skipped tests are likely an accident.

Done. We have ~200 skipped tests for the following reasons:

  • Testing expiration slows down the test suite
  • Not a pruneable cache pool.
  • Memcached cannot clear by prefix
  • REDIS_SENTINEL_HOSTS env var is not defined.
  • Memcached expects a TTL greater than 1 sec. Simulating a slow network is too hard

I'm checking for the REDIS_SENTINEL test.
Other skipped tests sounds legit to me.

@derrabus
Copy link
Member

All right, none of them is related to LDAP, so this PR should be good.

@wouterj
Copy link
Member

wouterj commented Nov 16, 2020

(fwiw, let's move the conversation of the skipped tests to another PR/issue, so we can merge this asap)

@derrabus
Copy link
Member

Thanks @lucasaba.

@derrabus derrabus merged commit 55707fb into symfony:4.4 Nov 16, 2020
@lucasaba
Copy link
Contributor Author

lucasaba commented Nov 16, 2020

Thank you all guys. As usual, has been a pleasure and a privilege. Learned a lot!

@derrabus
Copy link
Member

I'll merge this up to 5.1 now. Let's hope, the tests stay green. 😃

@derrabus
Copy link
Member

@derrabus
Copy link
Member

There was 1 error:

1) Symfony\Component\Ldap\Tests\Adapter\ExtLdap\LdapManagerTest::testUpdateOperationsThrowsExceptionWhenAddedDuplicatedValue
Undefined variable: con

/home/runner/work/symfony/symfony/src/Symfony/Component/Ldap/Adapter/ExtLdap/EntryManager.php:155
/home/runner/work/symfony/symfony/src/Symfony/Component/Ldap/Tests/Adapter/ExtLdap/LdapManagerTest.php:369

Anyone up for a quick fix before I move on to 5.2? 😁

@wouterj
Copy link
Member

wouterj commented Nov 16, 2020

throw new UpdateOperationException(sprintf('Error executing UpdateOperation on "%s": ', $dn).ldap_error($this->getConnectionResource()), ldap_errno($con));

$con should be $this->getConnectionResource(). Or we should do $con = $this->getConnectionResource(); (just like in other methods of this class)

@derrabus
Copy link
Member

That makes sense. I've extracted that variable on 4.4 already, in order to keep the diff small. #39094

derrabus added a commit that referenced this pull request Nov 16, 2020
This PR was merged into the 4.4 branch.

Discussion
----------

[Ldap] Fix undefined variable $con

| Q             | A
| ------------- | ---
| Branch?       | 4.4
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Tickets       | #39030 (comment)
| License       | MIT
| Doc PR        | N/A

This PR extracts the connection resource into a variable. This will fix an undefined variable error on 5.1.

Commits
-------

15da316 [Ldap] Fix undefined variable $con.
@derrabus
Copy link
Member

The LDAP integration tests are now green on 5.1, 5.2 and 5.x. 🎉

@jderusse
Copy link
Member

thank you for your help @lucasaba .

It helped to detect issue in 5.1 if I understand well, and would have prevent bugs in previous PRs. 🎉

@lucasaba
Copy link
Contributor Author

Ok, now I'm really flattered! You've made my day!!!!! ❤️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants