Skip to content

fix(auth): read wallet_id cookie in session restore endpoint - #430

Open
amberly-d wants to merge 1 commit into
Quantarq:mainfrom
amberly-d:fix/session-restore-read-cookie
Open

fix(auth): read wallet_id cookie in session restore endpoint#430
amberly-d wants to merge 1 commit into
Quantarq:mainfrom
amberly-d:fix/session-restore-read-cookie

Conversation

@amberly-d

Copy link
Copy Markdown
Contributor

Description

Fix GET /api/auth/session to read the httpOnly wallet_id cookie and look up the session in Redis via session_store. Previously the endpoint only accepted a query parameter that the frontend never sends.

Related Issue

Closes #419

Change Type

  • fix — bug fix
  • test — adding or updating tests

Testing Done

  • Valid cookie returns 200 with walletId
  • Missing cookie returns 401
  • Expired/invalid cookie returns 401
  • Query param backward compatibility preserved
  • 5 tests pass via pytest web_app/tests/test_auth_session.py -v

Screenshots (if UI changes)

None

Environment Variables

None

Checklist

  • make lint passes (pylint on changed .py files)
  • make test passes (pytest in quantara/web_app/tests/)
  • CI is green on this PR
  • Documentation updated (if applicable)
  • PR is linked to a related issue (Closes #419)

- GET /api/auth/session now reads the httpOnly wallet_id cookie
- Falls back to session_store.get_wallet_id(token) for Redis lookup
- Backward-compatible: query param still works if provided
- Removed stale REPO-002 comment
- Added 5 tests covering valid/missing/expired cookie and query param

Closes Quantarq#419
"/api/auth/session",
cookies={"wallet_id": "valid-token"},
)
assert resp.status_code == 200
)
assert resp.status_code == 200
body = resp.json()
assert body["authenticated"] is True
assert resp.status_code == 200
body = resp.json()
assert body["authenticated"] is True
assert body["walletId"] == "STELLAR-123"
class TestGetSessionMissingCookie:
def test_no_cookie_returns_401(self, client):
resp = client.get("/api/auth/session")
assert resp.status_code == 401
def test_no_cookie_returns_401(self, client):
resp = client.get("/api/auth/session")
assert resp.status_code == 401
assert resp.json()["detail"] == "No active wallet session"
class TestGetSessionBackwardCompat:
def test_query_param_still_works(self, client):
resp = client.get("/api/auth/session?wallet_id=QRPARAM-456")
assert resp.status_code == 200
resp = client.get("/api/auth/session?wallet_id=QRPARAM-456")
assert resp.status_code == 200
body = resp.json()
assert body["authenticated"] is True
assert resp.status_code == 200
body = resp.json()
assert body["authenticated"] is True
assert body["walletId"] == "QRPARAM-456"
"/api/auth/session?wallet_id=QUERY-WALLET",
cookies={"wallet_id": "cookie-token"},
)
assert resp.status_code == 200
cookies={"wallet_id": "cookie-token"},
)
assert resp.status_code == 200
assert resp.json()["walletId"] == "QUERY-WALLET"
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.

Session restore never reads the auth cookie: wallet session always fails

3 participants