@@ -109,11 +109,37 @@ def test_oauth_body_hash_with_body_none(self):
109109 oauth_body_hash_object = oauth_object .oauth_body_hash (OAuthExtTest .mock_prepared_request , OAuthExtTest .payload )
110110
111111 # Using mock data to find the hash value
112- hashlib_val = hashlib .sha256 (str (OAuthExtTest . mock_prepared_request . body ).encode ('utf8' )).digest ()
112+ hashlib_val = hashlib .sha256 (str ("" ).encode ('utf8' )).digest ()
113113 payload_hash_value = util .uri_rfc3986_encode (util .base64_encode (hashlib_val ))
114114
115115 self .assertEqual (oauth_body_hash_object ['oauth_body_hash' ], payload_hash_value )
116116
117+ def test_oauth_body_hash_with_body_empty_or_none (self ):
118+ def prep_request ():
119+ req = PreparedRequest ()
120+ req .prepare (headers = {'Content-type' : 'application/json' , 'Accept' : 'application/json' },
121+ method = "POST" ,
122+ url = "http://www.example.com" )
123+ return req
124+
125+ oauth_object = OAuth1RSA (OAuthExtTest .consumer_key , OAuthExtTest .signing_key )
126+ request_empty = prep_request ()
127+ request_none = prep_request ()
128+
129+ request_empty .body = ""
130+ request_none .body = None
131+
132+ # Passing data to the actual func to get the value
133+ empty_body_hash = oauth_object .oauth_body_hash (request_empty , OAuthExtTest .payload )
134+ none_body_hash = oauth_object .oauth_body_hash (request_none , OAuthExtTest .payload )
135+
136+ # Using mock data to find the hash value
137+ empty_string_hash = hashlib .sha256 (str ("" ).encode ('utf8' )).digest ()
138+ empty_string_encoded = util .uri_rfc3986_encode (util .base64_encode (empty_string_hash ))
139+
140+ self .assertEqual (empty_body_hash ['oauth_body_hash' ], empty_string_encoded )
141+ self .assertEqual (none_body_hash ['oauth_body_hash' ], empty_string_encoded )
142+
117143 def test_oauth_body_hash_with_body_multipart (self ):
118144 oauth_object = OAuth1RSA (OAuthExtTest .consumer_key , OAuthExtTest .signing_key )
119145 mock_request = PreparedRequest ()
0 commit comments