From fd3f62c787cf3fe022a95b4da4393b31e57298c2 Mon Sep 17 00:00:00 2001 From: 7000pctAUTO Date: Sun, 22 Mar 2026 11:22:37 +0000 Subject: [PATCH] Initial upload: snippet-manager with CI/CD workflow --- tests/test_crypto.py | 54 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 tests/test_crypto.py diff --git a/tests/test_crypto.py b/tests/test_crypto.py new file mode 100644 index 0000000..feb0cfc --- /dev/null +++ b/tests/test_crypto.py @@ -0,0 +1,54 @@ +"""Tests for encryption service.""" + +import tempfile +import os + +import pytest + +from snip.crypto.service import CryptoService + + +@pytest.fixture +def crypto_service(): + with tempfile.NamedTemporaryFile(suffix=".key", delete=False) as f: + key_file = f.name + service = CryptoService(key_file) + yield service + if os.path.exists(key_file): + os.unlink(key_file) + salt_file = f"{key_file}.salt" + if os.path.exists(salt_file): + os.unlink(salt_file) + + +def test_encrypt_decrypt(crypto_service): + """Test encryption and decryption round-trip.""" + plaintext = "Hello, World!" + password = "test_password_123" + + encrypted = crypto_service.encrypt(plaintext, password) + assert encrypted != plaintext + + decrypted = crypto_service.decrypt(encrypted, password) + assert decrypted == plaintext + + +def test_wrong_password_fails(crypto_service): + """Test that wrong password fails to decrypt.""" + plaintext = "Secret message" + password = "correct_password" + + encrypted = crypto_service.encrypt(plaintext, password) + + with pytest.raises(Exception): + crypto_service.decrypt(encrypted, "wrong_password") + + +def test_different_passwords_different_output(crypto_service): + """Test that different passwords produce different ciphertext.""" + plaintext = "Same text" + + encrypted1 = crypto_service.encrypt(plaintext, "password1") + encrypted2 = crypto_service.encrypt(plaintext, "password2") + + assert encrypted1 != encrypted2