fooder-api/fooder/test/utils/test_password_helper.py

25 lines
686 B
Python

from fooder.utils.password_helper import password_helper
import pytest
def test_password_hash_and_verify(faker):
password = faker.password()
hash = password_helper.hash(password)
assert password_helper.verify(password, hash)
def test_wrong_password_doesnt_verify(faker):
password = faker.password()
hash = password_helper.hash(password)
password2 = faker.password()
assert not password_helper.verify(password2, hash)
def test_wrong_hash_breaks(faker):
password = faker.password()
hash = password_helper.hash(password)
with pytest.raises(Exception, match="malformed"):
assert not password_helper.verify(password, hash + password)