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/?a=commitdiff_plain;h=7075ff39a5444683e24875d669b7bdf2471f869f;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 25df5a52..adf2d724 100644 --- a/src/allmydata/test/test_storage.py +++ b/src/allmydata/test/test_storage.py @@ -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): """