Skip to content

Commit 6b92bab

Browse files
committed
Lowercase scheme and authority per specification. Closes #29.
1 parent 05441cb commit 6b92bab

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

oauth2/__init__.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,8 @@ def url(self, value):
368368
raise ValueError("Unsupported URL %s (%s)." % (value, scheme))
369369

370370
# Normalized URL excludes params, query, and fragment.
371-
self.normalized_url = urlparse.urlunsplit((scheme, netloc, path, None, None))
371+
self.normalized_url = urlparse.urlunsplit((scheme.lower(),
372+
netloc.lower(), path, None, None))
372373
else:
373374
self.normalized_url = None
374375
self.__dict__['url'] = None

tests/test_oauth.py

+9-1
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ def _compare_tokens(self, new):
224224
# TODO: What about copying the verifier to the new token?
225225
# self.assertEqual(self.token.verifier, new.verifier)
226226

227-
def test_to_string(self):
227+
def test_to_string_magic_method(self):
228228
tok = oauth.Token('tooken', 'seecret')
229229
self.assertEqual(str(tok), 'oauth_token_secret=seecret&oauth_token=tooken')
230230

@@ -303,6 +303,14 @@ def test_url(self):
303303
self.assertEquals(req.normalized_url, exp2)
304304
self.assertEquals(req.url, url2)
305305

306+
def test_url_lowercases_scheme_and_authority(self):
307+
"""Lowercase scheme and authority in URL normalization."""
308+
# http://oauth.net/core/1.0a/#rfc.section.9.1.2
309+
# https://github.com/joestump/python-oauth2/issues/29
310+
url = 'HTTP://Example.com/resource'
311+
req = oauth.Request("GET", url)
312+
self.assertEquals(req.normalized_url, "http://example.com/resource")
313+
306314
def test_bad_url(self):
307315
request = oauth.Request()
308316
try:

0 commit comments

Comments
 (0)