]> 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, 16 Oct 2015 16:53:01 +0000 (17:53 +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 c27aabb081591e79e56a49100b1033293687275e..03ec2efd1ebe5183dcdf2b933e3531365ef5982c 100644 (file)
@@ -707,12 +707,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,
@@ -720,6 +721,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):
         """