Subir todos los cambios recientes a la rama principal
This commit is contained in:
27
backend/tests/test_security.py
Normal file
27
backend/tests/test_security.py
Normal file
@@ -0,0 +1,27 @@
|
||||
import pytest
|
||||
from app.core.security import SecurityUtils
|
||||
from datetime import timedelta
|
||||
|
||||
# Test password hashing and verification
|
||||
def test_password_hashing():
|
||||
plain_password = "securepassword123"
|
||||
hashed_password = SecurityUtils.hash_password(plain_password)
|
||||
|
||||
assert SecurityUtils.verify_password(plain_password, hashed_password) == True
|
||||
assert SecurityUtils.verify_password("wrongpassword", hashed_password) == False
|
||||
|
||||
# Test JWT token generation and validation
|
||||
def test_jwt_token_generation():
|
||||
payload = {"sub": "12345", "email": "test@example.com"}
|
||||
token = SecurityUtils.create_access_token(payload, expires_delta=timedelta(minutes=15))
|
||||
|
||||
decoded_payload = SecurityUtils.verify_token(token)
|
||||
assert decoded_payload is not None
|
||||
assert decoded_payload["sub"] == "12345"
|
||||
assert decoded_payload["email"] == "test@example.com"
|
||||
|
||||
# Test TOTP secret generation
|
||||
def test_totp_secret_generation():
|
||||
secret = SecurityUtils.generate_totp_secret()
|
||||
assert len(secret) > 0
|
||||
assert isinstance(secret, str)
|
||||
Reference in New Issue
Block a user