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
=== modified file 'tests/platform/windows/test_credentials.py'
--- tests/platform/windows/test_credentials.py 2011-07-04 15:02:47 +0000
+++ tests/platform/windows/test_credentials.py 2011-07-20 15:02:53 +0000
@@ -61,10 +61,26 @@
61 setattr(self, callback_name, None)61 setattr(self, callback_name, None)
6262
6363
64 def find_credentials(self, app_name, options, **kwargs):64 def find_credentials(self, app_name, options):
65 """Ask the U1 credentials."""65 """Ask the U1 credentials."""
66 return defer.succeed(TEST_CREDENTIALS)66 return defer.succeed(TEST_CREDENTIALS)
6767
68 def clear_credentials(self, app_name, options):
69 """Clear the U1 credentials."""
70 return defer.succeed(None)
71
72 def store_credentials(self, app_name, options):
73 """Store the U1 credentials."""
74 return defer.succeed(None)
75
76 def register(self, app_name, options):
77 """Store the U1 credentials."""
78 return defer.succeed(None)
79
80 def login(self, app_name, options):
81 """Store the U1 credentials."""
82 return defer.succeed(None)
83
6884
69class RemovableSignalTestCase(TestCase):85class RemovableSignalTestCase(TestCase):
70 """Tests for RemovableSignal."""86 """Tests for RemovableSignal."""
@@ -111,6 +127,39 @@
111 self.cm.find_credentials(reply_handler=ok, error_handler=error)127 self.cm.find_credentials(reply_handler=ok, error_handler=error)
112 return d128 return d
113129
130 def test_clear_credentials(self):
131 """Test the clear_credentials method."""
132 d = defer.Deferred()
133 ok = lambda: d.callback("ok")
134 error = lambda *args: d.errback(args)
135 self.cm.clear_credentials(reply_handler=ok, error_handler=error)
136 return d
137
138 def test_store_credentials(self):
139 """Test the store_credentials method."""
140 d = defer.Deferred()
141 ok = lambda: d.callback("ok")
142 error = lambda *args: d.errback(args)
143 self.cm.store_credentials(TEST_CREDENTIALS, reply_handler=ok,
144 error_handler=error)
145 return d
146
147 def test_register(self):
148 """Test the register method."""
149 d = defer.Deferred()
150 ok = lambda: d.callback("ok")
151 error = lambda *args: d.errback(args)
152 self.cm.register({}, reply_handler=ok, error_handler=error)
153 return d
154
155 def test_login(self):
156 """Test the login method."""
157 d = defer.Deferred()
158 ok = lambda: d.callback("ok")
159 error = lambda *args: d.errback(args)
160 self.cm.login({}, reply_handler=ok, error_handler=error)
161 return d
162
114 def test_register_to_credentials_found(self):163 def test_register_to_credentials_found(self):
115 """Test the register_to_credentials_found method."""164 """Test the register_to_credentials_found method."""
116 cb = lambda creds: self.assertEqual(creds, TEST_CREDENTIALS)165 cb = lambda creds: self.assertEqual(creds, TEST_CREDENTIALS)
117166
=== modified file 'tests/platform/windows/test_ipc.py'
--- tests/platform/windows/test_ipc.py 2011-07-15 17:09:43 +0000
+++ tests/platform/windows/test_ipc.py 2011-07-20 15:02:53 +0000
@@ -3263,13 +3263,20 @@
3263 return defer.fail(RandomException())3263 return defer.fail(RandomException())
3264 return defer.succeed(self.fake_credentials)3264 return defer.succeed(self.fake_credentials)
32653265
3266 def register(self, *args):3266 def register(self, window_id=0):
3267 """Register a new user."""3267 """Register a new user."""
3268 assert isinstance(window_id, (str, int))
3268 if self.should_fail:3269 if self.should_fail:
3269 return defer.fail(RandomException())3270 return defer.fail(RandomException())
3270 return defer.succeed(self.fake_credentials)3271 return defer.succeed(self.fake_credentials)
32713272
32723273
3274class EmptyCredentialsManagementTool(FakeCredentialsManagementTool):
3275 """A Fake CredentialsManagementTool that returns empty credentials."""
3276
3277 fake_credentials = {}
3278
3279
3273class FakeCredentialsManagementToolFails(FakeCredentialsManagementTool):3280class FakeCredentialsManagementToolFails(FakeCredentialsManagementTool):
3274 """A Fake CredentialsManagementTool that consistently fails."""3281 """A Fake CredentialsManagementTool that consistently fails."""
32753282
@@ -3338,6 +3345,22 @@
3338 token = self.ipc.main.event_q.pushed_events[0][1]["access_token"]3345 token = self.ipc.main.event_q.pushed_events[0][1]["access_token"]
3339 self.assertEqual(token, expected_token)3346 self.assertEqual(token, expected_token)
33403347
3348class IPCInterfaceEmptyCredentialsTestCase(IPCInterfaceTestCaseBase):
3349 """Tests for the IPCInterface with empty credentials."""
3350
3351 cmt_class = EmptyCredentialsManagementTool
3352
3353 @defer.inlineCallbacks
3354 def test_connect(self):
3355 """Test the connect method fails."""
3356 yield self.assertFailure(self.ipc.connect(), ipc.NoAccessToken)
3357
3358 @defer.inlineCallbacks
3359 def test_connect_autoconnecting(self):
3360 """Test the connect method when autoconnecting fails."""
3361 d = self.ipc.connect(autoconnecting=True)
3362 yield self.assertFailure(d, ipc.NoAccessToken)
3363
33413364
3342class IPCInterfaceFailingTestCase(IPCInterfaceTestCaseBase):3365class IPCInterfaceFailingTestCase(IPCInterfaceTestCaseBase):
3343 """Tests for the IPCInterface on a rainy day."""3366 """Tests for the IPCInterface on a rainy day."""
33443367
=== modified file 'ubuntuone/platform/windows/credentials.py'
--- ubuntuone/platform/windows/credentials.py 2011-07-04 15:02:47 +0000
+++ ubuntuone/platform/windows/credentials.py 2011-07-20 15:02:53 +0000
@@ -72,34 +72,34 @@
72 def find_credentials(self, reply_handler=NO_OP, error_handler=NO_OP):72 def find_credentials(self, reply_handler=NO_OP, error_handler=NO_OP):
73 """Ask the Ubuntu One credentials."""73 """Ask the Ubuntu One credentials."""
74 d = self.sso_proxy.find_credentials(APP_NAME, {})74 d = self.sso_proxy.find_credentials(APP_NAME, {})
75 d.addCallbacks(lambda _:reply_handler(), error_handler)75 d.addCallbacks(lambda _: reply_handler(), error_handler)
7676
77 def clear_credentials(self, reply_handler=NO_OP, error_handler=NO_OP):77 def clear_credentials(self, reply_handler=NO_OP, error_handler=NO_OP):
78 """Clear the Ubuntu One credentials."""78 """Clear the Ubuntu One credentials."""
79 self.sso_proxy.clear_credentials(APP_NAME, {},79 d = self.sso_proxy.clear_credentials(APP_NAME, {})
80 reply_handler=reply_handler, error_handler=error_handler)80 d.addCallbacks(lambda _: reply_handler(), error_handler)
8181
82 def store_credentials(self, credentials,82 def store_credentials(self, credentials,
83 reply_handler=NO_OP, error_handler=NO_OP):83 reply_handler=NO_OP, error_handler=NO_OP):
84 """Store the token for Ubuntu One application."""84 """Store the token for Ubuntu One application."""
85 self.sso_proxy.store_credentials(APP_NAME, credentials,85 d = self.sso_proxy.store_credentials(APP_NAME, credentials)
86 reply_handler=reply_handler, error_handler=error_handler)86 d.addCallbacks(lambda _: reply_handler(), error_handler)
8787
88 def register(self, args, reply_handler=NO_OP, error_handler=NO_OP):88 def register(self, args, reply_handler=NO_OP, error_handler=NO_OP):
89 """Get credentials if found else prompt to register to Ubuntu One."""89 """Get credentials if found else prompt to register to Ubuntu One."""
90 params = {HELP_TEXT_KEY: DESCRIPTION, TC_URL_KEY: TC_URL,90 params = {HELP_TEXT_KEY: DESCRIPTION, TC_URL_KEY: TC_URL,
91 PING_URL_KEY: PING_URL}91 PING_URL_KEY: PING_URL}
92 params.update(args)92 params.update(args)
93 self.sso_proxy.register(APP_NAME, params,93 d = self.sso_proxy.register(APP_NAME, params)
94 reply_handler=reply_handler, error_handler=error_handler)94 d.addCallbacks(lambda _: reply_handler(), error_handler)
9595
96 def login(self, args, reply_handler=NO_OP, error_handler=NO_OP):96 def login(self, args, reply_handler=NO_OP, error_handler=NO_OP):
97 """Get credentials if found else prompt to login to Ubuntu One."""97 """Get credentials if found else prompt to login to Ubuntu One."""
98 params = {HELP_TEXT_KEY: DESCRIPTION, TC_URL_KEY: TC_URL,98 params = {HELP_TEXT_KEY: DESCRIPTION, TC_URL_KEY: TC_URL,
99 PING_URL_KEY: PING_URL}99 PING_URL_KEY: PING_URL}
100 params.update(args)100 params.update(args)
101 self.sso_proxy.login(APP_NAME, params,101 d = self.sso_proxy.login(APP_NAME, params)
102 reply_handler=reply_handler, error_handler=error_handler)102 d.addCallbacks(lambda _: reply_handler(), error_handler)
103103
104 def register_to_credentials_stored(self, callback):104 def register_to_credentials_stored(self, callback):
105 """Register to the CredentialsStored dbus signal."""105 """Register to the CredentialsStored dbus signal."""
106106
=== modified file 'ubuntuone/platform/windows/ipc.py'
--- ubuntuone/platform/windows/ipc.py 2011-07-19 17:29:51 +0000
+++ ubuntuone/platform/windows/ipc.py 2011-07-20 15:02:53 +0000
@@ -1102,23 +1102,23 @@
1102 token = yield self._request_token(1102 token = yield self._request_token(
1103 autoconnecting=autoconnecting)1103 autoconnecting=autoconnecting)
1104 except Exception, e:1104 except Exception, e:
1105 logger.exception('failure while getting the token')
1105 raise NoAccessToken(e)1106 raise NoAccessToken(e)
11061107
1108 if not token:
1109 raise NoAccessToken("got empty credentials.")
1110
1107 self.main.event_q.push('SYS_USER_CONNECT', access_token=token)1111 self.main.event_q.push('SYS_USER_CONNECT', access_token=token)
11081112
1109 def _request_token(self, autoconnecting):1113 def _request_token(self, autoconnecting):
1110 """Request to SSO auth service to fetch the token."""1114 """Request to SSO auth service to fetch the token."""
1111 # call ubuntu sso1115 # call ubuntu sso
1112 try:1116 management = CredentialsManagementTool()
1113 management = CredentialsManagementTool()1117 # return the deferred, since we are no longer using signals
1114 # return the deferred, since we are no longer using signals1118 if autoconnecting:
1115 if autoconnecting:1119 return management.find_credentials()
1116 return management.find_credentials()1120 else:
1117 else:1121 return management.register(window_id=0) # no window ID
1118 return management.register({'window_id': '0'}) # no window ID
1119 except:
1120 logger.exception('failure while getting the token')
1121 raise
11221122
1123 def disconnect(self):1123 def disconnect(self):
1124 """ Push the SYS_USER_DISCONNECT event. """1124 """ Push the SYS_USER_DISCONNECT event. """
11251125
=== modified file 'ubuntuone/platform/windows/tools.py'
--- ubuntuone/platform/windows/tools.py 2011-07-15 17:03:13 +0000
+++ ubuntuone/platform/windows/tools.py 2011-07-20 15:02:53 +0000
@@ -38,7 +38,8 @@
38 """Check if there is a syncdaemon instance running."""38 """Check if there is a syncdaemon instance running."""
39 #TODO: Do not start two instances of this process39 #TODO: Do not start two instances of this process
40 # https://launchpad.net/bugs/80367240 # https://launchpad.net/bugs/803672
41 return False41 #NOTE: Changed to True so SD can be restarted while this bug is fixed
42 return True
4243
4344
44class SyncDaemonTool(object):45class SyncDaemonTool(object):

Subscribers

People subscribed via source and target branches