fix(auth): read wallet_id cookie in session restore endpoint - #430
Open
amberly-d wants to merge 1 commit into
Open
fix(auth): read wallet_id cookie in session restore endpoint#430amberly-d wants to merge 1 commit into
amberly-d wants to merge 1 commit into
Conversation
- 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" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
Testing Done
pytest web_app/tests/test_auth_session.py -vScreenshots (if UI changes)
None
Environment Variables
None
Checklist
make lintpasses (pylint on changed.pyfiles)make testpasses (pytest inquantara/web_app/tests/)Closes #419)