From f79b61bfb790bc8cc3f7b8e0efb9f0fdb99a0a68 Mon Sep 17 00:00:00 2001 From: Daniel Holmes Date: Mon, 14 Sep 2015 10:26:41 +1000 Subject: [PATCH 1/3] Update .travis.yml --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 128885c6..e4e5b1bb 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,5 +4,6 @@ python: - "2.7" - "3.3" - "3.4" + - "3.5" install: "pip install -r requirements.txt" script: py.test From dbd1be07e3514d98c1205dca7effa9ce30f0fee6 Mon Sep 17 00:00:00 2001 From: Arthur Barrett Date: Tue, 29 Sep 2015 13:29:29 -0400 Subject: [PATCH 2/3] Eliminates duplicated query parameters from normalized base string. --- oauth2/__init__.py | 12 ++++++++++-- tests/test_oauth.py | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 2 deletions(-) diff --git a/oauth2/__init__.py b/oauth2/__init__.py index a1776a75..d91bfce1 100644 --- a/oauth2/__init__.py +++ b/oauth2/__init__.py @@ -468,12 +468,20 @@ def get_normalized_parameters(self): # Include any query string parameters from the provided URL query = urlparse(self.url)[4] - url_items = self._split_url_string(query).items() url_items = [(to_utf8(k), to_utf8_optional_iterator(v)) for k, v in url_items if k != 'oauth_signature' ] - items.extend(url_items) + + # Merge together URL and POST parameters. + # Eliminates parameters duplicated between URL and POST. + items_dict = {} + for k,v in items: + items_dict.setdefault(k, []).append(v) + for k,v in url_items: + if not (k in items_dict and v in items_dict[k]): + items.append((k,v)) items.sort() + encoded_str = urlencode(items, True) # Encode signature parameters per Oauth Core 1.0 protocol # spec draft 7, section 3.6 diff --git a/tests/test_oauth.py b/tests/test_oauth.py index 58854564..54f4413a 100644 --- a/tests/test_oauth.py +++ b/tests/test_oauth.py @@ -744,6 +744,39 @@ def test_get_normalized_parameters_duplicate(self): self.assertEqual(expected, res) + def test_get_normalized_parameters_duplicate_url_and_post_parameters(self): + url = ("http://example.com/v2/search/videos" + '?oauth_nonce=79815175' + '&oauth_timestamp=1295397962' + '&oauth_consumer_key=mykey' + '&oauth_signature_method=HMAC-SHA1' + '&tag=one' + '&search=duplicate' + '&offset=10' + '&oauth_version=1.0' + '&oauth_signature=spWLI%2FGQjid7sQVd5%2FarahRxzJg%3D') + + # duplicates the "search" query parameter in the post parameters (same key and value) + parameters = { + "tag": "two", + "search": "duplicate", + } + req = oauth.Request("POST", url, parameters) + + res = req.get_normalized_parameters() + + expected = ('oauth_consumer_key=mykey' + '&oauth_nonce=79815175' + '&oauth_signature_method=HMAC-SHA1' + '&oauth_timestamp=1295397962' + '&oauth_version=1.0' + '&offset=10' + '&search=duplicate' + '&tag=one' + '&tag=two') + + self.assertEqual(expected, res) + def test_get_normalized_parameters_multiple(self): url = "http://example.com/v2/search/videos?oauth_nonce=79815175&oauth_timestamp=1295397962&oauth_consumer_key=mykey&oauth_signature_method=HMAC-SHA1&oauth_version=1.0&offset=10&oauth_signature=spWLI%2FGQjid7sQVd5%2FarahRxzJg%3D&tag=one&tag=two" From 655cd95146379736ac8d21070c1d0838c840f657 Mon Sep 17 00:00:00 2001 From: Arthur Barrett Date: Wed, 30 Sep 2015 09:58:35 -0400 Subject: [PATCH 3/3] Fixed style issues --- oauth2/__init__.py | 8 ++++---- tests/test_oauth.py | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/oauth2/__init__.py b/oauth2/__init__.py index d91bfce1..fc49e105 100644 --- a/oauth2/__init__.py +++ b/oauth2/__init__.py @@ -470,15 +470,15 @@ def get_normalized_parameters(self): query = urlparse(self.url)[4] url_items = self._split_url_string(query).items() url_items = [(to_utf8(k), to_utf8_optional_iterator(v)) for k, v in url_items if k != 'oauth_signature' ] - + # Merge together URL and POST parameters. # Eliminates parameters duplicated between URL and POST. items_dict = {} - for k,v in items: + for k, v in items: items_dict.setdefault(k, []).append(v) - for k,v in url_items: + for k, v in url_items: if not (k in items_dict and v in items_dict[k]): - items.append((k,v)) + items.append((k, v)) items.sort() diff --git a/tests/test_oauth.py b/tests/test_oauth.py index 54f4413a..7b272e24 100644 --- a/tests/test_oauth.py +++ b/tests/test_oauth.py @@ -756,7 +756,7 @@ def test_get_normalized_parameters_duplicate_url_and_post_parameters(self): '&oauth_version=1.0' '&oauth_signature=spWLI%2FGQjid7sQVd5%2FarahRxzJg%3D') - # duplicates the "search" query parameter in the post parameters (same key and value) + # duplicates the "search" query parameter parameters = { "tag": "two", "search": "duplicate",