Merge lp:~dobey/ubuntuone-storage-protocol/update-4-2 into lp:ubuntuone-storage-protocol/stable-4-2

Proposed by dobey
Status: Merged
Approved by: dobey
Approved revision: no longer in the source branch.
Merged at revision: 159
Proposed branch: lp:~dobey/ubuntuone-storage-protocol/update-4-2
Merge into: lp:ubuntuone-storage-protocol/stable-4-2
Diff against target: 151 lines (+56/-38)
2 files modified
tests/test_client.py (+37/-21)
ubuntuone/storageprotocol/client.py (+19/-17)
To merge this branch: bzr merge lp:~dobey/ubuntuone-storage-protocol/update-4-2
Reviewer Review Type Date Requested Status
Mike McCracken (community) Approve
Review via email: mp+148553@code.launchpad.net

Commit message

[Barry Warsaw]

    Switch from python-oauth to python-oauthlib for using OAuth.

To post a comment you must log in.
Revision history for this message
Mike McCracken (mikemc) :
review: Approve
Revision history for this message
Ubuntu One Auto Pilot (otto-pilot) wrote :

The attempt to merge lp:~dobey/ubuntuone-storage-protocol/update-4-2 into lp:ubuntuone-storage-protocol/stable-4-2 failed. Below is the output from the failed tests.

running build
running build_py
creating build
creating build/lib.linux-x86_64-2.7
creating build/lib.linux-x86_64-2.7/ubuntuone
copying ubuntuone/__init__.py -> build/lib.linux-x86_64-2.7/ubuntuone
creating build/lib.linux-x86_64-2.7/ubuntuone/storageprotocol
copying ubuntuone/storageprotocol/dircontent_pb2.py -> build/lib.linux-x86_64-2.7/ubuntuone/storageprotocol
copying ubuntuone/storageprotocol/delta.py -> build/lib.linux-x86_64-2.7/ubuntuone/storageprotocol
copying ubuntuone/storageprotocol/dircontent.py -> build/lib.linux-x86_64-2.7/ubuntuone/storageprotocol
copying ubuntuone/storageprotocol/sharersp.py -> build/lib.linux-x86_64-2.7/ubuntuone/storageprotocol
copying ubuntuone/storageprotocol/context.py -> build/lib.linux-x86_64-2.7/ubuntuone/storageprotocol
copying ubuntuone/storageprotocol/protocol_pb2.py -> build/lib.linux-x86_64-2.7/ubuntuone/storageprotocol
copying ubuntuone/storageprotocol/utils.py -> build/lib.linux-x86_64-2.7/ubuntuone/storageprotocol
copying ubuntuone/storageprotocol/errors.py -> build/lib.linux-x86_64-2.7/ubuntuone/storageprotocol
copying ubuntuone/storageprotocol/volumes.py -> build/lib.linux-x86_64-2.7/ubuntuone/storageprotocol
copying ubuntuone/storageprotocol/content_hash.py -> build/lib.linux-x86_64-2.7/ubuntuone/storageprotocol
copying ubuntuone/storageprotocol/proxy_tunnel.py -> build/lib.linux-x86_64-2.7/ubuntuone/storageprotocol
copying ubuntuone/storageprotocol/validators.py -> build/lib.linux-x86_64-2.7/ubuntuone/storageprotocol
copying ubuntuone/storageprotocol/__init__.py -> build/lib.linux-x86_64-2.7/ubuntuone/storageprotocol
copying ubuntuone/storageprotocol/client.py -> build/lib.linux-x86_64-2.7/ubuntuone/storageprotocol
copying ubuntuone/storageprotocol/request.py -> build/lib.linux-x86_64-2.7/ubuntuone/storageprotocol

Traceback (most recent call last):
  File "/usr/bin/u1trial", line 40, in <module>
    main()
  File "/usr/lib/python2.7/dist-packages/ubuntuone-dev-tools/ubuntuone/devtools/runners/__init__.py", line 277, in main
    suite = test_runner.get_suite(options)
  File "/usr/lib/python2.7/dist-packages/ubuntuone-dev-tools/ubuntuone/devtools/runners/__init__.py", line 173, in get_suite
    config['ignore-paths']))
  File "/usr/lib/python2.7/dist-packages/ubuntuone-dev-tools/ubuntuone/devtools/runners/__init__.py", line 157, in _collect_tests
    module_suite = self._load_unittest(filepath)
  File "/usr/lib/python2.7/dist-packages/ubuntuone-dev-tools/ubuntuone/devtools/runners/__init__.py", line 98, in _load_unittest
    module = __import__(modpath, None, None, [""])
  File "/mnt/tarmac/cache/ubuntuone-storage-protocol-stable-4-2/trunk/tests/test_query.py", line 35, in <module>
    from ubuntuone.storageprotocol.client import MultiQuery
  File "/mnt/tarmac/cache/ubuntuone-storage-protocol-stable-4-2/trunk/ubuntuone/storageprotocol/client.py", line 43, in <module>
    from oauthlib.oauth1 import Client, SIGNATURE_PLAINTEXT, SIGNATURE_TYPE_QUERY
ImportError: No module named oauthlib.oauth1

159. By Barry Warsaw

[Barry Warsaw]

    Switch from python-oauth to python-oauthlib for using OAuth.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'tests/test_client.py'
--- tests/test_client.py 2012-12-03 19:45:43 +0000
+++ tests/test_client.py 2013-02-14 20:28:33 +0000
@@ -38,6 +38,8 @@
38import unittest38import unittest
39import uuid39import uuid
4040
41from urlparse import urlparse, parse_qsl
42
41from twisted.application import internet, service43from twisted.application import internet, service
42from twisted.internet import defer44from twisted.internet import defer
43from twisted.internet.defer import Deferred, inlineCallbacks45from twisted.internet.defer import Deferred, inlineCallbacks
@@ -48,10 +50,12 @@
48from ubuntuone.storageprotocol.client import (50from ubuntuone.storageprotocol.client import (
49 StorageClient, CreateUDF, ListVolumes, DeleteVolume, GetDelta, Unlink,51 StorageClient, CreateUDF, ListVolumes, DeleteVolume, GetDelta, Unlink,
50 Authenticate, MakeFile, MakeDir, PutContent, Move, BytesMessageProducer,52 Authenticate, MakeFile, MakeDir, PutContent, Move, BytesMessageProducer,
51 oauth, TwistedTimestampChecker, tx_timestamp_checker,53 TwistedTimestampChecker, tx_timestamp_checker,
52)54)
55
53from ubuntuone.storageprotocol import volumes56from ubuntuone.storageprotocol import volumes
54from tests import test_delta_info57from tests import test_delta_info
58from oauthlib.oauth1 import Client
5559
56# let's not get picky about aatributes outside __init__ in tests60# let's not get picky about aatributes outside __init__ in tests
57# pylint: disable=W020161# pylint: disable=W0201
@@ -795,31 +799,43 @@
795799
796 def test_oauth_authenticate_uses_server_timestamp(self):800 def test_oauth_authenticate_uses_server_timestamp(self):
797 """The oauth authentication uses the server timestamp."""801 """The oauth authentication uses the server timestamp."""
798 fromcandt_call = []802 timestamps = []
799803
800 fake_token = oauth.OAuthToken('token', 'token_secret')804 original_sign = Client.sign
801 fake_consumer = oauth.OAuthConsumer('consumer_key', 'consumer_secret')805
802806 def fake_sign(self, *args, **kwargs):
803 fake_timestamp = object()807 """A fake Client.sign()."""
808 url, headers, body = original_sign(self, *args, **kwargs)
809 timestamps.extend(
810 value for name, value in parse_qsl(urlparse(url).query)
811 if name == 'oauth_timestamp')
812 return url, headers, body
813
814 fake_timestamp = '801'
804 timestamp_d = Deferred()815 timestamp_d = Deferred()
805 self.patch(tx_timestamp_checker, "get_faithful_time",816 self.patch(tx_timestamp_checker, "get_faithful_time",
806 lambda: timestamp_d)817 lambda: timestamp_d)
807 original_fromcandt = oauth.OAuthRequest.from_consumer_and_token818
808819 self.patch(Client, 'sign', fake_sign)
809 @staticmethod
810 def fake_from_consumer_and_token(**kwargs):
811 """A fake from_consumer_and_token."""
812 fromcandt_call.append(kwargs)
813 return original_fromcandt(**kwargs)
814
815 self.patch(oauth.OAuthRequest, "from_consumer_and_token",
816 fake_from_consumer_and_token)
817 protocol = FakedProtocol()820 protocol = FakedProtocol()
818 protocol.oauth_authenticate(fake_consumer, fake_token)821 # For backward compatibility of the API, oauth_authenticate() takes a
819 self.assertEqual(len(fromcandt_call), 0)822 # consumer object and a token object. Both of those must have .key
823 # and .secret attributes. In modern OAuth1 (i.e. RFC 5849)
824 # terminology, the consumer is really the OAuth client, and the token
825 # is really the OAuth resource owner.
826
827 class OAuthClient:
828 key = 'consumer_key'
829 secret = 'consumer_secret'
830
831 class OAuthResourceOwner:
832 key = 'token'
833 secret = 'token_secret'
834 protocol.oauth_authenticate(OAuthResourceOwner, OAuthClient)
835 self.assertEqual(len(timestamps), 0)
820 timestamp_d.callback(fake_timestamp)836 timestamp_d.callback(fake_timestamp)
821 parameters = fromcandt_call[0]["parameters"]837 self.assertEqual(len(timestamps), 1)
822 self.assertEqual(parameters["oauth_timestamp"], fake_timestamp)838 self.assertEqual(timestamps[0], fake_timestamp)
823839
824840
825class RootResource(resource.Resource):841class RootResource(resource.Resource):
826842
=== modified file 'ubuntuone/storageprotocol/client.py'
--- ubuntuone/storageprotocol/client.py 2012-12-03 19:45:43 +0000
+++ ubuntuone/storageprotocol/client.py 2013-02-14 20:28:33 +0000
@@ -39,7 +39,8 @@
3939
40from functools import partial40from functools import partial
41from itertools import chain41from itertools import chain
42from oauth import oauth42from urlparse import urlparse, parse_qsl
43from oauthlib.oauth1 import Client, SIGNATURE_PLAINTEXT, SIGNATURE_TYPE_QUERY
4344
44from twisted.internet.protocol import ClientFactory45from twisted.internet.protocol import ClientFactory
45from twisted.internet import reactor, defer46from twisted.internet import reactor, defer
@@ -143,29 +144,30 @@
143 def oauth_authenticate(self, consumer, token, metadata=None):144 def oauth_authenticate(self, consumer, token, metadata=None):
144 """Authenticate to a server using the OAuth provider.145 """Authenticate to a server using the OAuth provider.
145146
146 @param consumer: the OAuth consumer to authenticate with.147 @param consumer: the OAuth consumer (a.k.a. client in RFC 5849) to
147 @type consumer: `oauth.OAuthConsumer`148 authenticate with.
148 @param token: a previously acquired OAuth access token.149 @type consumer: object having both a `.key` and `.secret` attribute.
149 @type consumer: `oauth.OAuthToken`150 @param token: a previously acquired OAuth access token (a.k.a.
150 @param kwargs: key/values to send as metadata151 resource owner in RFC 5849).
152 @type token: object having both a `.key` and `.secret` attribute.
153 @param metadata: key/values to send as metadata
151154
152 Return a deferred that will get called with the request155 Return a deferred that will get called with the request
153 object when completed.156 object when completed.
154157
155 """158 """
156 timestamp = yield tx_timestamp_checker.get_faithful_time()159 timestamp = yield tx_timestamp_checker.get_faithful_time()
157 req = oauth.OAuthRequest.from_consumer_and_token(160 client = Client(consumer.key, consumer.secret,
158 oauth_consumer=consumer,161 token.key, token.secret,
159 token=token,162 signature_method=SIGNATURE_PLAINTEXT,
160 parameters={"oauth_timestamp": timestamp},163 signature_type=SIGNATURE_TYPE_QUERY,
161 http_method="GET",164 timestamp=timestamp)
162 http_url="storage://server")165 url, headers, body = client.sign('storage://server')
163 req.sign_request(166 # Parse out the authentication parameters from the query string.
164 oauth.OAuthSignatureMethod_PLAINTEXT(), consumer, token)
165
166 # Make sure all parameter values are strings.
167 auth_parameters = dict(167 auth_parameters = dict(
168 (key, str(value)) for key, value in req.parameters.iteritems())168 (name, value) for name, value in
169 parse_qsl(urlparse(url).query)
170 if name.startswith('oauth_'))
169 p = Authenticate(self, auth_parameters, metadata=metadata)171 p = Authenticate(self, auth_parameters, metadata=metadata)
170 p.start()172 p.start()
171 result = yield p.deferred173 result = yield p.deferred

Subscribers

People subscribed via source and target branches

to all changes: