mirror of
https://github.com/PR0M3TH3AN/SeedPass.git
synced 2026-10-27 07:52:03 +00:00
test(utils): Add test and error handling for wiped InMemorySecret
- Updated `InMemorySecret.get_bytes()` in `src/utils/memory_protection.py` to raise a `RuntimeError` if the secret has been wiped, replacing the previous `AttributeError`. - Added `test_access_after_wipe_raises_error` to `src/tests/test_memory_protection.py` to verify this behavior. Co-authored-by: PR0M3TH3AN <[email protected]>
This commit is contained in:
1 parent
335de7abe3
commit
d729466513
2 files changed
+15
No files matched your search
@@ -27,3 +27,16 @@ def test_inmemory_secret_wipe_clears_attributes():
|
||||
assert secret._nonce is None
|
||||
assert secret._cipher is None
|
||||
assert secret._encrypted is None
|
||||
|
||||
|
||||
def test_access_after_wipe_raises_error():
|
||||
secret = InMemorySecret(b"secret data")
|
||||
secret.wipe()
|
||||
|
||||
with pytest.raises(RuntimeError) as excinfo:
|
||||
secret.get_bytes()
|
||||
assert str(excinfo.value) == "Secret has been wiped"
|
||||
|
||||
with pytest.raises(RuntimeError) as excinfo:
|
||||
secret.get_str()
|
||||
assert str(excinfo.value) == "Secret has been wiped"
|
||||
@@ -17,6 +17,8 @@ class InMemorySecret:
|
||||
|
||||
def get_bytes(self) -> bytes:
|
||||
"""Decrypt and return the plaintext bytes."""
|
||||
if self._cipher is None:
|
||||
raise RuntimeError("Secret has been wiped")
|
||||
return self._cipher.decrypt(self._nonce, self._encrypted, None)
|
||||
|
||||
def wipe(self) -> None:
|
||||
|
||||
Reference in new issue
Block a user