@@ -533,15 +533,15 @@ def test_get_normalized_parameters(self):
533
533
'oauth_signature_method' : "HMAC-SHA1" ,
534
534
'oauth_token' : "ad180jjd733klru7" ,
535
535
'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 '
538
538
}
539
539
540
540
req = oauth .Request ("GET" , url , params )
541
541
542
542
res = req .get_normalized_parameters ()
543
543
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'
545
545
546
546
self .assertEquals (expected , res )
547
547
@@ -599,7 +599,7 @@ def test_get_normalized_string_escapes_spaces_properly(self):
599
599
600
600
@mock .patch ('oauth2.Request.make_timestamp' )
601
601
@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 ):
603
603
mock_make_nonce .return_value = 5
604
604
mock_make_timestamp .return_value = 6
605
605
@@ -653,6 +653,9 @@ def test_request_nonascii_bytes(self, mock_make_nonce, mock_make_timestamp):
653
653
self .failUnlessReallyEqual (req ['oauth_signature' ], 'OuMkgNFhlgcmEA1gIMII7aWLDgE=' )
654
654
655
655
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 )
656
659
657
660
def test_sign_request (self ):
658
661
url = "http://sp.example.com/"
@@ -673,13 +676,35 @@ def test_sign_request(self):
673
676
methods = {
674
677
'TQ6vGQ5A6IZn8dmeGB4+/Jl3EMI=' : oauth .SignatureMethod_HMAC_SHA1 (),
675
678
'con-test-secret&tok-test-secret' : oauth .SignatureMethod_PLAINTEXT ()
676
- }
679
+ }
677
680
678
681
for exp , method in methods .items ():
679
682
req .sign_request (method , con , tok )
680
683
self .assertEquals (req ['oauth_signature_method' ], method .name )
681
684
self .assertEquals (req ['oauth_signature' ], exp )
682
685
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
+
683
708
def test_from_request (self ):
684
709
url = "http://sp.example.com/"
685
710
0 commit comments