Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions services/auth/src/routers/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,9 @@ async def me(token: str = Depends(_get_token), db: AsyncSession = Depends(get_db
payload = decode_token(token)
except ValueError:
raise HTTPException(401, "invalid token")
if payload.get("type") != "access":
# issue #76: refresh-токен — не identity, как в Go-мидлварях (#53)
raise HTTPException(401, "not an access token")
user_id = payload["sub"]
# user_id is str from JWT; compare as UUID
import uuid
Expand Down
12 changes: 12 additions & 0 deletions services/auth/tests/test_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,18 @@ def test_me_oversized_token_rejected():
assert r.status_code == 401


def test_me_with_refresh_token_rejected():
# issue #76: refresh-токен — не identity для /me
mock_db = AsyncMock()
mock_db.execute = AsyncMock(return_value=FakeResult(None))
token = create_refresh_token(str(uuid.uuid4()))
c = client_with_mock(mock_db)
r = c.get("/api/v1/auth/me", headers={"Authorization": f"Bearer {token}"})
clear_overrides()
assert r.status_code == 401
mock_db.execute.assert_not_awaited()


def test_refresh_token_without_exp_rejected():
# issue #53: token without exp must not validate
import jwt as pyjwt
Expand Down
Loading