Island: Fix incomplete logic in RepositoryEncrypto.reset_key()

This commit is contained in:
Mike Salvatore 2022-07-11 11:38:23 -04:00
parent 5c65d581b5
commit e362875201
2 changed files with 11 additions and 0 deletions

View File

@ -52,6 +52,9 @@ class RepositoryEncryptor(ILockableEncryptor):
if self._key_file.is_file():
self._key_file.unlink()
self._password_based_encryptor = None
self._key_based_encryptor = None
def encrypt(self, plaintext: bytes) -> bytes:
if self._key_based_encryptor is None:
raise LockedKeyError("Cannot encrypt while the encryptor is locked)")

View File

@ -99,6 +99,14 @@ def test_reset(encryptor, key_file):
assert key_file_hash_1 != key_file_hash_2
def test_encrypt_after_reset(encryptor, key_file):
encryptor.unlock(SECRET)
encryptor.reset_key()
with pytest.raises(LockedKeyError):
encryptor.encrypt(PLAINTEXT)
def test_reset_before_unlock(encryptor):
# Test will fail if an exception is raised
encryptor.reset_key()