mirror of
https://github.com/PR0M3TH3AN/SeedPass.git
synced 2026-11-06 04:42:35 +00:00
Add checksum verification test
This commit is contained in:
1 parent
0838b05119
commit
95c8b7dd48
2 files changed
+40
-4
No files matched your search
@@ -0,0 +1,34 @@
|
||||
import re
|
||||
import sys
|
||||
from pathlib import Path
|
||||
from tempfile import TemporaryDirectory
|
||||
|
||||
from cryptography.fernet import Fernet
|
||||
|
||||
sys.path.append(str(Path(__file__).resolve().parents[1]))
|
||||
|
||||
from password_manager.encryption import EncryptionManager
|
||||
from utils.checksum import verify_and_update_checksum
|
||||
|
||||
|
||||
def test_encryption_checksum_workflow():
|
||||
with TemporaryDirectory() as tmpdir:
|
||||
tmp_path = Path(tmpdir)
|
||||
key = Fernet.generate_key()
|
||||
manager = EncryptionManager(key, tmp_path)
|
||||
|
||||
data = {"value": 1}
|
||||
manager.save_json_data(data)
|
||||
manager.update_checksum()
|
||||
|
||||
enc_file = tmp_path / "seedpass_passwords_db.json.enc"
|
||||
chk_file = tmp_path / "seedpass_passwords_db.json_checksum.txt"
|
||||
|
||||
checksum = chk_file.read_text().strip()
|
||||
assert re.fullmatch(r"[0-9a-f]{64}", checksum)
|
||||
|
||||
manager.save_json_data({"value": 2})
|
||||
assert not verify_and_update_checksum(str(enc_file), str(chk_file))
|
||||
|
||||
manager.update_checksum()
|
||||
assert verify_and_update_checksum(str(enc_file), str(chk_file))
|
||||
Reference in new issue
Block a user