@@ -598,6 +598,37 @@ def test_from_json_token_expiry(self):
598
598
instance = OAuth2Credentials .from_json (json .dumps (data ))
599
599
self .assertTrue (isinstance (instance , OAuth2Credentials ))
600
600
601
+ def test_unicode_header_checks (self ):
602
+ access_token = u'foo'
603
+ client_id = u'some_client_id'
604
+ client_secret = u'cOuDdkfjxxnv+'
605
+ refresh_token = u'1/0/a.df219fjls0'
606
+ token_expiry = str (datetime .datetime .utcnow ())
607
+ token_uri = str (GOOGLE_TOKEN_URI )
608
+ revoke_uri = str (GOOGLE_REVOKE_URI )
609
+ user_agent = u'refresh_checker/1.0'
610
+ credentials = OAuth2Credentials (access_token , client_id , client_secret ,
611
+ refresh_token , token_expiry , token_uri ,
612
+ user_agent , revoke_uri = revoke_uri )
613
+
614
+ # First, test that we correctly encode basic objects, making sure
615
+ # to include a bytes object. Note that oauth2client will normalize
616
+ # everything to bytes, no matter what python version we're in.
617
+ http = credentials .authorize (HttpMock (headers = {'status' : '200' }))
618
+ headers = {u'foo' : 3 , b'bar' : True , 'baz' : b'abc' }
619
+ cleaned_headers = {b'foo' : b'3' , b'bar' : b'True' , b'baz' : b'abc' }
620
+ http .request (u'http://example.com' , method = u'GET' , headers = headers )
621
+ for k , v in cleaned_headers .items ():
622
+ self .assertTrue (k in http .headers )
623
+ self .assertEqual (v , http .headers [k ])
624
+
625
+ # Next, test that we do fail on unicode.
626
+ unicode_str = six .unichr (40960 ) + 'abcd'
627
+ self .assertRaises (
628
+ NonAsciiHeaderError ,
629
+ http .request ,
630
+ u'http://example.com' , method = u'GET' , headers = {u'foo' : unicode_str })
631
+
601
632
def test_no_unicode_in_request_params (self ):
602
633
access_token = u'foo'
603
634
client_id = u'some_client_id'
0 commit comments