-
Notifications
You must be signed in to change notification settings - Fork 911
Specification improvement and bug fix to sign_request #138
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -485,8 +485,14 @@ def sign_request(self, signature_method, consumer, token): | |
"""Set the signature parameter to the result of sign.""" | ||
|
||
if not self.is_form_encoded: | ||
# according to | ||
# according to | ||
# http://oauth.googlecode.com/svn/spec/ext/body_hash/1.0/oauth-bodyhash.html | ||
# section 3.2 "If the request does not have an entity body, the hash should | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
# be taken over the empty string." | ||
if self.body is None: | ||
self.body = "" | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
# according to ibid | ||
# section 4.1.1 "OAuth Consumers MUST NOT include an | ||
# oauth_body_hash parameter on requests with form-encoded | ||
# request bodies." | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1289,6 +1289,38 @@ def mockrequest(cl, ur, **kw): | |
|
||
client.request(uri, 'GET') | ||
|
||
@mock.patch('httplib2.Http.request') | ||
def test_url_with_query_string_body_none(self, mockHttpRequest): | ||
uri = 'http://example.com/foo/bar/?show=thundercats&character=snarf' | ||
client = oauth.Client(self.consumer, None) | ||
random_result = random.randint(1,100) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
def mockrequest(cl, ur, **kw): | ||
self.failUnless(cl is client) | ||
self.failUnlessEqual(frozenset(kw.keys()), frozenset(['method', 'body', 'redirections', 'connection_type', 'headers'])) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
self.failUnlessEqual(kw['body'], None) | ||
self.failUnlessEqual(kw['connection_type'], None) | ||
self.failUnlessEqual(kw['method'], 'GET') | ||
self.failUnlessEqual(kw['redirections'], httplib2.DEFAULT_MAX_REDIRECTS) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
self.failUnless(isinstance(kw['headers'], dict)) | ||
|
||
req = oauth.Request.from_consumer_and_token(self.consumer, None, | ||
http_method='GET', http_url=uri, parameters={}) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
req.sign_request(oauth.SignatureMethod_HMAC_SHA1(), self.consumer, None) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
expected = parse_qsl(urlparse.urlparse(req.to_url()).query) | ||
actual = parse_qsl(urlparse.urlparse(ur).query) | ||
self.failUnlessEqual(len(expected), len(actual)) | ||
actual = dict(actual) | ||
for key, value in expected: | ||
if key not in ('oauth_signature', 'oauth_nonce', 'oauth_timestamp'): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
self.failUnlessEqual(actual[key], value) | ||
|
||
return random_result | ||
|
||
mockHttpRequest.side_effect = mockrequest | ||
|
||
client.request(uri, 'GET', body=None) | ||
|
||
@mock.patch('httplib2.Http.request') | ||
@mock.patch('oauth2.Request.from_consumer_and_token') | ||
def test_multiple_values_for_a_key(self, mockReqConstructor, mockHttpRequest): | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.