Merge lp:~alecu/ubuntu-sso-client/fix-ping-url into lp:ubuntu-sso-client

Proposed by Alejandro J. Cura
Status: Merged
Approved by: Natalia Bidart
Approved revision: 849
Merged at revision: 848
Proposed branch: lp:~alecu/ubuntu-sso-client/fix-ping-url
Merge into: lp:ubuntu-sso-client
Diff against target: 74 lines (+31/-3)
2 files modified
ubuntu_sso/utils/webclient/common.py (+6/-2)
ubuntu_sso/utils/webclient/tests/test_webclient.py (+25/-1)
To merge this branch: bzr merge lp:~alecu/ubuntu-sso-client/fix-ping-url
Reviewer Review Type Date Requested Status
Natalia Bidart (community) Approve
Diego Sarmentero (community) Approve
Review via email: mp+91825@code.launchpad.net

Commit message

- Use parameters set in the url for the OAuth signature (LP: #927664)

Description of the change

- Use parameters set in the url for the OAuth signature (LP: #927664)

To post a comment you must log in.
Revision history for this message
Diego Sarmentero (diegosarmentero) wrote :

+1

review: Approve
Revision history for this message
Natalia Bidart (nataliabidart) wrote :

Looks great!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'ubuntu_sso/utils/webclient/common.py'
2--- ubuntu_sso/utils/webclient/common.py 2012-02-01 19:00:40 +0000
3+++ ubuntu_sso/utils/webclient/common.py 2012-02-07 13:25:06 +0000
4@@ -15,11 +15,13 @@
5 # with this program. If not, see <http://www.gnu.org/licenses/>.
6 """The common bits of a webclient."""
7
8+import cgi
9 import collections
10
11 from httplib2 import iri2uri
12 from oauth import oauth
13 from twisted.internet import defer
14+from urlparse import urlparse
15
16 from ubuntu_sso.utils.webclient.timestamp import TimestampChecker
17
18@@ -114,8 +116,10 @@
19 credentials["consumer_secret"])
20 token = oauth.OAuthToken(credentials["token"],
21 credentials["token_secret"])
22- if parameters is None:
23- parameters = {}
24+ if not parameters:
25+ _, _, _, _, query, _ = urlparse(uri)
26+ parameters = dict(cgi.parse_qsl(query))
27+
28 if timestamp:
29 parameters["oauth_timestamp"] = timestamp
30
31
32=== modified file 'ubuntu_sso/utils/webclient/tests/test_webclient.py'
33--- ubuntu_sso/utils/webclient/tests/test_webclient.py 2012-02-03 16:42:13 +0000
34+++ ubuntu_sso/utils/webclient/tests/test_webclient.py 2012-02-07 13:25:06 +0000
35@@ -28,7 +28,7 @@
36 from ubuntuone.devtools.testcases.squid import SquidTestCase
37
38 from ubuntu_sso.utils import webclient
39-from ubuntu_sso.utils.webclient.common import BaseWebClient, HeaderDict
40+from ubuntu_sso.utils.webclient.common import BaseWebClient, HeaderDict, oauth
41 from ubuntu_sso.utils.webclient.tests import BaseMockWebServer
42
43 ANY_VALUE = object()
44@@ -533,6 +533,30 @@
45 """Check that the oauth signed iri is properly built with params."""
46 return self.test_build_signed_iri(params=self.sample_params)
47
48+ def patch_staticmethod(self, src, attr_name, replacement):
49+ """Alternate patch because self.patch fails restoring staticmethods."""
50+ original = getattr(src, attr_name)
51+ setattr(src, attr_name, staticmethod(replacement))
52+ self.addCleanup(setattr, src, attr_name, staticmethod(original))
53+
54+ def test_iri_parameters_used_in_oauth_signature(self):
55+ """The iri parameters are used in the oauth signature."""
56+ from_consumer_and_token = oauth.OAuthRequest.from_consumer_and_token
57+
58+ def fake_from_consumer_and_token(parameters=None, **kwargs):
59+ """Verify the parameters passed."""
60+ self.assertIn("fake_param", parameters)
61+ return from_consumer_and_token(
62+ parameters=parameters, **kwargs)
63+
64+ self.patch_staticmethod(oauth.OAuthRequest, "from_consumer_and_token",
65+ fake_from_consumer_and_token)
66+
67+ self.sample_url += "?fake_param=fake_value"
68+ self.wc.build_oauth_request(self.sample_method, self.sample_url,
69+ SAMPLE_CREDENTIALS, self.timestamp,
70+ parameters={})
71+
72
73 class OAuthHmacSha1TestCase(OAuthPlainTextTestCase):
74 """Test for the oauth signing code using HMAC-SHA1."""

Subscribers

People subscribed via source and target branches