krz/yoshi-cli

Archived

A password manager for the command line. cli password-manager terminal

Commit e5d61719e2

e5d61719e201a1c25e9907bd220bfcac4fc9a4f5

parent: 40128fb5b6

Verified · cmc

cmc <hello@cleberg.net> · 2024-11-07 03:20 UTC

remove tests for now

Layout: unified · split

tests/test_crypto.py deleted −73
@@ -1,73 +0,0 @@
1"""
2Test file for crypto.py
3"""
4
5import os
6from cryptography.fernet import Fernet
7from io import BytesIO
8from unittest import TestCase
9from crypto import generate_key, load_key, encrypt, decrypt
10from unittest.mock import patch
11
12class 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 """
20
21 def setUp(self):
22 """Initialize test environment by generating a new key."""
23 self.key = generate_key()
24 with open('vault.sqlite', 'wb') as vault:
25 vault.write(b'Hello, world!')
26
27 def tearDown(self):
28 """Clean up test data after each test."""
29 try:
30 os.remove('vault.sqlite')
31 except FileNotFoundError:
32 pass
33
34 def test_generate_key(self):
35 """Test that generate_key() returns a new key on each call."""
36 new_key = generate_key()
37 self.assertNotEqual(new_key, self.key)
38
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 """
46 key_file = 'key.bin'
47 with open(key_file, 'wb') as key:
48 key.write(self.key)
49 loaded_key = load_key(key_file)
50 self.assertEqual(loaded_key, self.key)
51
52 def test_encrypt_decrypt(self):
53 """Test the end-to-end encryption and decryption process."""
54 encrypt(self.key, filename='vault.sqlite')
55 with open('vault.sqlite', 'rb') as vault:
56 encrypted_data = vault.read()
57 decrypt(self.key)
58 with open('vault.sqlite', 'rb') as vault:
59 decrypted_data = vault.read()
60 f = Fernet(self.key)
61 self.assertEqual(f.decrypt(encrypted_data), b'Hello, world!')
62
63 def test_load_invalid_key(self):
64 """Test that load_key() raises a FileNotFoundError for invalid key files."""
65 key_file = 'key.bin'
66 try:
67 load_key(key_file)
68 self.fail('Expected FileNotFoundError')
69 except FileNotFoundError:
70 pass
71
72if __name__ == '__main__':
73 unittest.main()