Commit abbb065
committed
fix: honor read_only=false so e2e mutating requests are not rejected
The e2e leg was soft-failing (continue-on-error) with 23 failures.
Root cause (type b — wiring bug in RBAC, not the read-only middleware):
1. PRIMARY (19 failures): get_current_user() always granted role="viewer"
when no user_id was stamped on request.state. With auth disabled the
AuthMiddleware is not in the stack, so user_id is never set — every
unauthenticated caller got viewer, which blocked all routes declared with
require_role("admin") or require_role("operator") with HTTP 403.
Fix: create_fastapi_app() stamps app.state.auth_enabled=<flag>.
get_current_user() reads that flag: auth disabled → role="admin"
(unrestricted, operator intent); auth enabled but excluded path →
role="viewer" (least privilege, unchanged).
2. SECONDARY (4 failures, previously masked by #1): list_templates and
list_machines routes overlay result.total_count / result.next_cursor
on the response payload. Test mocks used plain Mock() objects, so
auto-created attributes (total_count, next_cursor) were non-None Mock
instances that survived the None-check and ended up in the JSONResponse,
causing TypeError: Object of type Mock is not JSON serializable.
Fix: explicitly set mock_result.total_count = None and
mock_result.next_cursor = None in the four affected test cases so the
route falls back to len(result.templates/machines).
Verification:
- read_only=True still blocks POST/PUT/DELETE with 403 READ_ONLY_MODE
- read_only=False (default) no longer blocks mutations
- auth_enabled=True + unauthenticated path still gets viewer (unchanged)
- 35/35 e2e tests pass; 386/386 unit/api tests pass; 0 regressions1 parent a211183 commit abbb065
3 files changed
Lines changed: 30 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
340 | 340 | | |
341 | 341 | | |
342 | 342 | | |
343 | | - | |
344 | | - | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
345 | 348 | | |
346 | 349 | | |
347 | 350 | | |
348 | 351 | | |
349 | 352 | | |
350 | 353 | | |
351 | 354 | | |
352 | | - | |
353 | | - | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
354 | 367 | | |
355 | 368 | | |
356 | 369 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
536 | 536 | | |
537 | 537 | | |
538 | 538 | | |
| 539 | + | |
| 540 | + | |
| 541 | + | |
| 542 | + | |
| 543 | + | |
539 | 544 | | |
540 | 545 | | |
541 | 546 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
373 | 373 | | |
374 | 374 | | |
375 | 375 | | |
| 376 | + | |
| 377 | + | |
376 | 378 | | |
377 | 379 | | |
378 | 380 | | |
| |||
401 | 403 | | |
402 | 404 | | |
403 | 405 | | |
| 406 | + | |
| 407 | + | |
404 | 408 | | |
405 | 409 | | |
406 | 410 | | |
| |||
647 | 651 | | |
648 | 652 | | |
649 | 653 | | |
| 654 | + | |
| 655 | + | |
650 | 656 | | |
651 | 657 | | |
652 | 658 | | |
| |||
757 | 763 | | |
758 | 764 | | |
759 | 765 | | |
| 766 | + | |
| 767 | + | |
760 | 768 | | |
761 | 769 | | |
762 | 770 | | |
| |||
0 commit comments