Skip to content

Commit 929773d

Browse files
committed
Fixing merge for branch 'rh-cleanup' of https://github.com/rickhanlonii/python-oauth2
1 parent 407ed64 commit 929773d

File tree

4 files changed

+28
-12
lines changed

4 files changed

+28
-12
lines changed

oauth10a/__init__.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -509,6 +509,8 @@ def sign_request(self, signature_method, consumer, token):
509509
# section 4.1.1 "OAuth Consumers MUST NOT include an
510510
# oauth_body_hash parameter on requests with form-encoded
511511
# request bodies."
512+
if not self.body:
513+
self.body = ''.encode('utf-8')
512514
self['oauth_body_hash'] = base64.b64encode(
513515
sha1(self.body).digest()
514516
)
@@ -683,7 +685,7 @@ def request(self, uri, method="GET", body=b'', headers=None,
683685
DEFAULT_POST_CONTENT_TYPE)
684686

685687
is_form_encoded = \
686-
headers.get('Content-Type') == 'application/x-www-form-urlencoded'
688+
headers.get('Content-Type', '').startswith('application/x-www-form-urlencoded')
687689

688690
if is_form_encoded and body:
689691
parameters = parse_qs(body)
@@ -784,6 +786,8 @@ def _check_signature(self, request, consumer, token):
784786
signature = request.get('oauth_signature')
785787
if signature is None:
786788
raise MissingSignature('Missing oauth_signature.')
789+
if isinstance(signature, str):
790+
signature = signature.encode('ascii', 'ignore')
787791

788792
# Validate the signature.
789793
valid = signature_method.check(request, consumer, token, signature)

oauth10a/clients/imap.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,14 @@ class IMAP4_SSL(imaplib.IMAP4_SSL):
3030
"""IMAP wrapper for imaplib.IMAP4_SSL that implements XOAUTH."""
3131

3232
def authenticate(self, url, consumer, token):
33-
if consumer is not None and not isinstance(consumer, oauth2.Consumer):
33+
if consumer is not None and not isinstance(consumer, oauth10a.Consumer):
3434
raise ValueError("Invalid consumer.")
3535

36-
if token is not None and not isinstance(token, oauth2.Token):
36+
if token is not None and not isinstance(token, oauth10a.Token):
3737
raise ValueError("Invalid token.")
3838

3939
imaplib.IMAP4_SSL.authenticate(
40-
self, 'XOAUTH', lambda x: oauth2.build_xoauth_string(url,
40+
self, 'XOAUTH', lambda x: oauth10a.build_xoauth_string(url,
4141
consumer,
4242
token)
4343
)

setup.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@
3030

3131
setup(name=PKG,
3232
version=verstr,
33-
description="library for OAuth version 1.9",
34-
author="Joe Stump",
35-
author_email="joe@simplegeo.com",
36-
url="http://github.com/joestump/python-oauth2",
33+
description="library for OAuth 1.0a version 1.9",
34+
author="Tim Sheerman-Chase",
35+
author_email="orders2008@sheerman-chase.org.uk",
36+
url="https://github.com/TimSC/python-oauth10a",
3737
classifiers=[
3838
"Intended Audience :: Developers",
3939
"Programming Language :: Python :: 2",

tests/test_oauth.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1269,7 +1269,7 @@ def sign(self, request, consumer, token):
12691269

12701270
class TestServer(unittest.TestCase):
12711271
def setUp(self):
1272-
url = "http://sp.example.com/"
1272+
self.url = "http://sp.example.com/"
12731273

12741274
params = {
12751275
'oauth_version': "1.0",
@@ -1286,7 +1286,7 @@ def setUp(self):
12861286

12871287
params['oauth_token'] = self.token.key
12881288
params['oauth_consumer_key'] = self.consumer.key
1289-
self.request = oauth.Request(method="GET", url=url, parameters=params)
1289+
self.request = oauth.Request(method="GET", url=self.url, parameters=params)
12901290

12911291
signature_method = oauth.SignatureMethod_HMAC_SHA1()
12921292
self.request.sign_request(signature_method, self.consumer, self.token)
@@ -1329,8 +1329,20 @@ def test_verify_request(self):
13291329
self.assertEqual(parameters['foo'], 59)
13301330
self.assertEqual(parameters['multi'], ['FOO', 'BAR'])
13311331

1332+
def test_verify_request_query_string(self):
1333+
server = oauth.Server()
1334+
server.add_signature_method(oauth.SignatureMethod_HMAC_SHA1())
1335+
1336+
signature_method = oauth.SignatureMethod_HMAC_SHA1()
1337+
request2 = oauth.Request.from_request("GET", self.url, query_string=urlencode(dict(self.request)))
1338+
request2.sign_request(signature_method, self.consumer, self.token)
1339+
request3 = oauth.Request.from_request("GET", self.url, query_string=urlencode(dict(request2)))
1340+
1341+
parameters = server.verify_request(request3, self.consumer,
1342+
self.token)
1343+
13321344
def test_verify_request_missing_signature(self):
1333-
from oauth2 import MissingSignature
1345+
from oauth10a import MissingSignature
13341346
server = oauth.Server()
13351347
server.add_signature_method(oauth.SignatureMethod_PLAINTEXT())
13361348
del self.request['oauth_signature_method']
@@ -1679,7 +1691,7 @@ def mockrequest(cl, ur, **kw):
16791691
client.request(uri, 'GET')
16801692

16811693
@mock.patch('httplib2.Http.request')
1682-
@mock.patch('oauth2.Request.from_consumer_and_token')
1694+
@mock.patch('oauth10a.Request.from_consumer_and_token')
16831695
def test_multiple_values_for_a_key(self, mockReqConstructor,
16841696
mockHttpRequest):
16851697
client = oauth.Client(self.consumer, None)

0 commit comments

Comments
 (0)