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
=== modified file 'ubuntu_sso/utils/tests/test_txsecrets.py'
--- ubuntu_sso/utils/tests/test_txsecrets.py 2010-11-17 00:30:35 +0000
+++ ubuntu_sso/utils/tests/test_txsecrets.py 2011-01-18 22:01:23 +0000
@@ -36,6 +36,9 @@
36# pylint: disable=E110136# pylint: disable=E1101
3737
3838
39ERROR_CREATE_BUT_LOCKED = "Cannot create an item in a locked collection"
40
41
39class SampleMiscException(Exception):42class SampleMiscException(Exception):
40 """An exception that will be turned into a DBus Exception."""43 """An exception that will be turned into a DBus Exception."""
4144
@@ -138,6 +141,8 @@
138 """141 """
139 if self.create_item_fail:142 if self.create_item_fail:
140 raise SampleMiscException()143 raise SampleMiscException()
144 if self.locked:
145 raise SampleMiscException(ERROR_CREATE_BUT_LOCKED)
141 attributes = properties[txsecrets.ATTRIBUTES_PROPERTY]146 attributes = properties[txsecrets.ATTRIBUTES_PROPERTY]
142 item_label = properties[txsecrets.LABEL_PROPERTY]147 item_label = properties[txsecrets.LABEL_PROPERTY]
143 session, parameters, value = secret148 session, parameters, value = secret
@@ -419,10 +424,11 @@
419 collection_name = "sample_keyring"424 collection_name = "sample_keyring"
420 coll = yield self.create_sample_collection(collection_name)425 coll = yield self.create_sample_collection(collection_name)
421 mock_collection = self.mock_service.collections[collection_name]426 mock_collection = self.mock_service.collections[collection_name]
422 mock_collection.locked = True
423 attr = {"key-type": "Ubuntu SSO credentials"}427 attr = {"key-type": "Ubuntu SSO credentials"}
424 sample_secret = "secret99!"428 sample_secret = "secret99!"
425 yield coll.create_item("Cucaracha", attr, sample_secret)429 yield coll.create_item("Cucaracha", attr, sample_secret)
430 mock_collection.locked = True
431
426 items = yield self.secretservice.search_items(attr)432 items = yield self.secretservice.search_items(attr)
427 self.assertEqual(len(items), 1)433 self.assertEqual(len(items), 1)
428 value = yield items[0].get_value()434 value = yield items[0].get_value()
@@ -435,11 +441,12 @@
435 collection_name = "sample_keyring"441 collection_name = "sample_keyring"
436 coll = yield self.create_sample_collection(collection_name)442 coll = yield self.create_sample_collection(collection_name)
437 mock_collection = self.mock_service.collections[collection_name]443 mock_collection = self.mock_service.collections[collection_name]
438 mock_collection.locked = True
439 mock_collection.unlock_prompts = True
440 attr = {"key-type": "Ubuntu SSO credentials"}444 attr = {"key-type": "Ubuntu SSO credentials"}
441 sample_secret = "secret99!"445 sample_secret = "secret99!"
442 yield coll.create_item("Cucaracha", attr, sample_secret)446 yield coll.create_item("Cucaracha", attr, sample_secret)
447 mock_collection.locked = True
448 mock_collection.unlock_prompts = True
449
443 items = yield self.secretservice.search_items(attr)450 items = yield self.secretservice.search_items(attr)
444 self.assertEqual(len(items), 1)451 self.assertEqual(len(items), 1)
445 value = yield items[0].get_value()452 value = yield items[0].get_value()
@@ -452,12 +459,13 @@
452 collection_name = "sample_keyring"459 collection_name = "sample_keyring"
453 coll = yield self.create_sample_collection(collection_name)460 coll = yield self.create_sample_collection(collection_name)
454 mock_collection = self.mock_service.collections[collection_name]461 mock_collection = self.mock_service.collections[collection_name]
455 mock_collection.locked = True
456 mock_collection.unlock_prompts = True
457 self.mock_service.dismissed = True462 self.mock_service.dismissed = True
458 attr = {"key-type": "Ubuntu SSO credentials"}463 attr = {"key-type": "Ubuntu SSO credentials"}
459 sample_secret = "secret99!"464 sample_secret = "secret99!"
460 yield coll.create_item("Cucaracha", attr, sample_secret)465 yield coll.create_item("Cucaracha", attr, sample_secret)
466 mock_collection.locked = True
467 mock_collection.unlock_prompts = True
468
461 d = self.secretservice.search_items(attr)469 d = self.secretservice.search_items(attr)
462 yield self.assertFailure(d, txsecrets.UserCancelled)470 yield self.assertFailure(d, txsecrets.UserCancelled)
463471
@@ -470,18 +478,18 @@
470 collection_name = "coll1"478 collection_name = "coll1"
471 coll = yield self.create_sample_collection(collection_name)479 coll = yield self.create_sample_collection(collection_name)
472 mock_coll1 = self.mock_service.collections[collection_name]480 mock_coll1 = self.mock_service.collections[collection_name]
481 unlocked_secret = "coll 1 secret!"
482 yield coll.create_item("Cucaracha", attr, unlocked_secret)
473 mock_coll1.locked = False483 mock_coll1.locked = False
474 mock_coll1.unlock_prompts = False484 mock_coll1.unlock_prompts = False
475 unlocked_secret = "coll 1 secret!"
476 yield coll.create_item("Cucaracha", attr, unlocked_secret)
477485
478 collection_name = "coll2"486 collection_name = "coll2"
479 coll = yield self.create_sample_collection(collection_name)487 coll = yield self.create_sample_collection(collection_name)
480 mock_coll2 = self.mock_service.collections[collection_name]488 mock_coll2 = self.mock_service.collections[collection_name]
489 locked_secret = "coll 2 secret!"
490 yield coll.create_item("Cucaracha", attr, locked_secret)
481 mock_coll2.locked = True491 mock_coll2.locked = True
482 mock_coll2.unlock_prompts = False492 mock_coll2.unlock_prompts = False
483 locked_secret = "coll 2 secret!"
484 yield coll.create_item("Cucaracha", attr, locked_secret)
485493
486 result = yield self.secretservice.search_items(attr)494 result = yield self.secretservice.search_items(attr)
487 self.assertEqual(len(result), 2)495 self.assertEqual(len(result), 2)
@@ -495,26 +503,26 @@
495 collection_name = "coll1"503 collection_name = "coll1"
496 coll = yield self.create_sample_collection(collection_name)504 coll = yield self.create_sample_collection(collection_name)
497 mock_coll1 = self.mock_service.collections[collection_name]505 mock_coll1 = self.mock_service.collections[collection_name]
506 unlocked_secret = "coll 1 secret!"
507 yield coll.create_item("Cucaracha", attr, unlocked_secret)
498 mock_coll1.locked = False508 mock_coll1.locked = False
499 mock_coll1.unlock_prompts = False509 mock_coll1.unlock_prompts = False
500 unlocked_secret = "coll 1 secret!"
501 yield coll.create_item("Cucaracha", attr, unlocked_secret)
502510
503 collection_name = "coll2"511 collection_name = "coll2"
504 coll = yield self.create_sample_collection(collection_name)512 coll = yield self.create_sample_collection(collection_name)
505 mock_coll2 = self.mock_service.collections[collection_name]513 mock_coll2 = self.mock_service.collections[collection_name]
514 locked_secret = "coll 2 secret!"
515 yield coll.create_item("Cucaracha", attr, locked_secret)
506 mock_coll2.locked = True516 mock_coll2.locked = True
507 mock_coll2.unlock_prompts = False517 mock_coll2.unlock_prompts = False
508 locked_secret = "coll 2 secret!"
509 yield coll.create_item("Cucaracha", attr, locked_secret)
510518
511 collection_name = "coll3"519 collection_name = "coll3"
512 coll = yield self.create_sample_collection(collection_name)520 coll = yield self.create_sample_collection(collection_name)
513 mock_coll3 = self.mock_service.collections[collection_name]521 mock_coll3 = self.mock_service.collections[collection_name]
522 locked_secret = "coll 3 secret!"
523 yield coll.create_item("Cucaracha", attr, locked_secret)
514 mock_coll3.locked = True524 mock_coll3.locked = True
515 mock_coll3.unlock_prompts = True525 mock_coll3.unlock_prompts = True
516 locked_secret = "coll 3 secret!"
517 yield coll.create_item("Cucaracha", attr, locked_secret)
518526
519 result = yield self.secretservice.search_items(attr)527 result = yield self.secretservice.search_items(attr)
520 self.assertEqual(len(result), 3)528 self.assertEqual(len(result), 3)
@@ -537,6 +545,22 @@
537 yield self.secretservice.get_default_collection()545 yield self.secretservice.get_default_collection()
538 self.assertEqual(len(self.mock_service.collections), 1)546 self.assertEqual(len(self.mock_service.collections), 1)
539547
548 @inlineCallbacks
549 def test_get_default_collection_is_unlocked(self):
550 """The default collection is unlocked before being returned."""
551 yield self.secretservice.open_session()
552 collection_name = "sample_keyring"
553 self.assertEqual(len(self.mock_service.collections), 0)
554 coll = yield self.create_sample_collection(collection_name)
555 self.assertEqual(len(self.mock_service.collections), 1)
556 mock_collection = self.mock_service.collections[collection_name]
557 mock_collection.locked = True
558 yield self.secretservice.get_default_collection()
559 attr = {"key-type": "Ubuntu 242 credentials"}
560 sample_secret = "secret!"
561 yield coll.create_item("Cucaracha", attr, sample_secret)
562 self.assertEqual(len(mock_collection.items), 1)
563
540564
541class CollectionTestCase(BaseTestCase):565class CollectionTestCase(BaseTestCase):
542 """Test the Collection class."""566 """Test the Collection class."""
543567
=== modified file 'ubuntu_sso/utils/txsecrets.py'
--- ubuntu_sso/utils/txsecrets.py 2010-11-30 12:19:43 +0000
+++ ubuntu_sso/utils/txsecrets.py 2011-01-18 22:01:23 +0000
@@ -172,11 +172,30 @@
172 """The collection were default items should be created."""172 """The collection were default items should be created."""
173 d = Deferred()173 d = Deferred()
174174
175 def prompt_handle(unlocked):
176 """Handle showing a prompt."""
177 collection_path = unlocked[0]
178 return Collection(self, collection_path)
179
180 def unlock_handler(unlocked, prompt):
181 """The objects were unlocked."""
182 if prompt != "/":
183 d2 = self.do_prompt(prompt)
184 d2.addCallback(prompt_handle)
185 d2.chainDeferred(d)
186 else:
187 d.callback(prompt_handle(unlocked))
188
175 def propertyget_handler(collection_paths):189 def propertyget_handler(collection_paths):
176 """The list of collection paths was retrieved."""190 """The list of collection paths was retrieved."""
177 if len(collection_paths) > 0:191 if len(collection_paths) > 0:
178 d.callback(Collection(self, DEFAULT_COLLECTION))192 # The collection was found, make sure it's unlocked
193 objects = dbus.Array([DEFAULT_COLLECTION], signature="o")
194 self.service.Unlock(objects,
195 reply_handler=unlock_handler,
196 error_handler=d.errback)
179 else:197 else:
198 # The collection was not found, so create it
180 self.create_collection(DEFAULT_LABEL).chainDeferred(d)199 self.create_collection(DEFAULT_LABEL).chainDeferred(d)
181200
182 self.properties.Get(SERVICE_IFACE, COLLECTIONS_PROPERTY,201 self.properties.Get(SERVICE_IFACE, COLLECTIONS_PROPERTY,

Subscribers

People subscribed via source and target branches