31 lines
748 B
Python
31 lines
748 B
Python
import jwt
|
|
|
|
from src.auth_project.core.config import settings
|
|
from src.auth_project.core.security import (
|
|
create_access_token,
|
|
hash_password,
|
|
verify_password,
|
|
)
|
|
|
|
|
|
def test_password_hashing() -> None:
|
|
password = "UnMotDePasseLong123!"
|
|
hashed = hash_password(password)
|
|
|
|
assert hashed != password
|
|
assert verify_password(password, hashed)
|
|
assert not verify_password("MauvaisMotDePasse", hashed)
|
|
|
|
|
|
def test_create_access_token() -> None:
|
|
token = create_access_token(user_id=42, role="user")
|
|
|
|
payload = jwt.decode(
|
|
token,
|
|
settings.jwt_secret_key,
|
|
algorithms=[settings.jwt_algorithm],
|
|
)
|
|
|
|
assert payload["sub"] == "42"
|
|
assert payload["role"] == "user"
|
|
assert "exp" in payload |