mirror of
https://github.com/HKUDS/DeepTutor.git
synced 2026-12-02 13:39:54 +08:00
The admin-gate test from #952 read `route.include_context`. That attribute only exists from FastAPI 0.141, where `include_router` stopped flattening the sub-router into the parent app; before that the routes are copied onto `app.routes` and there is no `include_context` at all. This project pins `fastapi>=0.100.0` with no upper bound, so the test passed on CI (which installs the latest) and raised `StopIteration` on any older satisfying install — `5115 passed, 1 failed` locally on 0.135.1. No structural assertion works across that range, so assert the actual property instead: send a valid `role=user` token and require 403. A response code does not care how the router is represented. An unauthenticated request would not have been enough — `require_auth` alone answers that with 401, so downgrading the router from `_admin` to `_auth` would still have looked gated. With a real non-admin token, both weakenings (`_admin` → `_auth`, and dropping the dependency entirely) let the request reach the handler and fail the test. Also patches `AUTH_SECRET`, without which `decode_token` rejects every token in a bare test environment and the 403 could never be distinguished from a 401. Co-authored-by: Frank <bingxizhao@novix.science>