Repository navigation
fix(preview): authenticate markdown document preview requests - #15589
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughMarkdown preview now uses the shared authenticated ChangesFile preview authentication and loading
Sequence DiagramsequenceDiagram
participant MdComponent
participant request_util
participant DocumentsAPI
MdComponent->>request_util: request(url, responseType='blob')
request_util->>DocumentsAPI: GET /documents/:id/preview (with auth)
DocumentsAPI-->>request_util: returns markdown blob or 401
request_util-->>MdComponent: blob.text() -> render or set error
🎯 3 (Moderate) | ⏱️ ~20 minutes
Suggested reviewers
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. 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 |
Route .md/.mdx preview through the shared request client so Authorization headers and interceptors match txt/image previewers. Add a unit test for AUTH_BETA token loading used by embedded search. Fixes infiniflow#15585
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
test/testcases/test_web_api/test_system_app/test_apps_init_unit.py (1)
188-190: ⚡ Quick winConsider adding a negative test case for invalid beta token.
The current test validates the happy path where the beta token is valid. Consider adding a test case to verify that authentication fails when the beta token is not found in the
APIToken.querylookup, ensuring the AUTH_BETA path correctly rejects invalid tokens.🧪 Example negative test case
Add after line 190:
# Test invalid beta token returns None async with quart_app.test_request_context("/", headers={"Authorization": "Bearer invalid-beta"}): user = apps_module._load_user(auth_types=[apps_module.AUTH_BETA]) assert user is None🤖 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 `@test/testcases/test_web_api/test_system_app/test_apps_init_unit.py` around lines 188 - 190, Add a negative test that asserts _load_user returns None when an invalid beta token is presented: within test_web_api/test_system_app/test_apps_init_unit.py create an async test_request_context with an Authorization header using an invalid beta token, call apps_module._load_user(auth_types=[apps_module.AUTH_BETA]) and assert the result is None; this verifies the AUTH_BETA path and the APIToken.query lookup correctly rejects tokens not found.
🤖 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 `@test/testcases/test_web_api/test_system_app/test_apps_init_unit.py`:
- Line 186: The UserService.query mock currently ignores arguments; update the
monkeypatch for apps_module.UserService.query so it validates the contract used
in api/apps/__init__.py by asserting or checking that it is called with
id=objs[0].tenant_id and status=StatusEnum.VALID.value (or return empty list if
not), then return [beta_user] only when those parameters match; reference
UserService.query, objs[0].tenant_id, and StatusEnum.VALID.value when
implementing the check so the test fails if the implementation passes incorrect
params.
---
Nitpick comments:
In `@test/testcases/test_web_api/test_system_app/test_apps_init_unit.py`:
- Around line 188-190: Add a negative test that asserts _load_user returns None
when an invalid beta token is presented: within
test_web_api/test_system_app/test_apps_init_unit.py create an async
test_request_context with an Authorization header using an invalid beta token,
call apps_module._load_user(auth_types=[apps_module.AUTH_BETA]) and assert the
result is None; this verifies the AUTH_BETA path and the APIToken.query lookup
correctly rejects tokens not found.
🪄 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: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 0fbd5923-836b-43a3-b318-76c02e0a7938
📒 Files selected for processing (1)
test/testcases/test_web_api/test_system_app/test_apps_init_unit.py
ebdcba5 to
dba6342
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #15589 +/- ##
=======================================
Coverage 93.16% 93.16%
=======================================
Files 10 10
Lines 717 717
Branches 118 118
=======================================
Hits 668 668
Misses 29 29
Partials 20 20 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Validate UserService.query tenant/status contract and reject unknown beta tokens in test_load_user_api_token_fallback_and_fallback_exception.
Summary
Fixes #15585.
requestclient (same as txt/image previewers) soAuthorizationheaders and interceptors are applied consistently.AUTH_BETAtoken loading for embedded search auth.Root cause
Search result preview for
.md/.mdxused rawfetch, which did not apply the same auth path as other preview types. That led to401onGET /api/v1/documents/{id}/previeweven when the user was logged in or using an embedded searchauthquery param.Test plan
authquery param, preview a markdown file — preview loads.