Coverage for backend/tests/test_utils.py: 100%
23 statements
« prev ^ index » next coverage.py v7.10.7, created at 2025-09-22 15:38 +0000
« prev ^ index » next coverage.py v7.10.7, created at 2025-09-22 15:38 +0000
1from app.utils import hash_password, verify_password
4class TestPasswordUtils:
6 def test_hash_is_not_plaintext(self) -> None:
7 """Check that hashed password is not plaintext."""
9 password = "securepassword"
10 hashed = hash_password(password)
11 assert hashed != password
12 assert isinstance(hashed, str)
14 def test_correct_password_verifies(self) -> None:
15 """Check that correct password verifies."""
17 password = "anothersecurepassword"
18 hashed = hash_password(password)
19 assert verify_password(password, hashed)
21 def test_incorrect_password_fails(self) -> None:
22 """Check that incorrect password fails."""
24 password = "correcthorsebatterystaple"
25 wrong_password = "correcthorsecarrotstaple"
26 hashed = hash_password(password)
27 assert not verify_password(wrong_password, hashed)
29 def test_hash_is_unique_due_to_salt(self) -> None:
30 """Check that hash is unique due to salt."""
32 password = "saltypassword"
33 hash1 = hash_password(password)
34 hash2 = hash_password(password)
35 assert hash1 != hash2 # because bcrypt adds salt
36 assert verify_password(password, hash1)
37 assert verify_password(password, hash2)