Fix checksum file naming and add tests

This commit is contained in:
thePR0M3TH3AN
2025-08-03 20:32:03 -04:00
parent bc8307f611
commit 42f9f0c4bb
2 changed files with 39 additions and 2 deletions

View File

@@ -1,5 +1,6 @@
import re
import sys
import hashlib
from pathlib import Path
from tempfile import TemporaryDirectory
@@ -23,7 +24,7 @@ def test_encryption_checksum_workflow():
manager.update_checksum()
enc_file = tmp_path / "seedpass_entries_db.json.enc"
chk_file = tmp_path / "seedpass_entries_db.json_checksum.txt"
chk_file = tmp_path / "seedpass_entries_db_checksum.txt"
checksum = chk_file.read_text().strip()
assert re.fullmatch(r"[0-9a-f]{64}", checksum)
@@ -33,3 +34,24 @@ def test_encryption_checksum_workflow():
manager.update_checksum()
assert verify_and_update_checksum(str(enc_file), str(chk_file))
def test_update_checksum_removes_legacy(tmp_path):
key = base64.urlsafe_b64encode(os.urandom(32))
manager = EncryptionManager(key, tmp_path)
manager.save_json_data({"value": 1})
legacy = tmp_path / "seedpass_entries_db.json_checksum.txt"
legacy.write_text("legacy")
manager.update_checksum()
enc_file = tmp_path / "seedpass_entries_db.json.enc"
new_chk = tmp_path / "seedpass_entries_db_checksum.txt"
assert new_chk.exists()
assert not legacy.exists()
expected = hashlib.sha256(enc_file.read_bytes()).hexdigest()
assert new_chk.read_text() == expected