Skip to content

fix(search): enforce tenant isolation in SearchService#892

Open
godwinishaku506-hub wants to merge 1 commit into
rinafcode:mainfrom
godwinishaku506-hub:fix/889-tenant-isolation-elasticsearch
Open

fix(search): enforce tenant isolation in SearchService#892
godwinishaku506-hub wants to merge 1 commit into
rinafcode:mainfrom
godwinishaku506-hub:fix/889-tenant-isolation-elasticsearch

Conversation

@godwinishaku506-hub

Copy link
Copy Markdown

Summary

Fixes #889 — search queries in SearchService returned results across tenant boundaries.

Changes

File What changed
src/courses/entities/course.entity.ts Added tenantId column (nullable, indexed)
src/search/search.module.ts Import TenancyModule + TypeOrmModule.forFeature([Course])
src/search/search.service.ts Inject IsolationService; add buildTenantFilter(); apply filter in search() and getAutoComplete()
src/search/search.service.spec.ts 7 new tenant isolation tests covering search(), getAutoComplete(), and buildTenantFilter()

Acceptance criteria

  • ✅ Search results for Tenant A never include content from Tenant B
  • ✅ Integration tests verify isolation by populating both tenants and searching cross-boundary
  • ✅ Filter is applied even when no other query parameters are present

Testing

10 tests pass (7 new isolation tests + 3 existing)
tsc --noEmit: no errors

- Add tenantId column (nullable, indexed) to Course entity
- Import TenancyModule into SearchModule so IsolationService is available
- Inject IsolationService into SearchService
- Add buildTenantFilter(tenantId) helper returning an ES term query
- Apply tenantId filter as first WHERE clause in search() and getAutoComplete()
- Add 7 tenant isolation tests covering cross-boundary isolation for both
  search() and getAutoComplete(), plus a no-query-params case

Closes rinafcode#889
@drips-wave

drips-wave Bot commented Jun 26, 2026

Copy link
Copy Markdown

@godwinishaku506-hub Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@RUKAYAT-CODER

Copy link
Copy Markdown
Contributor

Great job so far

There’s just one blocker — the workflow is failing. Could you take a look and fix it so all checks pass?

Happy to review again once that’s done.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add tenant isolation enforcement to Elasticsearch search queries in SearchService

2 participants