From: Itamar Turner-Trauring Date: Fri, 19 Apr 2013 13:26:07 +0000 (-0400) Subject: Fix bug when using oauth2client 1.1 instead of 1.0 (returned HTTP header was unicode... X-Git-Url: https://git.rkrishnan.org/specifications/%5B/%5D%20/flags/status?a=commitdiff_plain;h=f5b907034e254a05b85c7865dab17172b259ccb9;p=tahoe-lafs%2Ftahoe-lafs.git Fix bug when using oauth2client 1.1 instead of 1.0 (returned HTTP header was unicode rather than the expected bytes). --- diff --git a/src/allmydata/storage/backends/cloud/googlestorage/googlestorage_container.py b/src/allmydata/storage/backends/cloud/googlestorage/googlestorage_container.py index cfb10e26..369c9114 100644 --- a/src/allmydata/storage/backends/cloud/googlestorage/googlestorage_container.py +++ b/src/allmydata/storage/backends/cloud/googlestorage/googlestorage_container.py @@ -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 diff --git a/src/allmydata/test/test_storage.py b/src/allmydata/test/test_storage.py index c27aabb0..03ec2efd 100644 --- a/src/allmydata/test/test_storage.py +++ b/src/allmydata/test/test_storage.py @@ -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): """