diff options
-rw-r--r-- | account.py | 3 | ||||
-rw-r--r-- | tests/test_crypto.py | 29 |
2 files changed, 27 insertions, 5 deletions
@@ -12,8 +12,7 @@ class Account: """Represents a login account.""" def __init__(self, uuid: str, application: str, username: str, - password: str, url: str) -> None: - self.self = self + password: str, url: str) -> None: #pylint: R0913,R0917 self.uuid = uuid self.application = application self.username = username diff --git a/tests/test_crypto.py b/tests/test_crypto.py index 83fbe41..1296e76 100644 --- a/tests/test_crypto.py +++ b/tests/test_crypto.py @@ -1,27 +1,48 @@ -# test_crypto.py -import unittest -from io import BytesIO +""" +Test file for crypto.py +""" + +import os from cryptography.fernet import Fernet +from io import BytesIO +from unittest import TestCase from crypto import generate_key, load_key, encrypt, decrypt +from unittest.mock import patch class TestCryptoFunctions(unittest.TestCase): + """ + This test class checks the functionality of various encryption and + decryption functions. + + The tests cover key generation, loading, and usage in both encryption and + decryption processes. + """ def setUp(self): + """Initialize test environment by generating a new key.""" self.key = generate_key() with open('vault.sqlite', 'wb') as vault: vault.write(b'Hello, world!') def tearDown(self): + """Clean up test data after each test.""" try: os.remove('vault.sqlite') except FileNotFoundError: pass def test_generate_key(self): + """Test that generate_key() returns a new key on each call.""" new_key = generate_key() self.assertNotEqual(new_key, self.key) def test_load_key(self): + """ + Test that load_key() loads and returns the correct key from file. + + This function also checks for a FileNotFoundError when loading an + invalid key file. + """ key_file = 'key.bin' with open(key_file, 'wb') as key: key.write(self.key) @@ -29,6 +50,7 @@ class TestCryptoFunctions(unittest.TestCase): self.assertEqual(loaded_key, self.key) def test_encrypt_decrypt(self): + """Test the end-to-end encryption and decryption process.""" encrypt(self.key, filename='vault.sqlite') with open('vault.sqlite', 'rb') as vault: encrypted_data = vault.read() @@ -39,6 +61,7 @@ class TestCryptoFunctions(unittest.TestCase): self.assertEqual(f.decrypt(encrypted_data), b'Hello, world!') def test_load_invalid_key(self): + """Test that load_key() raises a FileNotFoundError for invalid key files.""" key_file = 'key.bin' try: load_key(key_file) |