Skip to content

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

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion oauth2/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • W291 trailing whitespace

# 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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • E501 line too long (87 > 79 characters)
  • W291 trailing whitespace

# be taken over the empty string."
if self.body is None:
self.body = ""

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • W293 blank line contains whitespace

# according to ibid
# section 4.1.1 "OAuth Consumers MUST NOT include an
# oauth_body_hash parameter on requests with form-encoded
# request bodies."
Expand Down
32 changes: 32 additions & 0 deletions tests/test_oauth.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • E231 missing whitespace after ','


def mockrequest(cl, ur, **kw):
self.failUnless(cl is client)
self.failUnlessEqual(frozenset(kw.keys()), frozenset(['method', 'body', 'redirections', 'connection_type', 'headers']))

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • E501 line too long (131 > 79 characters)

self.failUnlessEqual(kw['body'], None)
self.failUnlessEqual(kw['connection_type'], None)
self.failUnlessEqual(kw['method'], 'GET')
self.failUnlessEqual(kw['redirections'], httplib2.DEFAULT_MAX_REDIRECTS)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • E501 line too long (84 > 79 characters)

self.failUnless(isinstance(kw['headers'], dict))

req = oauth.Request.from_consumer_and_token(self.consumer, None,
http_method='GET', http_url=uri, parameters={})

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • E501 line too long (103 > 79 characters)

req.sign_request(oauth.SignatureMethod_HMAC_SHA1(), self.consumer, None)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • E501 line too long (84 > 79 characters)

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'):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • E501 line too long (84 > 79 characters)

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):
Expand Down