Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion at_client/atclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ def get_encryption_key_shared_by_me(self, key: SharedKey):
try:
return EncryptionUtil.rsa_decrypt_from_base64(response.get_raw_data_response(), self.keys[KeysUtil.encryption_private_key_name])
except Exception as e:
raise AtDecryptionException(f"Failed to decrypt {to_lookup} - e")
raise AtDecryptionException(f"Failed to decrypt {to_lookup} - {e}")

def get_encryption_key_shared_by_other(self, shared_key: SharedKey):
shared_shared_key_name = shared_key.get_shared_shared_key_name()
Expand Down
35 changes: 35 additions & 0 deletions test/decrypt_error_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import unittest
from unittest.mock import MagicMock

from at_client import AtClient
from at_client.common import AtSign
from at_client.common.keys import SharedKey
from at_client.util.keysutil import KeysUtil
from at_client.exception.atexception import AtDecryptionException


class DecryptErrorDetailTest(unittest.TestCase):
"""The shared-key decrypt error must include the real exception, not literal 'e'."""

def test_error_includes_exception_detail(self):
client = AtClient.__new__(AtClient) # bypass network __init__
client.atsign = AtSign("@alice")
client.keys = {KeysUtil.encryption_private_key_name: "not-a-valid-private-key"}

resp = MagicMock()
resp.is_error.return_value = False
resp.get_raw_data_response.return_value = "not-valid-rsa-ciphertext"
client.secondary_connection = MagicMock()
client.secondary_connection.execute_command.return_value = resp

key = SharedKey("k", AtSign("@alice"), AtSign("@bob"))
with self.assertRaises(AtDecryptionException) as ctx:
client.get_encryption_key_shared_by_me(key)

msg = str(ctx.exception)
self.assertFalse(msg.rstrip().endswith("- e")) # the bug printed a literal 'e'
self.assertIn("Failed to decrypt", msg)
Comment on lines +25 to +31


if __name__ == "__main__":
unittest.main()