新增 API 测试用例,修复失效接口问题
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
from jose import jwt
|
||||
|
||||
from app.core.config import settings
|
||||
from app.core.security import (
|
||||
create_access_token,
|
||||
create_refresh_token,
|
||||
get_password_hash,
|
||||
verify_password,
|
||||
)
|
||||
|
||||
|
||||
def test_password_hash_roundtrip():
|
||||
hashed = get_password_hash("secret123")
|
||||
assert hashed != "secret123"
|
||||
assert verify_password("secret123", hashed) is True
|
||||
assert verify_password("wrong", hashed) is False
|
||||
|
||||
|
||||
def test_create_access_token_sets_access_type():
|
||||
token = create_access_token("alice")
|
||||
payload = jwt.decode(token, settings.SECRET_KEY, algorithms=[settings.ALGORITHM])
|
||||
|
||||
assert payload["sub"] == "alice"
|
||||
assert payload["type"] == "access"
|
||||
assert "exp" in payload
|
||||
assert "iat" in payload
|
||||
|
||||
|
||||
def test_create_refresh_token_sets_refresh_type():
|
||||
token = create_refresh_token("alice")
|
||||
payload = jwt.decode(token, settings.SECRET_KEY, algorithms=[settings.ALGORITHM])
|
||||
|
||||
assert payload["sub"] == "alice"
|
||||
assert payload["type"] == "refresh"
|
||||
assert "exp" in payload
|
||||
assert "iat" in payload
|
||||
Reference in New Issue
Block a user