Skip to content

test(sso): rate-limit throttle tests (#9611) + callback host-case test fix (#10255) - #10270

Merged
mrveiss merged 7 commits into
Dev_new_guifrom
issue-9611
Jun 17, 2026
Merged

mrveiss merged 7 commits into
Dev_new_guifrom
issue-9611

Conversation

@mrveiss

@mrveiss mrveiss commented Jun 17, 2026

Copy link
Copy Markdown
Owner

Thinking Path

Umbrella #9930 fixes. #9611: PR #9610's SSO rate-limit tests were absent from test_sso_auth.py (module-level limiter instances are hard to patch). #10255: test_build_callback_url_case_insensitive failed — but _build_callback_url already lowercases the host (RFC 3986); the test asserted the wrong (uppercase) expectation. Both are test-only; production rate-limit + callback logic was already correct.

What Changed

  • Added 3 genuine throttle tests (login/callback/LDAP): patch the module-level _sso_*_limiter instances with a throttled AsyncMock, invoke the real endpoint functions, assert 429 + Retry-After and that acquire/get_retry_after_seconds were awaited.
  • Corrected the case-insensitive callback test to expect the lowercased host (localhost) the production code already returns.
  • Zero production code changed.

Verification

pytest tests/api/test_sso_auth.py → 8 passed (3 new rate-limit + corrected case test + existing). ruff + black clean. Rebased onto latest Dev_new_gui.

Model Used

Claude Opus 4.8 (implementer subagent + self-review)

Closes #9611
Closes #10255

mrveiss and others added 2 commits June 17, 2026 17:57
Test assertion was inverted — production code already normalises the host
to lowercase via urlsplit().hostname (RFC 3986 §3.2.2); the test incorrectly
expected the original mixed-case form.  Correct the assertion so the test
accurately reflects the intended security behaviour.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…ert 429 + Retry-After (#9611)

Add three tests covering the rate-limit guard in each SSO endpoint
(initiate_sso_login, oauth_callback, ldap_login).  The core challenge:
FastAPI's @router.get/post decorator replaces endpoint functions with
MagicMock objects when `router` itself is mocked, making the coroutines
unreachable.  Fix: stub APIRouter so .get/.post act as identity decorators,
preserving the real coroutine function in the module namespace.  Each test:
  - loads a fresh module instance (isolation)
  - replaces the module-level limiter with patch.object(_sso_auth, _LIMITER)
  - drives acquire→False / get_retry_after_seconds→30
  - asserts HTTP 429 + Retry-After: 30 header

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@github-actions

github-actions Bot commented Jun 17, 2026 •

Copy link
Copy Markdown
Contributor

✅ SSOT Configuration Compliance: Passing

🎉 No hardcoded values detected that have SSOT config equivalents!

github-actions Bot and others added 5 commits June 17, 2026 15:09
Applied Black, isort, and autoflake to match code-quality checks.
Triggered by workflow auto-fix-formatting.yml.

Co-Authored-By: Paperclip <noreply@paperclip.ing>
@mrveiss

mrveiss commented Jun 17, 2026

Copy link
Copy Markdown
Owner Author

Review — APPROVED ✅ (admin-merge: sole failure is known infra)

Test-only change (SLM test_sso_auth.py): 3 genuine rate-limit throttle tests (assert 429 + Retry-After, patch module-level limiters, invoke real endpoints) + corrected case-insensitive callback assertion. 8 tests green locally; ruff/black clean.

Required CI: code-quality ✅, startup-import-smoke ✅, Test Summary ✅, Analyze Python ✅, SAST ✅, hardened-smoke-test ✅. The lone smoke-test fail is the known intermittent runner disk-full (no space left on device writing triton/_C/libtriton.so — the torch/CUDA Docker layer), NOT a code failure; a test-only diff cannot affect the image build. Admin-merging per documented practice.

@mrveiss
mrveiss merged commit d78c5e5 into Dev_new_gui Jun 17, 2026
25 of 26 checks passed
@mrveiss
mrveiss deleted the issue-9611 branch June 17, 2026 21: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.

1 participant