summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatt McClure <matthewlmcclure@gmail.com>2013-05-02 23:14:43 -0400
committerMatt McClure <matthewlmcclure@gmail.com>2013-05-02 23:18:30 -0400
commita5b85002f49c5029ce7a0d73fc8576003a39237b (patch)
tree81474b9e43f09ba1fa715715061800a07fd782f4
parent0a1e428802838ea8a965f90edac144dd1f8d719a (diff)
downloadoauthlib-a5b85002f49c5029ce7a0d73fc8576003a39237b.tar.gz
Update, comment on, and test the implementation.
-rw-r--r--oauthlib/oauth1/rfc5849/__init__.py7
-rw-r--r--oauthlib/oauth1/rfc5849/signature.py23
-rw-r--r--tests/oauth1/rfc5849/test_signatures.py4
3 files changed, 32 insertions, 2 deletions
diff --git a/oauthlib/oauth1/rfc5849/__init__.py b/oauthlib/oauth1/rfc5849/__init__.py
index 7daf44d..974777e 100644
--- a/oauthlib/oauth1/rfc5849/__init__.py
+++ b/oauthlib/oauth1/rfc5849/__init__.py
@@ -97,6 +97,13 @@ class Client(object):
def get_oauth_signature(self, request):
"""Get an OAuth signature to be used in signing a request
+
+ To satisfy `section 3.4.1.2`_ item 2, if the request argument's
+ headers dict attribute contains a Host item, its value will
+ replace any netloc part of the request argument's uri attribute
+ value.
+
+ .. _`section 3.4.1.2`: http://tools.ietf.org/html/rfc5849#section-3.4.1.2
"""
if self.signature_method == SIGNATURE_PLAINTEXT:
# fast-path
diff --git a/oauthlib/oauth1/rfc5849/signature.py b/oauthlib/oauth1/rfc5849/signature.py
index 9d6fa34..f784150 100644
--- a/oauthlib/oauth1/rfc5849/signature.py
+++ b/oauthlib/oauth1/rfc5849/signature.py
@@ -118,6 +118,8 @@ def normalize_base_string_uri(uri, host=None):
is represented by the base string URI: "https://www.example.net:8080/".
.. _`section 3.4.1.2`: http://tools.ietf.org/html/rfc5849#section-3.4.1.2
+
+ The host argument overrides the netloc part of the uri argument.
"""
if not isinstance(uri, unicode_type):
raise ValueError('uri must be a unicode object.')
@@ -133,11 +135,12 @@ def normalize_base_string_uri(uri, host=None):
# 1. The scheme and host MUST be in lowercase.
scheme = scheme.lower()
- netloc = (host or netloc).lower()
+ netloc = netloc.lower()
# 2. The host and port values MUST match the content of the HTTP
# request "Host" header field.
- # TODO: enforce this constraint
+ if host is not None:
+ netloc = host.lower()
# 3. The port MUST be included if it is not the default port for the
# scheme, and MUST be excluded if it is the default. Specifically,
@@ -514,6 +517,15 @@ def verify_hmac_sha1(request, client_secret=None,
Per `section 3.4`_ of the spec.
.. _`section 3.4`: http://tools.ietf.org/html/rfc5849#section-3.4
+
+ To satisfy `RFC2616 section 5.2`_ item 1, the request argument's uri
+ attribute MUST be an absolute URI whose netloc part identifies the
+ origin server or gateway on which the resource resides. Any Host
+ item of the request argument's headers dict attribute will be
+ ignored.
+
+ .. _`RFC2616 section 5.2`: http://tools.ietf.org/html/rfc2616#section-5.2
+
"""
norm_params = normalize_parameters(request.params)
uri = normalize_base_string_uri(request.uri)
@@ -532,6 +544,13 @@ def verify_rsa_sha1(request, rsa_public_key):
.. _`section 3.4.3`: http://tools.ietf.org/html/rfc5849#section-3.4.3
+ To satisfy `RFC2616 section 5.2`_ item 1, the request argument's uri
+ attribute MUST be an absolute URI whose netloc part identifies the
+ origin server or gateway on which the resource resides. Any Host
+ item of the request argument's headers dict attribute will be
+ ignored.
+
+ .. _`RFC2616 section 5.2`: http://tools.ietf.org/html/rfc2616#section-5.2
"""
from Crypto.PublicKey import RSA
from Crypto.Signature import PKCS1_v1_5
diff --git a/tests/oauth1/rfc5849/test_signatures.py b/tests/oauth1/rfc5849/test_signatures.py
index 8d4ce85..afdcfc0 100644
--- a/tests/oauth1/rfc5849/test_signatures.py
+++ b/tests/oauth1/rfc5849/test_signatures.py
@@ -86,6 +86,10 @@ class SignatureTests(TestCase):
uri = "http://www.example.com:80"
self.assertEquals(normalize_base_string_uri(uri), "http://www.example.com")
+ host = "alternatehost.example.com"
+ self.assertEquals(normalize_base_string_uri(uri, host),
+ "http://alternatehost.example.com")
+
def test_collect_parameters(self):
""" We check against parameters multiple times in case things change after more
parameters are added.