diff --git a/oauth2/__init__.py b/oauth2/__init__.py index a1776a75..77b4e5ee 100644 --- a/oauth2/__init__.py +++ b/oauth2/__init__.py @@ -372,7 +372,8 @@ def url(self, value): raise ValueError("Unsupported URL %s (%s)." % (value, scheme)) # Normalized URL excludes params, query, and fragment. - self.normalized_url = urlunsplit((scheme, netloc, path, None, None)) + self.normalized_url = urlunsplit((scheme.lower(), + netloc.lower(), path, None, None)) else: self.normalized_url = None self.__dict__['url'] = None diff --git a/tests/test_oauth.py b/tests/test_oauth.py index 58854564..f345c23c 100644 --- a/tests/test_oauth.py +++ b/tests/test_oauth.py @@ -364,6 +364,14 @@ def test_url(self): self.assertEqual(req.normalized_url, exp2) self.assertEqual(req.url, url2) + def test_url_lowercases_scheme_and_authority(self): + """Lowercase scheme and authority in URL normalization.""" + # http://oauth.net/core/1.0a/#rfc.section.9.1.2 + # https://github.com/joestump/python-oauth2/issues/29 + url = 'HTTP://Example.com/resource' + req = oauth.Request("GET", url) + self.assertEquals(req.normalized_url, "http://example.com/resource") + def test_bad_url(self): request = oauth.Request() try: