Commit 51da30891e
Verified · cmc
Layout: unified · split
account.py +1 −2
| @@ -12,8 +12,7 @@ class Account: | ||
| 12 | 12 | """Represents a login account.""" |
| 13 | 13 | |
| 14 | 14 | def __init__(self, uuid: str, application: str, username: str, |
| 15 | password: str, url: str) -> None: | |
| 16 | self.self = self | |
| 15 | password: str, url: str) -> None: #pylint: R0913,R0917 | |
| 17 | 16 | self.uuid = uuid |
| 18 | 17 | self.application = application |
| 19 | 18 | self.username = username |
tests/test_crypto.py +26 −3
| @@ -1,27 +1,48 @@ | ||
| 1 | # test_crypto.py | |
| 2 | import unittest | |
| 3 | from io import BytesIO | |
| 1 | """ | |
| 2 | Test file for crypto.py | |
| 3 | """ | |
| 4 | ||
| 5 | import os | |
| 4 | 6 | from cryptography.fernet import Fernet |
| 7 | from io import BytesIO | |
| 8 | from unittest import TestCase | |
| 5 | 9 | from crypto import generate_key, load_key, encrypt, decrypt |
| 10 | from unittest.mock import patch | |
| 6 | 11 | |
| 7 | 12 | class TestCryptoFunctions(unittest.TestCase): |
| 13 | """ | |
| 14 | This test class checks the functionality of various encryption and | |
| 15 | decryption functions. | |
| 16 | ||
| 17 | The tests cover key generation, loading, and usage in both encryption and | |
| 18 | decryption processes. | |
| 19 | """ | |
| 8 | 20 | |
| 9 | 21 | def setUp(self): |
| 22 | """Initialize test environment by generating a new key.""" | |
| 10 | 23 | self.key = generate_key() |
| 11 | 24 | with open('vault.sqlite', 'wb') as vault: |
| 12 | 25 | vault.write(b'Hello, world!') |
| 13 | 26 | |
| 14 | 27 | def tearDown(self): |
| 28 | """Clean up test data after each test.""" | |
| 15 | 29 | try: |
| 16 | 30 | os.remove('vault.sqlite') |
| 17 | 31 | except FileNotFoundError: |
| 18 | 32 | pass |
| 19 | 33 | |
| 20 | 34 | def test_generate_key(self): |
| 35 | """Test that generate_key() returns a new key on each call.""" | |
| 21 | 36 | new_key = generate_key() |
| 22 | 37 | self.assertNotEqual(new_key, self.key) |
| 23 | 38 | |
| 24 | 39 | def test_load_key(self): |
| 40 | """ | |
| 41 | Test that load_key() loads and returns the correct key from file. | |
| 42 | ||
| 43 | This function also checks for a FileNotFoundError when loading an | |
| 44 | invalid key file. | |
| 45 | """ | |
| 25 | 46 | key_file = 'key.bin' |
| 26 | 47 | with open(key_file, 'wb') as key: |
| 27 | 48 | key.write(self.key) |
| @@ -29,6 +50,7 @@ class TestCryptoFunctions(unittest.TestCase): | ||
| 29 | 50 | self.assertEqual(loaded_key, self.key) |
| 30 | 51 | |
| 31 | 52 | def test_encrypt_decrypt(self): |
| 53 | """Test the end-to-end encryption and decryption process.""" | |
| 32 | 54 | encrypt(self.key, filename='vault.sqlite') |
| 33 | 55 | with open('vault.sqlite', 'rb') as vault: |
| 34 | 56 | encrypted_data = vault.read() |
| @@ -39,6 +61,7 @@ class TestCryptoFunctions(unittest.TestCase): | ||
| 39 | 61 | self.assertEqual(f.decrypt(encrypted_data), b'Hello, world!') |
| 40 | 62 | |
| 41 | 63 | def test_load_invalid_key(self): |
| 64 | """Test that load_key() raises a FileNotFoundError for invalid key files.""" | |
| 42 | 65 | key_file = 'key.bin' |
| 43 | 66 | try: |
| 44 | 67 | load_key(key_file) |