Skip to content

fix(tests): rewrite tests/test_websocket_auth.py::test_ws_valid_token_not_rejected for ticket-based auth (C-002 / #550) #765

Closed

Description

@AndriiPasternak31

Summary

tests/test_websocket_auth.py::TestWebSocketAuthentication::test_ws_valid_token_not_rejected (the integration variant, NOT tests/unit/test_websocket_auth.py) asserts that GET /ws?token=<JWT> does NOT return 403. Today the request correctly returns 403 because C-002 / #550 removed JWT-in-URL support in favor of single-use opaque tickets minted via POST /api/ws/ticket.

The integration test was missed when the unit-tier WebSocket-auth tests were updated for the ticket flow. The current behavior is correct production behavior; the test is misleading anyone running the integration suite into thinking there's a regression.

Context

Discovered via full test suite run on 2026-05-09:

FAILED test_websocket_auth.py::TestWebSocketAuthentication::test_ws_valid_token_not_rejected
E   AssertionError: Valid token should not get 403
E   assert 403 != 403

architecture.md "WebSocket Security (C-002, #550)" documents the new flow:

  1. Client POST /api/ws/ticket (JWT in Authorization header) → backend mints a 32-byte urlsafe ticket, stores it in Redis with a 30s TTL, returns it.
  2. Client connects to /ws?ticket=<opaque>. Backend atomically GETDELs the Redis key and only then accepts the WebSocket.
  3. JWT never enters the WebSocket URL.

Acceptance Criteria

  • Test mints a ticket via POST /api/ws/ticket and connects to /ws?ticket=<opaque>.
  • Asserts the upgrade is accepted (101) or that the server does not reject with 403.
  • Add a negative test asserting /ws?token=<JWT> returns 403, pinning the new behavior so this regression cannot recur silently.
  • Cross-reference architecture.md "WebSocket Security (C-002, SEC: WebSocket JWT passed in URL query param — CSWSH and token leakage #550)" in the test docstring.

Reproduction

cd tests && source .venv/bin/activate
pytest test_websocket_auth.py::TestWebSocketAuthentication::test_ws_valid_token_not_rejected -v

Why this matters

Today this failure looks like a regression to anyone running the suite, but it's actually the correct production behavior. The misleading test is a tax on every test-suite review.

Related

Activity

  1. added
    priority-p2
    type-bug
    status-in-progress
    on May 10, 2026
  2. added
    status-in-dev
    and removed
    status-in-progress
    on May 18, 2026
  3. vybe commented on Jun 1, 2026

    @vybe
    Contributor

    Shipped in v0.6.0 (released via #998).

  4. removed
    status-in-dev
    on Jun 1, 2026
  5. added a commit that references this issue on Jun 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

priority-p2type-bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions