Skip to content

Commit

Permalink
Fix for #384
Browse files Browse the repository at this point in the history
  • Loading branch information
br-olf committed Mar 21, 2024
1 parent e43ca6c commit 4a59392
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
2 changes: 2 additions & 0 deletions pykeepass/pykeepass.py
Original file line number Diff line number Diff line change
Expand Up @@ -710,6 +710,8 @@ def deref(self, value):
if search_in == 'uuid':
search_value = uuid.UUID(search_value)
ref_entry = self.find_entries(first=True, **{search_in: search_value})
if ref_entry is None:
return None
value = value.replace(ref, getattr(ref_entry, wanted_field))
return self.deref(value)

Expand Down
14 changes: 14 additions & 0 deletions tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,20 @@ def test_references(self):
self.assertNotEqual(original_entry, clone1)
self.assertNotEqual(clone1, clone2)

def test_broken_reference(self):
# TODO: move the entry into test databases
broken_entry_title = 'broken reference'
self.kp.add_entry(
self.kp.root_group,
title=broken_entry_title,
username='{REF:U@I:AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA}',
password='{REF:P@I:AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA}',
)
broken_entry = self.kp.find_entries(title=broken_entry_title, first=True)
self.assertEqual(broken_entry.deref('username'), None)
self.assertEqual(broken_entry.deref('password'), None)
self.kp.delete_entry(broken_entry)

def test_set_and_get_fields(self):
time = datetime.now(timezone.utc).replace(microsecond=0)
changed_time = time + timedelta(hours=9)
Expand Down

0 comments on commit 4a59392

Please sign in to comment.