krz/yoshi-cli

Archived

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

Commit 51da30891e

51da30891ecb75b2f565ee02b1b3648adaa0f931

parent: 00eaf465f1

Verified · cmc

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

add docstrings, fix imports, and disable certain pylint warnings

Layout: unified · split

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