fix(redis): 修复 Redis 流读取兼容性问题
- 支持 bytes 和 str 类型的 entry_id - 支持 list 类型响应格式 - 优化 payload 解码处理
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from uuid import UUID
|
||||
|
||||
import pytest
|
||||
from fastapi import HTTPException
|
||||
|
||||
from core.auth.jwt_verifier import TokenValidationError
|
||||
import v1.users.dependencies as deps
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_get_current_user_falls_back_to_supabase_validation(monkeypatch) -> None:
|
||||
class _BrokenVerifier:
|
||||
def verify(self, token: str) -> dict[str, object]:
|
||||
del token
|
||||
raise TokenValidationError("Token validation failed")
|
||||
|
||||
monkeypatch.setattr(deps, "get_jwt_verifier", lambda: _BrokenVerifier())
|
||||
|
||||
async def _fallback(token: str):
|
||||
del token
|
||||
return deps.CurrentUser(
|
||||
id=UUID("e8845a17-282b-4a63-8025-194a06235958"),
|
||||
email="dagronl@126.com",
|
||||
role="authenticated",
|
||||
)
|
||||
|
||||
monkeypatch.setattr(deps, "_verify_user_with_supabase", _fallback)
|
||||
|
||||
user = await deps.get_current_user(authorization="Bearer valid-token")
|
||||
|
||||
assert str(user.id) == "e8845a17-282b-4a63-8025-194a06235958"
|
||||
assert user.email == "dagronl@126.com"
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_get_current_user_raises_401_when_fallback_fails(monkeypatch) -> None:
|
||||
class _BrokenVerifier:
|
||||
def verify(self, token: str) -> dict[str, object]:
|
||||
del token
|
||||
raise TokenValidationError("Token validation failed")
|
||||
|
||||
monkeypatch.setattr(deps, "get_jwt_verifier", lambda: _BrokenVerifier())
|
||||
|
||||
async def _fallback(token: str):
|
||||
del token
|
||||
return None
|
||||
|
||||
monkeypatch.setattr(deps, "_verify_user_with_supabase", _fallback)
|
||||
|
||||
with pytest.raises(HTTPException) as exc:
|
||||
await deps.get_current_user(authorization="Bearer invalid-token")
|
||||
|
||||
assert exc.value.status_code == 401
|
||||
Reference in New Issue
Block a user