Merge lp:~nataliabidart/ubuntu-sso-client/no-more-deprecated-service into lp:ubuntu-sso-client

Proposed by Natalia Bidart
Status: Merged
Approved by: Natalia Bidart
Approved revision: 796
Merged at revision: 796
Proposed branch: lp:~nataliabidart/ubuntu-sso-client/no-more-deprecated-service
Merge into: lp:ubuntu-sso-client
Diff against target: 1346 lines (+45/-836)
9 files modified
bin/ubuntu-sso-login (+2/-3)
bin/windows-ubuntu-sso-login (+1/-3)
ubuntu_sso/main/__init__.py (+1/-98)
ubuntu_sso/main/linux.py (+0/-107)
ubuntu_sso/main/tests/test_common.py (+3/-75)
ubuntu_sso/main/tests/test_linux.py (+33/-176)
ubuntu_sso/main/tests/test_windows.py (+2/-189)
ubuntu_sso/main/windows.py (+3/-181)
ubuntu_sso/qt/controllers.py (+0/-4)
To merge this branch: bzr merge lp:~nataliabidart/ubuntu-sso-client/no-more-deprecated-service
Reviewer Review Type Date Requested Status
Manuel de la Peña (community) Approve
Roberto Alsina (community) Approve
Review via email: mp+77241@code.launchpad.net

Commit message

- Removing the deprecated SSOCredentials interface (LP: #859635).

To post a comment you must log in.
Revision history for this message
Roberto Alsina (ralsina) wrote :

+1

review: Approve
Revision history for this message
Manuel de la Peña (mandel) wrote :

About time we get these classes out :)

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'bin/ubuntu-sso-login'
--- bin/ubuntu-sso-login 2011-01-11 19:13:19 +0000
+++ bin/ubuntu-sso-login 2011-09-27 21:50:39 +0000
@@ -29,7 +29,7 @@
29# the locale and imports decimal, and that generates the following trace:29# the locale and imports decimal, and that generates the following trace:
30# Traceback (most recent call last):30# Traceback (most recent call last):
31# File "/usr/lib/ubuntu-sso-client/ubuntu-sso-login", line 3331# File "/usr/lib/ubuntu-sso-client/ubuntu-sso-login", line 33
32# from ubuntu_sso.main import SSOLogin, SSOCredentials32# from ubuntu_sso.main import SSOLogin
33# File "/usr/lib/pymodules/python2.6/ubuntu_sso/main.py", line 4233# File "/usr/lib/pymodules/python2.6/ubuntu_sso/main.py", line 42
34# from lazr.restfulclient.resource import ServiceRoot34# from lazr.restfulclient.resource import ServiceRoot
35# File "/usr/lib/python2.6/dist-packages/lazr/restfulclient/resource.py",35# File "/usr/lib/python2.6/dist-packages/lazr/restfulclient/resource.py",
@@ -52,7 +52,7 @@
5252
53from ubuntu_sso import (DBUS_BUS_NAME, DBUS_ACCOUNT_PATH, DBUS_CRED_PATH,53from ubuntu_sso import (DBUS_BUS_NAME, DBUS_ACCOUNT_PATH, DBUS_CRED_PATH,
54 DBUS_CREDENTIALS_PATH)54 DBUS_CREDENTIALS_PATH)
55from ubuntu_sso.main import SSOLogin, SSOCredentials, CredentialsManagement55from ubuntu_sso.main import SSOLogin, CredentialsManagement
5656
57from ubuntu_sso.logger import setup_logging57from ubuntu_sso.logger import setup_logging
5858
@@ -93,7 +93,6 @@
93 logger.info("Starting Ubuntu SSO login manager for bus %r.", DBUS_BUS_NAME)93 logger.info("Starting Ubuntu SSO login manager for bus %r.", DBUS_BUS_NAME)
94 bus_name = dbus.service.BusName(DBUS_BUS_NAME, bus=dbus.SessionBus())94 bus_name = dbus.service.BusName(DBUS_BUS_NAME, bus=dbus.SessionBus())
95 SSOLogin(bus_name, object_path=DBUS_ACCOUNT_PATH)95 SSOLogin(bus_name, object_path=DBUS_ACCOUNT_PATH)
96 SSOCredentials(bus_name, object_path=DBUS_CRED_PATH)
97 CredentialsManagement(timeout_func=gtk.timeout_add,96 CredentialsManagement(timeout_func=gtk.timeout_add,
98 shutdown_func=gtk.main_quit,97 shutdown_func=gtk.main_quit,
99 bus_name=bus_name, object_path=DBUS_CREDENTIALS_PATH)98 bus_name=bus_name, object_path=DBUS_CREDENTIALS_PATH)
10099
=== modified file 'bin/windows-ubuntu-sso-login'
--- bin/windows-ubuntu-sso-login 2011-07-22 22:00:45 +0000
+++ bin/windows-ubuntu-sso-login 2011-09-27 21:50:39 +0000
@@ -37,7 +37,6 @@
37from ubuntu_sso.main.windows import (37from ubuntu_sso.main.windows import (
38 CredentialsManagement,38 CredentialsManagement,
39 LOCALHOST,39 LOCALHOST,
40 SSOCredentials,
41 SSOLogin,40 SSOLogin,
42 UbuntuSSORoot,41 UbuntuSSORoot,
43 get_activation_config,42 get_activation_config,
@@ -61,9 +60,8 @@
61 port = yield ai.get_port()60 port = yield ai.get_port()
6261
63 login = SSOLogin('ignored')62 login = SSOLogin('ignored')
64 creds = SSOCredentials()
65 creds_management = CredentialsManagement(add_timeout, reactor.stop)63 creds_management = CredentialsManagement(add_timeout, reactor.stop)
66 root = UbuntuSSORoot(login, creds, creds_management)64 root = UbuntuSSORoot(soo_login=login, cred_manager=creds_management)
6765
68 reactor.listenTCP(port, PBServerFactory(root), interface=LOCALHOST)66 reactor.listenTCP(port, PBServerFactory(root), interface=LOCALHOST)
6967
7068
=== modified file 'ubuntu_sso/main/__init__.py'
--- ubuntu_sso/main/__init__.py 2011-09-14 18:15:33 +0000
+++ ubuntu_sso/main/__init__.py 2011-09-27 21:50:39 +0000
@@ -19,11 +19,8 @@
19# with this program. If not, see <http://www.gnu.org/licenses/>.19# with this program. If not, see <http://www.gnu.org/licenses/>.
20"""Main object implementations."""20"""Main object implementations."""
2121
22import os
23import sys22import sys
24import warnings
2523
26from ubuntu_sso import NO_OP
27from ubuntu_sso.account import Account24from ubuntu_sso.account import Account
28from ubuntu_sso.credentials import (25from ubuntu_sso.credentials import (
29 Credentials,26 Credentials,
@@ -37,7 +34,7 @@
37 UI_MODULE_KEY,34 UI_MODULE_KEY,
38 WINDOW_ID_KEY,35 WINDOW_ID_KEY,
39)36)
40from ubuntu_sso.keyring import get_token_name, U1_APP_NAME, Keyring37from ubuntu_sso.keyring import get_token_name, Keyring
41from ubuntu_sso.logger import setup_logging38from ubuntu_sso.logger import setup_logging
4239
4340
@@ -46,20 +43,6 @@
46TIMEOUT_INTERVAL = 10000 # 10 seconds43TIMEOUT_INTERVAL = 10000 # 10 seconds
4744
4845
49class SSOLoginProcessor(Account):
50 """Login and register users using the Ubuntu Single Sign On service.
51
52 Alias classname to maintain backwards compatibility. DO NOT USE, use
53 ubuntu_sso.account.Account instead.
54 """
55
56 def __init__(self, sso_service_class=None):
57 """Create a new SSO Account manager."""
58 msg = 'Use ubuntu_sso.account.Account instead.'
59 warnings.warn(msg, DeprecationWarning)
60 super(SSOLoginProcessor, self).__init__(sso_service_class)
61
62
63def except_to_errdict(e):46def except_to_errdict(e):
64 """Turn an exception into a dictionary to return thru DBus."""47 """Turn an exception into a dictionary to return thru DBus."""
65 result = {48 result = {
@@ -169,84 +152,6 @@
169 thread_execute(f, app_name, result_cb, error_cb)152 thread_execute(f, app_name, result_cb, error_cb)
170153
171154
172class SSOCredentialsRoot(object):
173 """Object that gets credentials, and login/registers if needed.
174
175 This class is DEPRECATED, use CredentialsManagementRoot instead.
176
177 """
178
179 def __init__(self):
180 self.ping_url = os.environ.get('USSOC_PING_URL', U1_PING_URL)
181 msg = 'Use ubuntu_sso.main.CredentialsManagementRoot instead.'
182 warnings.warn(msg, DeprecationWarning)
183
184 def find_credentials(self, app_name, callback=NO_OP, errback=NO_OP):
185 """Get the credentials from the keyring or {} if not there."""
186
187 def log_result(result):
188 """Log the result and continue."""
189 logger.info('find_credentials: app_name "%s", result is {}? %s',
190 app_name, result == {})
191 return result
192
193 d = Credentials(app_name=app_name).find_credentials()
194 # pylint: disable=E1101
195 d.addCallback(log_result)
196 d.addCallbacks(callback, errback)
197
198 def login_or_register_to_get_credentials(self, app_name,
199 terms_and_conditions_url,
200 help_text, window_id,
201 success_cb, error_cb, denial_cb,
202 ui_module='ubuntu_sso.gtk.gui'):
203 """Get credentials if found else prompt GUI to login or register.
204
205 'app_name' will be displayed in the GUI.
206 'terms_and_conditions_url' will be the URL pointing to T&C.
207 'help_text' is an explanatory text for the end-users, will be shown
208 below the headers.
209 'window_id' is the id of the window which will be set as a parent of
210 the GUI. If 0, no parent will be set.
211
212 """
213 ping_url = self.ping_url if app_name == U1_APP_NAME else None
214 obj = Credentials(app_name=app_name, ping_url=ping_url,
215 tc_url=terms_and_conditions_url,
216 help_text=help_text, window_id=window_id,
217 success_cb=success_cb, error_cb=error_cb,
218 denial_cb=denial_cb, ui_module=ui_module)
219 obj.register()
220
221 def login_to_get_credentials(self, app_name, help_text, window_id,
222 success_cb, error_cb, denial_cb,
223 ui_module='ubuntu_sso.gtk.gui'):
224 """Get credentials if found else prompt GUI just to login
225
226 'app_name' will be displayed in the GUI.
227 'help_text' is an explanatory text for the end-users, will be shown
228 before the login fields.
229 'window_id' is the id of the window which will be set as a parent of
230 the GUI. If 0, no parent will be set.
231
232 """
233 ping_url = self.ping_url if app_name == U1_APP_NAME else None
234 obj = Credentials(app_name=app_name, ping_url=ping_url, tc_url=None,
235 help_text=help_text, window_id=window_id,
236 success_cb=success_cb, error_cb=error_cb,
237 denial_cb=denial_cb, ui_module=ui_module)
238 obj.login()
239
240 def clear_token(self, app_name, callback=NO_OP, errback=NO_OP):
241 """Clear the token for an application from the keyring.
242
243 'app_name' is the name of the application.
244 """
245 d = Credentials(app_name=app_name).clear_credentials()
246 # pylint: disable=E1101
247 d.addCallbacks(lambda _: callback(), errback)
248
249
250class CredentialsManagementRoot(object):155class CredentialsManagementRoot(object):
251 """Object that manages credentials.156 """Object that manages credentials.
252157
@@ -434,7 +339,6 @@
434if sys.platform == 'win32':339if sys.platform == 'win32':
435 from ubuntu_sso.main import windows340 from ubuntu_sso.main import windows
436 SSOLogin = windows.SSOLogin341 SSOLogin = windows.SSOLogin
437 SSOCredentials = windows.SSOCredentials
438 CredentialsManagement = windows.CredentialsManagement342 CredentialsManagement = windows.CredentialsManagement
439 TIMEOUT_INTERVAL = 10000000000 # forever343 TIMEOUT_INTERVAL = 10000000000 # forever
440 thread_execute = windows.blocking344 thread_execute = windows.blocking
@@ -442,7 +346,6 @@
442else:346else:
443 from ubuntu_sso.main import linux347 from ubuntu_sso.main import linux
444 SSOLogin = linux.SSOLogin348 SSOLogin = linux.SSOLogin
445 SSOCredentials = linux.SSOCredentials
446 CredentialsManagement = linux.CredentialsManagement349 CredentialsManagement = linux.CredentialsManagement
447 thread_execute = linux.blocking350 thread_execute = linux.blocking
448 get_sso_login_backend = linux.get_sso_login_backend351 get_sso_login_backend = linux.get_sso_login_backend
449352
=== modified file 'ubuntu_sso/main/linux.py'
--- ubuntu_sso/main/linux.py 2011-09-14 18:15:33 +0000
+++ ubuntu_sso/main/linux.py 2011-09-27 21:50:39 +0000
@@ -28,24 +28,19 @@
28"""28"""
2929
30import threading30import threading
31import warnings
3231
33import dbus.service32import dbus.service
3433
35from ubuntu_sso import (34from ubuntu_sso import (
36 DBUS_ACCOUNT_PATH,35 DBUS_ACCOUNT_PATH,
37 DBUS_CREDENTIALS_IFACE,36 DBUS_CREDENTIALS_IFACE,
38 DBUS_IFACE_CRED_NAME,
39 DBUS_IFACE_USER_NAME,37 DBUS_IFACE_USER_NAME,
40 NO_OP,
41)38)
42from ubuntu_sso.account import Account39from ubuntu_sso.account import Account
43from ubuntu_sso.credentials import ERROR_KEY, ERROR_DETAIL_KEY
44from ubuntu_sso.logger import setup_logging40from ubuntu_sso.logger import setup_logging
45from ubuntu_sso.main import (41from ubuntu_sso.main import (
46 CredentialsManagementRoot,42 CredentialsManagementRoot,
47 SSOLoginRoot,43 SSOLoginRoot,
48 SSOCredentialsRoot,
49 except_to_errdict,44 except_to_errdict,
50)45)
5146
@@ -83,8 +78,6 @@
83 dbus.service.Object.__init__(self, object_path=object_path,78 dbus.service.Object.__init__(self, object_path=object_path,
84 bus_name=bus_name)79 bus_name=bus_name)
85 self.root = SSOLoginRoot(sso_login_processor_class, sso_service_class)80 self.root = SSOLoginRoot(sso_login_processor_class, sso_service_class)
86 msg = 'Use ubuntu_sso.main.CredentialsManagement instead.'
87 warnings.warn(msg, DeprecationWarning)
8881
89 # generate_capcha signals82 # generate_capcha signals
90 @dbus.service.signal(DBUS_IFACE_USER_NAME, signature="ss")83 @dbus.service.signal(DBUS_IFACE_USER_NAME, signature="ss")
@@ -220,106 +213,6 @@
220 self.PasswordChangeError)213 self.PasswordChangeError)
221214
222215
223class SSOCredentials(dbus.service.Object):
224 """DBus object that gets credentials, and login/registers if needed.
225
226 This class is Deprecated. DO NOT USE, use CredentialsManagement instead.
227
228 """
229
230 # Operator not preceded by a space (fails with dbus decorators)
231 # pylint: disable=C0322
232
233 def __init__(self, *args, **kwargs):
234 dbus.service.Object.__init__(self, *args, **kwargs)
235 self.root = SSOCredentialsRoot()
236 warnings.warn('%r DBus object is deprecated, please use %r instead.' %
237 (DBUS_IFACE_CRED_NAME, DBUS_CREDENTIALS_IFACE),
238 DeprecationWarning)
239
240 def _process_error(self, app_name, error_dict):
241 """Process the 'error_dict' and emit CredentialsError."""
242 msg = error_dict.get(ERROR_KEY, 'No error message given.')
243 detail = error_dict.get(ERROR_DETAIL_KEY, 'No detailed error given.')
244 self.CredentialsError(app_name, msg, detail)
245
246 @dbus.service.signal(DBUS_IFACE_CRED_NAME, signature="s")
247 def AuthorizationDenied(self, app_name):
248 """Signal thrown when the user denies the authorization."""
249 logger.info('SSOCredentials: emitting AuthorizationDenied with '
250 'app_name "%s"', app_name)
251
252 @dbus.service.signal(DBUS_IFACE_CRED_NAME, signature="sa{ss}")
253 def CredentialsFound(self, app_name, credentials):
254 """Signal thrown when the credentials are found."""
255 logger.info('SSOCredentials: emitting CredentialsFound with '
256 'app_name "%s"', app_name)
257
258 @dbus.service.signal(DBUS_IFACE_CRED_NAME, signature="sss")
259 def CredentialsError(self, app_name, error_message, detailed_error):
260 """Signal thrown when there is a problem finding the credentials."""
261 logger.error('SSOCredentials: emitting CredentialsError with app_name '
262 '"%s" and error_message %r', app_name, error_message)
263
264 @dbus.service.method(dbus_interface=DBUS_IFACE_CRED_NAME,
265 in_signature="s", out_signature="a{ss}",
266 async_callbacks=("callback", "errback"))
267 def find_credentials(self, app_name, callback=NO_OP, errback=NO_OP):
268 """Get the credentials from the keyring or {} if not there."""
269 self.root.find_credentials(app_name, callback, errback)
270
271 @dbus.service.method(dbus_interface=DBUS_IFACE_CRED_NAME,
272 in_signature="sssx", out_signature="")
273 def login_or_register_to_get_credentials(self, app_name,
274 terms_and_conditions_url,
275 help_text, window_id):
276 """Get credentials if found else prompt GUI to login or register.
277
278 'app_name' will be displayed in the GUI.
279 'terms_and_conditions_url' will be the URL pointing to T&C.
280 'help_text' is an explanatory text for the end-users, will be shown
281 below the headers.
282 'window_id' is the id of the window which will be set as a parent of
283 the GUI. If 0, no parent will be set.
284
285 """
286 self.root.login_or_register_to_get_credentials(app_name,
287 terms_and_conditions_url,
288 help_text, window_id,
289 self.CredentialsFound,
290 self._process_error,
291 self.AuthorizationDenied,
292 ui_module='ubuntu_sso.gtk.gui')
293
294 @dbus.service.method(dbus_interface=DBUS_IFACE_CRED_NAME,
295 in_signature="ssx", out_signature="")
296 def login_to_get_credentials(self, app_name, help_text, window_id):
297 """Get credentials if found else prompt GUI just to login
298
299 'app_name' will be displayed in the GUI.
300 'help_text' is an explanatory text for the end-users, will be shown
301 before the login fields.
302 'window_id' is the id of the window which will be set as a parent of
303 the GUI. If 0, no parent will be set.
304
305 """
306 self.root.login_to_get_credentials(app_name, help_text, window_id,
307 self.CredentialsFound,
308 self._process_error,
309 self.AuthorizationDenied,
310 ui_module='ubuntu_sso.gtk.gui')
311
312 @dbus.service.method(dbus_interface=DBUS_IFACE_CRED_NAME,
313 in_signature='s', out_signature='',
314 async_callbacks=("callback", "errback"))
315 def clear_token(self, app_name, callback=NO_OP, errback=NO_OP):
316 """Clear the token for an application from the keyring.
317
318 'app_name' is the name of the application.
319 """
320 self.root.clear_token(app_name, callback, errback)
321
322
323class CredentialsManagement(dbus.service.Object):216class CredentialsManagement(dbus.service.Object):
324 """DBus object that manages credentials.217 """DBus object that manages credentials.
325218
326219
=== modified file 'ubuntu_sso/main/tests/test_common.py'
--- ubuntu_sso/main/tests/test_common.py 2011-08-22 16:21:36 +0000
+++ ubuntu_sso/main/tests/test_common.py 2011-09-27 21:50:39 +0000
@@ -21,39 +21,14 @@
21# with this program. If not, see <http://www.gnu.org/licenses/>.21# with this program. If not, see <http://www.gnu.org/licenses/>.
22"""Tests share by diff platforms."""22"""Tests share by diff platforms."""
2323
24import os
25
26from unittest import TestCase24from unittest import TestCase
25
27from mocker import MockerTestCase, MATCH26from mocker import MockerTestCase, MATCH
27
28from ubuntu_sso.main import (28from ubuntu_sso.main import (
29 CredentialsManagement,29 CredentialsManagement,
30 SSOCredentialsRoot,
31 SSOCredentials,
32 SSOLogin,30 SSOLogin,
33 U1_PING_URL)31)
34
35
36class EnvironOverridesTestCase(TestCase):
37 """Some URLs can be set from the environment for testing/QA purposes."""
38
39 def test_override_ping_url(self):
40 """The ping url can be set from the environ via USSOC_PING_URL."""
41 fake_url = 'this is not really a URL'
42 old_url = os.environ.get('USSOC_PING_URL')
43 os.environ['USSOC_PING_URL'] = fake_url
44 try:
45 creds = SSOCredentialsRoot()
46 self.assertEqual(creds.ping_url, fake_url)
47 finally:
48 if old_url:
49 os.environ['USSOC_PING_URL'] = old_url
50 else:
51 del os.environ['USSOC_PING_URL']
52
53 def test_no_override_ping_url(self):
54 """If the environ is unset, the default ping url is used."""
55 creds = SSOCredentialsRoot()
56 self.assertEqual(creds.ping_url, U1_PING_URL)
5732
5833
59class SSOLoginMockedTestCase(MockerTestCase):34class SSOLoginMockedTestCase(MockerTestCase):
@@ -142,53 +117,6 @@
142 self.login.set_new_password(app_name, email, token, new_password)117 self.login.set_new_password(app_name, email, token, new_password)
143118
144119
145class SSOCredentialsMockedTestCase(MockerTestCase):
146 """Test that the call are relied correctly."""
147
148 def setUp(self):
149 """Setup tests."""
150 super(SSOCredentialsMockedTestCase, self).setUp()
151 self.root = self.mocker.mock()
152 mockbusname = self.mocker.mock()
153 mockbus = self.mocker.mock()
154 mockbusname.get_bus()
155 self.mocker.result(mockbus)
156 self.cred = SSOCredentials(mockbus)
157 self.cred.root = self.root
158 self.mocker.reset()
159
160 def test_find_credentials(self):
161 """Test that the call is relayed."""
162 app_name = 'app'
163 result_cb = error_cb = lambda: None
164 self.root.find_credentials(app_name, MATCH(callable), MATCH(callable))
165 self.mocker.mock()
166 self.mocker.replay()
167 self.cred.find_credentials(app_name, result_cb, error_cb)
168
169 def test_login_or_register_to_get_credentials(self):
170 """Test that the call is relayed."""
171 app_name = 'app'
172 terms = 'terms'
173 help_text = 'help'
174 window_id = 'id'
175 self.root.login_or_register_to_get_credentials(app_name, terms,
176 help_text, window_id, MATCH(callable),
177 MATCH(callable), MATCH(callable),
178 ui_module=MATCH(lambda x: isinstance(x, str)))
179 self.mocker.replay()
180 self.cred.login_or_register_to_get_credentials(app_name, terms,
181 help_text, window_id)
182
183 def test_clear_token(self):
184 """Test that the call is relayed."""
185 app_name = 'app'
186 result_cb = error_cb = lambda: None
187 self.root.clear_token(app_name, MATCH(callable), MATCH(callable))
188 self.mocker.replay()
189 self.cred.clear_token(app_name, result_cb, error_cb)
190
191
192class CredentialsManagementMockedTestCase(MockerTestCase, TestCase):120class CredentialsManagementMockedTestCase(MockerTestCase, TestCase):
193 """Test that the call are relied correctly."""121 """Test that the call are relied correctly."""
194122
195123
=== modified file 'ubuntu_sso/main/tests/test_linux.py'
--- ubuntu_sso/main/tests/test_linux.py 2011-08-22 16:21:36 +0000
+++ ubuntu_sso/main/tests/test_linux.py 2011-09-27 21:50:39 +0000
@@ -21,11 +21,9 @@
21"""Tests for the main SSO client code."""21"""Tests for the main SSO client code."""
2222
23import logging23import logging
24import os
2524
26from mocker import Mocker, MockerTestCase, ARGS, KWARGS, MATCH25from mocker import Mocker, ARGS, KWARGS
27from twisted.internet import defer26from twisted.internet import defer
28from twisted.internet.defer import Deferred, inlineCallbacks
29from twisted.trial.unittest import TestCase27from twisted.trial.unittest import TestCase
30from ubuntuone.devtools.handlers import MementoHandler28from ubuntuone.devtools.handlers import MementoHandler
3129
@@ -34,9 +32,12 @@
34import ubuntu_sso.main.linux32import ubuntu_sso.main.linux
3533
36from ubuntu_sso import DBUS_CREDENTIALS_IFACE34from ubuntu_sso import DBUS_CREDENTIALS_IFACE
37from ubuntu_sso.keyring import U1_APP_NAME35from ubuntu_sso.main import (
38from ubuntu_sso.main import (U1_PING_URL, except_to_errdict,36 except_to_errdict,
39 CredentialsManagement, SSOCredentials, SSOLogin, TIMEOUT_INTERVAL)37 CredentialsManagement,
38 SSOLogin,
39 TIMEOUT_INTERVAL,
40)
40from ubuntu_sso.main.linux import blocking41from ubuntu_sso.main.linux import blocking
41from ubuntu_sso.main import (HELP_TEXT_KEY, PING_URL_KEY,42from ubuntu_sso.main import (HELP_TEXT_KEY, PING_URL_KEY,
42 TC_URL_KEY, UI_CLASS_KEY, UI_MODULE_KEY, WINDOW_ID_KEY,43 TC_URL_KEY, UI_CLASS_KEY, UI_MODULE_KEY, WINDOW_ID_KEY,
@@ -116,7 +117,7 @@
116117
117 def test_generate_captcha(self):118 def test_generate_captcha(self):
118 """Test that the captcha method works ok."""119 """Test that the captcha method works ok."""
119 d = Deferred()120 d = defer.Deferred()
120 filename = "sample filename"121 filename = "sample filename"
121 expected_result = "expected result"122 expected_result = "expected result"
122 self.create_mock_processor().generate_captcha(filename)123 self.create_mock_processor().generate_captcha(filename)
@@ -139,7 +140,7 @@
139140
140 def test_generate_captcha_error(self):141 def test_generate_captcha_error(self):
141 """Test that the captcha method fails as expected."""142 """Test that the captcha method fails as expected."""
142 d = Deferred()143 d = defer.Deferred()
143 filename = "sample filename"144 filename = "sample filename"
144 expected_result = "expected result"145 expected_result = "expected result"
145 self.create_mock_processor().generate_captcha(filename)146 self.create_mock_processor().generate_captcha(filename)
@@ -162,7 +163,7 @@
162163
163 def test_register_user(self):164 def test_register_user(self):
164 """Test that the register_user method works ok."""165 """Test that the register_user method works ok."""
165 d = Deferred()166 d = defer.Deferred()
166 expected_result = "expected result"167 expected_result = "expected result"
167 self.create_mock_processor().register_user(EMAIL, PASSWORD, NAME,168 self.create_mock_processor().register_user(EMAIL, PASSWORD, NAME,
168 CAPTCHA_ID, CAPTCHA_SOLUTION)169 CAPTCHA_ID, CAPTCHA_SOLUTION)
@@ -186,7 +187,7 @@
186187
187 def test_register_user_error(self):188 def test_register_user_error(self):
188 """Test that the register_user method fails as expected."""189 """Test that the register_user method fails as expected."""
189 d = Deferred()190 d = defer.Deferred()
190 expected_result = "expected result"191 expected_result = "expected result"
191 self.create_mock_processor().register_user(EMAIL, PASSWORD, NAME,192 self.create_mock_processor().register_user(EMAIL, PASSWORD, NAME,
192 CAPTCHA_ID, CAPTCHA_SOLUTION)193 CAPTCHA_ID, CAPTCHA_SOLUTION)
@@ -210,7 +211,7 @@
210211
211 def test_login(self):212 def test_login(self):
212 """Test that the login method works ok."""213 """Test that the login method works ok."""
213 d = Deferred()214 d = defer.Deferred()
214 processor = self.create_mock_processor()215 processor = self.create_mock_processor()
215 processor.login(EMAIL, PASSWORD, TOKEN_NAME)216 processor.login(EMAIL, PASSWORD, TOKEN_NAME)
216 self.mocker.result(TOKEN)217 self.mocker.result(TOKEN)
@@ -236,7 +237,7 @@
236237
237 def test_login_user_not_validated(self):238 def test_login_user_not_validated(self):
238 """Test that the login sends EmailNotValidated signal."""239 """Test that the login sends EmailNotValidated signal."""
239 d = Deferred()240 d = defer.Deferred()
240 processor = self.create_mock_processor()241 processor = self.create_mock_processor()
241 processor.login(EMAIL, PASSWORD, TOKEN_NAME)242 processor.login(EMAIL, PASSWORD, TOKEN_NAME)
242 self.mocker.result(TOKEN)243 self.mocker.result(TOKEN)
@@ -262,7 +263,7 @@
262263
263 def test_login_error_get_token_name(self):264 def test_login_error_get_token_name(self):
264 """The login method fails as expected when get_token_name fails."""265 """The login method fails as expected when get_token_name fails."""
265 d = Deferred()266 d = defer.Deferred()
266 self.create_mock_processor()267 self.create_mock_processor()
267 self.patch(ubuntu_sso.main.linux, "blocking", fake_err_blocking)268 self.patch(ubuntu_sso.main.linux, "blocking", fake_err_blocking)
268269
@@ -290,7 +291,7 @@
290291
291 def test_login_error_set_credentials(self):292 def test_login_error_set_credentials(self):
292 """The login method fails as expected when set_credentials fails."""293 """The login method fails as expected when set_credentials fails."""
293 d = Deferred()294 d = defer.Deferred()
294 processor = self.create_mock_processor()295 processor = self.create_mock_processor()
295 processor.login(EMAIL, PASSWORD, TOKEN_NAME)296 processor.login(EMAIL, PASSWORD, TOKEN_NAME)
296 self.mocker.result(TOKEN)297 self.mocker.result(TOKEN)
@@ -324,7 +325,7 @@
324325
325 def test_validate_email(self):326 def test_validate_email(self):
326 """Test that the validate_email method works ok."""327 """Test that the validate_email method works ok."""
327 d = Deferred()328 d = defer.Deferred()
328 self.create_mock_processor().validate_email(EMAIL, PASSWORD,329 self.create_mock_processor().validate_email(EMAIL, PASSWORD,
329 EMAIL_TOKEN, TOKEN_NAME)330 EMAIL_TOKEN, TOKEN_NAME)
330 self.mocker.result(TOKEN)331 self.mocker.result(TOKEN)
@@ -347,7 +348,7 @@
347348
348 def test_validate_email_error(self):349 def test_validate_email_error(self):
349 """Test that the validate_email method fails as expected."""350 """Test that the validate_email method fails as expected."""
350 d = Deferred()351 d = defer.Deferred()
351 self.create_mock_processor()352 self.create_mock_processor()
352 self.patch(ubuntu_sso.main.linux, "blocking", fake_err_blocking)353 self.patch(ubuntu_sso.main.linux, "blocking", fake_err_blocking)
353354
@@ -374,7 +375,7 @@
374375
375 def test_request_password_reset_token(self):376 def test_request_password_reset_token(self):
376 """Test that the request_password_reset_token method works ok."""377 """Test that the request_password_reset_token method works ok."""
377 d = Deferred()378 d = defer.Deferred()
378 processor = self.create_mock_processor()379 processor = self.create_mock_processor()
379 processor.request_password_reset_token(EMAIL)380 processor.request_password_reset_token(EMAIL)
380 self.patch(ubuntu_sso.main, "thread_execute", fake_ok_blocking)381 self.patch(ubuntu_sso.main, "thread_execute", fake_ok_blocking)
@@ -396,7 +397,7 @@
396397
397 def test_request_password_reset_token_error(self):398 def test_request_password_reset_token_error(self):
398 """Test the request_password_reset_token method fails as expected."""399 """Test the request_password_reset_token method fails as expected."""
399 d = Deferred()400 d = defer.Deferred()
400401
401 self.create_mock_processor().request_password_reset_token(EMAIL)402 self.create_mock_processor().request_password_reset_token(EMAIL)
402 self.mocker.result(EMAIL)403 self.mocker.result(EMAIL)
@@ -418,7 +419,7 @@
418419
419 def test_set_new_password(self):420 def test_set_new_password(self):
420 """Test that the set_new_password method works ok."""421 """Test that the set_new_password method works ok."""
421 d = Deferred()422 d = defer.Deferred()
422 self.create_mock_processor().set_new_password(EMAIL, EMAIL_TOKEN,423 self.create_mock_processor().set_new_password(EMAIL, EMAIL_TOKEN,
423 PASSWORD)424 PASSWORD)
424 self.mocker.result(EMAIL)425 self.mocker.result(EMAIL)
@@ -440,7 +441,7 @@
440441
441 def test_set_new_password_error(self):442 def test_set_new_password_error(self):
442 """Test that the set_new_password method fails as expected."""443 """Test that the set_new_password method fails as expected."""
443 d = Deferred()444 d = defer.Deferred()
444 expected_result = "expected result"445 expected_result = "expected result"
445446
446 self.create_mock_processor().set_new_password(EMAIL, EMAIL_TOKEN,447 self.create_mock_processor().set_new_password(EMAIL, EMAIL_TOKEN,
@@ -470,7 +471,7 @@
470471
471 def test_blocking(self):472 def test_blocking(self):
472 """Test the normal behaviour."""473 """Test the normal behaviour."""
473 d = Deferred()474 d = defer.Deferred()
474 expected_result = "expected result"475 expected_result = "expected result"
475476
476 def f():477 def f():
@@ -488,7 +489,7 @@
488489
489 def test_blocking_error(self):490 def test_blocking_error(self):
490 """Test the behaviour when an Exception is raised."""491 """Test the behaviour when an Exception is raised."""
491 d = Deferred()492 d = defer.Deferred()
492 expected_error_message = "expected error message"493 expected_error_message = "expected error message"
493494
494 def f():495 def f():
@@ -559,150 +560,6 @@
559 self.assertEqual(result["errtype"], e.__class__.__name__)560 self.assertEqual(result["errtype"], e.__class__.__name__)
560561
561562
562class RegisterSampleException(Exception):
563 """A mock exception thrown just when testing."""
564
565
566class ApplicationCredentialsTestCase(TestCase, MockerTestCase):
567 """Tests for the ApplicationCredentials related DBus methods."""
568
569 timeout = 5
570
571 def setUp(self):
572 MockerTestCase.setUp(self)
573
574 self.client = SSOCredentials(self.mocker.mock())
575
576 mock_class = self.mocker.replace("ubuntu_sso.credentials.Credentials")
577 mock_class(app_name=APP_NAME)
578 self.creds_obj = self.mocker.mock()
579 self.mocker.result(self.creds_obj)
580
581 @inlineCallbacks
582 def test_find_credentials(self):
583 """find_credentials immediately returns the token when found."""
584 expected_creds = "expected creds"
585 self.creds_obj.find_credentials()
586 self.mocker.result(defer.succeed(expected_creds))
587 self.mocker.replay()
588
589 d = Deferred()
590 self.client.find_credentials(APP_NAME, d.callback, d.errback)
591 creds = yield d
592 self.assertEqual(creds, expected_creds)
593
594 @inlineCallbacks
595 def test_credentials_not_found(self):
596 """find_credentials immediately returns {} when no creds found."""
597 expected_creds = {}
598 self.creds_obj.find_credentials()
599 self.mocker.result(defer.succeed(expected_creds))
600 self.mocker.replay()
601
602 d = Deferred()
603 self.client.find_credentials(APP_NAME, d.callback, d.errback)
604 creds = yield d
605 self.assertEqual(creds, expected_creds)
606
607
608class ApplicationCredentialsGUITestCase(TestCase, MockerTestCase):
609 """Tests for the ApplicationCredentials register/login DBus method."""
610
611 app_name = APP_NAME
612 ping_url = None
613
614 def setUp(self):
615 MockerTestCase.setUp(self)
616 self.client = SSOCredentials(self.mocker.mock())
617 self.args = {PING_URL_KEY: self.ping_url,
618 TC_URL_KEY: TC_URL, HELP_TEXT_KEY: HELP_TEXT,
619 WINDOW_ID_KEY: WINDOW_ID,
620 SUCCESS_CB_KEY: self.client.CredentialsFound,
621 ERROR_CB_KEY: self.client._process_error,
622 DENIAL_CB_KEY: self.client.AuthorizationDenied}
623
624 def test_login_or_register(self):
625 """login_or_register is correct."""
626 self.args[UI_MODULE_KEY] = MATCH(lambda x: isinstance(x, str))
627 mock_class = self.mocker.replace("ubuntu_sso.credentials.Credentials")
628 mock_class(app_name=self.app_name, **self.args)
629 creds_obj = self.mocker.mock()
630 self.mocker.result(creds_obj)
631
632 creds_obj.register()
633 self.mocker.replay()
634
635 args = (self.app_name, TC_URL, HELP_TEXT, WINDOW_ID)
636 self.client.login_or_register_to_get_credentials(*args)
637
638 def test_login_only(self):
639 """login_or_register is correct."""
640 self.args[TC_URL_KEY] = None
641 self.args[UI_MODULE_KEY] = MATCH(lambda x: isinstance(x, str))
642 mock_class = self.mocker.replace("ubuntu_sso.credentials.Credentials")
643 mock_class(app_name=self.app_name, **self.args)
644 creds_obj = self.mocker.mock()
645 self.mocker.result(creds_obj)
646
647 creds_obj.login()
648 self.mocker.replay()
649
650 args = (self.app_name, HELP_TEXT, WINDOW_ID)
651 self.client.login_to_get_credentials(*args)
652
653
654class ApplicationCredentialsU1TestCase(ApplicationCredentialsGUITestCase):
655 """Tests for the ApplicationCredentials register/login DBus method.
656
657 Specifically for APP_NAME == U1_APP_NAME.
658
659 """
660
661 app_name = U1_APP_NAME
662 ping_url = U1_PING_URL
663
664
665class ApplicationCredentialsClearTokenTestCase(TestCase, MockerTestCase):
666 """Tests for the ApplicationCredentials related DBus methods."""
667
668 def test_clear_token(self):
669 """Check that clear_token tries removing the correct token."""
670 mock_class = self.mocker.replace("ubuntu_sso.credentials.Credentials")
671 mock_class(app_name=APP_NAME)
672 creds_obj = self.mocker.mock()
673 self.mocker.result(creds_obj)
674
675 creds_obj.clear_credentials()
676 self.mocker.result(defer.succeed(None))
677 self.mocker.replay()
678
679 client = SSOCredentials(self.mocker.mock())
680 client.clear_token(APP_NAME)
681
682
683class EnvironOverridesTestCase(TestCase):
684 """Some URLs can be set from the environment for testing/QA purposes."""
685
686 def test_override_ping_url(self):
687 """The ping url can be set from the environ via USSOC_PING_URL."""
688 fake_url = 'this is not really a URL'
689 old_url = os.environ.get('USSOC_PING_URL')
690 os.environ['USSOC_PING_URL'] = fake_url
691 try:
692 creds = SSOCredentials(None)
693 self.assertEqual(creds.root.ping_url, fake_url)
694 finally:
695 if old_url:
696 os.environ['USSOC_PING_URL'] = old_url
697 else:
698 del os.environ['USSOC_PING_URL']
699
700 def test_no_override_ping_url(self):
701 """If the environ is unset, the default ping url is used."""
702 creds = SSOCredentials(None)
703 self.assertEqual(creds.root.ping_url, U1_PING_URL)
704
705
706class CredentialsManagementTestCase(TestCase):563class CredentialsManagementTestCase(TestCase):
707 """Tests for the CredentialsManagement DBus interface."""564 """Tests for the CredentialsManagement DBus interface."""
708565
@@ -776,7 +633,7 @@
776633
777 def test_find_credentials(self):634 def test_find_credentials(self):
778 """Keep proper track of on going requests."""635 """Keep proper track of on going requests."""
779 d = Deferred()636 d = defer.Deferred()
780637
781 def verify(*args):638 def verify(*args):
782 """Make the check."""639 """Make the check."""
@@ -790,7 +647,7 @@
790647
791 def test_clear_credentials(self):648 def test_clear_credentials(self):
792 """Keep proper track of on going requests."""649 """Keep proper track of on going requests."""
793 d = Deferred()650 d = defer.Deferred()
794651
795 def verify(*args):652 def verify(*args):
796 """Make the check."""653 """Make the check."""
@@ -804,7 +661,7 @@
804661
805 def test_store_credentials(self):662 def test_store_credentials(self):
806 """Keep proper track of on going requests."""663 """Keep proper track of on going requests."""
807 d = Deferred()664 d = defer.Deferred()
808665
809 def verify(*args):666 def verify(*args):
810 """Make the check."""667 """Make the check."""
@@ -1004,7 +861,7 @@
1004 If the creds are found, CredentialsFound is emitted.861 If the creds are found, CredentialsFound is emitted.
1005862
1006 """863 """
1007 d = Deferred()864 d = defer.Deferred()
1008865
1009 def verify(app_name, creds):866 def verify(app_name, creds):
1010 """The actual test."""867 """The actual test."""
@@ -1032,7 +889,7 @@
1032 If the creds are not found, CredentialsNotFound is emitted.889 If the creds are not found, CredentialsNotFound is emitted.
1033890
1034 """891 """
1035 d = Deferred()892 d = defer.Deferred()
1036893
1037 def verify(app_name):894 def verify(app_name):
1038 """The actual test."""895 """The actual test."""
@@ -1056,7 +913,7 @@
1056913
1057 def test_find_credentials_error(self):914 def test_find_credentials_error(self):
1058 """If find_credentials fails, CredentialsError is sent."""915 """If find_credentials fails, CredentialsError is sent."""
1059 d = Deferred()916 d = defer.Deferred()
1060917
1061 def verify(app_name, errdict):918 def verify(app_name, errdict):
1062 """The actual test."""919 """The actual test."""
@@ -1091,7 +948,7 @@
1091948
1092 def test_clear_credentials_does_not_block(self):949 def test_clear_credentials_does_not_block(self):
1093 """Calling clear_credentials does not block but return thru signals."""950 """Calling clear_credentials does not block but return thru signals."""
1094 d = Deferred()951 d = defer.Deferred()
1095952
1096 def verify(app_name):953 def verify(app_name):
1097 """The actual test."""954 """The actual test."""
@@ -1115,7 +972,7 @@
1115972
1116 def test_clear_credentials_error(self):973 def test_clear_credentials_error(self):
1117 """If clear_credentials fails, CredentialsError is sent."""974 """If clear_credentials fails, CredentialsError is sent."""
1118 d = Deferred()975 d = defer.Deferred()
1119976
1120 def verify(app_name, errdict):977 def verify(app_name, errdict):
1121 """The actual test."""978 """The actual test."""
@@ -1152,7 +1009,7 @@
1152 If the creds are stored, CredentialsStored is emitted.1009 If the creds are stored, CredentialsStored is emitted.
11531010
1154 """1011 """
1155 d = Deferred()1012 d = defer.Deferred()
11561013
1157 def verify(app_name):1014 def verify(app_name):
1158 """The actual test."""1015 """The actual test."""
@@ -1176,7 +1033,7 @@
11761033
1177 def test_store_credentials_error(self):1034 def test_store_credentials_error(self):
1178 """If store_credentials fails, CredentialsError is sent."""1035 """If store_credentials fails, CredentialsError is sent."""
1179 d = Deferred()1036 d = defer.Deferred()
11801037
1181 def verify(app_name, errdict):1038 def verify(app_name, errdict):
1182 """The actual test."""1039 """The actual test."""
11831040
=== modified file 'ubuntu_sso/main/tests/test_windows.py'
--- ubuntu_sso/main/tests/test_windows.py 2011-09-14 18:21:11 +0000
+++ ubuntu_sso/main/tests/test_windows.py 2011-09-27 21:50:39 +0000
@@ -37,8 +37,6 @@
37 CredentialsManagementClient,37 CredentialsManagementClient,
38 LOCALHOST,38 LOCALHOST,
39 SignalBroadcaster,39 SignalBroadcaster,
40 SSOCredentials,
41 SSOCredentialsClient,
42 SSOLogin,40 SSOLogin,
43 SSOLoginClient,41 SSOLoginClient,
44 UbuntuSSORoot,42 UbuntuSSORoot,
@@ -269,7 +267,7 @@
269 self.root = self.mocker.mock()267 self.root = self.mocker.mock()
270 self.login = SSOLogin(None)268 self.login = SSOLogin(None)
271 # start pb269 # start pb
272 self.sso_root = UbuntuSSORoot(self.login, None, None)270 self.sso_root = UbuntuSSORoot(sso_login=self.login)
273 self.server_factory = SaveProtocolServerFactory(self.sso_root)271 self.server_factory = SaveProtocolServerFactory(self.sso_root)
274 # pylint: disable=E1101272 # pylint: disable=E1101
275 port = get_sso_pb_port()273 port = get_sso_pb_port()
@@ -542,191 +540,6 @@
542 self.mocker.verify()540 self.mocker.verify()
543541
544542
545class SSOCredentialsTestCase(TestCase):
546 """Test the credentials class."""
547
548 @defer.inlineCallbacks
549 def setUp(self):
550 """Set up tests."""
551 yield super(SSOCredentialsTestCase, self).setUp()
552 self.mocker = Mocker()
553 self.root = self.mocker.mock()
554 self.except_to_errdict = self.mocker.replace(
555 'ubuntu_sso.main.except_to_errdict')
556 self.creds = SSOCredentials(None)
557 self.creds.root = self.root
558 # start pb
559 self.sso_root = UbuntuSSORoot(None, self.creds, None)
560 self.server_factory = SaveProtocolServerFactory(self.sso_root)
561 # pylint: disable=E1101
562 port = get_sso_pb_port()
563 self.listener = reactor.listenTCP(port, self.server_factory)
564 self.client_factory = PBClientFactory()
565 self.connector = reactor.connectTCP(LOCALHOST, port,
566 self.client_factory)
567 self.client = yield self._get_client()
568 # pylint: enable=E1101
569
570 def tearDown(self):
571 """Clean reactor."""
572 if self.server_factory.protocolInstance is not None:
573 self.server_factory.protocolInstance.transport.loseConnection()
574 return defer.gatherResults([self._tearDownServer(),
575 self._tearDownClient()])
576
577 def _tearDownServer(self):
578 """Teardown the server."""
579 return defer.maybeDeferred(self.listener.stopListening)
580
581 def _tearDownClient(self):
582 """Tear down the client."""
583 self.connector.disconnect()
584 return defer.succeed(None)
585
586 @defer.inlineCallbacks
587 def _get_client(self):
588 """Get the client."""
589 # request the remote object and create a client
590 root = yield self.client_factory.getRootObject()
591 remote = yield root.callRemote('get_sso_credentials')
592 client = SSOCredentialsClient(remote)
593 yield client.register_to_signals()
594 # set the cb
595 for signal_name in ['on_authorization_denied_cb',
596 'on_credentials_found_cb',
597 'on_credentials_error_cb']:
598 setattr(client, signal_name, self.mocker.mock())
599 defer.returnValue(client)
600
601 @defer.inlineCallbacks
602 def test_emit_authorization_denied(self):
603 """Test that the cb is executed."""
604 app_name = 'app'
605
606 self.client.on_authorization_denied_cb(app_name)
607 self.mocker.replay()
608 self.creds.emit_authorization_denied(app_name)
609 yield self.client.unregister_to_signals()
610 self.mocker.verify()
611
612 @defer.inlineCallbacks
613 def test_emit_credentials_found(self):
614 """Test that the cb was executed."""
615 app_name = 'app'
616 credentials = 'cred'
617
618 self.client.on_credentials_found_cb(app_name, credentials)
619 self.mocker.replay()
620 self.creds.emit_credentials_found(app_name, credentials)
621 yield self.client.unregister_to_signals()
622 self.mocker.verify()
623
624 @defer.inlineCallbacks
625 def test_emit_credentials_error(self):
626 """Test that the cb was executed."""
627 app_name = 'app'
628 raised_error = 'error'
629 detail = 'detail'
630
631 self.client.on_credentials_error_cb(app_name, raised_error, detail)
632 self.mocker.replay()
633 self.creds.emit_credentials_error(app_name, raised_error, detail)
634 yield self.client.unregister_to_signals()
635 self.mocker.verify()
636
637 @defer.inlineCallbacks
638 def test_find_credentials_no_kword(self):
639 """Ensure that the root is called."""
640 app_name = 'app'
641 callback = lambda: None
642 errback = lambda: None
643
644 self.root.find_credentials(app_name, MATCH(callable),
645 MATCH(callable))
646 self.mocker.replay()
647 yield self.client.find_credentials(app_name, callback, errback)
648 yield self.client.unregister_to_signals()
649
650 @defer.inlineCallbacks
651 def test_find_credentials_(self):
652 """Ensure that the root is called."""
653 app_name = 'app'
654 callback = lambda: None
655 errback = lambda: None
656
657 self.root.find_credentials(app_name, MATCH(callable),
658 MATCH(callable))
659 self.mocker.replay()
660 yield self.client.find_credentials(app_name, callback=callback,
661 errback=errback)
662 yield self.client.unregister_to_signals()
663
664 @defer.inlineCallbacks
665 def test_login_or_register_to_get_credentials(self):
666 """Ensure that the root is called."""
667 app_name = 'app'
668 terms = 'terms'
669 help_txt = 'help'
670 window_id = 'window_id'
671
672 # pylint: disable=W0212
673 self.root.login_or_register_to_get_credentials(app_name, terms,
674 help_txt, window_id,
675 self.creds.emit_credentials_found,
676 self.creds._process_error,
677 self.creds.emit_authorization_denied,
678 ui_module='ubuntu_sso.qt.gui')
679 # pylint: enable=W0212
680 self.mocker.replay()
681 yield self.client.login_or_register_to_get_credentials(app_name, terms,
682 help_txt, window_id)
683 yield self.client.unregister_to_signals()
684
685 @defer.inlineCallbacks
686 def test_login_to_get_credentials(self):
687 """Ensure that the root is called."""
688 app_name = 'app'
689 help_txt = 'help'
690 window_id = 'window_id'
691
692 # pylint: disable=W0212
693 self.root.login_to_get_credentials(app_name, help_txt, window_id,
694 self.creds.emit_credentials_found,
695 self.creds._process_error,
696 self.creds.emit_authorization_denied,
697 ui_module='ubuntu_sso.qt.gui')
698 # pylint: enable=W0212
699 self.mocker.replay()
700 yield self.client.login_to_get_credentials(app_name, help_txt,
701 window_id)
702 yield self.client.unregister_to_signals()
703
704 @defer.inlineCallbacks
705 def test_clear_token_no_kword(self):
706 """Ensure that the root is called."""
707 app_name = 'app'
708 callback = lambda: None
709 errback = lambda: None
710
711 self.root.clear_token(app_name, MATCH(callable), MATCH(callable))
712 self.mocker.replay()
713 yield self.client.clear_token(app_name, callback, errback)
714 yield self.client.unregister_to_signals()
715
716 @defer.inlineCallbacks
717 def test_clear_token(self):
718 """Ensure that the root is called."""
719 app_name = 'app'
720 callback = lambda: None
721 errback = lambda: None
722
723 self.root.clear_token(app_name, MATCH(callable), MATCH(callable))
724 self.mocker.replay()
725 yield self.client.clear_token(app_name, callback=callback,
726 errback=errback)
727 yield self.client.unregister_to_signals()
728
729
730class CredentialsManagementTestCase(TestCase):543class CredentialsManagementTestCase(TestCase):
731 """Test the management class."""544 """Test the management class."""
732545
@@ -741,7 +554,7 @@
741 self.creds = CredentialsManagement(None, None)554 self.creds = CredentialsManagement(None, None)
742 self.creds.root = self.root555 self.creds.root = self.root
743 # start pb556 # start pb
744 self.sso_root = UbuntuSSORoot(None, None, self.creds)557 self.sso_root = UbuntuSSORoot(cred_manager=self.creds)
745 self.server_factory = SaveProtocolServerFactory(self.sso_root)558 self.server_factory = SaveProtocolServerFactory(self.sso_root)
746 # pylint: disable=E1101559 # pylint: disable=E1101
747 port = get_sso_pb_port()560 port = get_sso_pb_port()
748561
=== modified file 'ubuntu_sso/main/windows.py'
--- ubuntu_sso/main/windows.py 2011-09-14 20:59:39 +0000
+++ ubuntu_sso/main/windows.py 2011-09-27 21:50:39 +0000
@@ -17,8 +17,6 @@
17# with this program. If not, see <http://www.gnu.org/licenses/>.17# with this program. If not, see <http://www.gnu.org/licenses/>.
18"""Main implementation on windows."""18"""Main implementation on windows."""
1919
20import warnings
21
22from functools import wraps20from functools import wraps
2321
24# pylint: disable=F040122# pylint: disable=F0401
@@ -36,14 +34,11 @@
36 Root,34 Root,
37)35)
3836
39from ubuntu_sso import NO_OP
40from ubuntu_sso.account import Account37from ubuntu_sso.account import Account
41from ubuntu_sso.credentials import ERROR_KEY, ERROR_DETAIL_KEY
42from ubuntu_sso.logger import setup_logging38from ubuntu_sso.logger import setup_logging
43from ubuntu_sso.main import (39from ubuntu_sso.main import (
44 CredentialsManagementRoot,40 CredentialsManagementRoot,
45 SSOLoginRoot,41 SSOLoginRoot,
46 SSOCredentialsRoot,
47 except_to_errdict,42 except_to_errdict,
48)43)
49from ubuntu_sso.utils.tcpactivation import ActivationConfig, ActivationClient44from ubuntu_sso.utils.tcpactivation import ActivationConfig, ActivationClient
@@ -334,100 +329,6 @@
334 self.emit_password_change_error)329 self.emit_password_change_error)
335330
336331
337class SSOCredentials(Referenceable, SignalBroadcaster):
338 """DBus object that gets credentials, and login/registers if needed."""
339
340 __metaclass__ = RemoteMeta
341
342 # calls that will be accessible remotely
343 remote_calls = [
344 'find_credentials',
345 'login_or_register_to_get_credentials',
346 'login_to_get_credentials',
347 'clear_token',
348 ]
349
350 def __init__(self, *args, **kwargs):
351 super(SSOCredentials, self).__init__()
352 self.root = SSOCredentialsRoot()
353
354 def _process_error(self, app_name, error_dict):
355 """Process the 'error_dict' and emit CredentialsError."""
356 msg = error_dict.get(ERROR_KEY, 'No error message given.')
357 detail = error_dict.get(ERROR_DETAIL_KEY, 'No detailed error given.')
358 self.emit_credentials_error(app_name, msg, detail)
359
360 def emit_authorization_denied(self, app_name):
361 """Signal thrown when the user denies the authorization."""
362 logger.info('SSOCredentials: emitting AuthorizationDenied with '
363 'app_name "%s"', app_name)
364 self.emit_signal('on_authorization_denied', app_name)
365
366 def emit_credentials_found(self, app_name, credentials):
367 """Signal thrown when the credentials are found."""
368 logger.info('SSOCredentials: emitting CredentialsFound with '
369 'app_name "%s"', app_name)
370 self.emit_signal('on_credentials_found', app_name, credentials)
371
372 def emit_credentials_error(self, app_name, error_message, detailed_error):
373 """Signal thrown when there is a problem finding the credentials."""
374 logger.error('SSOCredentials: emitting CredentialsError with app_name '
375 '"%s" and error_message %r', app_name, error_message)
376 self.emit_signal('on_credentials_error', app_name, error_message,
377 detailed_error)
378
379 def find_credentials(self, app_name, callback=NO_OP, errback=NO_OP):
380 """Get the credentials from the keyring or {} if not there."""
381 self.root.find_credentials(app_name, remote_handler(callback),
382 remote_handler(errback))
383
384 def login_or_register_to_get_credentials(self, app_name,
385 terms_and_conditions_url,
386 help_text, window_id,
387 ui_module='ubuntu_sso.qt.gui'):
388 """Get credentials if found else prompt GUI to login or register.
389
390 'app_name' will be displayed in the GUI.
391 'terms_and_conditions_url' will be the URL pointing to T&C.
392 'help_text' is an explanatory text for the end-users, will be shown
393 below the headers.
394 'window_id' is the id of the window which will be set as a parent of
395 the GUI. If 0, no parent will be set.
396
397 """
398 self.root.login_or_register_to_get_credentials(app_name,
399 terms_and_conditions_url,
400 help_text, window_id,
401 self.emit_credentials_found,
402 self._process_error,
403 self.emit_authorization_denied,
404 ui_module=ui_module)
405
406 def login_to_get_credentials(self, app_name, help_text, window_id):
407 """Get credentials if found else prompt GUI just to login
408
409 'app_name' will be displayed in the GUI.
410 'help_text' is an explanatory text for the end-users, will be shown
411 before the login fields.
412 'window_id' is the id of the window which will be set as a parent of
413 the GUI. If 0, no parent will be set.
414
415 """
416 self.root.login_to_get_credentials(app_name, help_text, window_id,
417 self.emit_credentials_found,
418 self._process_error,
419 self.emit_authorization_denied,
420 ui_module='ubuntu_sso.qt.gui')
421
422 def clear_token(self, app_name, callback=NO_OP, errback=NO_OP):
423 """Clear the token for an application from the keyring.
424
425 'app_name' is the name of the application.
426 """
427 self.root.clear_token(app_name, remote_handler(callback),
428 remote_handler(errback))
429
430
431class CredentialsManagement(Referenceable, SignalBroadcaster):332class CredentialsManagement(Referenceable, SignalBroadcaster):
432 """Object that manages credentials.333 """Object that manages credentials.
433334
@@ -595,24 +496,19 @@
595 # calls that will be accessible remotely496 # calls that will be accessible remotely
596 remote_calls = [497 remote_calls = [
597 'get_sso_login',498 'get_sso_login',
598 'get_sso_credentials',499 'get_cred_manager',
599 'get_cred_manager']500 ]
600501
601 def __init__(self, sso_login, sso_credentials, cred_manager):502 def __init__(self, sso_login=None, cred_manager=None):
602 """Create a new instance that will expose the objects."""503 """Create a new instance that will expose the objects."""
603 super(UbuntuSSORoot, self).__init__()504 super(UbuntuSSORoot, self).__init__()
604 self._sso_login = sso_login505 self._sso_login = sso_login
605 self._sso_credentials = sso_credentials
606 self._cred_manager = cred_manager506 self._cred_manager = cred_manager
607507
608 def get_sso_login(self):508 def get_sso_login(self):
609 """Return the sso_login."""509 """Return the sso_login."""
610 return self._sso_login510 return self._sso_login
611511
612 def get_sso_credentials(self):
613 """Return the sso credentials."""
614 return self._sso_credentials
615
616 def get_cred_manager(self):512 def get_cred_manager(self):
617 """Return the credentials manager."""513 """Return the credentials manager."""
618 return self._cred_manager514 return self._cred_manager
@@ -807,80 +703,6 @@
807 """Call the matching method in the processor."""703 """Call the matching method in the processor."""
808704
809705
810class SSOCredentialsClient(RemoteClient, Referenceable):
811 """Deprecated client for the remote SSOCredentials object.
812
813 This class is deprecated!
814 """
815
816 __metaclass__ = RemoteMeta
817
818 # calls that will be accessible remotely
819 remote_calls = [
820 'on_authorization_denied',
821 'on_credentials_found',
822 'on_credentials_error',
823 ]
824
825 def __init__(self, remote_login):
826 """Create a client for the cred API."""
827 warnings.warn("SSOCredentialsClient is deprecated.",
828 DeprecationWarning)
829 super(SSOCredentialsClient, self).__init__(remote_login)
830
831 @signal
832 def on_authorization_denied(self, app_name):
833 """Signal thrown when the user denies the authorization."""
834
835 @signal
836 def on_credentials_found(self, app_name, credentials):
837 """Signal thrown when the credentials are found."""
838
839 @signal
840 def on_credentials_error(self, app_name, error_message, detailed_error):
841 """Signal thrown when there is a problem finding the credentials."""
842
843 @callbacks(callbacks_names=[('callback', 2), ('errback', 3)])
844 @remote
845 def find_credentials(self, app_name, callback=NO_OP, errback=NO_OP):
846 """Get the credentials from the keyring or {} if not there."""
847
848 @remote
849 def login_or_register_to_get_credentials(self, app_name,
850 terms_and_conditions_url,
851 help_text, window_id):
852 """Get credentials if found else prompt GUI to login or register.
853
854 'app_name' will be displayed in the GUI.
855 'terms_and_conditions_url' will be the URL pointing to T&C.
856 'help_text' is an explanatory text for the end-users, will be shown
857 below the headers.
858 'window_id' is the id of the window which will be set as a parent of
859 the GUI. If 0, no parent will be set.
860
861 """
862
863 @remote
864 def login_to_get_credentials(self, app_name, help_text, window_id):
865 """Get credentials if found else prompt GUI just to login
866
867 'app_name' will be displayed in the GUI.
868 'help_text' is an explanatory text for the end-users, will be shown
869 before the login fields.
870 'window_id' is the id of the window which will be set as a parent of
871 the GUI. If 0, no parent will be set.
872
873 """
874
875 @callbacks(callbacks_names=[('callback', 2), ('errback', 3)])
876 @remote
877 def clear_token(self, app_name, callback=NO_OP, errback=NO_OP):
878 """Clear the token for an application from the keyring.
879
880 'app_name' is the name of the application.
881 """
882
883
884class CredentialsManagementClient(RemoteClient, Referenceable):706class CredentialsManagementClient(RemoteClient, Referenceable):
885 """Client that can perform calls to the remote CredManagement object."""707 """Client that can perform calls to the remote CredManagement object."""
886708
887709
=== modified file 'ubuntu_sso/qt/controllers.py'
--- ubuntu_sso/qt/controllers.py 2011-09-21 21:41:04 +0000
+++ ubuntu_sso/qt/controllers.py 2011-09-27 21:50:39 +0000
@@ -77,9 +77,6 @@
77logger = setup_logging('ubuntu_sso.controllers')77logger = setup_logging('ubuntu_sso.controllers')
78FAKE_URL = '<a href="http://one.ubuntu.com">%s</a>'78FAKE_URL = '<a href="http://one.ubuntu.com">%s</a>'
7979
80# pylint: disable=W0511
81# disabled warnings about TODO comments
82
8380
84# Based on the gtk implementation81# Based on the gtk implementation
85def _build_general_error_message(errordict):82def _build_general_error_message(errordict):
@@ -916,7 +913,6 @@
916 logger.debug('UbuntuSSOWizardController.on_registration_success')913 logger.debug('UbuntuSSOWizardController.on_registration_success')
917 result = yield self.registration_success_callback(unicode(app_name),914 result = yield self.registration_success_callback(unicode(app_name),
918 unicode(email))915 unicode(email))
919 # TODO: what to do?
920 logger.debug('Result from callback is %s', result)916 logger.debug('Result from callback is %s', result)
921 if result == 0:917 if result == 0:
922 logger.info('Success in calling the given registration_callback')918 logger.info('Success in calling the given registration_callback')

Subscribers

People subscribed via source and target branches