@@ -533,15 +533,15 @@ def test_get_normalized_parameters(self):
533533 'oauth_signature_method' : "HMAC-SHA1" ,
534534 'oauth_token' : "ad180jjd733klru7" ,
535535 'multi' : ['FOO' ,'BAR' , u'\u00ae ' , '\xc2 \xae ' ],
536- 'uni_utf8 ' : '\xc2 \xae ' ,
537- 'uni_unicode ' : u'\u00ae '
536+ 'uni_utf8_bytes ' : '\xc2 \xae ' ,
537+ 'uni_unicode_object ' : u'\u00ae '
538538 }
539539
540540 req = oauth .Request ("GET" , url , params )
541541
542542 res = req .get_normalized_parameters ()
543543
544- expected = 'multi=BAR&multi=FOO&multi=%C2%AE&multi=%C2%AE&oauth_consumer_key=0685bd9184jfhq22&oauth_nonce=4572616e48616d6d65724c61686176&oauth_signature_method=HMAC-SHA1&oauth_timestamp=137131200&oauth_token=ad180jjd733klru7&oauth_version=1.0&uni_unicode =%C2%AE&uni_utf8 =%C2%AE'
544+ expected = 'multi=BAR&multi=FOO&multi=%C2%AE&multi=%C2%AE&oauth_consumer_key=0685bd9184jfhq22&oauth_nonce=4572616e48616d6d65724c61686176&oauth_signature_method=HMAC-SHA1&oauth_timestamp=137131200&oauth_token=ad180jjd733klru7&oauth_version=1.0&uni_unicode_object =%C2%AE&uni_utf8_bytes =%C2%AE'
545545
546546 self .assertEquals (expected , res )
547547
@@ -599,7 +599,7 @@ def test_get_normalized_string_escapes_spaces_properly(self):
599599
600600 @mock .patch ('oauth2.Request.make_timestamp' )
601601 @mock .patch ('oauth2.Request.make_nonce' )
602- def test_request_nonascii_bytes (self , mock_make_nonce , mock_make_timestamp ):
602+ def test_request_nonutf8_bytes (self , mock_make_nonce , mock_make_timestamp ):
603603 mock_make_nonce .return_value = 5
604604 mock_make_timestamp .return_value = 6
605605
@@ -653,6 +653,9 @@ def test_request_nonascii_bytes(self, mock_make_nonce, mock_make_timestamp):
653653 self .failUnlessReallyEqual (req ['oauth_signature' ], 'OuMkgNFhlgcmEA1gIMII7aWLDgE=' )
654654
655655
656+ # Also if there are non-utf8 bytes in the query args.
657+ url = "http://sp.example.com/?q=\x92 " # cp1252
658+ self .assertRaises (TypeError , oauth .Request , method = "GET" , url = url , parameters = params )
656659
657660 def test_sign_request (self ):
658661 url = "http://sp.example.com/"
@@ -673,13 +676,35 @@ def test_sign_request(self):
673676 methods = {
674677 'TQ6vGQ5A6IZn8dmeGB4+/Jl3EMI=' : oauth .SignatureMethod_HMAC_SHA1 (),
675678 'con-test-secret&tok-test-secret' : oauth .SignatureMethod_PLAINTEXT ()
676- }
679+ }
677680
678681 for exp , method in methods .items ():
679682 req .sign_request (method , con , tok )
680683 self .assertEquals (req ['oauth_signature_method' ], method .name )
681684 self .assertEquals (req ['oauth_signature' ], exp )
682685
686+ # Also if there are non-ascii chars in the URL.
687+ url = "http://sp.example.com/\xe2 \x80 \x99 " # utf-8 bytes
688+ req = oauth .Request (method = "GET" , url = url , parameters = params )
689+ req .sign_request (oauth .SignatureMethod_HMAC_SHA1 (), con , tok )
690+ self .assertEquals (req ['oauth_signature' ], 'KagU7uiAAEvkZEzej2fcbyRXtzo=' )
691+
692+ url = u'http://sp.example.com/\u2019 ' # Python unicode object
693+ req = oauth .Request (method = "GET" , url = url , parameters = params )
694+ req .sign_request (oauth .SignatureMethod_HMAC_SHA1 (), con , tok )
695+ self .assertEquals (req ['oauth_signature' ], 'KagU7uiAAEvkZEzej2fcbyRXtzo=' )
696+
697+ # Also if there are non-ascii chars in the query args.
698+ url = "http://sp.example.com/?q=\xe2 \x80 \x99 " # utf-8 bytes
699+ req = oauth .Request (method = "GET" , url = url , parameters = params )
700+ req .sign_request (oauth .SignatureMethod_HMAC_SHA1 (), con , tok )
701+ self .assertEquals (req ['oauth_signature' ], '5hyI7ovTVkcCyLeOKYzugnIvseo=' )
702+
703+ url = u'http://sp.example.com/?q=\u2019 ' # Python unicode object
704+ req = oauth .Request (method = "GET" , url = url , parameters = params )
705+ req .sign_request (oauth .SignatureMethod_HMAC_SHA1 (), con , tok )
706+ self .assertEquals (req ['oauth_signature' ], '5hyI7ovTVkcCyLeOKYzugnIvseo=' )
707+
683708 def test_from_request (self ):
684709 url = "http://sp.example.com/"
685710
0 commit comments