From 6b92bab0a436b0de28afdfc50d20e87066646666 Mon Sep 17 00:00:00 2001 From: Joe Stump Date: Wed, 29 Jul 2015 09:13:56 -0700 Subject: [PATCH 1/2] Lowercase scheme and authority per specification. Closes #29. --- oauth2/__init__.py | 3 ++- tests/test_oauth.py | 10 +++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/oauth2/__init__.py b/oauth2/__init__.py index 6c66de1f..3b9c7417 100644 --- a/oauth2/__init__.py +++ b/oauth2/__init__.py @@ -368,7 +368,8 @@ def url(self, value): raise ValueError("Unsupported URL %s (%s)." % (value, scheme)) # Normalized URL excludes params, query, and fragment. - self.normalized_url = urlparse.urlunsplit((scheme, netloc, path, None, None)) + self.normalized_url = urlparse.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 1399c291..5e96e586 100644 --- a/tests/test_oauth.py +++ b/tests/test_oauth.py @@ -224,7 +224,7 @@ def _compare_tokens(self, new): # TODO: What about copying the verifier to the new token? # self.assertEqual(self.token.verifier, new.verifier) - def test_to_string(self): + def test_to_string_magic_method(self): tok = oauth.Token('tooken', 'seecret') self.assertEqual(str(tok), 'oauth_token_secret=seecret&oauth_token=tooken') @@ -303,6 +303,14 @@ def test_url(self): self.assertEquals(req.normalized_url, exp2) self.assertEquals(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: From c3d8b72e4a44d9285f4ea8cd81c8b9e20ef1783f Mon Sep 17 00:00:00 2001 From: "Daniel J Holmes (jaitaiwan)" Date: Thu, 30 Jul 2015 13:46:34 +1000 Subject: [PATCH 2/2] Should be compiling against 3 --- .travis.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.travis.yml b/.travis.yml index 7796bb8a..128885c6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,5 +2,7 @@ language: python python: - "2.6" - "2.7" + - "3.3" + - "3.4" install: "pip install -r requirements.txt" script: py.test