mirror of
https://github.com/PR0M3TH3AN/SeedPass.git
synced 2025-09-08 23:38:49 +00:00
Add unit tests and update docs
This commit is contained in:
@@ -7,4 +7,6 @@ monstr @ git+https://github.com/monty888/monstr.git@master#egg=monstr
|
||||
mnemonic
|
||||
aiohttp
|
||||
bcrypt
|
||||
bip85
|
||||
bip85
|
||||
pytest>=7.0
|
||||
|
||||
|
38
src/tests/test_fingerprint_encryption.py
Normal file
38
src/tests/test_fingerprint_encryption.py
Normal file
@@ -0,0 +1,38 @@
|
||||
import hashlib
|
||||
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 utils.fingerprint import generate_fingerprint
|
||||
from password_manager.encryption import EncryptionManager
|
||||
|
||||
|
||||
def test_generate_fingerprint_deterministic():
|
||||
seed = "abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about"
|
||||
expected = (
|
||||
hashlib.sha256(seed.strip().lower().encode("utf-8")).hexdigest()[:16].upper()
|
||||
)
|
||||
fp1 = generate_fingerprint(seed)
|
||||
fp2 = generate_fingerprint(seed.upper())
|
||||
assert fp1 == expected
|
||||
assert fp1 == fp2
|
||||
|
||||
|
||||
def test_encryption_round_trip():
|
||||
with TemporaryDirectory() as tmpdir:
|
||||
key = Fernet.generate_key()
|
||||
manager = EncryptionManager(key, Path(tmpdir))
|
||||
data = b"secret data"
|
||||
rel_path = Path("testfile.enc")
|
||||
manager.encrypt_and_save_file(data, rel_path)
|
||||
decrypted = manager.decrypt_file(rel_path)
|
||||
assert decrypted == data
|
||||
|
||||
# parent seed round trip
|
||||
seed = "correct horse battery staple"
|
||||
manager.encrypt_parent_seed(seed)
|
||||
assert manager.decrypt_parent_seed() == seed
|
Reference in New Issue
Block a user