Skip to content
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

[PM-13008] Add ldap integration tests #637

Open
wants to merge 28 commits into
base: main
Choose a base branch
from
Open

Conversation

eliykat
Copy link
Member

@eliykat eliykat commented Oct 2, 2024

🎟️ Tracking

https://bitwarden.atlassian.net/browse/PM-13008

See the parent ticket https://bitwarden.atlassian.net/browse/PM-13007 for additional context.

📔 Objective

Add integration tests for LdapDirectoryService.

We don't have any integration tests for our directory services, so this was a bit of trial and error, and is open to feedback about the best way to structure these.

The tests use jest because I still needed a test runner and I wanted to isolate LdapDirectoryService from the rest of the app and from the Bitwarden server. The integration is purely between our directory service implementation and the external directory service, which to me is the "here be dragons" part of our code at the moment.

This PR uses the OpenLdap docker image that we already recommend for local development. That's ideal because we can spin it up with seed data on demand. Additional integration tests will probably involve actual third party cloud services or Azure VMs which will require more investigation and setup.

Once this is merged I can remove the OpenLdap configuration from the server repository and update the contributing docs. It really belongs with this repo.

📸 Screenshots

⏰ Reminders before review

  • Contributor guidelines followed
  • All formatters and local linters executed and passed
  • Written new unit and / or integration tests where applicable
  • Used internationalization (i18n) for all UI strings
  • CI builds passed
  • Communicated to DevOps any deployment requirements
  • Updated any necessary documentation (Confluence, contributing docs) or informed the documentation team

🦮 Reviewer guidelines

  • 👍 (:+1:) or similar for great changes
  • 📝 (:memo:) or ℹ️ (:information_source:) for notes or general info
  • ❓ (:question:) for questions
  • 🤔 (:thinking:) or 💭 (:thought_balloon:) for more open inquiry that's not quite a confirmed issue and could potentially benefit from discussion
  • 🎨 (:art:) for suggestions / improvements
  • ❌ (:x:) or ⚠️ (:warning:) for more significant problems or concerns needing attention
  • 🌱 (:seedling:) or ♻️ (:recycle:) for future improvements or indications of technical debt
  • ⛏ (:pick:) for minor or nitpick changes

Copy link

codecov bot commented Oct 2, 2024

Codecov Report

Attention: Patch coverage is 22.22222% with 63 lines in your changes missing coverage. Please review.

Project coverage is 8.62%. Comparing base (cf106b1) to head (bda1104).
Report is 17 commits behind head on main.

✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
...ervices/ldap-directory.service.integration.spec.ts 0.00% 58 Missing ⚠️
src/models/groupEntry.ts 73.33% 4 Missing ⚠️
src/models/userEntry.ts 87.50% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff            @@
##            main    #637      +/-   ##
========================================
+ Coverage   2.29%   8.62%   +6.33%     
========================================
  Files         59      60       +1     
  Lines       2573    2655      +82     
  Branches     467     475       +8     
========================================
+ Hits          59     229     +170     
+ Misses      2511    2403     -108     
- Partials       3      23      +20     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

github-actions bot commented Oct 2, 2024

Logo
Checkmarx One – Scan Summary & Details84abe62a-f346-4e99-8c51-dceab5071bd8

New Issues

Severity Issue Source File / Package Checkmarx Insight
MEDIUM Container Capabilities Unrestricted /docker-compose.yml: 2 Some capabilities are not needed in certain (or any) containers. Make sure that you only add capabilities that your container needs. Drop unnecessa...
MEDIUM Container Capabilities Unrestricted /docker-compose.yml: 19 Some capabilities are not needed in certain (or any) containers. Make sure that you only add capabilities that your container needs. Drop unnecessa...
MEDIUM Healthcheck Not Set /docker-compose.yml: 2 Check containers periodically to see if they are running properly.
MEDIUM Healthcheck Not Set /docker-compose.yml: 19 Check containers periodically to see if they are running properly.
MEDIUM Privileged Ports Mapped In Container /docker-compose.yml: 12 Privileged ports (1 to 1023) should not be mapped. Also you should drop net_bind_service linux capability from the container unless you absolutely ...
MEDIUM Privileged Ports Mapped In Container /docker-compose.yml: 26 Privileged ports (1 to 1023) should not be mapped. Also you should drop net_bind_service linux capability from the container unless you absolutely ...
MEDIUM Security Opt Not Set /docker-compose.yml: 19 Attribute 'security_opt' should be defined.
MEDIUM Security Opt Not Set /docker-compose.yml: 2 Attribute 'security_opt' should be defined.
LOW Use_Of_Hardcoded_Password /src/services/ldap-directory.service.integration.spec.ts: 159 Attack Vector

Testing based on last modified date is probably too difficult to scale
once we start using cloud directory services
Copy link
Member Author

Choose a reason for hiding this comment

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

I'm not sure whether this should be separate to the existing test.yml file. As we add more integration tests it seems useful to keep it separate, but I'm not sure how this affects code coverage reporting.

As it stands this is mostly a copy/paste of test.yml.

We may want to use https://github.com/dorny/paths-filter down the line to selectively run different tests based on which directory service was changed. (The standard path filter only applies to the whole workflow, not steps within it.)

Copy link
Member Author

Choose a reason for hiding this comment

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

The toJSON/fromJSON methods were added as helpers to instantiate the fixture data. It's maybe a bit weird to add this to runtime code, but the Jsonify type is based on the toJSON return type, so it was the tidiest and least verbose way to add type safety and factory methods to the fixture data.

beforeEach(() => {
logService = mock();
i18nService = mock();
stateService = mock();
Copy link
Member Author

Choose a reason for hiding this comment

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

Future refactor: it would be good to remove stateService from the directory service implementations and pass in their config as arguments instead.

@eliykat eliykat marked this pull request as ready for review October 2, 2024 02:07
@eliykat eliykat requested a review from a team as a code owner October 2, 2024 02:07
Comment on lines +53 to +57
getLdapConfiguration({
ssl: true,
startTls: true,
sslAllowUnauthorized: true, // TODO: this could be more robust if we configured certs correctly
}),
Copy link
Member Author

Choose a reason for hiding this comment

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

This is a bit of a half baked SSL config at the moment, I just wanted something in place. Ideally we'd specify a certificate and not use sslAllowUnauthorized.

Comment on lines 67 to 70
# Tests in apps/ are typechecked when their app is built, so we just do it here for libs/
# See https://bitwarden.atlassian.net/browse/EC-497
- name: Run typechecking
run: npm run test:types --coverage
Copy link
Contributor

Choose a reason for hiding this comment

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

You probably don't need this, it's not required to run tests and is already done in the main test job.

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed in bda1104.

@@ -0,0 +1 @@
COMPOSE_PROJECT_NAME=directory-connector
Copy link
Contributor

Choose a reason for hiding this comment

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

What's this for?

Copy link
Member Author

Choose a reason for hiding this comment

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

It gives a nice name to the grouping in docker desktop:

Screenshot 2024-10-07 at 1 31 00 PM

Copy link
Contributor

@addisonbeck addisonbeck Oct 7, 2024

Choose a reason for hiding this comment

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

Does it make more sense to set this in docker-compose.yml? Docker's documentation says it will take the top level name value here.

Also, if you're planning to use this as the scaffolding location for local development containers it doesn't make sense to put it in the integration-tests folder. I do think it's reasonable to put docker-compose.yml (and .env if you keep it) in project root.

@eliykat
Copy link
Member Author

eliykat commented Oct 7, 2024

I realised belatedly that the OpenLDAP Docker image is unmaintained since ~3 years ago: https://github.com/osixia/docker-openldap.

I'll look at changing it out for https://hub.docker.com/r/bitnami/openldap, which appears maintained and published by Vmware. Other suggestions are welcome.

@eliykat eliykat added the hold do not merge, do not approve yet label Oct 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
hold do not merge, do not approve yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants