Merge lp:~alecu/ubuntu-sso-client/store-keyring-on-main-thread into lp:ubuntu-sso-client/stable-1-0

Proposed by Alejandro J. Cura
Status: Merged
Approved by: John Lenton
Approved revision: 641
Merged at revision: 640
Proposed branch: lp:~alecu/ubuntu-sso-client/store-keyring-on-main-thread
Merge into: lp:ubuntu-sso-client/stable-1-0
Diff against target: 109 lines (+28/-11)
2 files modified
ubuntu_sso/main.py (+20/-8)
ubuntu_sso/tests/test_main.py (+8/-3)
To merge this branch: bzr merge lp:~alecu/ubuntu-sso-client/store-keyring-on-main-thread
Reviewer Review Type Date Requested Status
John Lenton (community) Approve
Natalia Bidart (community) Approve
Review via email: mp+40005@code.launchpad.net

Commit message

Store credentials on the keyring *only* from the main thread (LP: #656545)

Description of the change

Store credentials on the keyring *only* from the main thread (LP: #656545)

To post a comment you must log in.
641. By Alejandro J. Cura

NO_OP for consistency

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

The solution is hacky but sadly we don't have other, cleaner option :-(

Thanks for the fix!

review: Approve
Revision history for this message
John Lenton (chipaca) wrote :

it's not at all clear to me that this fixes the issue. But I'm OK with us trying :)

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'ubuntu_sso/main.py'
--- ubuntu_sso/main.py 2010-11-01 21:01:14 +0000
+++ ubuntu_sso/main.py 2010-11-03 19:34:01 +0000
@@ -55,6 +55,7 @@
55logger = setup_logging("ubuntu_sso.main")55logger = setup_logging("ubuntu_sso.main")
56PING_URL = "https://one.ubuntu.com/oauth/sso-finished-so-get-tokens/"56PING_URL = "https://one.ubuntu.com/oauth/sso-finished-so-get-tokens/"
57SERVICE_URL = "https://login.ubuntu.com/api/1.0"57SERVICE_URL = "https://login.ubuntu.com/api/1.0"
58NO_OP = lambda *args, **kwargs: None
5859
5960
60class NoDefaultConfigError(Exception):61class NoDefaultConfigError(Exception):
@@ -96,10 +97,16 @@
96 """The new password could not be set."""97 """The new password could not be set."""
9798
9899
99def keyring_store_credentials(app_name, credentials):100def keyring_store_credentials(app_name, credentials, callback, *cb_args):
100 """Store the credentials in the keyring."""101 """Store the credentials in the keyring."""
101 logger.info('keyring_store_credentials: app_name "%s".', app_name)102
102 Keyring(app_name).set_ubuntusso_attr(credentials)103 def _inner():
104 """Store the credentials, and trigger the callback."""
105 logger.info('keyring_store_credentials: app_name "%s".', app_name)
106 Keyring(app_name).set_ubuntusso_attr(credentials)
107 callback(*cb_args)
108
109 gobject.idle_add(_inner)
103110
104111
105def keyring_get_credentials(app_name):112def keyring_get_credentials(app_name):
@@ -422,8 +429,8 @@
422 token_name)429 token_name)
423 logger.debug('user is validated? %r.', is_validated)430 logger.debug('user is validated? %r.', is_validated)
424 if is_validated:431 if is_validated:
425 keyring_store_credentials(app_name, credentials)432 keyring_store_credentials(app_name, credentials,
426 self.LoggedIn(app_name, email)433 self.LoggedIn, app_name, email)
427 else:434 else:
428 self.UserNotValidated(app_name, email)435 self.UserNotValidated(app_name, email)
429 blocking(f, app_name, success_cb, self.LoginError)436 blocking(f, app_name, success_cb, self.LoginError)
@@ -450,9 +457,14 @@
450 token_name = get_token_name(app_name)457 token_name = get_token_name(app_name)
451 credentials = self.processor.validate_email(email, password,458 credentials = self.processor.validate_email(email, password,
452 email_token, token_name)459 email_token, token_name)
453 keyring_store_credentials(app_name, credentials)460
454 return email461 def _email_stored():
455 blocking(f, app_name, self.EmailValidated, self.EmailValidationError)462 """The email was stored, so call the signal."""
463 self.EmailValidated(app_name, email)
464
465 keyring_store_credentials(app_name, credentials, _email_stored)
466
467 blocking(f, app_name, NO_OP, self.EmailValidationError)
456468
457 # request_password_reset_token signals469 # request_password_reset_token signals
458 @dbus.service.signal(DBUS_IFACE_USER_NAME, signature="ss")470 @dbus.service.signal(DBUS_IFACE_USER_NAME, signature="ss")
459471
=== modified file 'ubuntu_sso/tests/test_main.py'
--- ubuntu_sso/tests/test_main.py 2010-11-01 21:01:14 +0000
+++ ubuntu_sso/tests/test_main.py 2010-11-03 19:34:01 +0000
@@ -417,12 +417,13 @@
417 mockbus._register_object_path(ARGS)417 mockbus._register_object_path(ARGS)
418 self.mockprocessorclass = None418 self.mockprocessorclass = None
419419
420 def ksc(k, val):420 def ksc(k, val, callback, *cb_args):
421 """Assert over token and app_name."""421 """Assert over token and app_name."""
422 self.assertEqual(k, APP_NAME)422 self.assertEqual(k, APP_NAME)
423 self.assertEqual(val, TOKEN)423 self.assertEqual(val, TOKEN)
424 self.keyring_was_set = True424 self.keyring_was_set = True
425 self.keyring_values = k, val425 self.keyring_values = k, val
426 callback(*cb_args)
426427
427 self.patch(ubuntu_sso.main, "keyring_store_credentials", ksc)428 self.patch(ubuntu_sso.main, "keyring_store_credentials", ksc)
428 self.keyring_was_set = False429 self.keyring_was_set = False
@@ -870,7 +871,7 @@
870 self.assertEqual(result["errtype"], e.__class__.__name__)871 self.assertEqual(result["errtype"], e.__class__.__name__)
871872
872873
873class KeyringCredentialsTestCase(MockerTestCase):874class KeyringCredentialsTestCase(TestCase, MockerTestCase):
874 """Check the functions that access the keyring."""875 """Check the functions that access the keyring."""
875876
876 # Invalid name (should match ([a-z_][a-z0-9_]*|[A-Z_][A-Z0-9_]*)$)877 # Invalid name (should match ([a-z_][a-z0-9_]*|[A-Z_][A-Z0-9_]*)$)
@@ -878,15 +879,19 @@
878879
879 def test_keyring_store_cred(self):880 def test_keyring_store_cred(self):
880 """Verify the method that stores credentials."""881 """Verify the method that stores credentials."""
882 idle_add = lambda f, *args, **kwargs: f(*args, **kwargs)
883 self.patch(gobject, "idle_add", idle_add)
881 token_value = TOKEN884 token_value = TOKEN
882 mockKeyringClass = self.mocker.replace("ubuntu_sso.keyring.Keyring")885 mockKeyringClass = self.mocker.replace("ubuntu_sso.keyring.Keyring")
883 mockKeyringClass(APP_NAME)886 mockKeyringClass(APP_NAME)
884 mockKeyring = self.mocker.mock()887 mockKeyring = self.mocker.mock()
888 callback = self.mocker.mock()
885 self.mocker.result(mockKeyring)889 self.mocker.result(mockKeyring)
886 mockKeyring.set_ubuntusso_attr(token_value)890 mockKeyring.set_ubuntusso_attr(token_value)
891 callback(1, 2, 3)
887 self.mocker.replay()892 self.mocker.replay()
888893
889 keyring_store_credentials(APP_NAME, token_value)894 keyring_store_credentials(APP_NAME, token_value, callback, 1, 2, 3)
890895
891 def test_keyring_get_cred(self):896 def test_keyring_get_cred(self):
892 """The method returns the right token."""897 """The method returns the right token."""

Subscribers

People subscribed via source and target branches