This repository has been archived by the owner on Nov 5, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 430
Switched headers to be normalized as strings, not bytes, in keeping with httplib2. #136
Closed
foozlevazquez
wants to merge
1
commit into
googleapis:master
from
foozlevazquez:fix-header-strings-for-httplib2
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,7 @@ | |
Unit tests for oauth2client. | ||
""" | ||
|
||
# pylint: disable=bad-indentation | ||
__author__ = '[email protected] (Joe Gregorio)' | ||
|
||
import base64 | ||
|
@@ -531,7 +532,7 @@ def test_token_refresh_success(self): | |
]) | ||
http = self.credentials.authorize(http) | ||
resp, content = http.request('http://example.com') | ||
self.assertEqual(b'Bearer 1/3w', content[b'Authorization']) | ||
self.assertEqual('Bearer 1/3w', content['Authorization']) | ||
self.assertFalse(self.credentials.access_token_expired) | ||
self.assertEqual(token_response, self.credentials.token_response) | ||
|
||
|
@@ -599,17 +600,17 @@ def test_unicode_header_checks(self): | |
|
||
# First, test that we correctly encode basic objects, making sure | ||
# to include a bytes object. Note that oauth2client will normalize | ||
# everything to bytes, no matter what python version we're in. | ||
# everything to strings, no matter what python version we're in. | ||
http = credentials.authorize(HttpMock(headers={'status': '200'})) | ||
headers = {u'foo': 3, b'bar': True, 'baz': b'abc'} | ||
cleaned_headers = {b'foo': b'3', b'bar': b'True', b'baz': b'abc'} | ||
cleaned_headers = {'foo': '3', 'bar': 'True', 'baz': 'abc'} | ||
http.request(u'http://example.com', method=u'GET', headers=headers) | ||
for k, v in cleaned_headers.items(): | ||
self.assertTrue(k in http.headers) | ||
self.assertEqual(v, http.headers[k]) | ||
|
||
# Next, test that we do fail on unicode. | ||
unicode_str = six.unichr(40960) + 'abcd' | ||
unicode_str = u'\u2602' + 'abcd' | ||
self.assertRaises( | ||
NonAsciiHeaderError, | ||
http.request, | ||
|
@@ -631,14 +632,21 @@ def test_no_unicode_in_request_params(self): | |
http = HttpMock(headers={'status': '200'}) | ||
http = credentials.authorize(http) | ||
http.request(u'http://example.com', method=u'GET', headers={u'foo': u'bar'}) | ||
|
||
# oauth2client uses httplib2 and httplib2 says: | ||
# "** THE RESPONSE HEADERS ARE STRINGS, BUT THE CONTENT BODY IS BYTES **" | ||
# and from https://github.com/jcgregorio/httplib2/wiki/Examples-Python3 | ||
# "In httplib2, the response headers are strings..." | ||
# | ||
# So, the headers should be of type str. | ||
for k, v in six.iteritems(http.headers): | ||
self.assertEqual(six.binary_type, type(k)) | ||
self.assertEqual(six.binary_type, type(v)) | ||
self.assertTrue(isinstance(k, str)) | ||
self.assertTrue(isinstance(v, str)) | ||
|
||
# Test again with unicode strings that can't simply be converted to ASCII. | ||
try: | ||
http.request( | ||
u'http://example.com', method=u'GET', headers={u'foo': u'\N{COMET}'}) | ||
u'http://example.com', method=u'GET', headers={u'foo': u'\u2602'}) | ||
self.fail('Expected exception to be raised.') | ||
except NonAsciiHeaderError: | ||
pass | ||
|
@@ -724,7 +732,7 @@ def test_auth_header_sent(self): | |
]) | ||
http = self.credentials.authorize(http) | ||
resp, content = http.request('http://example.com') | ||
self.assertEqual(b'Bearer foo', content[b'Authorization']) | ||
self.assertEqual('Bearer foo', content['Authorization']) | ||
|
||
|
||
class TestAssertionCredentials(unittest.TestCase): | ||
|
@@ -755,7 +763,7 @@ def test_assertion_refresh(self): | |
]) | ||
http = self.credentials.authorize(http) | ||
resp, content = http.request('http://example.com') | ||
self.assertEqual(b'Bearer 1/3w', content[b'Authorization']) | ||
self.assertEqual('Bearer 1/3w', content['Authorization']) | ||
|
||
def test_token_revoke_success(self): | ||
_token_revoke_test_helper( | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This comment was marked as spam.
Sorry, something went wrong.