Merge lp:~alecu/ubuntuone-client/unbreak-connect into lp:ubuntuone-client

Proposed by Alejandro J. Cura
Status: Merged
Approved by: Roberto Alsina
Approved revision: 1061
Merged at revision: 1061
Proposed branch: lp:~alecu/ubuntuone-client/unbreak-connect
Merge into: lp:ubuntuone-client
Diff against target: 220 lines (+95/-22)
5 files modified
tests/platform/windows/test_credentials.py (+50/-1)
tests/platform/windows/test_ipc.py (+24/-1)
ubuntuone/platform/windows/credentials.py (+9/-9)
ubuntuone/platform/windows/ipc.py (+10/-10)
ubuntuone/platform/windows/tools.py (+2/-1)
To merge this branch: bzr merge lp:~alecu/ubuntuone-client/unbreak-connect
Reviewer Review Type Date Requested Status
Roberto Alsina (community) Approve
Natalia Bidart (community) Approve
Review via email: mp+68309@code.launchpad.net

Commit message

Fix CredentialsManager so connect and restart now work (LP: #811307)

Description of the change

Fix CredentialsManager so connect and restart now work (LP: #811307)

To post a comment you must log in.
Revision history for this message
Natalia Bidart (nataliabidart) wrote :

Can we have somehow this branch managing the fact that

token = yield self._request_token(autoconnecting=autoconnecting)

can return the empty dict when autoconnecting is True and there are no credentials in the system?
In that case, the current linux behavior is to also raise NoAccessToken.

review: Needs Information
Revision history for this message
Alejandro J. Cura (alecu) wrote :

Fixed empty dictionary as suggested by Natalia.

1060. By Alejandro J. Cura

handle empty credentials as NoAccessToken

1061. By Alejandro J. Cura

spaces after the colon in lambdas

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

Great branch!

review: Approve
Revision history for this message
Roberto Alsina (ralsina) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'tests/platform/windows/test_credentials.py'
2--- tests/platform/windows/test_credentials.py 2011-07-04 15:02:47 +0000
3+++ tests/platform/windows/test_credentials.py 2011-07-20 15:02:53 +0000
4@@ -61,10 +61,26 @@
5 setattr(self, callback_name, None)
6
7
8- def find_credentials(self, app_name, options, **kwargs):
9+ def find_credentials(self, app_name, options):
10 """Ask the U1 credentials."""
11 return defer.succeed(TEST_CREDENTIALS)
12
13+ def clear_credentials(self, app_name, options):
14+ """Clear the U1 credentials."""
15+ return defer.succeed(None)
16+
17+ def store_credentials(self, app_name, options):
18+ """Store the U1 credentials."""
19+ return defer.succeed(None)
20+
21+ def register(self, app_name, options):
22+ """Store the U1 credentials."""
23+ return defer.succeed(None)
24+
25+ def login(self, app_name, options):
26+ """Store the U1 credentials."""
27+ return defer.succeed(None)
28+
29
30 class RemovableSignalTestCase(TestCase):
31 """Tests for RemovableSignal."""
32@@ -111,6 +127,39 @@
33 self.cm.find_credentials(reply_handler=ok, error_handler=error)
34 return d
35
36+ def test_clear_credentials(self):
37+ """Test the clear_credentials method."""
38+ d = defer.Deferred()
39+ ok = lambda: d.callback("ok")
40+ error = lambda *args: d.errback(args)
41+ self.cm.clear_credentials(reply_handler=ok, error_handler=error)
42+ return d
43+
44+ def test_store_credentials(self):
45+ """Test the store_credentials method."""
46+ d = defer.Deferred()
47+ ok = lambda: d.callback("ok")
48+ error = lambda *args: d.errback(args)
49+ self.cm.store_credentials(TEST_CREDENTIALS, reply_handler=ok,
50+ error_handler=error)
51+ return d
52+
53+ def test_register(self):
54+ """Test the register method."""
55+ d = defer.Deferred()
56+ ok = lambda: d.callback("ok")
57+ error = lambda *args: d.errback(args)
58+ self.cm.register({}, reply_handler=ok, error_handler=error)
59+ return d
60+
61+ def test_login(self):
62+ """Test the login method."""
63+ d = defer.Deferred()
64+ ok = lambda: d.callback("ok")
65+ error = lambda *args: d.errback(args)
66+ self.cm.login({}, reply_handler=ok, error_handler=error)
67+ return d
68+
69 def test_register_to_credentials_found(self):
70 """Test the register_to_credentials_found method."""
71 cb = lambda creds: self.assertEqual(creds, TEST_CREDENTIALS)
72
73=== modified file 'tests/platform/windows/test_ipc.py'
74--- tests/platform/windows/test_ipc.py 2011-07-15 17:09:43 +0000
75+++ tests/platform/windows/test_ipc.py 2011-07-20 15:02:53 +0000
76@@ -3263,13 +3263,20 @@
77 return defer.fail(RandomException())
78 return defer.succeed(self.fake_credentials)
79
80- def register(self, *args):
81+ def register(self, window_id=0):
82 """Register a new user."""
83+ assert isinstance(window_id, (str, int))
84 if self.should_fail:
85 return defer.fail(RandomException())
86 return defer.succeed(self.fake_credentials)
87
88
89+class EmptyCredentialsManagementTool(FakeCredentialsManagementTool):
90+ """A Fake CredentialsManagementTool that returns empty credentials."""
91+
92+ fake_credentials = {}
93+
94+
95 class FakeCredentialsManagementToolFails(FakeCredentialsManagementTool):
96 """A Fake CredentialsManagementTool that consistently fails."""
97
98@@ -3338,6 +3345,22 @@
99 token = self.ipc.main.event_q.pushed_events[0][1]["access_token"]
100 self.assertEqual(token, expected_token)
101
102+class IPCInterfaceEmptyCredentialsTestCase(IPCInterfaceTestCaseBase):
103+ """Tests for the IPCInterface with empty credentials."""
104+
105+ cmt_class = EmptyCredentialsManagementTool
106+
107+ @defer.inlineCallbacks
108+ def test_connect(self):
109+ """Test the connect method fails."""
110+ yield self.assertFailure(self.ipc.connect(), ipc.NoAccessToken)
111+
112+ @defer.inlineCallbacks
113+ def test_connect_autoconnecting(self):
114+ """Test the connect method when autoconnecting fails."""
115+ d = self.ipc.connect(autoconnecting=True)
116+ yield self.assertFailure(d, ipc.NoAccessToken)
117+
118
119 class IPCInterfaceFailingTestCase(IPCInterfaceTestCaseBase):
120 """Tests for the IPCInterface on a rainy day."""
121
122=== modified file 'ubuntuone/platform/windows/credentials.py'
123--- ubuntuone/platform/windows/credentials.py 2011-07-04 15:02:47 +0000
124+++ ubuntuone/platform/windows/credentials.py 2011-07-20 15:02:53 +0000
125@@ -72,34 +72,34 @@
126 def find_credentials(self, reply_handler=NO_OP, error_handler=NO_OP):
127 """Ask the Ubuntu One credentials."""
128 d = self.sso_proxy.find_credentials(APP_NAME, {})
129- d.addCallbacks(lambda _:reply_handler(), error_handler)
130+ d.addCallbacks(lambda _: reply_handler(), error_handler)
131
132 def clear_credentials(self, reply_handler=NO_OP, error_handler=NO_OP):
133 """Clear the Ubuntu One credentials."""
134- self.sso_proxy.clear_credentials(APP_NAME, {},
135- reply_handler=reply_handler, error_handler=error_handler)
136+ d = self.sso_proxy.clear_credentials(APP_NAME, {})
137+ d.addCallbacks(lambda _: reply_handler(), error_handler)
138
139 def store_credentials(self, credentials,
140 reply_handler=NO_OP, error_handler=NO_OP):
141 """Store the token for Ubuntu One application."""
142- self.sso_proxy.store_credentials(APP_NAME, credentials,
143- reply_handler=reply_handler, error_handler=error_handler)
144+ d = self.sso_proxy.store_credentials(APP_NAME, credentials)
145+ d.addCallbacks(lambda _: reply_handler(), error_handler)
146
147 def register(self, args, reply_handler=NO_OP, error_handler=NO_OP):
148 """Get credentials if found else prompt to register to Ubuntu One."""
149 params = {HELP_TEXT_KEY: DESCRIPTION, TC_URL_KEY: TC_URL,
150 PING_URL_KEY: PING_URL}
151 params.update(args)
152- self.sso_proxy.register(APP_NAME, params,
153- reply_handler=reply_handler, error_handler=error_handler)
154+ d = self.sso_proxy.register(APP_NAME, params)
155+ d.addCallbacks(lambda _: reply_handler(), error_handler)
156
157 def login(self, args, reply_handler=NO_OP, error_handler=NO_OP):
158 """Get credentials if found else prompt to login to Ubuntu One."""
159 params = {HELP_TEXT_KEY: DESCRIPTION, TC_URL_KEY: TC_URL,
160 PING_URL_KEY: PING_URL}
161 params.update(args)
162- self.sso_proxy.login(APP_NAME, params,
163- reply_handler=reply_handler, error_handler=error_handler)
164+ d = self.sso_proxy.login(APP_NAME, params)
165+ d.addCallbacks(lambda _: reply_handler(), error_handler)
166
167 def register_to_credentials_stored(self, callback):
168 """Register to the CredentialsStored dbus signal."""
169
170=== modified file 'ubuntuone/platform/windows/ipc.py'
171--- ubuntuone/platform/windows/ipc.py 2011-07-19 17:29:51 +0000
172+++ ubuntuone/platform/windows/ipc.py 2011-07-20 15:02:53 +0000
173@@ -1102,23 +1102,23 @@
174 token = yield self._request_token(
175 autoconnecting=autoconnecting)
176 except Exception, e:
177+ logger.exception('failure while getting the token')
178 raise NoAccessToken(e)
179
180+ if not token:
181+ raise NoAccessToken("got empty credentials.")
182+
183 self.main.event_q.push('SYS_USER_CONNECT', access_token=token)
184
185 def _request_token(self, autoconnecting):
186 """Request to SSO auth service to fetch the token."""
187 # call ubuntu sso
188- try:
189- management = CredentialsManagementTool()
190- # return the deferred, since we are no longer using signals
191- if autoconnecting:
192- return management.find_credentials()
193- else:
194- return management.register({'window_id': '0'}) # no window ID
195- except:
196- logger.exception('failure while getting the token')
197- raise
198+ management = CredentialsManagementTool()
199+ # return the deferred, since we are no longer using signals
200+ if autoconnecting:
201+ return management.find_credentials()
202+ else:
203+ return management.register(window_id=0) # no window ID
204
205 def disconnect(self):
206 """ Push the SYS_USER_DISCONNECT event. """
207
208=== modified file 'ubuntuone/platform/windows/tools.py'
209--- ubuntuone/platform/windows/tools.py 2011-07-15 17:03:13 +0000
210+++ ubuntuone/platform/windows/tools.py 2011-07-20 15:02:53 +0000
211@@ -38,7 +38,8 @@
212 """Check if there is a syncdaemon instance running."""
213 #TODO: Do not start two instances of this process
214 # https://launchpad.net/bugs/803672
215- return False
216+ #NOTE: Changed to True so SD can be restarted while this bug is fixed
217+ return True
218
219
220 class SyncDaemonTool(object):

Subscribers

People subscribed via source and target branches