1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
from pygitweb.password_hash import hash_password, verify_password
def test_hash_and_verify_roundtrip() -> None:
stored = hash_password("secret-password", config_salt="a1b2c3d4e5f67890")
assert stored.startswith("scrypt$131072$8$1$")
assert verify_password("secret-password", stored, config_salt="a1b2c3d4e5f67890")
assert not verify_password("wrong", stored, config_salt="a1b2c3d4e5f67890")
def test_verify_legacy_hash_without_config_salt() -> None:
stored = hash_password("legacy")
assert verify_password("legacy", stored, config_salt="0123456789abcdef")
def test_verify_rejects_weak_parameters() -> None:
stored = hash_password("x")
parts = stored.split("$")
parts[1] = "65536"
assert not verify_password("x", "$".join(parts))