Skip to content

Commit 63db42c

Browse files
committed
Accomodate hash randomization.
1 parent 4000723 commit 63db42c

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

oauth2/__init__.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -405,14 +405,14 @@ def to_header(self, realm=''):
405405

406406
def to_postdata(self):
407407
"""Serialize as post data for a POST request."""
408-
d = {}
409-
for k, v in self.items():
410-
d[k.encode('utf-8')] = to_utf8_optional_iterator(v)
408+
items = []
409+
for k, v in sorted(self.items()): # predictable for testing
410+
items.append((k.encode('utf-8'), to_utf8_optional_iterator(v)))
411411

412412
# tell urlencode to deal with sequence values and map them correctly
413413
# to resulting querystring. for example self["k"] = ["v1", "v2"] will
414414
# result in 'k=v1&k=v2' and not k=%5B%27v1%27%2C+%27v2%27%5D
415-
return urlencode(d, True).replace('+', '%20')
415+
return urlencode(items, True).replace('+', '%20')
416416

417417
def to_url(self):
418418
"""Serialize as a URL for a GET request."""

tests/test_oauth.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -499,13 +499,14 @@ def test_to_postdata_nonascii(self):
499499
self.failUnlessReallyEqual(
500500
req.to_postdata(),
501501
('nonasciithing=q%C2%BFu%C3%A9%20%2Caasp%20u%3F..a.s'
502-
'&oauth_nonce=4572616e48616d6d65724c61686176'
503-
'&oauth_timestamp=137131200'
504502
'&oauth_consumer_key=0685bd9184jfhq22'
503+
'&oauth_nonce=4572616e48616d6d65724c61686176'
504+
'&oauth_signature=wOJIO9A2W5mFwDgiDvZbTSMK%252FPY%253D'
505505
'&oauth_signature_method=HMAC-SHA1'
506-
'&oauth_version=1.0'
506+
'&oauth_timestamp=137131200'
507507
'&oauth_token=ad180jjd733klru7'
508-
'&oauth_signature=wOJIO9A2W5mFwDgiDvZbTSMK%252FPY%253D'))
508+
'&oauth_version=1.0'
509+
))
509510

510511
def test_to_postdata(self):
511512
realm = "http://sp.example.com/"

0 commit comments

Comments
 (0)