test: create automated tests for ldap login - #36810
Conversation
|
Looks like this PR is not ready to merge, because of the following issues:
Please fix the issues and try again If you have any trouble, please check the PR guidelines |
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #36810 +/- ##
===========================================
- Coverage 68.67% 68.59% -0.08%
===========================================
Files 4165 4308 +143
Lines 159294 172630 +13336
Branches 28215 31008 +2793
===========================================
+ Hits 109390 118418 +9028
- Misses 44747 48905 +4158
- Partials 5157 5307 +150
Flags with carried forward coverage won't be shown. Click here to find out more. 🚀 New features to boost your workflow:
|
b8f856d to
0ca9dd7
Compare
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
Included review availability: Your plan includes up to 10 reviews per rolling hour; 8 remain after this review. 📜 Recent review details⏰ Context from checks skipped due to timeout. (5)
|
| Layer / File(s) | Summary |
|---|---|
LDAP configuration and fixture apps/meteor/tests/e2e/ldap.spec.ts, development/ldap/02-data.ldif |
The suite defines LDAP authentication, lookup, field mapping, and avatar settings. The fixture adds the ldap.e2e user with encoded credentials and JPEG data. |
LDAP setup and cleanup apps/meteor/tests/e2e/ldap.spec.ts |
Helpers apply settings, wait for connection readiness, preserve original settings, and remove the test user after execution. |
LDAP connection and login assertions apps/meteor/tests/e2e/ldap.spec.ts |
Tests verify connection testing, user search, credential login, mapped profile fields, and avatar synchronization. |
Estimated code review effort: 3 (Moderate) | ~20 minutes
Merge Risk: ⚪ Minimal · up to 62678
This PR adds isolated LDAP end-to-end test coverage and preserves test-state cleanup; no actionable merge-blocking risk remains beyond normal checks and review.
Sequence Diagram(s)
sequenceDiagram
participant LDAP E2E suite
participant Rocket.Chat LDAP service
participant LDAP server
LDAP E2E suite->>Rocket.Chat LDAP service: submit LDAP credentials
Rocket.Chat LDAP service->>LDAP server: search and authenticate ldap.e2e
LDAP server-->>Rocket.Chat LDAP service: return mapped fields and JPEG photo
Rocket.Chat LDAP service-->>LDAP E2E suite: complete login and render profile
Suggested labels: type: chore, area: authentication
Suggested reviewers: dougfabris
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
| Check name | Status | Explanation |
|---|---|---|
| Description Check | ✅ Passed | Check skipped - CodeRabbit’s high-level summary is enabled. |
| Title check | ✅ Passed | The title clearly identifies the main change: adding automated tests for LDAP authentication. |
| Docstring Coverage | ✅ Passed | No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. |
| Linked Issues check | ✅ Passed | Check skipped because no linked issues were found for this pull request. |
| Out of Scope Changes check | ✅ Passed | Check skipped because no linked issues were found for this pull request. |
✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
- Create stacked PR
- Commit on current branch
Warning
Review ran into problems
🔥 Problems
Errors were encountered while retrieving linked issues.
Errors (1)
- QA-95: Request failed with status code 401
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
Comment @coderabbitai help to get the list of available commands.
5113cd7 to
6858cfb
Compare
0079df6 to
bbab67a
Compare
bbab67a to
b6b2a49
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
apps/meteor/tests/e2e/ldap.spec.ts (1)
113-133: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winUse test names that state the expected result.
connection,user search, andlogin using LDAP credentialsdescribe scope or action. Rename them to state the expected behavior, such as successful connection, returned LDAP user, and successful mapped login.As per coding guidelines, “Use descriptive test names that clearly communicate expected behavior in Playwright tests.”
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@apps/meteor/tests/e2e/ldap.spec.ts` around lines 113 - 133, Rename the Playwright tests around the connection, user search, and LDAP login flows to describe their expected outcomes rather than their actions. Update the test names in the connection and user-search cases, and the following login test, to clearly state successful connection, successful LDAP user retrieval, and successful mapped login.Source: Coding guidelines
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@apps/meteor/tests/e2e/ldap.spec.ts`:
- Around line 124-130: Update the LDAP test around the /ldap.testSearch request
to validate that the login flow returns the expected ldap.e2e user, rather than
asserting only result.success. Use the login response’s returned user data or an
admin-users endpoint to assert ldap.e2e is present, while preserving the
existing successful-response check.
---
Nitpick comments:
In `@apps/meteor/tests/e2e/ldap.spec.ts`:
- Around line 113-133: Rename the Playwright tests around the connection, user
search, and LDAP login flows to describe their expected outcomes rather than
their actions. Update the test names in the connection and user-search cases,
and the following login test, to clearly state successful connection, successful
LDAP user retrieval, and successful mapped login.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 1e06c187-84b4-4d2c-b56f-8a6a7c82b176
⛔ Files ignored due to path filters (1)
apps/meteor/tests/e2e/ldap.spec.ts-snapshots/ldap-avatar-linux.jpegis excluded by!**/*.jpeg
📒 Files selected for processing (2)
apps/meteor/tests/e2e/ldap.spec.tsdevelopment/ldap/02-data.ldif
📜 Review details
⏰ Context from checks skipped due to timeout. (2)
- GitHub Check: cubic · AI code reviewer
- GitHub Check: Hacktron Security Check
🧰 Additional context used
📓 Path-based instructions (5)
**/*.{ts,tsx,js}
📄 CodeRabbit inference engine (.cursor/rules/playwright.mdc)
**/*.{ts,tsx,js}: Write concise, technical TypeScript/JavaScript with accurate typing in Playwright tests
Avoid code comments in the implementation
Files:
apps/meteor/tests/e2e/ldap.spec.ts
**/*.spec.ts
📄 CodeRabbit inference engine (.cursor/rules/playwright.mdc)
**/*.spec.ts: Use descriptive test names that clearly communicate expected behavior in Playwright tests
Use.spec.tsextension for test files (e.g.,login.spec.ts)
Files:
apps/meteor/tests/e2e/ldap.spec.ts
apps/meteor/tests/e2e/**/*.spec.ts
📄 CodeRabbit inference engine (.cursor/rules/playwright.mdc)
apps/meteor/tests/e2e/**/*.spec.ts: All test files must be created inapps/meteor/tests/e2e/directory
Avoid usingpage.locator()in Playwright tests - always prefer semantic locators such aspage.getByRole(),page.getByLabel(),page.getByText(), orpage.getByTitle()
Usetest.beforeAll()andtest.afterAll()for setup/teardown in Playwright tests
Usetest.step()for complex test scenarios to improve organization in Playwright tests
Group related tests in the same file
Utilize Playwright fixtures (test,page,expect) for consistency in test files
Prefer web-first assertions (toBeVisible,toHaveText, etc.) in Playwright tests
Useexpectmatchers for assertions (toEqual,toContain,toBeTruthy,toHaveLength, etc.) instead ofassertstatements in Playwright tests
Usepage.waitFor()with specific conditions instead of hardcoded timeouts in Playwright tests
Implement proper wait strategies for dynamic content in Playwright tests
Maintain test isolation between test cases in Playwright tests
Ensure clean state for each test execution in Playwright tests
Ensure tests run reliably in parallel without shared state conflicts
Files:
apps/meteor/tests/e2e/ldap.spec.ts
apps/meteor/tests/e2e/**/*.{ts,spec.ts}
📄 CodeRabbit inference engine (.cursor/rules/playwright.mdc)
apps/meteor/tests/e2e/**/*.{ts,spec.ts}: Store commonly used locators in variables/constants for reuse
Follow Page Object Model pattern consistently in Playwright tests
Files:
apps/meteor/tests/e2e/ldap.spec.ts
apps/meteor/**
📄 CodeRabbit inference engine (CLAUDE.md)
The main Rocket.Chat Meteor application resides in
apps/meteor/; place its application code there rather than in other monorepo areas.
Files:
apps/meteor/tests/e2e/ldap.spec.ts
🧠 Learnings (6)
📚 Learning: 2026-02-24T19:22:48.358Z
Learnt from: juliajforesti
Repo: RocketChat/Rocket.Chat PR: 38493
File: apps/meteor/tests/e2e/omnichannel/omnichannel-send-pdf-transcript.spec.ts:66-67
Timestamp: 2026-02-24T19:22:48.358Z
Learning: In Playwright end-to-end tests (e.g., under apps/meteor/tests/e2e/...), prefer locating elements by translated text (getByText) and ARIA roles (getByRole) over data-qa attributes. If translation values change, update the corresponding test locators accordingly. Never use data-qa locators. This guideline applies to all Playwright e2e test specs in the repository and helps keep tests robust to UI text changes and accessible semantics.
Applied to files:
apps/meteor/tests/e2e/ldap.spec.ts
📚 Learning: 2026-02-24T19:39:42.247Z
Learnt from: juliajforesti
Repo: RocketChat/Rocket.Chat PR: 38493
File: apps/meteor/tests/e2e/page-objects/fragments/message.ts:7-7
Timestamp: 2026-02-24T19:39:42.247Z
Learning: In RocketChat e2e tests, avoid using data-qa attributes to locate elements. Prefer semantic locators such as getByRole, getByLabel, getByText, getByTitle and ARIA-based selectors. Apply this rule to all TypeScript files under apps/meteor/tests/e2e to improve test reliability, accessibility, and maintainability.
Applied to files:
apps/meteor/tests/e2e/ldap.spec.ts
📚 Learning: 2026-02-26T19:25:44.063Z
Learnt from: gabriellsh
Repo: RocketChat/Rocket.Chat PR: 38778
File: packages/ui-voip/src/providers/useMediaSession.ts:192-192
Timestamp: 2026-02-26T19:25:44.063Z
Learning: In the Rocket.Chat repository, do not reference Biome lint rules in code review feedback. Biome is not used even if biome.json exists; only reference Biome rules if there is explicit, project-wide usage documented. For TypeScript files, review lint implications without Biome guidance unless the project enables Biome rules.
Applied to files:
apps/meteor/tests/e2e/ldap.spec.ts
📚 Learning: 2026-02-26T19:25:44.063Z
Learnt from: gabriellsh
Repo: RocketChat/Rocket.Chat PR: 38778
File: packages/ui-voip/src/providers/useMediaSession.ts:192-192
Timestamp: 2026-02-26T19:25:44.063Z
Learning: In this repository (RocketChat/Rocket.Chat), Biome lint rules are not used even if a biome.json exists. When reviewing TypeScript files (e.g., packages/ui-voip/src/providers/useMediaSession.ts), ensure lint suggestions do not reference Biome-specific rules. Rely on general ESLint/TypeScript lint rules and project conventions instead.
Applied to files:
apps/meteor/tests/e2e/ldap.spec.ts
📚 Learning: 2026-03-06T18:10:15.268Z
Learnt from: tassoevan
Repo: RocketChat/Rocket.Chat PR: 39397
File: packages/gazzodown/src/code/CodeBlock.spec.tsx:47-68
Timestamp: 2026-03-06T18:10:15.268Z
Learning: In tests (especially those using testing-library/dom/jsdom) for Rocket.Chat components, the HTML <code> element has an implicit ARIA role of 'code'. Therefore, screen.getByRole('code') or screen.findByRole('code') will locate <code> elements even without a role attribute. Do not flag findByRole('code') as invalid in reviews; prefer using the implicit role instead of adding role="code" unless necessary for accessibility.
Applied to files:
apps/meteor/tests/e2e/ldap.spec.ts
📚 Learning: 2026-05-06T12:21:44.083Z
Learnt from: juliajforesti
Repo: RocketChat/Rocket.Chat PR: 40256
File: apps/meteor/client/components/CreateDiscussion/CreateDiscussion.tsx:121-149
Timestamp: 2026-05-06T12:21:44.083Z
Learning: Field wrappers in rocket.chat/fuselage-forms (Field, FieldLabel, FieldRow, FieldError, FieldHint) auto-create htmlFor/id associations, aria-describedby, and role="alert" for errors. Do not manually set htmlFor, id, aria-describedby, or role attributes when using these wrappers. This automatic wiring does not apply to plain rocket.chat/fuselage components, which require explicit ID wiring per the accessibility docs. In code reviews, prefer using fuselage-forms wrappers for form fields and verify there is no unnecessary manual ID/aria wiring in files that use these wrappers. If a component uses plain fuselage components, ensure proper id wiring as per docs.
Applied to files:
apps/meteor/tests/e2e/ldap.spec.ts
🔇 Additional comments (3)
apps/meteor/tests/e2e/ldap.spec.ts (2)
18-77: LGTM!
79-111: 🩺 Stability & AvailabilityNo change needed for LDAP cross-worker exclusion.
apps/meteor/playwright.config.tssetsworkers: 1, andldap.spec.tsis the only tracked file underapps/meteor/tests/e2e/that mutates LDAP settings.development/ldap/02-data.ldif (1)
20-35: LGTM!
| }, | ||
| { | ||
| message: 'LDAP settings did not propagate to the running server', | ||
| timeout: 15_000, |
There was a problem hiding this comment.
I checked the saveSettings, and it waits for the database updates but not for the settings notifications to finish. Since we test the LDAP connection right after that, it might still read the old settings on slower runs, so I thought it would be better to keep it, since without it the poll would use Playwright’s default 5-second timeout, wdyt?
| test('connection', async ({ api }) => { | ||
| await test.step('expect to successfully execute a connection test', async () => { | ||
| const response = await api.post('/ldap.testConnection', {}); | ||
| expect(response.status()).toBe(200); | ||
| const result = await response.json(); | ||
| expect(result.success).toBe(true); | ||
| }); | ||
| }); | ||
|
|
||
| test('user search', async ({ api }) => { | ||
| await test.step('expect to successfully search for LDAP users', async () => { | ||
| const response = await api.post('/ldap.testSearch', { | ||
| username: ldapUsername, | ||
| }); | ||
| expect(response.status()).toBe(200); | ||
| const result = await response.json(); | ||
| expect(result.success).toBe(true); | ||
| expect(result.message).toBe('LDAP_User_Found'); | ||
| }); |
There was a problem hiding this comment.
this is testing just the API, why we're doing through playwright?
| await test.step('expect LDAP user data to have been mapped to the correct fields', async () => { | ||
| const user = await getUserInfo(api, ldapUsername); | ||
|
|
||
| expect(user).toBeDefined(); | ||
| expect(user?.username).toBe(ldapUsername); | ||
| expect(user?.name).toBe('LDAP E2E'); | ||
| expect(user?.emails).toBeDefined(); | ||
| expect(user?.emails?.[0].address).toBe('ldap.e2e@space.air'); | ||
| }); |
There was a problem hiding this comment.
again an API test, not much value doing through playwright
There was a problem hiding this comment.
hmm, yes, I considered moving it, but the API suite would also need the LDAP settings setup and restoration since rc isn’t configured to use it there, I thought keeping these checks here might be simpler and keep it similar to saml, but let me know what you think!
There was a problem hiding this comment.
All reported issues were addressed across 1 file (changes from recent commits).
Tip: Review your code locally with the cubic CLI to iterate faster.
Re-trigger cubic
Proposed changes
Adds end-to-end coverage for LDAP authentication using the existing OpenLDAP CI service.
/ldap.testConnectionand/ldap.testSearch.ldap.e2eidentity underou=othersso the test does not overlap with ABAC synchronization.jpegPhotoavatar synchronization by comparing the served avatar with a Playwright image snapshot./users.deletebefore and after the suite to keep runs isolated.Issue(s)
QA-95
Test coverage
Validation
Further comments
The avatar baseline is intentionally committed because Playwright uses it for pixel comparison. The Linux suffix is generated automatically by Playwright and matches the CI platform.
Summary by CodeRabbit