Merge lp:~alecu/ubuntu-sso-client/unlock-keyring-when-storing into lp:ubuntu-sso-client

Proposed by Alejandro J. Cura
Status: Merged
Approved by: Alejandro J. Cura
Approved revision: 670
Merged at revision: 670
Proposed branch: lp:~alecu/ubuntu-sso-client/unlock-keyring-when-storing
Merge into: lp:ubuntu-sso-client
Diff against target: 181 lines (+59/-16)
2 files modified
ubuntu_sso/utils/tests/test_txsecrets.py (+39/-15)
ubuntu_sso/utils/txsecrets.py (+20/-1)
To merge this branch: bzr merge lp:~alecu/ubuntu-sso-client/unlock-keyring-when-storing
Reviewer Review Type Date Requested Status
Roberto Alsina (community) Approve
Natalia Bidart (community) Approve
Review via email: mp+46690@code.launchpad.net

Commit message

Make sure the default keyring is unlocked when getting it (LP: #703343).

Description of the change

Make sure the default keyring is unlocked when getting it

To post a comment you must log in.
Revision history for this message
Alejandro J. Cura (alecu) wrote :

To test this:

 * Stop syncdaemon: u1sdtool -q
 * Start "seahorse" and delete the "Ubuntu One" credentials
 * Lock the keyring: right click on the default keyring ("Passwords: login" or "Passwords: default"), and click on "Lock"
 * Start syncdaemon again: u1sdtool -c

Now try to login as your u1 user, and when it previously failed, it should now ask for your keyring password in order to unlock it.

Revision history for this message
Natalia Bidart (nataliabidart) wrote :

Approving, works like a charm.

When running the test suite, I've got: http://pastebin.ubuntu.com/555779/
This is a test-intereference issue that I need to address (LP: #704941).

review: Approve
Revision history for this message
Roberto Alsina (ralsina) wrote :

Got the same error as natalia, but that doesn't seem to really be a problem with this branch, so +1

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'ubuntu_sso/utils/tests/test_txsecrets.py'
2--- ubuntu_sso/utils/tests/test_txsecrets.py 2010-11-17 00:30:35 +0000
3+++ ubuntu_sso/utils/tests/test_txsecrets.py 2011-01-18 22:01:23 +0000
4@@ -36,6 +36,9 @@
5 # pylint: disable=E1101
6
7
8+ERROR_CREATE_BUT_LOCKED = "Cannot create an item in a locked collection"
9+
10+
11 class SampleMiscException(Exception):
12 """An exception that will be turned into a DBus Exception."""
13
14@@ -138,6 +141,8 @@
15 """
16 if self.create_item_fail:
17 raise SampleMiscException()
18+ if self.locked:
19+ raise SampleMiscException(ERROR_CREATE_BUT_LOCKED)
20 attributes = properties[txsecrets.ATTRIBUTES_PROPERTY]
21 item_label = properties[txsecrets.LABEL_PROPERTY]
22 session, parameters, value = secret
23@@ -419,10 +424,11 @@
24 collection_name = "sample_keyring"
25 coll = yield self.create_sample_collection(collection_name)
26 mock_collection = self.mock_service.collections[collection_name]
27- mock_collection.locked = True
28 attr = {"key-type": "Ubuntu SSO credentials"}
29 sample_secret = "secret99!"
30 yield coll.create_item("Cucaracha", attr, sample_secret)
31+ mock_collection.locked = True
32+
33 items = yield self.secretservice.search_items(attr)
34 self.assertEqual(len(items), 1)
35 value = yield items[0].get_value()
36@@ -435,11 +441,12 @@
37 collection_name = "sample_keyring"
38 coll = yield self.create_sample_collection(collection_name)
39 mock_collection = self.mock_service.collections[collection_name]
40- mock_collection.locked = True
41- mock_collection.unlock_prompts = True
42 attr = {"key-type": "Ubuntu SSO credentials"}
43 sample_secret = "secret99!"
44 yield coll.create_item("Cucaracha", attr, sample_secret)
45+ mock_collection.locked = True
46+ mock_collection.unlock_prompts = True
47+
48 items = yield self.secretservice.search_items(attr)
49 self.assertEqual(len(items), 1)
50 value = yield items[0].get_value()
51@@ -452,12 +459,13 @@
52 collection_name = "sample_keyring"
53 coll = yield self.create_sample_collection(collection_name)
54 mock_collection = self.mock_service.collections[collection_name]
55- mock_collection.locked = True
56- mock_collection.unlock_prompts = True
57 self.mock_service.dismissed = True
58 attr = {"key-type": "Ubuntu SSO credentials"}
59 sample_secret = "secret99!"
60 yield coll.create_item("Cucaracha", attr, sample_secret)
61+ mock_collection.locked = True
62+ mock_collection.unlock_prompts = True
63+
64 d = self.secretservice.search_items(attr)
65 yield self.assertFailure(d, txsecrets.UserCancelled)
66
67@@ -470,18 +478,18 @@
68 collection_name = "coll1"
69 coll = yield self.create_sample_collection(collection_name)
70 mock_coll1 = self.mock_service.collections[collection_name]
71+ unlocked_secret = "coll 1 secret!"
72+ yield coll.create_item("Cucaracha", attr, unlocked_secret)
73 mock_coll1.locked = False
74 mock_coll1.unlock_prompts = False
75- unlocked_secret = "coll 1 secret!"
76- yield coll.create_item("Cucaracha", attr, unlocked_secret)
77
78 collection_name = "coll2"
79 coll = yield self.create_sample_collection(collection_name)
80 mock_coll2 = self.mock_service.collections[collection_name]
81+ locked_secret = "coll 2 secret!"
82+ yield coll.create_item("Cucaracha", attr, locked_secret)
83 mock_coll2.locked = True
84 mock_coll2.unlock_prompts = False
85- locked_secret = "coll 2 secret!"
86- yield coll.create_item("Cucaracha", attr, locked_secret)
87
88 result = yield self.secretservice.search_items(attr)
89 self.assertEqual(len(result), 2)
90@@ -495,26 +503,26 @@
91 collection_name = "coll1"
92 coll = yield self.create_sample_collection(collection_name)
93 mock_coll1 = self.mock_service.collections[collection_name]
94+ unlocked_secret = "coll 1 secret!"
95+ yield coll.create_item("Cucaracha", attr, unlocked_secret)
96 mock_coll1.locked = False
97 mock_coll1.unlock_prompts = False
98- unlocked_secret = "coll 1 secret!"
99- yield coll.create_item("Cucaracha", attr, unlocked_secret)
100
101 collection_name = "coll2"
102 coll = yield self.create_sample_collection(collection_name)
103 mock_coll2 = self.mock_service.collections[collection_name]
104+ locked_secret = "coll 2 secret!"
105+ yield coll.create_item("Cucaracha", attr, locked_secret)
106 mock_coll2.locked = True
107 mock_coll2.unlock_prompts = False
108- locked_secret = "coll 2 secret!"
109- yield coll.create_item("Cucaracha", attr, locked_secret)
110
111 collection_name = "coll3"
112 coll = yield self.create_sample_collection(collection_name)
113 mock_coll3 = self.mock_service.collections[collection_name]
114+ locked_secret = "coll 3 secret!"
115+ yield coll.create_item("Cucaracha", attr, locked_secret)
116 mock_coll3.locked = True
117 mock_coll3.unlock_prompts = True
118- locked_secret = "coll 3 secret!"
119- yield coll.create_item("Cucaracha", attr, locked_secret)
120
121 result = yield self.secretservice.search_items(attr)
122 self.assertEqual(len(result), 3)
123@@ -537,6 +545,22 @@
124 yield self.secretservice.get_default_collection()
125 self.assertEqual(len(self.mock_service.collections), 1)
126
127+ @inlineCallbacks
128+ def test_get_default_collection_is_unlocked(self):
129+ """The default collection is unlocked before being returned."""
130+ yield self.secretservice.open_session()
131+ collection_name = "sample_keyring"
132+ self.assertEqual(len(self.mock_service.collections), 0)
133+ coll = yield self.create_sample_collection(collection_name)
134+ self.assertEqual(len(self.mock_service.collections), 1)
135+ mock_collection = self.mock_service.collections[collection_name]
136+ mock_collection.locked = True
137+ yield self.secretservice.get_default_collection()
138+ attr = {"key-type": "Ubuntu 242 credentials"}
139+ sample_secret = "secret!"
140+ yield coll.create_item("Cucaracha", attr, sample_secret)
141+ self.assertEqual(len(mock_collection.items), 1)
142+
143
144 class CollectionTestCase(BaseTestCase):
145 """Test the Collection class."""
146
147=== modified file 'ubuntu_sso/utils/txsecrets.py'
148--- ubuntu_sso/utils/txsecrets.py 2010-11-30 12:19:43 +0000
149+++ ubuntu_sso/utils/txsecrets.py 2011-01-18 22:01:23 +0000
150@@ -172,11 +172,30 @@
151 """The collection were default items should be created."""
152 d = Deferred()
153
154+ def prompt_handle(unlocked):
155+ """Handle showing a prompt."""
156+ collection_path = unlocked[0]
157+ return Collection(self, collection_path)
158+
159+ def unlock_handler(unlocked, prompt):
160+ """The objects were unlocked."""
161+ if prompt != "/":
162+ d2 = self.do_prompt(prompt)
163+ d2.addCallback(prompt_handle)
164+ d2.chainDeferred(d)
165+ else:
166+ d.callback(prompt_handle(unlocked))
167+
168 def propertyget_handler(collection_paths):
169 """The list of collection paths was retrieved."""
170 if len(collection_paths) > 0:
171- d.callback(Collection(self, DEFAULT_COLLECTION))
172+ # The collection was found, make sure it's unlocked
173+ objects = dbus.Array([DEFAULT_COLLECTION], signature="o")
174+ self.service.Unlock(objects,
175+ reply_handler=unlock_handler,
176+ error_handler=d.errback)
177 else:
178+ # The collection was not found, so create it
179 self.create_collection(DEFAULT_LABEL).chainDeferred(d)
180
181 self.properties.Get(SERVICE_IFACE, COLLECTIONS_PROPERTY,

Subscribers

People subscribed via source and target branches