← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] lp:~bac/launchpadlib/bug-877374 into lp:launchpadlib

 

Brad Crittenden has proposed merging lp:~bac/launchpadlib/bug-877374 into lp:launchpadlib.

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)
Related bugs:
  Bug #877374 in launchpadlib : "Traceback when the credentials storage returns unicode"
  https://bugs.launchpad.net/launchpadlib/+bug/877374

For more details, see:
https://code.launchpad.net/~bac/launchpadlib/bug-877374/+merge/81878

Kwallet is reported to sometimes return Unicode which causes the config parser to implode.  The fix is to encode to UTF-8 before passing on for parsing.
-- 
https://code.launchpad.net/~bac/launchpadlib/bug-877374/+merge/81878
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~bac/launchpadlib/bug-877374 into lp:launchpadlib.
=== modified file 'src/launchpadlib/credentials.py'
--- src/launchpadlib/credentials.py	2011-01-10 14:34:03 +0000
+++ src/launchpadlib/credentials.py	2011-11-10 16:58:23 +0000
@@ -319,6 +319,7 @@
         credential_string = keyring.get_password(
             'launchpadlib', unique_key)
         if credential_string is not None:
+            credential_string = credential_string.encode('utf8')
             return Credentials.from_string(credential_string)
         return None
 

=== modified file 'src/launchpadlib/launchpad.py'
--- src/launchpadlib/launchpad.py	2011-09-29 15:48:31 +0000
+++ src/launchpadlib/launchpad.py	2011-11-10 16:58:23 +0000
@@ -608,4 +608,3 @@
         if not os.path.exists(cache_path):
             os.makedirs(cache_path, 0700)
         return (service_root, launchpadlib_dir, cache_path, service_root_dir)
-

=== modified file 'src/launchpadlib/tests/test_credential_store.py'
--- src/launchpadlib/tests/test_credential_store.py	2011-01-03 15:27:08 +0000
+++ src/launchpadlib/tests/test_credential_store.py	2011-11-10 16:58:23 +0000
@@ -136,3 +136,21 @@
         with fake_keyring(self.keyring):
             self.assertEquals(None, self.store.load("no such key"))
 
+
+    def test_keyring_returns_unicode(self):
+        # Kwallet is reported to sometimes return Unicode, which broke the
+        # credentials parsing.  This test ensures a Unicode password is
+        # handled correctly.  (See bug lp:877374)
+        class UnicodeInMemoryKeyring(InMemoryKeyring):
+            def get_password(self, service, username):
+                return unicode(
+                    super(UnicodeInMemoryKeyring, self).get_password(
+                        service, username))
+
+        self.keyring = UnicodeInMemoryKeyring()
+        with fake_keyring(self.keyring):
+            credential = self.make_credential("consumer key")
+            self.store.save(credential, "unique key")
+            credential2 = self.store.load("unique key")
+            self.assertEquals(
+                credential.consumer.key, credential2.consumer.key)