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
1=== modified file 'tests/test_client.py'
2--- tests/test_client.py 2012-12-03 19:45:43 +0000
3+++ tests/test_client.py 2013-02-14 20:28:33 +0000
4@@ -38,6 +38,8 @@
5 import unittest
6 import uuid
7
8+from urlparse import urlparse, parse_qsl
9+
10 from twisted.application import internet, service
11 from twisted.internet import defer
12 from twisted.internet.defer import Deferred, inlineCallbacks
13@@ -48,10 +50,12 @@
14 from ubuntuone.storageprotocol.client import (
15 StorageClient, CreateUDF, ListVolumes, DeleteVolume, GetDelta, Unlink,
16 Authenticate, MakeFile, MakeDir, PutContent, Move, BytesMessageProducer,
17- oauth, TwistedTimestampChecker, tx_timestamp_checker,
18+ TwistedTimestampChecker, tx_timestamp_checker,
19 )
20+
21 from ubuntuone.storageprotocol import volumes
22 from tests import test_delta_info
23+from oauthlib.oauth1 import Client
24
25 # let's not get picky about aatributes outside __init__ in tests
26 # pylint: disable=W0201
27@@ -795,31 +799,43 @@
28
29 def test_oauth_authenticate_uses_server_timestamp(self):
30 """The oauth authentication uses the server timestamp."""
31- fromcandt_call = []
32-
33- fake_token = oauth.OAuthToken('token', 'token_secret')
34- fake_consumer = oauth.OAuthConsumer('consumer_key', 'consumer_secret')
35-
36- fake_timestamp = object()
37+ timestamps = []
38+
39+ original_sign = Client.sign
40+
41+ def fake_sign(self, *args, **kwargs):
42+ """A fake Client.sign()."""
43+ url, headers, body = original_sign(self, *args, **kwargs)
44+ timestamps.extend(
45+ value for name, value in parse_qsl(urlparse(url).query)
46+ if name == 'oauth_timestamp')
47+ return url, headers, body
48+
49+ fake_timestamp = '801'
50 timestamp_d = Deferred()
51 self.patch(tx_timestamp_checker, "get_faithful_time",
52 lambda: timestamp_d)
53- original_fromcandt = oauth.OAuthRequest.from_consumer_and_token
54-
55- @staticmethod
56- def fake_from_consumer_and_token(**kwargs):
57- """A fake from_consumer_and_token."""
58- fromcandt_call.append(kwargs)
59- return original_fromcandt(**kwargs)
60-
61- self.patch(oauth.OAuthRequest, "from_consumer_and_token",
62- fake_from_consumer_and_token)
63+
64+ self.patch(Client, 'sign', fake_sign)
65 protocol = FakedProtocol()
66- protocol.oauth_authenticate(fake_consumer, fake_token)
67- self.assertEqual(len(fromcandt_call), 0)
68+ # For backward compatibility of the API, oauth_authenticate() takes a
69+ # consumer object and a token object. Both of those must have .key
70+ # and .secret attributes. In modern OAuth1 (i.e. RFC 5849)
71+ # terminology, the consumer is really the OAuth client, and the token
72+ # is really the OAuth resource owner.
73+
74+ class OAuthClient:
75+ key = 'consumer_key'
76+ secret = 'consumer_secret'
77+
78+ class OAuthResourceOwner:
79+ key = 'token'
80+ secret = 'token_secret'
81+ protocol.oauth_authenticate(OAuthResourceOwner, OAuthClient)
82+ self.assertEqual(len(timestamps), 0)
83 timestamp_d.callback(fake_timestamp)
84- parameters = fromcandt_call[0]["parameters"]
85- self.assertEqual(parameters["oauth_timestamp"], fake_timestamp)
86+ self.assertEqual(len(timestamps), 1)
87+ self.assertEqual(timestamps[0], fake_timestamp)
88
89
90 class RootResource(resource.Resource):
91
92=== modified file 'ubuntuone/storageprotocol/client.py'
93--- ubuntuone/storageprotocol/client.py 2012-12-03 19:45:43 +0000
94+++ ubuntuone/storageprotocol/client.py 2013-02-14 20:28:33 +0000
95@@ -39,7 +39,8 @@
96
97 from functools import partial
98 from itertools import chain
99-from oauth import oauth
100+from urlparse import urlparse, parse_qsl
101+from oauthlib.oauth1 import Client, SIGNATURE_PLAINTEXT, SIGNATURE_TYPE_QUERY
102
103 from twisted.internet.protocol import ClientFactory
104 from twisted.internet import reactor, defer
105@@ -143,29 +144,30 @@
106 def oauth_authenticate(self, consumer, token, metadata=None):
107 """Authenticate to a server using the OAuth provider.
108
109- @param consumer: the OAuth consumer to authenticate with.
110- @type consumer: `oauth.OAuthConsumer`
111- @param token: a previously acquired OAuth access token.
112- @type consumer: `oauth.OAuthToken`
113- @param kwargs: key/values to send as metadata
114+ @param consumer: the OAuth consumer (a.k.a. client in RFC 5849) to
115+ authenticate with.
116+ @type consumer: object having both a `.key` and `.secret` attribute.
117+ @param token: a previously acquired OAuth access token (a.k.a.
118+ resource owner in RFC 5849).
119+ @type token: object having both a `.key` and `.secret` attribute.
120+ @param metadata: key/values to send as metadata
121
122 Return a deferred that will get called with the request
123 object when completed.
124
125 """
126 timestamp = yield tx_timestamp_checker.get_faithful_time()
127- req = oauth.OAuthRequest.from_consumer_and_token(
128- oauth_consumer=consumer,
129- token=token,
130- parameters={"oauth_timestamp": timestamp},
131- http_method="GET",
132- http_url="storage://server")
133- req.sign_request(
134- oauth.OAuthSignatureMethod_PLAINTEXT(), consumer, token)
135-
136- # Make sure all parameter values are strings.
137+ client = Client(consumer.key, consumer.secret,
138+ token.key, token.secret,
139+ signature_method=SIGNATURE_PLAINTEXT,
140+ signature_type=SIGNATURE_TYPE_QUERY,
141+ timestamp=timestamp)
142+ url, headers, body = client.sign('storage://server')
143+ # Parse out the authentication parameters from the query string.
144 auth_parameters = dict(
145- (key, str(value)) for key, value in req.parameters.iteritems())
146+ (name, value) for name, value in
147+ parse_qsl(urlparse(url).query)
148+ if name.startswith('oauth_'))
149 p = Authenticate(self, auth_parameters, metadata=metadata)
150 p.start()
151 result = yield p.deferred

Subscribers

People subscribed via source and target branches

to all changes: