Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: idan/oauthlib
...
head fork: cmr/oauthlib
compare: use_request_objects
Checking mergeability… Don't worry, you can still create the pull request.
  • 4 commits
  • 7 files changed
  • 1 commit comment
  • 1 contributor
View
20 oauthlib/common.py
@@ -9,6 +9,7 @@
to all implementations of OAuth.
"""
+import copy
import re
import urllib
import urlparse
@@ -151,5 +152,20 @@ def uri_query(self):
@property
def uri_query_params(self):
- return urlparse.parse_qsl(self.uri_query, keep_blank_values=True,
- strict_parsing=True)
+ if self.uri_query:
+ return urlparse.parse_qsl(self.uri_query, keep_blank_values=True,
+ strict_parsing=True)
+ else:
+ return []
+
+ @property
+ def urlencoded_body(self):
+ return urlencode(self.body or [])
+
+ def clone(self):
+ cloned_request = Request(self.uri, http_method=self.http_method,
+ body=self.body,
+ headers=copy.copy(self.headers))
+ cloned_request.oauth_params = self.oauth_params
+ return cloned_request
+
View
122 oauthlib/oauth1/rfc5849/__init__.py
@@ -13,18 +13,7 @@
import urlparse
from oauthlib.common import Request, urlencode
-from . import parameters, signature, utils
-
-SIGNATURE_HMAC = u"HMAC-SHA1"
-SIGNATURE_RSA = u"RSA-SHA1"
-SIGNATURE_PLAINTEXT = u"PLAINTEXT"
-SIGNATURE_METHODS = (SIGNATURE_HMAC, SIGNATURE_RSA, SIGNATURE_PLAINTEXT)
-
-SIGNATURE_TYPE_AUTH_HEADER = u'AUTH_HEADER'
-SIGNATURE_TYPE_QUERY = u'QUERY'
-SIGNATURE_TYPE_BODY = u'BODY'
-
-CONTENT_TYPE_FORM_URLENCODED = u'application/x-www-form-urlencoded'
+from . import constants, parameters, signature, utils
class Client(object):
@@ -34,8 +23,8 @@ def __init__(self, client_key,
resource_owner_key=None,
resource_owner_secret=None,
callback_uri=None,
- signature_method=SIGNATURE_HMAC,
- signature_type=SIGNATURE_TYPE_AUTH_HEADER,
+ signature_method=constants.SIGNATURE_METHOD_HMAC,
+ signature_type=constants.SIGNATURE_TYPE_AUTH_HEADER,
rsa_key=None, verifier=None):
self.client_key = client_key
self.client_secret = client_secret
@@ -47,23 +36,21 @@ def __init__(self, client_key,
self.rsa_key = rsa_key
self.verifier = verifier
- if self.signature_method == SIGNATURE_RSA and self.rsa_key is None:
+ if (self.signature_method == constants.SIGNATURE_METHOD_RSA and
+ self.rsa_key is None):
raise ValueError('rsa_key is required when using RSA signature method.')
def get_oauth_signature(self, request):
"""Get an OAuth signature to be used in signing a request
"""
- if self.signature_method == SIGNATURE_PLAINTEXT:
+ if self.signature_method == constants.SIGNATURE_METHOD_PLAINTEXT:
# fast-path
return signature.sign_plaintext(self.client_secret,
self.resource_owner_secret)
- uri, headers, body = self._render(request)
+ request = self._render(request)
- collected_params = signature.collect_parameters(
- uri_query=urlparse.urlparse(uri).query,
- body=body,
- headers=headers)
+ collected_params = signature.collect_parameters(request)
logging.debug("Collected params: {0}".format(collected_params))
normalized_params = signature.normalize_parameters(collected_params)
@@ -76,14 +63,13 @@ def get_oauth_signature(self, request):
logging.debug("Base signing string: {0}".format(base_string))
- if self.signature_method == SIGNATURE_HMAC:
+ if self.signature_method == constants.SIGNATURE_METHOD_HMAC:
sig = signature.sign_hmac_sha1(base_string, self.client_secret,
self.resource_owner_secret)
- elif self.signature_method == SIGNATURE_RSA:
+ elif self.signature_method == constants.SIGNATURE_METHOD_RSA:
sig = signature.sign_rsa_sha1(base_string, self.rsa_key)
else:
- sig = signature.sign_plaintext(self.client_secret,
- self.resource_owner_secret)
+ raise ValueError("Unknown signature method: %s" % self.signature_method)
logging.debug("Signature: {0}".format(sig))
return sig
@@ -110,36 +96,12 @@ def get_oauth_params(self):
def _render(self, request, formencode=False):
"""Render a signed request according to signature type
- Returns a 3-tuple containing the request URI, headers, and body.
+ Returns a rendered Request instance.
If the formencode argument is True and the body contains parameters, it
is escaped and returned as a valid formencoded string.
"""
- # TODO what if there are body params on a header-type auth?
- # TODO what if there are query params on a body-type auth?
-
- uri, headers, body = request.uri, request.headers, request.body
-
- # TODO: right now these prepare_* methods are very narrow in scope--they
- # only affect their little thing. In some cases (for example, with
- # header auth) it might be advantageous to allow these methods to touch
- # other parts of the request, like the headers—so the prepare_headers
- # method could also set the Content-Type header to x-www-form-urlencoded
- # like the spec requires. This would be a fundamental change though, and
- # I'm not sure how I feel about it.
- if self.signature_type == SIGNATURE_TYPE_AUTH_HEADER:
- headers = parameters.prepare_headers(request.oauth_params, request.headers)
- elif self.signature_type == SIGNATURE_TYPE_BODY and request.decoded_body is not None:
- body = parameters.prepare_form_encoded_body(request.oauth_params, request.decoded_body)
- if formencode:
- body = urlencode(body)
- headers['Content-Type'] = u'application/x-www-form-urlencoded'
- elif self.signature_type == SIGNATURE_TYPE_QUERY:
- uri = parameters.prepare_request_uri_query(request.oauth_params, request.uri)
- else:
- raise ValueError('Unknown signature type specified.')
-
- return uri, headers, body
+ return parameters.prepare_request(request, self.signature_type)
def sign(self, uri, http_method=u'GET', body=None, headers=None):
"""Sign a request
@@ -171,8 +133,9 @@ def sign(self, uri, http_method=u'GET', body=None, headers=None):
# sanity check
content_type = request.headers.get('Content-Type', None)
multipart = content_type and content_type.startswith('multipart/')
- should_have_params = content_type == CONTENT_TYPE_FORM_URLENCODED
+ should_have_params = content_type == constants.CONTENT_TYPE_FORM_URLENCODED
has_params = request.decoded_body is not None
+
# 3.4.1.3.1. Parameter Sources
# [Parameters are collected from the HTTP request entity-body, but only
# if [...]:
@@ -188,7 +151,6 @@ def sign(self, uri, http_method=u'GET', body=None, headers=None):
# header field set to "application/x-www-form-urlencoded".
elif not should_have_params and has_params:
raise ValueError("Body contains parameters but Content-Type header was not set.")
-
# 3.5.2. Form-Encoded Body
# Protocol parameters can be transmitted in the HTTP request entity-
# body, but only if the following REQUIRED conditions are met:
@@ -198,7 +160,7 @@ def sign(self, uri, http_method=u'GET', body=None, headers=None):
# [W3C.REC-html40-19980424].
# o The HTTP request entity-header includes the "Content-Type" header
# field set to "application/x-www-form-urlencoded".
- elif self.signature_type == SIGNATURE_TYPE_BODY and not (
+ elif self.signature_type == constants.SIGNATURE_TYPE_BODY and not (
should_have_params and has_params and not multipart):
raise ValueError('Body signatures may only be used with form-urlencoded content')
@@ -209,12 +171,14 @@ def sign(self, uri, http_method=u'GET', body=None, headers=None):
request.oauth_params.append((u'oauth_signature', self.get_oauth_signature(request)))
# render the signed request and return it
- return self._render(request, formencode=True)
+ request = self._render(request)
+ return request.uri, request.headers, request.urlencoded_body
class Server(object):
"""A server used to verify OAuth 1.0 RFC 5849 requests"""
- def __init__(self, signature_method=SIGNATURE_HMAC, rsa_key=None):
+ def __init__(self, signature_method=constants.SIGNATURE_METHOD_HMAC,
+ rsa_key=None):
self.signature_method = signature_method
self.rsa_key = rsa_key
@@ -224,29 +188,6 @@ def get_client_secret(self, client_key):
def get_resource_owner_secret(self, resource_owner_key):
raise NotImplementedError("Subclasses must implement this function.")
- def get_signature_type_and_params(self, uri_query, headers, body):
- signature_types_with_oauth_params = filter(lambda s: s[1], (
- (SIGNATURE_TYPE_AUTH_HEADER, utils.filter_oauth_params(
- signature.collect_parameters(headers=headers,
- exclude_oauth_signature=False))),
- (SIGNATURE_TYPE_BODY, utils.filter_oauth_params(
- signature.collect_parameters(body=body,
- exclude_oauth_signature=False))),
- (SIGNATURE_TYPE_QUERY, utils.filter_oauth_params(
- signature.collect_parameters(uri_query=uri_query,
- exclude_oauth_signature=False))),
- ))
-
- if len(signature_types_with_oauth_params) > 1:
- raise ValueError('oauth_ params must come from only 1 signature type but were found in %s' % ', '.join(
- [s[0] for s in signature_types_with_oauth_params]))
- try:
- signature_type, params = signature_types_with_oauth_params[0]
- except IndexError:
- raise ValueError('oauth_ params are missing. Could not determine signature type.')
-
- return signature_type, dict(params)
-
def check_client_key(self, client_key):
raise NotImplementedError("Subclasses must implement this function.")
@@ -268,13 +209,11 @@ def check_request_signature(self, uri, http_method=u'GET', body='',
.. _`section 3.2`: http://tools.ietf.org/html/rfc5849#section-3.2
"""
- headers = headers or {}
- signature_type = None
- # FIXME: urlparse does not return unicode!
- uri_query = urlparse.urlparse(uri).query
-
- signature_type, params = self.get_signature_type_and_params(uri_query,
- headers, body)
+ request = Request(uri, http_method=http_method, body=body,
+ headers=headers)
+ signature_type = parameters.get_signature_type(request)
+ params = signature.collect_parameters(request,
+ exclude_oauth_signature=False)
# the parameters may not include duplicate oauth entries
filtered_params = utils.filter_oauth_params(params)
@@ -301,7 +240,7 @@ def check_request_signature(self, uri, http_method=u'GET', body='',
raise ValueError("Invalid OAuth version.")
# signature method must be valid
- if not signature_method in SIGNATURE_METHODS:
+ if not signature_method in constants.SIGNATURE_METHODS:
raise ValueError("Invalid signature method.")
# ensure client key is valid
@@ -321,7 +260,7 @@ def check_request_signature(self, uri, http_method=u'GET', body='',
# oauth_client parameters depend on client chosen signature method
# which may vary for each request, section 3.4
# HMAC-SHA1 and PLAINTEXT share parameters
- if signature_method == SIGNATURE_RSA:
+ if signature_method == constants.SIGNATURE_METHOD_RSA:
oauth_client = Client(client_key,
resource_owner_key=resource_owner_key,
callback_uri=callback_uri,
@@ -341,10 +280,11 @@ def check_request_signature(self, uri, http_method=u'GET', body='',
signature_type=signature_type,
verifier=verifier)
- request = Request(uri, http_method, body, headers)
- request.oauth_params = params
+ new_request = request.clone()
+ new_request.oauth_params = params.items()
- client_signature = oauth_client.get_oauth_signature(request)
+ client_signature = oauth_client.get_oauth_signature(new_request)
# FIXME: use near constant time string compare to avoid timing attacks
return client_signature == request_signature
+
View
23 oauthlib/oauth1/rfc5849/constants.py
@@ -0,0 +1,23 @@
+SIGNATURE_METHOD_HMAC = u"HMAC-SHA1"
+SIGNATURE_METHOD_RSA = u"RSA-SHA1"
+SIGNATURE_METHOD_PLAINTEXT = u"PLAINTEXT"
+SIGNATURE_METHODS = (
+ SIGNATURE_METHOD_HMAC,
+ SIGNATURE_METHOD_RSA,
+ SIGNATURE_METHOD_PLAINTEXT,
+)
+
+SIGNATURE_TYPE_AUTH_HEADER = u'AUTH_HEADER'
+SIGNATURE_TYPE_QUERY = u'QUERY'
+SIGNATURE_TYPE_BODY = u'BODY'
+SIGNATURE_TYPES = (
+ SIGNATURE_TYPE_AUTH_HEADER,
+ SIGNATURE_TYPE_QUERY,
+ SIGNATURE_TYPE_BODY,
+)
+
+CONTENT_TYPE_FORM_URLENCODED = u'application/x-www-form-urlencoded'
+CONTENT_TYPES = (
+ CONTENT_TYPE_FORM_URLENCODED,
+)
+
View
104 oauthlib/oauth1/rfc5849/parameters.py
@@ -11,14 +11,58 @@
"""
from urlparse import urlparse, urlunparse
-from . import utils
+from . import constants, utils
from oauthlib.common import extract_params, urlencode
+def get_signature_type(request):
+ """**Determine the signature type of a request**
+ Per `section 3.5`_ of the spec.
-# TODO: do we need filter_params now that oauth_params are handled by Request?
-# We can easily pass in just oauth protocol params.
-@utils.filter_params
-def prepare_headers(oauth_params, headers=None, realm=None):
+ .. _`section 3.5`: http://tools.ietf.org/html/rfc5849#section-3.5
+ """
+ signature_types = []
+
+ # When making an OAuth-authenticated request, protocol parameters as
+ # well as any other parameter using the "oauth_" prefix SHALL be
+ # included in the request using one and only one of the following
+ # locations, listed in order of decreasing preference:
+
+ # 1. The HTTP "Authorization" header field as described in
+ # `Section 3.5.1`_.
+ #
+ # .. _`Section 3.5.1`: http://tools.ietf.org/html/rfc5849#section-3.5.1
+ if request.headers:
+ headers_lower = dict(
+ (k.lower(), v) for k, v in request.headers.items())
+ authorization_header = headers_lower.get(u'authorization')
+ if authorization_header is not None:
+ header_oauth_params = utils.filter_oauth_params(
+ utils.parse_authorization_header(authorization_header))
+ if header_oauth_params:
+ signature_types.append(constants.SIGNATURE_TYPE_AUTH_HEADER)
+
+ # 2. The HTTP request entity-body as described in `Section 3.5.2`_.
+ #
+ # .. _`Section 3.5.2`: http://tools.ietf.org/html/rfc5849#section-3.5.2
+ if utils.filter_oauth_params(extract_params(request.body) or []):
+ signature_types.append(constants.SIGNATURE_TYPE_BODY)
+
+ # 3. The HTTP request URI query as described in `Section 3.5.3`_.
+ #
+ # .. _`Section 3.5.3`: http://tools.ietf.org/html/rfc5849#section-3.5.3
+ if utils.filter_oauth_params(request.uri_query_params):
+ signature_types.append(constants.SIGNATURE_TYPE_QUERY)
+
+ if len(signature_types) > 1:
+ raise ValueError('oauth_ params must come from only 1 signature type but were found in %s' % ', '.join(
+ signature_types))
+ try:
+ return signature_types[0]
+ except IndexError:
+ raise ValueError('oauth_ params are missing. Could not determine signature type.')
+
+
+def prepare_headers(request, realm=None):
"""**Prepare the Authorization header.**
Per `section 3.5.1`_ of the spec.
@@ -41,12 +85,14 @@ def prepare_headers(oauth_params, headers=None, realm=None):
.. _`section 3.5.1`: http://tools.ietf.org/html/rfc5849#section-3.5.1
.. _`RFC2617`: http://tools.ietf.org/html/rfc2617
"""
- headers = headers or {}
+ if not request.oauth_params:
+ raise ValueError('request.oauth_params must be present.')
+ new_request = request.clone()
# Protocol parameters SHALL be included in the "Authorization" header
# field as follows:
authorization_header_parameters_parts = []
- for oauth_parameter_name, value in oauth_params:
+ for oauth_parameter_name, value in new_request.oauth_params:
# 1. Parameter names and values are encoded per Parameter Encoding
# (`Section 3.6`_)
#
@@ -81,10 +127,8 @@ def prepare_headers(oauth_params, headers=None, realm=None):
authorization_header = u'OAuth %s' % authorization_header_parameters
# contribute the Authorization header to the given headers
- full_headers = {}
- full_headers.update(headers)
- full_headers[u'Authorization'] = authorization_header
- return full_headers
+ new_request.headers[u'Authorization'] = authorization_header
+ return new_request
def _append_params(oauth_params, params):
@@ -108,7 +152,7 @@ def _append_params(oauth_params, params):
return merged
-def prepare_form_encoded_body(oauth_params, body):
+def prepare_form_encoded_body(request):
"""Prepare the Form-Encoded Body.
Per `section 3.5.2`_ of the spec.
@@ -116,11 +160,18 @@ def prepare_form_encoded_body(oauth_params, body):
.. _`section 3.5.2`: http://tools.ietf.org/html/rfc5849#section-3.5.2
"""
+ if not request.oauth_params:
+ raise ValueError('request.oauth_params must be present.')
+
# append OAuth params to the existing body
- return _append_params(oauth_params, body)
+ new_request = request.clone()
+ body = _append_params(new_request.oauth_params, new_request.body)
+ new_request.body = body
+ new_request.headers['Content-Type'] = u'application/x-www-form-urlencoded'
+ return new_request
-def prepare_request_uri_query(oauth_params, uri):
+def prepare_request_uri_query(request):
"""Prepare the Request URI Query.
Per `section 3.5.3`_ of the spec.
@@ -128,7 +179,26 @@ def prepare_request_uri_query(oauth_params, uri):
.. _`section 3.5.3`: http://tools.ietf.org/html/rfc5849#section-3.5.3
"""
+ new_request = request.clone()
+
# append OAuth params to the existing set of query components
- sch, net, path, par, query, fra = urlparse(uri)
- query = urlencode(_append_params(oauth_params, extract_params(query) or []))
- return urlunparse((sch, net, path, par, query, fra))
+ sch, net, path, par, query, fra = urlparse(new_request.uri)
+ query = urlencode(_append_params(new_request.oauth_params,
+ extract_params(query) or []))
+ new_request.uri = urlunparse((sch, net, path, par, query, fra))
+ return new_request
+
+
+PREPARE_BY_SIGNATURE_TYPE = {
+ constants.SIGNATURE_TYPE_AUTH_HEADER: prepare_headers,
+ constants.SIGNATURE_TYPE_QUERY: prepare_form_encoded_body,
+ constants.SIGNATURE_TYPE_BODY: prepare_request_uri_query,
+}
+
+
+def prepare_request(request, signature_type):
+ try:
+ return PREPARE_BY_SIGNATURE_TYPE[signature_type](request)
+ except KeyError:
+ raise ValueError('Unknown signature type specified.')
+
View
13 oauthlib/oauth1/rfc5849/signature.py
@@ -167,8 +167,7 @@ def normalize_base_string_uri(uri):
#
# .. _`section 3.4.1.3`: http://tools.ietf.org/html/rfc5849#section-3.4.1.3
-def collect_parameters(uri_query='', body=[], headers=None,
- exclude_oauth_signature=True):
+def collect_parameters(request, exclude_oauth_signature=True):
"""**Parameter Sources**
Parameters starting with `oauth_` will be unescaped.
@@ -226,7 +225,7 @@ def collect_parameters(uri_query='', body=[], headers=None,
.. _`section 3.4.1.3.1`: http://tools.ietf.org/html/rfc5849#section-3.4.1.3.1
"""
- headers = headers or {}
+ headers = request.headers or {}
params = []
# The parameters from the following sources are collected into a single
@@ -240,9 +239,9 @@ def collect_parameters(uri_query='', body=[], headers=None,
# `W3C.REC-html40-19980424`_, Section 17.13.4.
#
# .. _`RFC3986, Section 3.4`: http://tools.ietf.org/html/rfc3986#section-3.4
- # .. _`W3C.REC-html40-19980424`: http://tools.ietf.org/html/rfc5849#ref-W3C.REC-html40-19980424
- if uri_query:
- params.extend(urlparse.parse_qsl(uri_query, keep_blank_values=True))
+ # .. _`W3C.REC-html40-19i980424`: http://tools.ietf.org/html/rfc5849#ref-W3C.REC-html40-19980424
+ if request.uri_query:
+ params.extend(urlparse.parse_qsl(request.uri_query, keep_blank_values=True))
# * The OAuth HTTP "Authorization" header field (`Section 3.5.1`_) if
# present. The header's content is parsed into a list of name/value
@@ -271,7 +270,7 @@ def collect_parameters(uri_query='', body=[], headers=None,
# .._`W3C.REC-html40-19980424`: http://tools.ietf.org/html/rfc5849#ref-W3C.REC-html40-19980424
# TODO: enforce header param inclusion conditions
- bodyparams = extract_params(body) or []
+ bodyparams = extract_params(request.body) or []
params.extend(bodyparams)
# ensure all oauth params are unescaped
View
41 tests/oauth1/rfc5849/test_parameters.py
@@ -1,12 +1,16 @@
# -*- coding: utf-8 -*-
from __future__ import absolute_import
-from oauthlib.common import urlencode
+from oauthlib.common import urlencode, Request
from oauthlib.oauth1.rfc5849.parameters import (_append_params, prepare_headers,
prepare_form_encoded_body, prepare_request_uri_query)
from ...unittest import TestCase
class ParameterTests(TestCase):
+ data_params = [
+ (u'data_param_foo', u'foo'),
+ (u'data_param_1', u'1'),
+ ]
auth_only_params = [
(u'oauth_consumer_key', u"9djdj82h48djs9d2"),
(u'oauth_token', u"kkk9d7dh3k39sjv7"),
@@ -15,9 +19,7 @@ class ParameterTests(TestCase):
(u'oauth_nonce', u"7d8f3e4a"),
(u'oauth_signature', u"bYT5CMsGcbgUdFHObYMEfcx6bsw=")
]
- auth_and_data = list(auth_only_params)
- auth_and_data.append((u'data_param_foo', u'foo'))
- auth_and_data.append((u'data_param_1', u'1'))
+ auth_and_data = auth_only_params + data_params
realm = u'testrealm'
norealm_authorization_header = u' '.join((
u'OAuth',
@@ -58,31 +60,32 @@ def test_append_params(self):
self.assertEqual(_append_params(unordered_1, unordered_2), expected)
def test_prepare_headers(self):
+ request = Request(u'http://www.google.com/')
+ request.oauth_params = self.auth_only_params
self.assertEqual(
- prepare_headers(self.auth_only_params, {}),
+ prepare_headers(request).headers,
{u'Authorization': self.norealm_authorization_header})
- self.assertEqual(
- prepare_headers(self.auth_only_params, {}, realm=self.realm),
- {u'Authorization': self.withrealm_authorization_header})
- def test_prepare_headers_ignore_data(self):
+ def test_prepare_headers_with_realm(self):
+ request = Request(u'http://www.google.com/')
+ request.oauth_params = self.auth_only_params
self.assertEqual(
- prepare_headers(self.auth_and_data, {}),
- {u'Authorization': self.norealm_authorization_header})
- self.assertEqual(
- prepare_headers(self.auth_and_data, {}, realm=self.realm),
+ prepare_headers(request, realm=self.realm).headers,
{u'Authorization': self.withrealm_authorization_header})
def test_prepare_form_encoded_body(self):
- existing_body = u''
- form_encoded_body = 'data_param_foo=foo&data_param_1=1&oauth_consumer_key=9djdj82h48djs9d2&oauth_token=kkk9d7dh3k39sjv7&oauth_signature_method=HMAC-SHA1&oauth_timestamp=137131201&oauth_nonce=7d8f3e4a&oauth_signature=bYT5CMsGcbgUdFHObYMEfcx6bsw%3D'
+ request = Request(u'http://www.google.com/', body=self.data_params)
+ request.oauth_params = self.auth_only_params
+ form_encoded_body = u'data_param_foo=foo&data_param_1=1&oauth_consumer_key=9djdj82h48djs9d2&oauth_token=kkk9d7dh3k39sjv7&oauth_signature_method=HMAC-SHA1&oauth_timestamp=137131201&oauth_nonce=7d8f3e4a&oauth_signature=bYT5CMsGcbgUdFHObYMEfcx6bsw%3D'
self.assertEqual(
- urlencode(prepare_form_encoded_body(self.auth_and_data, existing_body)),
+ urlencode(prepare_form_encoded_body(request).body),
form_encoded_body)
def test_prepare_request_uri_query(self):
- url = u'http://notarealdomain.com/foo/bar/baz?some=args&go=here'
- request_uri_query = u'http://notarealdomain.com/foo/bar/baz?some=args&go=here&data_param_foo=foo&data_param_1=1&oauth_consumer_key=9djdj82h48djs9d2&oauth_token=kkk9d7dh3k39sjv7&oauth_signature_method=HMAC-SHA1&oauth_timestamp=137131201&oauth_nonce=7d8f3e4a&oauth_signature=bYT5CMsGcbgUdFHObYMEfcx6bsw%3D'
+ request = Request(u'http://notarealdomain.com/foo/bar/baz?some=args&go=here')
+ request.oauth_params = self.auth_only_params
+ request_uri_query = u'http://notarealdomain.com/foo/bar/baz?some=args&go=here&oauth_consumer_key=9djdj82h48djs9d2&oauth_token=kkk9d7dh3k39sjv7&oauth_signature_method=HMAC-SHA1&oauth_timestamp=137131201&oauth_nonce=7d8f3e4a&oauth_signature=bYT5CMsGcbgUdFHObYMEfcx6bsw%3D'
self.assertEqual(
- prepare_request_uri_query(self.auth_and_data, url),
+ prepare_request_uri_query(request).uri,
request_uri_query)
+
View
32 tests/oauth1/rfc5849/test_signatures.py
@@ -3,6 +3,7 @@
import urllib
from oauthlib.oauth1.rfc5849.signature import *
+from oauthlib.common import Request
from ...unittest import TestCase
@@ -85,16 +86,14 @@ def test_collect_parameters(self):
""" We check against parameters multiple times in case things change after more
parameters are added.
"""
- # check against empty parameters
- # check against empty parameters
- # check against empty parameters
- self.assertEquals(collect_parameters(), [])
+
+ uri = u'http://example.com/request?%s' % self.uri_query
# Check against uri_query
# Check against uri_query
# Check against uri_query
-
- parameters = collect_parameters(uri_query=self.uri_query)
+ request = Request(uri)
+ parameters = collect_parameters(request)
self.assertEquals(len(parameters), 6)
self.assertEquals(parameters[0], ('b5', '=%3D'))
@@ -108,9 +107,10 @@ def test_collect_parameters(self):
# check against authorization header as well
# check against authorization header as well
- parameters = collect_parameters(uri_query=self.uri_query, headers={
+ request = Request(uri, headers={
'Authorization': self.authorization_header,
})
+ parameters = collect_parameters(request)
# Redo the checks against all the parameters. Duplicated code but better safety
self.assertEquals(len(parameters), 11)
@@ -129,10 +129,10 @@ def test_collect_parameters(self):
# Add in the body.
# TODO - add more valid content for the body. Daniel Greenfeld 2012/03/12
# Redo again the checks against all the parameters. Duplicated code but better safety
- parameters = collect_parameters(uri_query=self.uri_query,
- body=self.body, headers={
- 'Authorization': self.authorization_header,
- })
+ request = Request(uri, body=self.body, headers={
+ 'Authorization': self.authorization_header,
+ })
+ parameters = collect_parameters(request)
self.assertEquals(len(parameters), 12)
self.assertEquals(parameters[0], ('b5', '=%3D'))
self.assertEquals(parameters[1], ('a3', 'a'))
@@ -150,11 +150,13 @@ def test_collect_parameters(self):
def test_normalize_parameters(self):
""" We copy some of the variables from the test method above."""
+ uri = u'http://example.com/request?%s' % self.uri_query
+
# Create the parameters
- parameters = collect_parameters(uri_query=unicode(self.uri_query),
- body=unicode(self.body), headers={
- u'Authorization': unicode(self.authorization_header),
- })
+ request = Request(uri, body=unicode(self.body), headers={
+ u'Authorization': unicode(self.authorization_header),
+ })
+ parameters = collect_parameters(request)
normalized = normalize_parameters(parameters)
# check the parameters type

Showing you all comments on commits in this comparison.

@kennethreitz
Collaborator

What are the plans here?

Something went wrong with that request. Please try again.