Skip to content

Commit

Permalink
Merge pull request #104 from openpassword/handle-deleted-items
Browse files Browse the repository at this point in the history
Handle deleted items
  • Loading branch information
mlopes committed Feb 8, 2015
2 parents 610046e + 4fa8434 commit 13751a2
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 6 deletions.
20 changes: 18 additions & 2 deletions blimey/agile_keychain/_manager/_item_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,12 @@ def get_by_id(self, item_id):
except FileNotFoundError:
raise ItemNotFoundException

return EncryptedAgileKeychainItem(data)
item = EncryptedAgileKeychainItem(data)

if self._is_deleted(item):
raise ItemNotFoundException

return item

def get_all_items(self):
item_paths = glob.glob(os.path.join(self._base_path, "data", "default", "*.1password"))
Expand All @@ -29,7 +34,11 @@ def get_all_items(self):
for item_path in item_paths:
basename = os.path.basename(item_path)
item_id, _ = os.path.splitext(basename)
items.append(self.get_by_id(item_id))

try:
items.append(self.get_by_id(item_id))
except ItemNotFoundException:
continue

return items

Expand Down Expand Up @@ -62,3 +71,10 @@ def _update_contents_file(self):

with open(os.path.join(self._base_path, "data", "default", "contents.js"), "w") as file:
json.dump(contents, file)

def _is_deleted(self, item):
if item['uuid'] is None:
return True

if item['typeName'] == 'system.Tombstone':
return True
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"uuid":"320BE3D1B490458F82314E1A2B99552A","updatedAt":1423411358,"locationKey":"","openContents":{"contentsHash":"fe62a730"},"keyID":"98EB2E946008403280A3A8D9261018A4","trashed":true,"title":"","location":"","encrypted":"U2FsdGVkX19LvzFrVOVBfUxXpWEDI/cNx2iwSaMpu9I=\u0000","createdAt":1423411343,"typeName":"system.Tombstone"}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"uuid":"ECE79F0A4BDF44CE8E7986897D84D1EC","updatedAt":1423411623,"securityLevel":"SL5","contentsHash":"b0516b42","trashed":true,"title":"Trashed Note","encrypted":"U2FsdGVkX19rj4xVqOj2JlJ9UdO3uncPqSIHVNb4SmkM2je\/b92H2AWp2sLRvokGqN\/W3dLvOaJctMetjLcavA==","createdAt":1423410518,"typeName":"securenotes.SecureNote"}
2 changes: 1 addition & 1 deletion tests/fixtures/test.agilekeychain/data/default/contents.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 18 additions & 3 deletions tests/integration/openpassword/agile_keychain/test_item_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,21 @@ def it_throws_if_requested_item_is_not_found(self):
item_manager = ItemManager(self._fixture_path)
item_manager.get_by_id('notfoundid')

def it_gets_all_items(self):
# 1Password 3 changes deleted item type to system.Tombstone
# Refer to the item in the fixture for an example of this
@raises(ItemNotFoundException)
def it_throws_if_requested_item_is_of_type_tombstone(self):
item_manager = ItemManager(self._fixture_path)
item_manager.get_by_id('320BE3D1B490458F82314E1A2B99552A')

# 1Password 4+ replaces the item contents with "{}"
# Refer to the item in the fixture for an example of this
@raises(ItemNotFoundException)
def it_throws_if_requested_item_is_empty(self):
item_manager = ItemManager(self._fixture_path)
item_manager.get_by_id('CAF7A781A71E44CFBB63F9356B46A0C9')

def it_gets_all_non_null_and_non_tombstoned_items(self):
item_manager = ItemManager(self._fixture_path)
items = item_manager.get_all_items()

Expand All @@ -39,10 +53,11 @@ def it_gets_all_items(self):
'97019BEBCF9E402F8F0C033474B1B85D',
'9E7673CCBB5B4AC9A7A8838835CB7E83',
'B851D6E3232842B0858BC10968632A9C',
'D05009E62D7D401CB8ACF2FE6981C031'
'D05009E62D7D401CB8ACF2FE6981C031',
'ECE79F0A4BDF44CE8E7986897D84D1EC'
]

assert len(items) == 9
assert len(items) == len(expected_item_uuids)

for item in items:
assert item['uuid'] in expected_item_uuids
Expand Down

0 comments on commit 13751a2

Please sign in to comment.