@@ -622,14 +622,14 @@ def test_request_nonutf8_bytes(self, mock_make_nonce, mock_make_timestamp):
622
622
url = u'http://sp.example.com/\u2019 '
623
623
req = oauth .Request (method = "GET" , url = url , parameters = params )
624
624
req .sign_request (oauth .SignatureMethod_HMAC_SHA1 (), con , None )
625
- self .failUnlessReallyEqual (req ['oauth_signature' ], '/DgF7cY2friC01cmOAFdu8S0z+A =' )
625
+ self .failUnlessReallyEqual (req ['oauth_signature' ], 'cMzvCkhvLL57+sTIxLITTHfkqZk =' )
626
626
627
627
# And if it is a utf-8-encoded-then-percent-encoded non-ascii
628
628
# thing, we'll decode it and use it.
629
629
url = "http://sp.example.com/%E2%80%99"
630
630
req = oauth .Request (method = "GET" , url = url , parameters = params )
631
631
req .sign_request (oauth .SignatureMethod_HMAC_SHA1 (), con , None )
632
- self .failUnlessReallyEqual (req ['oauth_signature' ], 'anzjnpdqCUJWvePgDiwMb7Q8g28 =' )
632
+ self .failUnlessReallyEqual (req ['oauth_signature' ], 'yMLKOyNKC/DkyhUOb8DLSvceEWE =' )
633
633
634
634
# Same thing with the params.
635
635
url = "http://sp.example.com/"
@@ -643,20 +643,74 @@ def test_request_nonutf8_bytes(self, mock_make_nonce, mock_make_timestamp):
643
643
params ['non_oauth_thing' ] = u'\u2019 '
644
644
req = oauth .Request (method = "GET" , url = url , parameters = params )
645
645
req .sign_request (oauth .SignatureMethod_HMAC_SHA1 (), con , None )
646
- self .failUnlessReallyEqual (req ['oauth_signature' ], 'QcgQMe9XzNxDWpechlQKFCd2orw =' )
646
+ self .failUnlessReallyEqual (req ['oauth_signature' ], '0GU50m0v60CVDB5JnoBXnvvvKx4 =' )
647
647
648
648
# And if it is a utf-8-encoded non-ascii thing, we'll decode
649
649
# it and use it.
650
650
params ['non_oauth_thing' ] = '\xc2 \xae '
651
651
req = oauth .Request (method = "GET" , url = url , parameters = params )
652
652
req .sign_request (oauth .SignatureMethod_HMAC_SHA1 (), con , None )
653
- self .failUnlessReallyEqual (req ['oauth_signature' ], 'OuMkgNFhlgcmEA1gIMII7aWLDgE =' )
653
+ self .failUnlessReallyEqual (req ['oauth_signature' ], 'pqOCu4qvRTiGiXB8Z61Jsey0pMM =' )
654
654
655
655
656
656
# Also if there are non-utf8 bytes in the query args.
657
657
url = "http://sp.example.com/?q=\x92 " # cp1252
658
658
self .assertRaises (TypeError , oauth .Request , method = "GET" , url = url , parameters = params )
659
659
660
+ def test_request_hash_of_body (self ):
661
+ tok = oauth .Token (key = "token" , secret = "tok-test-secret" )
662
+ con = oauth .Consumer (key = "consumer" , secret = "con-test-secret" )
663
+
664
+ # Example 1a from Appendix A.1 of
665
+ # http://oauth.googlecode.com/svn/spec/ext/body_hash/1.0/oauth-bodyhash.html
666
+ # Except that we get a differetn result than they do.
667
+
668
+ params = {
669
+ 'oauth_version' : "1.0" ,
670
+ 'oauth_token' : tok .key ,
671
+ 'oauth_nonce' : 10288510250934 ,
672
+ 'oauth_timestamp' : 1236874155 ,
673
+ 'oauth_consumer_key' : con .key
674
+ }
675
+
676
+ url = u"http://www.example.com/resource"
677
+ req = oauth .Request (method = "PUT" , url = url , parameters = params , body = "Hello World!" , is_form_encoded = False )
678
+ req .sign_request (oauth .SignatureMethod_HMAC_SHA1 (), con , None )
679
+ self .failUnlessReallyEqual (req ['oauth_body_hash' ], 'Lve95gjOVATpfV8EL5X4nxwjKHE=' )
680
+ self .failUnlessReallyEqual (req ['oauth_signature' ], 't+MX8l/0S8hdbVQL99nD0X1fPnM=' )
681
+ # oauth-bodyhash.html A.1 has
682
+ # '08bUFF%2Fjmp59mWB7cSgCYBUpJ0U%3D', but I don't see how that
683
+ # is possible.
684
+
685
+ # Example 1b
686
+ params = {
687
+ 'oauth_version' : "1.0" ,
688
+ 'oauth_token' : tok .key ,
689
+ 'oauth_nonce' : 10369470270925 ,
690
+ 'oauth_timestamp' : 1236874236 ,
691
+ 'oauth_consumer_key' : con .key
692
+ }
693
+
694
+ req = oauth .Request (method = "PUT" , url = url , parameters = params , body = "Hello World!" , is_form_encoded = False )
695
+ req .sign_request (oauth .SignatureMethod_HMAC_SHA1 (), con , None )
696
+ self .failUnlessReallyEqual (req ['oauth_body_hash' ], 'Lve95gjOVATpfV8EL5X4nxwjKHE=' )
697
+ self .failUnlessReallyEqual (req ['oauth_signature' ], 'CTFmrqJIGT7NsWJ42OrujahTtTc=' )
698
+
699
+ # Appendix A.2
700
+ params = {
701
+ 'oauth_version' : "1.0" ,
702
+ 'oauth_token' : tok .key ,
703
+ 'oauth_nonce' : 8628868109991 ,
704
+ 'oauth_timestamp' : 1238395022 ,
705
+ 'oauth_consumer_key' : con .key
706
+ }
707
+
708
+ req = oauth .Request (method = "GET" , url = url , parameters = params , is_form_encoded = False )
709
+ req .sign_request (oauth .SignatureMethod_HMAC_SHA1 (), con , None )
710
+ self .failUnlessReallyEqual (req ['oauth_body_hash' ], '2jmj7l5rSw0yVb/vlWAYkK/YBwk=' )
711
+ self .failUnlessReallyEqual (req ['oauth_signature' ], 'Zhl++aWSP0O3/hYQ0CuBc7jv38I=' )
712
+
713
+
660
714
def test_sign_request (self ):
661
715
url = "http://sp.example.com/"
662
716
@@ -674,7 +728,7 @@ def test_sign_request(self):
674
728
req = oauth .Request (method = "GET" , url = url , parameters = params )
675
729
676
730
methods = {
677
- 'TQ6vGQ5A6IZn8dmeGB4+/Jl3EMI =' : oauth .SignatureMethod_HMAC_SHA1 (),
731
+ 'DX01TdHws7OninCLK9VztNTH1M4 =' : oauth .SignatureMethod_HMAC_SHA1 (),
678
732
'con-test-secret&tok-test-secret' : oauth .SignatureMethod_PLAINTEXT ()
679
733
}
680
734
@@ -687,23 +741,23 @@ def test_sign_request(self):
687
741
url = "http://sp.example.com/\xe2 \x80 \x99 " # utf-8 bytes
688
742
req = oauth .Request (method = "GET" , url = url , parameters = params )
689
743
req .sign_request (oauth .SignatureMethod_HMAC_SHA1 (), con , tok )
690
- self .assertEquals (req ['oauth_signature' ], 'KagU7uiAAEvkZEzej2fcbyRXtzo =' )
744
+ self .assertEquals (req ['oauth_signature' ], 'loFvp5xC7YbOgd9exIO6TxB7H4s =' )
691
745
692
746
url = u'http://sp.example.com/\u2019 ' # Python unicode object
693
747
req = oauth .Request (method = "GET" , url = url , parameters = params )
694
748
req .sign_request (oauth .SignatureMethod_HMAC_SHA1 (), con , tok )
695
- self .assertEquals (req ['oauth_signature' ], 'KagU7uiAAEvkZEzej2fcbyRXtzo =' )
749
+ self .assertEquals (req ['oauth_signature' ], 'loFvp5xC7YbOgd9exIO6TxB7H4s =' )
696
750
697
751
# Also if there are non-ascii chars in the query args.
698
752
url = "http://sp.example.com/?q=\xe2 \x80 \x99 " # utf-8 bytes
699
753
req = oauth .Request (method = "GET" , url = url , parameters = params )
700
754
req .sign_request (oauth .SignatureMethod_HMAC_SHA1 (), con , tok )
701
- self .assertEquals (req ['oauth_signature' ], '5hyI7ovTVkcCyLeOKYzugnIvseo =' )
755
+ self .assertEquals (req ['oauth_signature' ], 'IBw5mfvoCsDjgpcsVKbyvsDqQaU =' )
702
756
703
757
url = u'http://sp.example.com/?q=\u2019 ' # Python unicode object
704
758
req = oauth .Request (method = "GET" , url = url , parameters = params )
705
759
req .sign_request (oauth .SignatureMethod_HMAC_SHA1 (), con , tok )
706
- self .assertEquals (req ['oauth_signature' ], '5hyI7ovTVkcCyLeOKYzugnIvseo =' )
760
+ self .assertEquals (req ['oauth_signature' ], 'IBw5mfvoCsDjgpcsVKbyvsDqQaU =' )
707
761
708
762
def test_from_request (self ):
709
763
url = "http://sp.example.com/"
0 commit comments