Skip to content

SLM backend: add direct test coverage for GET /api/auth/me #16385

Description

@mrveiss

What

Found while implementing #16374. #16374's nginx auth_request gate on /autobot-api/ targets GET /api/auth/me (autobot-slm-backend/api/auth.py, get_current_user_info) as its session-verify endpoint: 2xx for a valid SLM session, 401/403 otherwise (services/auth.py's security = HTTPBearer() and get_current_user).

get_current_user itself is exercised indirectly by other tests (autobot-slm-backend/tests/api/test_slm_endpoints_12515.py, test_drift_resolve.py, test_local_admin_socket_15728.py, test_step_up_auth.py), but nothing tests the /api/auth/me route directly — valid-session-gives-2xx / missing-or-invalid-gives-401 for that specific route has no test today. Not added in #16374 itself: this repo's SLM API tests bootstrap a heavy stub environment per file (see test_auth_logout.py's module-level sys.modules dance) rather than a real TestClient, and building that correctly for a new route is separate scope from the nginx template change.

Why it matters now

This route is no longer just a UI convenience call — it is the fail-closed gate protecting every /autobot-api/* request from carrying backend-admin credentials. A regression in get_current_user_info or its get_current_user dependency (e.g. always returning 200, or crashing in a way nginx's auth_request treats as pass-through) would silently reopen #16374.

Acceptance criteria

  • A test asserts GET /api/auth/me returns 2xx for a valid session token (via the real get_current_user dependency, not a mock of the route itself).
  • A test asserts it returns 401 (or 403, matching HTTPBearer's default) for a missing or invalid token.

Activity

  1. added this to the v0.9.0 milestone on Sep 12, 2026
  2. modified the milestones: v0.9.0, v0.10.0 on Sep 17, 2026
  3. mrveiss commented on Oct 3, 2026

    @mrveiss
    OwnerAuthor

    Closed — both criteria delivered in autobot-slm-backend/tests/api/test_auth_me_16385.py, verified at 2a6c281760

    AC1 — 2xx for a valid session token, via the real get_current_user.
    TestAuthMeValidToken::test_valid_token_returns_2xx mints a token, calls
    GET /api/auth/me through a TestClient, and asserts both halves:

    assert 200 <= resp.status_code < 300, resp.text
    assert resp.json() == {"username": "testuser", "is_admin": False, "user_type": "slm_admin"}

    The status range and the body, not one standing in for the other.

    AC2 — 401 for a missing or invalid token. Six assertions at :260, :271, :277,
    :288, :293, :299, covering missing, malformed and well-formed-but-wrong-signature,
    plus the password-epoch cases where a token issued before a password change is rejected
    and one issued after is accepted.

    And the test is wired to the real dependency rather than a stand-in, which is what
    the criterion's "via the real get_current_user" was guarding against. The file says
    so at :13 and :19: other tests patch get_current_user_info with a MagicMock and
    can never produce a real HTTP outcome, so this one leaves get_current_user as the
    genuine dependency. :26-28 adds that get_current_user_info is extracted from
    api/auth.py by AST, not by import, so a future change to that route's body or
    decorator is caught rather than silently bypassed.

    That last point is why this closes rather than merely passing: the test asserts the
    route's real behaviour and would notice if the route stopped being the thing under test.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions