]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/commitdiff
Fix bug when using oauth2client 1.1 instead of 1.0 (returned HTTP header was unicode...
authorItamar Turner-Trauring <itamar@blake.(none)>
Fri, 19 Apr 2013 13:26:07 +0000 (09:26 -0400)
committerDaira Hopwood <daira@jacaranda.org>
Fri, 17 Apr 2015 21:31:39 +0000 (22:31 +0100)
src/allmydata/storage/backends/cloud/googlestorage/googlestorage_container.py
src/allmydata/test/test_storage.py

index cfb10e26bb8b4557edb9a89f22ac3a785c24084f..369c9114fd4965daf2954b37e3cdc54aa65930d1 100644 (file)
@@ -83,7 +83,12 @@ class AuthenticationClient(object):
         def refreshed(ignore):
             headers = {}
             self._credentials.apply(headers)
-            return headers['Authorization']
+            result = headers['Authorization']
+            # The value was bytes in oauth2client 1.0, unicode in 1.1, maybe
+            # they'll change it again in 1.2...
+            if isinstance(result, unicode):
+                result = result.encode("ascii")
+            return result
         d.addCallback(refreshed)
         return d
 
index 52b13984796c01c2e0b0174d0126baf0f5a371f6..01a926512d58fbc3fd1f41e2fb71e448c71902a7 100644 (file)
@@ -700,12 +700,13 @@ class GoogleStorageAuthenticationClient(unittest.TestCase):
     def test_header(self):
         """
         AuthenticationClient.get_authorization_header() returns a value to be
-        used for the Authorization header.
+        used for the Authorization header, which is ASCII-encoded if
+        necessary.
         """
         from oauth2client.client import SignedJwtAssertionCredentials
         class NoNetworkCreds(SignedJwtAssertionCredentials):
             def refresh(self, http):
-                self.access_token = "xxx"
+                self.access_token = u"xxx"
         auth = googlestorage_container.AuthenticationClient(
             "u@example.com", "xxx123",
             _credentialsClass=NoNetworkCreds,
@@ -713,6 +714,7 @@ class GoogleStorageAuthenticationClient(unittest.TestCase):
         result = []
         auth.get_authorization_header().addCallback(result.append)
         self.assertEqual(result, ["Bearer xxx"])
+        self.assertIsInstance(result[0], bytes)
 
     def test_one_refresh(self):
         """