from __future__ import annotations import hashlib from pathlib import Path from app.utils.hashing import sha256_bytes, sha256_file def test_sha256_bytes_matches_hashlib(): data = b"legacyhub" * 1000 assert sha256_bytes(data) == hashlib.sha256(data).hexdigest() def test_sha256_file_streaming_matches_hashlib(tmp_path: Path): payload = b"\x01\x02\x03" * 5_000_000 # 15 MiB - exercises chunking target = tmp_path / "blob.bin" target.write_bytes(payload) assert sha256_file(target) == hashlib.sha256(payload).hexdigest() def test_sha256_file_distinguishes_content(tmp_path: Path): a = tmp_path / "a.bin" b = tmp_path / "b.bin" a.write_bytes(b"alpha") b.write_bytes(b"beta") assert sha256_file(a) != sha256_file(b)