From e66c26921e8b1ea7df4c7b1dd06c2d9e5c88e767 Mon Sep 17 00:00:00 2001 From: Itamar Turner-Trauring Date: Fri, 19 Apr 2013 09:26:07 -0400 Subject: [PATCH] Fix bug when using oauth2client 1.1 instead of 1.0 (returned HTTP header was unicode rather than the expected bytes). --- .../cloud/googlestorage/googlestorage_container.py | 7 ++++++- src/allmydata/test/test_storage.py | 6 ++++-- 2 files changed, 10 insertions(+), 3 deletions(-) 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 7e70a02b..d22bc1d9 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): """ -- 2.45.2