Andrei — Neagoie Python
class UserNotFoundError(AuthenticationError): """Raised when user doesn't exist""" pass
def test_register_user_success(self, auth_service): user = auth_service.register_user("test@example.com", "ValidPass123!") assert user.email == "test@example.com" assert user.user_id is not None andrei neagoie python
def test_verify_wrong_password(self): hasher = PasswordHasher() hashed = hasher.hash_password("Correct123!") assert not hasher.verify_password("Wrong456!", hashed) class TestAuthenticationService: @pytest.fixture def auth_service(self): return AuthenticationService(secret_key="test-secret-key-123") andrei neagoie python
class RateLimitExceededError(AuthenticationError): """Raised when too many attempts""" pass andrei neagoie python
import jwt from jwt.exceptions import InvalidTokenError, ExpiredSignatureError class AuthenticationError(Exception): """Base exception for authentication errors""" pass
def test_hash_password_weak(self): hasher = PasswordHasher() with pytest.raises(ValidationError): hasher.hash_password("weak")
def is_locked(self) -> bool: """Check if user account is currently locked""" if self.locked_until and datetime.utcnow() < self.locked_until: return True return False class PasswordHasher: """Handles secure password hashing and verification"""