Skip to content

Commit 13751a2

Browse files
committed
Merge pull request #104 from openpassword/handle-deleted-items
Handle deleted items
2 parents 610046e + 4fa8434 commit 13751a2

File tree

6 files changed

+40
-6
lines changed

6 files changed

+40
-6
lines changed

blimey/agile_keychain/_manager/_item_manager.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,12 @@ def get_by_id(self, item_id):
2020
except FileNotFoundError:
2121
raise ItemNotFoundException
2222

23-
return EncryptedAgileKeychainItem(data)
23+
item = EncryptedAgileKeychainItem(data)
24+
25+
if self._is_deleted(item):
26+
raise ItemNotFoundException
27+
28+
return item
2429

2530
def get_all_items(self):
2631
item_paths = glob.glob(os.path.join(self._base_path, "data", "default", "*.1password"))
@@ -29,7 +34,11 @@ def get_all_items(self):
2934
for item_path in item_paths:
3035
basename = os.path.basename(item_path)
3136
item_id, _ = os.path.splitext(basename)
32-
items.append(self.get_by_id(item_id))
37+
38+
try:
39+
items.append(self.get_by_id(item_id))
40+
except ItemNotFoundException:
41+
continue
3342

3443
return items
3544

@@ -62,3 +71,10 @@ def _update_contents_file(self):
6271

6372
with open(os.path.join(self._base_path, "data", "default", "contents.js"), "w") as file:
6473
json.dump(contents, file)
74+
75+
def _is_deleted(self, item):
76+
if item['uuid'] is None:
77+
return True
78+
79+
if item['typeName'] == 'system.Tombstone':
80+
return True
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"uuid":"320BE3D1B490458F82314E1A2B99552A","updatedAt":1423411358,"locationKey":"","openContents":{"contentsHash":"fe62a730"},"keyID":"98EB2E946008403280A3A8D9261018A4","trashed":true,"title":"","location":"","encrypted":"U2FsdGVkX19LvzFrVOVBfUxXpWEDI/cNx2iwSaMpu9I=\u0000","createdAt":1423411343,"typeName":"system.Tombstone"}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"uuid":"ECE79F0A4BDF44CE8E7986897D84D1EC","updatedAt":1423411623,"securityLevel":"SL5","contentsHash":"b0516b42","trashed":true,"title":"Trashed Note","encrypted":"U2FsdGVkX19rj4xVqOj2JlJ9UdO3uncPqSIHVNb4SmkM2je\/b92H2AWp2sLRvokGqN\/W3dLvOaJctMetjLcavA==","createdAt":1423410518,"typeName":"securenotes.SecureNote"}

tests/fixtures/test.agilekeychain/data/default/contents.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/integration/openpassword/agile_keychain/test_item_manager.py

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,21 @@ def it_throws_if_requested_item_is_not_found(self):
2626
item_manager = ItemManager(self._fixture_path)
2727
item_manager.get_by_id('notfoundid')
2828

29-
def it_gets_all_items(self):
29+
# 1Password 3 changes deleted item type to system.Tombstone
30+
# Refer to the item in the fixture for an example of this
31+
@raises(ItemNotFoundException)
32+
def it_throws_if_requested_item_is_of_type_tombstone(self):
33+
item_manager = ItemManager(self._fixture_path)
34+
item_manager.get_by_id('320BE3D1B490458F82314E1A2B99552A')
35+
36+
# 1Password 4+ replaces the item contents with "{}"
37+
# Refer to the item in the fixture for an example of this
38+
@raises(ItemNotFoundException)
39+
def it_throws_if_requested_item_is_empty(self):
40+
item_manager = ItemManager(self._fixture_path)
41+
item_manager.get_by_id('CAF7A781A71E44CFBB63F9356B46A0C9')
42+
43+
def it_gets_all_non_null_and_non_tombstoned_items(self):
3044
item_manager = ItemManager(self._fixture_path)
3145
items = item_manager.get_all_items()
3246

@@ -39,10 +53,11 @@ def it_gets_all_items(self):
3953
'97019BEBCF9E402F8F0C033474B1B85D',
4054
'9E7673CCBB5B4AC9A7A8838835CB7E83',
4155
'B851D6E3232842B0858BC10968632A9C',
42-
'D05009E62D7D401CB8ACF2FE6981C031'
56+
'D05009E62D7D401CB8ACF2FE6981C031',
57+
'ECE79F0A4BDF44CE8E7986897D84D1EC'
4358
]
4459

45-
assert len(items) == 9
60+
assert len(items) == len(expected_item_uuids)
4661

4762
for item in items:
4863
assert item['uuid'] in expected_item_uuids

0 commit comments

Comments
 (0)