Repository navigation
Fix #6: require authentication in test/offline mode too - #13
Open
xiaoyao-666-coder wants to merge 2 commits into
Open
xiaoyao-666-coder wants to merge 2 commits into
xiaoyao-666-coder wants to merge 2 commits into
Conversation
- _require_access now returns 401 without valid credentials in every mode (test/offline used to let anonymous requests through while rejecting invalid cookies); _require_service_access also authenticates outside production (logged-in user in test/offline, service token only in production, unchanged). - No anonymous-mode switch was added: /api/health and /api/ready stay public for smoke tests, and clients/tests authenticate via register/login. Update the regression test that enshrined the anonymous behaviour and the tests that relied on anonymous access. - Add backend/tests/test_anon_access.py (12 tests) and a login_client helper in conftest.py. Closes zhengdaodeguL#6.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #6.
test/offline 模式下无 Cookie 也能调用受保护接口并读取他人会话,有无效 Cookie 反而 401,行为正好倒挂。根因:
_require_access只在 production/local 或“带了 Cookie”时才 401;_require_service_access在非生产模式直接放行。_require_access改为所有模式下无有效凭证一律 401;_require_service_access在非生产模式也鉴权(登录用户会话;生产模式仍仅 service token,行为不变)。/api/health、/api/ready保持公开已够探活,前端和测试都走注册/登录拿 Cookie。backend/tests/test_anon_access.py(12 个测试)与 conftest 的login_clienthelper。验证:
MEDGUIDE_MODE=test python -m pytest -q backend/tests533 passed(基线 521 + 12 新);前端未改动。行为变更请注意:test/offline/local 模式现在也要先登录才能调受保护接口;部署 smoke 测试只用 health/ready 不受影响。