21 lines
666 B
Python
21 lines
666 B
Python
import re
|
|
|
|
from salt import hash_password, verify_password
|
|
|
|
|
|
def test_hash_password_round_trip() -> None:
|
|
salt, hashed = hash_password("correct horse battery staple")
|
|
assert verify_password("correct horse battery staple", salt, hashed)
|
|
assert not verify_password("wrong", salt, hashed)
|
|
|
|
|
|
def test_hash_password_returns_base64() -> None:
|
|
salt, hashed = hash_password("secret")
|
|
base64_pattern = re.compile(r"^[A-Za-z0-9+/]+={0,2}$")
|
|
assert base64_pattern.fullmatch(salt)
|
|
assert base64_pattern.fullmatch(hashed)
|
|
|
|
|
|
def test_verify_password_handles_invalid_base64() -> None:
|
|
assert verify_password("secret", "**invalid**", "???") is False
|