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
=== modified file 'ubuntu_sso/utils/webclient/common.py'
--- ubuntu_sso/utils/webclient/common.py 2012-02-01 19:00:40 +0000
+++ ubuntu_sso/utils/webclient/common.py 2012-02-07 13:25:06 +0000
@@ -15,11 +15,13 @@
15# with this program. If not, see <http://www.gnu.org/licenses/>.15# with this program. If not, see <http://www.gnu.org/licenses/>.
16"""The common bits of a webclient."""16"""The common bits of a webclient."""
1717
18import cgi
18import collections19import collections
1920
20from httplib2 import iri2uri21from httplib2 import iri2uri
21from oauth import oauth22from oauth import oauth
22from twisted.internet import defer23from twisted.internet import defer
24from urlparse import urlparse
2325
24from ubuntu_sso.utils.webclient.timestamp import TimestampChecker26from ubuntu_sso.utils.webclient.timestamp import TimestampChecker
2527
@@ -114,8 +116,10 @@
114 credentials["consumer_secret"])116 credentials["consumer_secret"])
115 token = oauth.OAuthToken(credentials["token"],117 token = oauth.OAuthToken(credentials["token"],
116 credentials["token_secret"])118 credentials["token_secret"])
117 if parameters is None:119 if not parameters:
118 parameters = {}120 _, _, _, _, query, _ = urlparse(uri)
121 parameters = dict(cgi.parse_qsl(query))
122
119 if timestamp:123 if timestamp:
120 parameters["oauth_timestamp"] = timestamp124 parameters["oauth_timestamp"] = timestamp
121125
122126
=== modified file 'ubuntu_sso/utils/webclient/tests/test_webclient.py'
--- ubuntu_sso/utils/webclient/tests/test_webclient.py 2012-02-03 16:42:13 +0000
+++ ubuntu_sso/utils/webclient/tests/test_webclient.py 2012-02-07 13:25:06 +0000
@@ -28,7 +28,7 @@
28from ubuntuone.devtools.testcases.squid import SquidTestCase28from ubuntuone.devtools.testcases.squid import SquidTestCase
2929
30from ubuntu_sso.utils import webclient30from ubuntu_sso.utils import webclient
31from ubuntu_sso.utils.webclient.common import BaseWebClient, HeaderDict31from ubuntu_sso.utils.webclient.common import BaseWebClient, HeaderDict, oauth
32from ubuntu_sso.utils.webclient.tests import BaseMockWebServer32from ubuntu_sso.utils.webclient.tests import BaseMockWebServer
3333
34ANY_VALUE = object()34ANY_VALUE = object()
@@ -533,6 +533,30 @@
533 """Check that the oauth signed iri is properly built with params."""533 """Check that the oauth signed iri is properly built with params."""
534 return self.test_build_signed_iri(params=self.sample_params)534 return self.test_build_signed_iri(params=self.sample_params)
535535
536 def patch_staticmethod(self, src, attr_name, replacement):
537 """Alternate patch because self.patch fails restoring staticmethods."""
538 original = getattr(src, attr_name)
539 setattr(src, attr_name, staticmethod(replacement))
540 self.addCleanup(setattr, src, attr_name, staticmethod(original))
541
542 def test_iri_parameters_used_in_oauth_signature(self):
543 """The iri parameters are used in the oauth signature."""
544 from_consumer_and_token = oauth.OAuthRequest.from_consumer_and_token
545
546 def fake_from_consumer_and_token(parameters=None, **kwargs):
547 """Verify the parameters passed."""
548 self.assertIn("fake_param", parameters)
549 return from_consumer_and_token(
550 parameters=parameters, **kwargs)
551
552 self.patch_staticmethod(oauth.OAuthRequest, "from_consumer_and_token",
553 fake_from_consumer_and_token)
554
555 self.sample_url += "?fake_param=fake_value"
556 self.wc.build_oauth_request(self.sample_method, self.sample_url,
557 SAMPLE_CREDENTIALS, self.timestamp,
558 parameters={})
559
536560
537class OAuthHmacSha1TestCase(OAuthPlainTextTestCase):561class OAuthHmacSha1TestCase(OAuthPlainTextTestCase):
538 """Test for the oauth signing code using HMAC-SHA1."""562 """Test for the oauth signing code using HMAC-SHA1."""

Subscribers

People subscribed via source and target branches