Skip to content

test(analytics): cover every verb in saved-query tenant isolation - #2138

Merged
cyberantonz merged 4 commits into
constructorfabric:mainfrom
cyberantonz:test/saved-query-tenant-isolation
Aug 3, 2026
Merged

test(analytics): cover every verb in saved-query tenant isolation#2138
cyberantonz merged 4 commits into
constructorfabric:mainfrom
cyberantonz:test/saved-query-tenant-isolation

Conversation

@cyberantonz

@cyberantonz cyberantonz commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

Summary

QA flagged missing tenant-isolation tests for the saved-query CRUD (/v1/queries*). A test existed (saved_query_is_tenant_scoped) but only asserted cross-tenant GET; the mutation paths were uncovered.

This extends the live test to cover the full surface for a query owned by tenant A when accessed as tenant B:

  • LIST does not contain the foreign row
  • GET / PUT / DELETE / POST .../run each return 404 (table-driven, per-request assert labels)
  • the owner still reads the row back unchanged afterwards — proving the foreign PUT/DELETE mutated nothing

No production-code changes; the handlers already resolve every verb tenant-filtered.

Testing

Ran the saved-query suite against a local MariaDB (migrations applied via analytics migrate):

INTEGRATION_TESTS_MARIADB_URL=... cargo test -p analytics saved_query -- --include-ignored
test result: ok. 11 passed; 0 failed

clippy + rustfmt clean.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Improved tenant isolation for saved queries.
    • Saved queries are now verified as inaccessible to other tenants through listing, viewing, editing, deleting, and execution.
    • Saved queries remain available and unchanged for their owning tenant.

The tenant-isolation live test only asserted cross-tenant GET. Extend it
to assert LIST invisibility, 404 on cross-tenant GET/PUT/DELETE/run, and
that the owner's row is unchanged after the foreign write attempts.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Signed-off-by: Anton Zelenov <antonz@constructor.tech>
@cyberantonz
cyberantonz requested a review from a team as a code owner August 3, 2026 08:08
@coderabbitai

coderabbitai Bot commented Aug 3, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@cyberantonz, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 10 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 898c73aa-86d4-4179-9695-0a0c1a37eeef

📥 Commits

Reviewing files that changed from the base of the PR and between ce5e379 and 3f44a0c.

📒 Files selected for processing (1)
  • src/backend/services/analytics/src/api/http_live_tests.rs
📝 Walkthrough

Walkthrough

The tenant-isolation test now verifies that tenant B cannot list or access tenant A’s saved query through any saved-query operation. It also verifies that tenant A can still retrieve the unchanged query.

Changes

Saved query tenant isolation

Layer / File(s) Summary
Cross-tenant saved-query operation checks
src/backend/services/analytics/src/api/http_live_tests.rs
The test checks tenant B’s list, GET, PUT, DELETE, and run requests. Each request returns 404 for tenant A’s saved query. The test then confirms tenant A can retrieve the unchanged query.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related PRs

Suggested reviewers: ktursunov

🚥 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 and concisely describes the added tenant-isolation coverage for all saved-query verbs.
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
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 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 `@src/backend/services/analytics/src/api/http_live_tests.rs`:
- Around line 720-722: Remove the prose comments near the tenant-isolation
requests in the live HTTP tests, including the additional comment at the other
indicated location; leave the test names, requests, assertions, and assertion
messages unchanged.
- Around line 720-776: Split the oversized http_live_tests module into focused
feature submodules, moving the saved-query helpers and tests—including the
cross-tenant test around app, create_body, and query endpoint coverage—into a
dedicated saved-query module. Preserve existing shared test setup and behavior,
and leave unrelated live HTTP tests in their current feature-focused module.
🪄 Autofix (Beta)

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: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: a5523b2c-e304-4255-9395-73699508b950

📥 Commits

Reviewing files that changed from the base of the PR and between d8c6888 and ce5e379.

📒 Files selected for processing (1)
  • src/backend/services/analytics/src/api/http_live_tests.rs

Comment thread src/backend/services/analytics/src/api/http_live_tests.rs Outdated
Comment thread src/backend/services/analytics/src/api/http_live_tests.rs Outdated
cyberantonz and others added 2 commits August 3, 2026 16:31
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Signed-off-by: Anton Zelenov <antonz@constructor.tech>
@cyberantonz
cyberantonz enabled auto-merge August 3, 2026 08:36
@cyberantonz
cyberantonz added this pull request to the merge queue Aug 3, 2026
Merged via the queue into constructorfabric:main with commit 11f500d Aug 3, 2026
43 of 44 checks passed
@cyberantonz
cyberantonz deleted the test/saved-query-tenant-isolation branch August 3, 2026 11:00
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.

2 participants