Merge lp:~nataliabidart/ubuntu-sso-client/no-more-deprecated-service into lp:ubuntu-sso-client
- no-more-deprecated-service
- Merge into trunk
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 |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Manuel de la Peña (community) | Approve | ||
Roberto Alsina (community) | Approve | ||
Review via email:
|
Commit message
- Removing the deprecated SSOCredentials interface (LP: #859635).
Description of the change
To post a comment you must log in.
Revision history for this message
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
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
1 | === modified file 'bin/ubuntu-sso-login' | |||
2 | --- bin/ubuntu-sso-login 2011-01-11 19:13:19 +0000 | |||
3 | +++ bin/ubuntu-sso-login 2011-09-27 21:50:39 +0000 | |||
4 | @@ -29,7 +29,7 @@ | |||
5 | 29 | # the locale and imports decimal, and that generates the following trace: | 29 | # the locale and imports decimal, and that generates the following trace: |
6 | 30 | # Traceback (most recent call last): | 30 | # Traceback (most recent call last): |
7 | 31 | # File "/usr/lib/ubuntu-sso-client/ubuntu-sso-login", line 33 | 31 | # File "/usr/lib/ubuntu-sso-client/ubuntu-sso-login", line 33 |
9 | 32 | # from ubuntu_sso.main import SSOLogin, SSOCredentials | 32 | # from ubuntu_sso.main import SSOLogin |
10 | 33 | # File "/usr/lib/pymodules/python2.6/ubuntu_sso/main.py", line 42 | 33 | # File "/usr/lib/pymodules/python2.6/ubuntu_sso/main.py", line 42 |
11 | 34 | # from lazr.restfulclient.resource import ServiceRoot | 34 | # from lazr.restfulclient.resource import ServiceRoot |
12 | 35 | # File "/usr/lib/python2.6/dist-packages/lazr/restfulclient/resource.py", | 35 | # File "/usr/lib/python2.6/dist-packages/lazr/restfulclient/resource.py", |
13 | @@ -52,7 +52,7 @@ | |||
14 | 52 | 52 | ||
15 | 53 | from ubuntu_sso import (DBUS_BUS_NAME, DBUS_ACCOUNT_PATH, DBUS_CRED_PATH, | 53 | from ubuntu_sso import (DBUS_BUS_NAME, DBUS_ACCOUNT_PATH, DBUS_CRED_PATH, |
16 | 54 | DBUS_CREDENTIALS_PATH) | 54 | DBUS_CREDENTIALS_PATH) |
18 | 55 | from ubuntu_sso.main import SSOLogin, SSOCredentials, CredentialsManagement | 55 | from ubuntu_sso.main import SSOLogin, CredentialsManagement |
19 | 56 | 56 | ||
20 | 57 | from ubuntu_sso.logger import setup_logging | 57 | from ubuntu_sso.logger import setup_logging |
21 | 58 | 58 | ||
22 | @@ -93,7 +93,6 @@ | |||
23 | 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) |
24 | 94 | bus_name = dbus.service.BusName(DBUS_BUS_NAME, bus=dbus.SessionBus()) | 94 | bus_name = dbus.service.BusName(DBUS_BUS_NAME, bus=dbus.SessionBus()) |
25 | 95 | SSOLogin(bus_name, object_path=DBUS_ACCOUNT_PATH) | 95 | SSOLogin(bus_name, object_path=DBUS_ACCOUNT_PATH) |
26 | 96 | SSOCredentials(bus_name, object_path=DBUS_CRED_PATH) | ||
27 | 97 | CredentialsManagement(timeout_func=gtk.timeout_add, | 96 | CredentialsManagement(timeout_func=gtk.timeout_add, |
28 | 98 | shutdown_func=gtk.main_quit, | 97 | shutdown_func=gtk.main_quit, |
29 | 99 | bus_name=bus_name, object_path=DBUS_CREDENTIALS_PATH) | 98 | bus_name=bus_name, object_path=DBUS_CREDENTIALS_PATH) |
30 | 100 | 99 | ||
31 | === modified file 'bin/windows-ubuntu-sso-login' | |||
32 | --- bin/windows-ubuntu-sso-login 2011-07-22 22:00:45 +0000 | |||
33 | +++ bin/windows-ubuntu-sso-login 2011-09-27 21:50:39 +0000 | |||
34 | @@ -37,7 +37,6 @@ | |||
35 | 37 | from ubuntu_sso.main.windows import ( | 37 | from ubuntu_sso.main.windows import ( |
36 | 38 | CredentialsManagement, | 38 | CredentialsManagement, |
37 | 39 | LOCALHOST, | 39 | LOCALHOST, |
38 | 40 | SSOCredentials, | ||
39 | 41 | SSOLogin, | 40 | SSOLogin, |
40 | 42 | UbuntuSSORoot, | 41 | UbuntuSSORoot, |
41 | 43 | get_activation_config, | 42 | get_activation_config, |
42 | @@ -61,9 +60,8 @@ | |||
43 | 61 | port = yield ai.get_port() | 60 | port = yield ai.get_port() |
44 | 62 | 61 | ||
45 | 63 | login = SSOLogin('ignored') | 62 | login = SSOLogin('ignored') |
46 | 64 | creds = SSOCredentials() | ||
47 | 65 | creds_management = CredentialsManagement(add_timeout, reactor.stop) | 63 | creds_management = CredentialsManagement(add_timeout, reactor.stop) |
49 | 66 | root = UbuntuSSORoot(login, creds, creds_management) | 64 | root = UbuntuSSORoot(soo_login=login, cred_manager=creds_management) |
50 | 67 | 65 | ||
51 | 68 | reactor.listenTCP(port, PBServerFactory(root), interface=LOCALHOST) | 66 | reactor.listenTCP(port, PBServerFactory(root), interface=LOCALHOST) |
52 | 69 | 67 | ||
53 | 70 | 68 | ||
54 | === modified file 'ubuntu_sso/main/__init__.py' | |||
55 | --- ubuntu_sso/main/__init__.py 2011-09-14 18:15:33 +0000 | |||
56 | +++ ubuntu_sso/main/__init__.py 2011-09-27 21:50:39 +0000 | |||
57 | @@ -19,11 +19,8 @@ | |||
58 | 19 | # with this program. If not, see <http://www.gnu.org/licenses/>. | 19 | # with this program. If not, see <http://www.gnu.org/licenses/>. |
59 | 20 | """Main object implementations.""" | 20 | """Main object implementations.""" |
60 | 21 | 21 | ||
61 | 22 | import os | ||
62 | 23 | import sys | 22 | import sys |
63 | 24 | import warnings | ||
64 | 25 | 23 | ||
65 | 26 | from ubuntu_sso import NO_OP | ||
66 | 27 | from ubuntu_sso.account import Account | 24 | from ubuntu_sso.account import Account |
67 | 28 | from ubuntu_sso.credentials import ( | 25 | from ubuntu_sso.credentials import ( |
68 | 29 | Credentials, | 26 | Credentials, |
69 | @@ -37,7 +34,7 @@ | |||
70 | 37 | UI_MODULE_KEY, | 34 | UI_MODULE_KEY, |
71 | 38 | WINDOW_ID_KEY, | 35 | WINDOW_ID_KEY, |
72 | 39 | ) | 36 | ) |
74 | 40 | from ubuntu_sso.keyring import get_token_name, U1_APP_NAME, Keyring | 37 | from ubuntu_sso.keyring import get_token_name, Keyring |
75 | 41 | from ubuntu_sso.logger import setup_logging | 38 | from ubuntu_sso.logger import setup_logging |
76 | 42 | 39 | ||
77 | 43 | 40 | ||
78 | @@ -46,20 +43,6 @@ | |||
79 | 46 | TIMEOUT_INTERVAL = 10000 # 10 seconds | 43 | TIMEOUT_INTERVAL = 10000 # 10 seconds |
80 | 47 | 44 | ||
81 | 48 | 45 | ||
82 | 49 | class SSOLoginProcessor(Account): | ||
83 | 50 | """Login and register users using the Ubuntu Single Sign On service. | ||
84 | 51 | |||
85 | 52 | Alias classname to maintain backwards compatibility. DO NOT USE, use | ||
86 | 53 | ubuntu_sso.account.Account instead. | ||
87 | 54 | """ | ||
88 | 55 | |||
89 | 56 | def __init__(self, sso_service_class=None): | ||
90 | 57 | """Create a new SSO Account manager.""" | ||
91 | 58 | msg = 'Use ubuntu_sso.account.Account instead.' | ||
92 | 59 | warnings.warn(msg, DeprecationWarning) | ||
93 | 60 | super(SSOLoginProcessor, self).__init__(sso_service_class) | ||
94 | 61 | |||
95 | 62 | |||
96 | 63 | def except_to_errdict(e): | 46 | def except_to_errdict(e): |
97 | 64 | """Turn an exception into a dictionary to return thru DBus.""" | 47 | """Turn an exception into a dictionary to return thru DBus.""" |
98 | 65 | result = { | 48 | result = { |
99 | @@ -169,84 +152,6 @@ | |||
100 | 169 | thread_execute(f, app_name, result_cb, error_cb) | 152 | thread_execute(f, app_name, result_cb, error_cb) |
101 | 170 | 153 | ||
102 | 171 | 154 | ||
103 | 172 | class SSOCredentialsRoot(object): | ||
104 | 173 | """Object that gets credentials, and login/registers if needed. | ||
105 | 174 | |||
106 | 175 | This class is DEPRECATED, use CredentialsManagementRoot instead. | ||
107 | 176 | |||
108 | 177 | """ | ||
109 | 178 | |||
110 | 179 | def __init__(self): | ||
111 | 180 | self.ping_url = os.environ.get('USSOC_PING_URL', U1_PING_URL) | ||
112 | 181 | msg = 'Use ubuntu_sso.main.CredentialsManagementRoot instead.' | ||
113 | 182 | warnings.warn(msg, DeprecationWarning) | ||
114 | 183 | |||
115 | 184 | def find_credentials(self, app_name, callback=NO_OP, errback=NO_OP): | ||
116 | 185 | """Get the credentials from the keyring or {} if not there.""" | ||
117 | 186 | |||
118 | 187 | def log_result(result): | ||
119 | 188 | """Log the result and continue.""" | ||
120 | 189 | logger.info('find_credentials: app_name "%s", result is {}? %s', | ||
121 | 190 | app_name, result == {}) | ||
122 | 191 | return result | ||
123 | 192 | |||
124 | 193 | d = Credentials(app_name=app_name).find_credentials() | ||
125 | 194 | # pylint: disable=E1101 | ||
126 | 195 | d.addCallback(log_result) | ||
127 | 196 | d.addCallbacks(callback, errback) | ||
128 | 197 | |||
129 | 198 | def login_or_register_to_get_credentials(self, app_name, | ||
130 | 199 | terms_and_conditions_url, | ||
131 | 200 | help_text, window_id, | ||
132 | 201 | success_cb, error_cb, denial_cb, | ||
133 | 202 | ui_module='ubuntu_sso.gtk.gui'): | ||
134 | 203 | """Get credentials if found else prompt GUI to login or register. | ||
135 | 204 | |||
136 | 205 | 'app_name' will be displayed in the GUI. | ||
137 | 206 | 'terms_and_conditions_url' will be the URL pointing to T&C. | ||
138 | 207 | 'help_text' is an explanatory text for the end-users, will be shown | ||
139 | 208 | below the headers. | ||
140 | 209 | 'window_id' is the id of the window which will be set as a parent of | ||
141 | 210 | the GUI. If 0, no parent will be set. | ||
142 | 211 | |||
143 | 212 | """ | ||
144 | 213 | ping_url = self.ping_url if app_name == U1_APP_NAME else None | ||
145 | 214 | obj = Credentials(app_name=app_name, ping_url=ping_url, | ||
146 | 215 | tc_url=terms_and_conditions_url, | ||
147 | 216 | help_text=help_text, window_id=window_id, | ||
148 | 217 | success_cb=success_cb, error_cb=error_cb, | ||
149 | 218 | denial_cb=denial_cb, ui_module=ui_module) | ||
150 | 219 | obj.register() | ||
151 | 220 | |||
152 | 221 | def login_to_get_credentials(self, app_name, help_text, window_id, | ||
153 | 222 | success_cb, error_cb, denial_cb, | ||
154 | 223 | ui_module='ubuntu_sso.gtk.gui'): | ||
155 | 224 | """Get credentials if found else prompt GUI just to login | ||
156 | 225 | |||
157 | 226 | 'app_name' will be displayed in the GUI. | ||
158 | 227 | 'help_text' is an explanatory text for the end-users, will be shown | ||
159 | 228 | before the login fields. | ||
160 | 229 | 'window_id' is the id of the window which will be set as a parent of | ||
161 | 230 | the GUI. If 0, no parent will be set. | ||
162 | 231 | |||
163 | 232 | """ | ||
164 | 233 | ping_url = self.ping_url if app_name == U1_APP_NAME else None | ||
165 | 234 | obj = Credentials(app_name=app_name, ping_url=ping_url, tc_url=None, | ||
166 | 235 | help_text=help_text, window_id=window_id, | ||
167 | 236 | success_cb=success_cb, error_cb=error_cb, | ||
168 | 237 | denial_cb=denial_cb, ui_module=ui_module) | ||
169 | 238 | obj.login() | ||
170 | 239 | |||
171 | 240 | def clear_token(self, app_name, callback=NO_OP, errback=NO_OP): | ||
172 | 241 | """Clear the token for an application from the keyring. | ||
173 | 242 | |||
174 | 243 | 'app_name' is the name of the application. | ||
175 | 244 | """ | ||
176 | 245 | d = Credentials(app_name=app_name).clear_credentials() | ||
177 | 246 | # pylint: disable=E1101 | ||
178 | 247 | d.addCallbacks(lambda _: callback(), errback) | ||
179 | 248 | |||
180 | 249 | |||
181 | 250 | class CredentialsManagementRoot(object): | 155 | class CredentialsManagementRoot(object): |
182 | 251 | """Object that manages credentials. | 156 | """Object that manages credentials. |
183 | 252 | 157 | ||
184 | @@ -434,7 +339,6 @@ | |||
185 | 434 | if sys.platform == 'win32': | 339 | if sys.platform == 'win32': |
186 | 435 | from ubuntu_sso.main import windows | 340 | from ubuntu_sso.main import windows |
187 | 436 | SSOLogin = windows.SSOLogin | 341 | SSOLogin = windows.SSOLogin |
188 | 437 | SSOCredentials = windows.SSOCredentials | ||
189 | 438 | CredentialsManagement = windows.CredentialsManagement | 342 | CredentialsManagement = windows.CredentialsManagement |
190 | 439 | TIMEOUT_INTERVAL = 10000000000 # forever | 343 | TIMEOUT_INTERVAL = 10000000000 # forever |
191 | 440 | thread_execute = windows.blocking | 344 | thread_execute = windows.blocking |
192 | @@ -442,7 +346,6 @@ | |||
193 | 442 | else: | 346 | else: |
194 | 443 | from ubuntu_sso.main import linux | 347 | from ubuntu_sso.main import linux |
195 | 444 | SSOLogin = linux.SSOLogin | 348 | SSOLogin = linux.SSOLogin |
196 | 445 | SSOCredentials = linux.SSOCredentials | ||
197 | 446 | CredentialsManagement = linux.CredentialsManagement | 349 | CredentialsManagement = linux.CredentialsManagement |
198 | 447 | thread_execute = linux.blocking | 350 | thread_execute = linux.blocking |
199 | 448 | get_sso_login_backend = linux.get_sso_login_backend | 351 | get_sso_login_backend = linux.get_sso_login_backend |
200 | 449 | 352 | ||
201 | === modified file 'ubuntu_sso/main/linux.py' | |||
202 | --- ubuntu_sso/main/linux.py 2011-09-14 18:15:33 +0000 | |||
203 | +++ ubuntu_sso/main/linux.py 2011-09-27 21:50:39 +0000 | |||
204 | @@ -28,24 +28,19 @@ | |||
205 | 28 | """ | 28 | """ |
206 | 29 | 29 | ||
207 | 30 | import threading | 30 | import threading |
208 | 31 | import warnings | ||
209 | 32 | 31 | ||
210 | 33 | import dbus.service | 32 | import dbus.service |
211 | 34 | 33 | ||
212 | 35 | from ubuntu_sso import ( | 34 | from ubuntu_sso import ( |
213 | 36 | DBUS_ACCOUNT_PATH, | 35 | DBUS_ACCOUNT_PATH, |
214 | 37 | DBUS_CREDENTIALS_IFACE, | 36 | DBUS_CREDENTIALS_IFACE, |
215 | 38 | DBUS_IFACE_CRED_NAME, | ||
216 | 39 | DBUS_IFACE_USER_NAME, | 37 | DBUS_IFACE_USER_NAME, |
217 | 40 | NO_OP, | ||
218 | 41 | ) | 38 | ) |
219 | 42 | from ubuntu_sso.account import Account | 39 | from ubuntu_sso.account import Account |
220 | 43 | from ubuntu_sso.credentials import ERROR_KEY, ERROR_DETAIL_KEY | ||
221 | 44 | from ubuntu_sso.logger import setup_logging | 40 | from ubuntu_sso.logger import setup_logging |
222 | 45 | from ubuntu_sso.main import ( | 41 | from ubuntu_sso.main import ( |
223 | 46 | CredentialsManagementRoot, | 42 | CredentialsManagementRoot, |
224 | 47 | SSOLoginRoot, | 43 | SSOLoginRoot, |
225 | 48 | SSOCredentialsRoot, | ||
226 | 49 | except_to_errdict, | 44 | except_to_errdict, |
227 | 50 | ) | 45 | ) |
228 | 51 | 46 | ||
229 | @@ -83,8 +78,6 @@ | |||
230 | 83 | dbus.service.Object.__init__(self, object_path=object_path, | 78 | dbus.service.Object.__init__(self, object_path=object_path, |
231 | 84 | bus_name=bus_name) | 79 | bus_name=bus_name) |
232 | 85 | self.root = SSOLoginRoot(sso_login_processor_class, sso_service_class) | 80 | self.root = SSOLoginRoot(sso_login_processor_class, sso_service_class) |
233 | 86 | msg = 'Use ubuntu_sso.main.CredentialsManagement instead.' | ||
234 | 87 | warnings.warn(msg, DeprecationWarning) | ||
235 | 88 | 81 | ||
236 | 89 | # generate_capcha signals | 82 | # generate_capcha signals |
237 | 90 | @dbus.service.signal(DBUS_IFACE_USER_NAME, signature="ss") | 83 | @dbus.service.signal(DBUS_IFACE_USER_NAME, signature="ss") |
238 | @@ -220,106 +213,6 @@ | |||
239 | 220 | self.PasswordChangeError) | 213 | self.PasswordChangeError) |
240 | 221 | 214 | ||
241 | 222 | 215 | ||
242 | 223 | class SSOCredentials(dbus.service.Object): | ||
243 | 224 | """DBus object that gets credentials, and login/registers if needed. | ||
244 | 225 | |||
245 | 226 | This class is Deprecated. DO NOT USE, use CredentialsManagement instead. | ||
246 | 227 | |||
247 | 228 | """ | ||
248 | 229 | |||
249 | 230 | # Operator not preceded by a space (fails with dbus decorators) | ||
250 | 231 | # pylint: disable=C0322 | ||
251 | 232 | |||
252 | 233 | def __init__(self, *args, **kwargs): | ||
253 | 234 | dbus.service.Object.__init__(self, *args, **kwargs) | ||
254 | 235 | self.root = SSOCredentialsRoot() | ||
255 | 236 | warnings.warn('%r DBus object is deprecated, please use %r instead.' % | ||
256 | 237 | (DBUS_IFACE_CRED_NAME, DBUS_CREDENTIALS_IFACE), | ||
257 | 238 | DeprecationWarning) | ||
258 | 239 | |||
259 | 240 | def _process_error(self, app_name, error_dict): | ||
260 | 241 | """Process the 'error_dict' and emit CredentialsError.""" | ||
261 | 242 | msg = error_dict.get(ERROR_KEY, 'No error message given.') | ||
262 | 243 | detail = error_dict.get(ERROR_DETAIL_KEY, 'No detailed error given.') | ||
263 | 244 | self.CredentialsError(app_name, msg, detail) | ||
264 | 245 | |||
265 | 246 | @dbus.service.signal(DBUS_IFACE_CRED_NAME, signature="s") | ||
266 | 247 | def AuthorizationDenied(self, app_name): | ||
267 | 248 | """Signal thrown when the user denies the authorization.""" | ||
268 | 249 | logger.info('SSOCredentials: emitting AuthorizationDenied with ' | ||
269 | 250 | 'app_name "%s"', app_name) | ||
270 | 251 | |||
271 | 252 | @dbus.service.signal(DBUS_IFACE_CRED_NAME, signature="sa{ss}") | ||
272 | 253 | def CredentialsFound(self, app_name, credentials): | ||
273 | 254 | """Signal thrown when the credentials are found.""" | ||
274 | 255 | logger.info('SSOCredentials: emitting CredentialsFound with ' | ||
275 | 256 | 'app_name "%s"', app_name) | ||
276 | 257 | |||
277 | 258 | @dbus.service.signal(DBUS_IFACE_CRED_NAME, signature="sss") | ||
278 | 259 | def CredentialsError(self, app_name, error_message, detailed_error): | ||
279 | 260 | """Signal thrown when there is a problem finding the credentials.""" | ||
280 | 261 | logger.error('SSOCredentials: emitting CredentialsError with app_name ' | ||
281 | 262 | '"%s" and error_message %r', app_name, error_message) | ||
282 | 263 | |||
283 | 264 | @dbus.service.method(dbus_interface=DBUS_IFACE_CRED_NAME, | ||
284 | 265 | in_signature="s", out_signature="a{ss}", | ||
285 | 266 | async_callbacks=("callback", "errback")) | ||
286 | 267 | def find_credentials(self, app_name, callback=NO_OP, errback=NO_OP): | ||
287 | 268 | """Get the credentials from the keyring or {} if not there.""" | ||
288 | 269 | self.root.find_credentials(app_name, callback, errback) | ||
289 | 270 | |||
290 | 271 | @dbus.service.method(dbus_interface=DBUS_IFACE_CRED_NAME, | ||
291 | 272 | in_signature="sssx", out_signature="") | ||
292 | 273 | def login_or_register_to_get_credentials(self, app_name, | ||
293 | 274 | terms_and_conditions_url, | ||
294 | 275 | help_text, window_id): | ||
295 | 276 | """Get credentials if found else prompt GUI to login or register. | ||
296 | 277 | |||
297 | 278 | 'app_name' will be displayed in the GUI. | ||
298 | 279 | 'terms_and_conditions_url' will be the URL pointing to T&C. | ||
299 | 280 | 'help_text' is an explanatory text for the end-users, will be shown | ||
300 | 281 | below the headers. | ||
301 | 282 | 'window_id' is the id of the window which will be set as a parent of | ||
302 | 283 | the GUI. If 0, no parent will be set. | ||
303 | 284 | |||
304 | 285 | """ | ||
305 | 286 | self.root.login_or_register_to_get_credentials(app_name, | ||
306 | 287 | terms_and_conditions_url, | ||
307 | 288 | help_text, window_id, | ||
308 | 289 | self.CredentialsFound, | ||
309 | 290 | self._process_error, | ||
310 | 291 | self.AuthorizationDenied, | ||
311 | 292 | ui_module='ubuntu_sso.gtk.gui') | ||
312 | 293 | |||
313 | 294 | @dbus.service.method(dbus_interface=DBUS_IFACE_CRED_NAME, | ||
314 | 295 | in_signature="ssx", out_signature="") | ||
315 | 296 | def login_to_get_credentials(self, app_name, help_text, window_id): | ||
316 | 297 | """Get credentials if found else prompt GUI just to login | ||
317 | 298 | |||
318 | 299 | 'app_name' will be displayed in the GUI. | ||
319 | 300 | 'help_text' is an explanatory text for the end-users, will be shown | ||
320 | 301 | before the login fields. | ||
321 | 302 | 'window_id' is the id of the window which will be set as a parent of | ||
322 | 303 | the GUI. If 0, no parent will be set. | ||
323 | 304 | |||
324 | 305 | """ | ||
325 | 306 | self.root.login_to_get_credentials(app_name, help_text, window_id, | ||
326 | 307 | self.CredentialsFound, | ||
327 | 308 | self._process_error, | ||
328 | 309 | self.AuthorizationDenied, | ||
329 | 310 | ui_module='ubuntu_sso.gtk.gui') | ||
330 | 311 | |||
331 | 312 | @dbus.service.method(dbus_interface=DBUS_IFACE_CRED_NAME, | ||
332 | 313 | in_signature='s', out_signature='', | ||
333 | 314 | async_callbacks=("callback", "errback")) | ||
334 | 315 | def clear_token(self, app_name, callback=NO_OP, errback=NO_OP): | ||
335 | 316 | """Clear the token for an application from the keyring. | ||
336 | 317 | |||
337 | 318 | 'app_name' is the name of the application. | ||
338 | 319 | """ | ||
339 | 320 | self.root.clear_token(app_name, callback, errback) | ||
340 | 321 | |||
341 | 322 | |||
342 | 323 | class CredentialsManagement(dbus.service.Object): | 216 | class CredentialsManagement(dbus.service.Object): |
343 | 324 | """DBus object that manages credentials. | 217 | """DBus object that manages credentials. |
344 | 325 | 218 | ||
345 | 326 | 219 | ||
346 | === modified file 'ubuntu_sso/main/tests/test_common.py' | |||
347 | --- ubuntu_sso/main/tests/test_common.py 2011-08-22 16:21:36 +0000 | |||
348 | +++ ubuntu_sso/main/tests/test_common.py 2011-09-27 21:50:39 +0000 | |||
349 | @@ -21,39 +21,14 @@ | |||
350 | 21 | # with this program. If not, see <http://www.gnu.org/licenses/>. | 21 | # with this program. If not, see <http://www.gnu.org/licenses/>. |
351 | 22 | """Tests share by diff platforms.""" | 22 | """Tests share by diff platforms.""" |
352 | 23 | 23 | ||
353 | 24 | import os | ||
354 | 25 | |||
355 | 26 | from unittest import TestCase | 24 | from unittest import TestCase |
356 | 25 | |||
357 | 27 | from mocker import MockerTestCase, MATCH | 26 | from mocker import MockerTestCase, MATCH |
358 | 27 | |||
359 | 28 | from ubuntu_sso.main import ( | 28 | from ubuntu_sso.main import ( |
360 | 29 | CredentialsManagement, | 29 | CredentialsManagement, |
361 | 30 | SSOCredentialsRoot, | ||
362 | 31 | SSOCredentials, | ||
363 | 32 | SSOLogin, | 30 | SSOLogin, |
388 | 33 | U1_PING_URL) | 31 | ) |
365 | 34 | |||
366 | 35 | |||
367 | 36 | class EnvironOverridesTestCase(TestCase): | ||
368 | 37 | """Some URLs can be set from the environment for testing/QA purposes.""" | ||
369 | 38 | |||
370 | 39 | def test_override_ping_url(self): | ||
371 | 40 | """The ping url can be set from the environ via USSOC_PING_URL.""" | ||
372 | 41 | fake_url = 'this is not really a URL' | ||
373 | 42 | old_url = os.environ.get('USSOC_PING_URL') | ||
374 | 43 | os.environ['USSOC_PING_URL'] = fake_url | ||
375 | 44 | try: | ||
376 | 45 | creds = SSOCredentialsRoot() | ||
377 | 46 | self.assertEqual(creds.ping_url, fake_url) | ||
378 | 47 | finally: | ||
379 | 48 | if old_url: | ||
380 | 49 | os.environ['USSOC_PING_URL'] = old_url | ||
381 | 50 | else: | ||
382 | 51 | del os.environ['USSOC_PING_URL'] | ||
383 | 52 | |||
384 | 53 | def test_no_override_ping_url(self): | ||
385 | 54 | """If the environ is unset, the default ping url is used.""" | ||
386 | 55 | creds = SSOCredentialsRoot() | ||
387 | 56 | self.assertEqual(creds.ping_url, U1_PING_URL) | ||
389 | 57 | 32 | ||
390 | 58 | 33 | ||
391 | 59 | class SSOLoginMockedTestCase(MockerTestCase): | 34 | class SSOLoginMockedTestCase(MockerTestCase): |
392 | @@ -142,53 +117,6 @@ | |||
393 | 142 | self.login.set_new_password(app_name, email, token, new_password) | 117 | self.login.set_new_password(app_name, email, token, new_password) |
394 | 143 | 118 | ||
395 | 144 | 119 | ||
396 | 145 | class SSOCredentialsMockedTestCase(MockerTestCase): | ||
397 | 146 | """Test that the call are relied correctly.""" | ||
398 | 147 | |||
399 | 148 | def setUp(self): | ||
400 | 149 | """Setup tests.""" | ||
401 | 150 | super(SSOCredentialsMockedTestCase, self).setUp() | ||
402 | 151 | self.root = self.mocker.mock() | ||
403 | 152 | mockbusname = self.mocker.mock() | ||
404 | 153 | mockbus = self.mocker.mock() | ||
405 | 154 | mockbusname.get_bus() | ||
406 | 155 | self.mocker.result(mockbus) | ||
407 | 156 | self.cred = SSOCredentials(mockbus) | ||
408 | 157 | self.cred.root = self.root | ||
409 | 158 | self.mocker.reset() | ||
410 | 159 | |||
411 | 160 | def test_find_credentials(self): | ||
412 | 161 | """Test that the call is relayed.""" | ||
413 | 162 | app_name = 'app' | ||
414 | 163 | result_cb = error_cb = lambda: None | ||
415 | 164 | self.root.find_credentials(app_name, MATCH(callable), MATCH(callable)) | ||
416 | 165 | self.mocker.mock() | ||
417 | 166 | self.mocker.replay() | ||
418 | 167 | self.cred.find_credentials(app_name, result_cb, error_cb) | ||
419 | 168 | |||
420 | 169 | def test_login_or_register_to_get_credentials(self): | ||
421 | 170 | """Test that the call is relayed.""" | ||
422 | 171 | app_name = 'app' | ||
423 | 172 | terms = 'terms' | ||
424 | 173 | help_text = 'help' | ||
425 | 174 | window_id = 'id' | ||
426 | 175 | self.root.login_or_register_to_get_credentials(app_name, terms, | ||
427 | 176 | help_text, window_id, MATCH(callable), | ||
428 | 177 | MATCH(callable), MATCH(callable), | ||
429 | 178 | ui_module=MATCH(lambda x: isinstance(x, str))) | ||
430 | 179 | self.mocker.replay() | ||
431 | 180 | self.cred.login_or_register_to_get_credentials(app_name, terms, | ||
432 | 181 | help_text, window_id) | ||
433 | 182 | |||
434 | 183 | def test_clear_token(self): | ||
435 | 184 | """Test that the call is relayed.""" | ||
436 | 185 | app_name = 'app' | ||
437 | 186 | result_cb = error_cb = lambda: None | ||
438 | 187 | self.root.clear_token(app_name, MATCH(callable), MATCH(callable)) | ||
439 | 188 | self.mocker.replay() | ||
440 | 189 | self.cred.clear_token(app_name, result_cb, error_cb) | ||
441 | 190 | |||
442 | 191 | |||
443 | 192 | class CredentialsManagementMockedTestCase(MockerTestCase, TestCase): | 120 | class CredentialsManagementMockedTestCase(MockerTestCase, TestCase): |
444 | 193 | """Test that the call are relied correctly.""" | 121 | """Test that the call are relied correctly.""" |
445 | 194 | 122 | ||
446 | 195 | 123 | ||
447 | === modified file 'ubuntu_sso/main/tests/test_linux.py' | |||
448 | --- ubuntu_sso/main/tests/test_linux.py 2011-08-22 16:21:36 +0000 | |||
449 | +++ ubuntu_sso/main/tests/test_linux.py 2011-09-27 21:50:39 +0000 | |||
450 | @@ -21,11 +21,9 @@ | |||
451 | 21 | """Tests for the main SSO client code.""" | 21 | """Tests for the main SSO client code.""" |
452 | 22 | 22 | ||
453 | 23 | import logging | 23 | import logging |
454 | 24 | import os | ||
455 | 25 | 24 | ||
457 | 26 | from mocker import Mocker, MockerTestCase, ARGS, KWARGS, MATCH | 25 | from mocker import Mocker, ARGS, KWARGS |
458 | 27 | from twisted.internet import defer | 26 | from twisted.internet import defer |
459 | 28 | from twisted.internet.defer import Deferred, inlineCallbacks | ||
460 | 29 | from twisted.trial.unittest import TestCase | 27 | from twisted.trial.unittest import TestCase |
461 | 30 | from ubuntuone.devtools.handlers import MementoHandler | 28 | from ubuntuone.devtools.handlers import MementoHandler |
462 | 31 | 29 | ||
463 | @@ -34,9 +32,12 @@ | |||
464 | 34 | import ubuntu_sso.main.linux | 32 | import ubuntu_sso.main.linux |
465 | 35 | 33 | ||
466 | 36 | from ubuntu_sso import DBUS_CREDENTIALS_IFACE | 34 | from ubuntu_sso import DBUS_CREDENTIALS_IFACE |
470 | 37 | from ubuntu_sso.keyring import U1_APP_NAME | 35 | from ubuntu_sso.main import ( |
471 | 38 | from ubuntu_sso.main import (U1_PING_URL, except_to_errdict, | 36 | except_to_errdict, |
472 | 39 | CredentialsManagement, SSOCredentials, SSOLogin, TIMEOUT_INTERVAL) | 37 | CredentialsManagement, |
473 | 38 | SSOLogin, | ||
474 | 39 | TIMEOUT_INTERVAL, | ||
475 | 40 | ) | ||
476 | 40 | from ubuntu_sso.main.linux import blocking | 41 | from ubuntu_sso.main.linux import blocking |
477 | 41 | from ubuntu_sso.main import (HELP_TEXT_KEY, PING_URL_KEY, | 42 | from ubuntu_sso.main import (HELP_TEXT_KEY, PING_URL_KEY, |
478 | 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, |
479 | @@ -116,7 +117,7 @@ | |||
480 | 116 | 117 | ||
481 | 117 | def test_generate_captcha(self): | 118 | def test_generate_captcha(self): |
482 | 118 | """Test that the captcha method works ok.""" | 119 | """Test that the captcha method works ok.""" |
484 | 119 | d = Deferred() | 120 | d = defer.Deferred() |
485 | 120 | filename = "sample filename" | 121 | filename = "sample filename" |
486 | 121 | expected_result = "expected result" | 122 | expected_result = "expected result" |
487 | 122 | self.create_mock_processor().generate_captcha(filename) | 123 | self.create_mock_processor().generate_captcha(filename) |
488 | @@ -139,7 +140,7 @@ | |||
489 | 139 | 140 | ||
490 | 140 | def test_generate_captcha_error(self): | 141 | def test_generate_captcha_error(self): |
491 | 141 | """Test that the captcha method fails as expected.""" | 142 | """Test that the captcha method fails as expected.""" |
493 | 142 | d = Deferred() | 143 | d = defer.Deferred() |
494 | 143 | filename = "sample filename" | 144 | filename = "sample filename" |
495 | 144 | expected_result = "expected result" | 145 | expected_result = "expected result" |
496 | 145 | self.create_mock_processor().generate_captcha(filename) | 146 | self.create_mock_processor().generate_captcha(filename) |
497 | @@ -162,7 +163,7 @@ | |||
498 | 162 | 163 | ||
499 | 163 | def test_register_user(self): | 164 | def test_register_user(self): |
500 | 164 | """Test that the register_user method works ok.""" | 165 | """Test that the register_user method works ok.""" |
502 | 165 | d = Deferred() | 166 | d = defer.Deferred() |
503 | 166 | expected_result = "expected result" | 167 | expected_result = "expected result" |
504 | 167 | self.create_mock_processor().register_user(EMAIL, PASSWORD, NAME, | 168 | self.create_mock_processor().register_user(EMAIL, PASSWORD, NAME, |
505 | 168 | CAPTCHA_ID, CAPTCHA_SOLUTION) | 169 | CAPTCHA_ID, CAPTCHA_SOLUTION) |
506 | @@ -186,7 +187,7 @@ | |||
507 | 186 | 187 | ||
508 | 187 | def test_register_user_error(self): | 188 | def test_register_user_error(self): |
509 | 188 | """Test that the register_user method fails as expected.""" | 189 | """Test that the register_user method fails as expected.""" |
511 | 189 | d = Deferred() | 190 | d = defer.Deferred() |
512 | 190 | expected_result = "expected result" | 191 | expected_result = "expected result" |
513 | 191 | self.create_mock_processor().register_user(EMAIL, PASSWORD, NAME, | 192 | self.create_mock_processor().register_user(EMAIL, PASSWORD, NAME, |
514 | 192 | CAPTCHA_ID, CAPTCHA_SOLUTION) | 193 | CAPTCHA_ID, CAPTCHA_SOLUTION) |
515 | @@ -210,7 +211,7 @@ | |||
516 | 210 | 211 | ||
517 | 211 | def test_login(self): | 212 | def test_login(self): |
518 | 212 | """Test that the login method works ok.""" | 213 | """Test that the login method works ok.""" |
520 | 213 | d = Deferred() | 214 | d = defer.Deferred() |
521 | 214 | processor = self.create_mock_processor() | 215 | processor = self.create_mock_processor() |
522 | 215 | processor.login(EMAIL, PASSWORD, TOKEN_NAME) | 216 | processor.login(EMAIL, PASSWORD, TOKEN_NAME) |
523 | 216 | self.mocker.result(TOKEN) | 217 | self.mocker.result(TOKEN) |
524 | @@ -236,7 +237,7 @@ | |||
525 | 236 | 237 | ||
526 | 237 | def test_login_user_not_validated(self): | 238 | def test_login_user_not_validated(self): |
527 | 238 | """Test that the login sends EmailNotValidated signal.""" | 239 | """Test that the login sends EmailNotValidated signal.""" |
529 | 239 | d = Deferred() | 240 | d = defer.Deferred() |
530 | 240 | processor = self.create_mock_processor() | 241 | processor = self.create_mock_processor() |
531 | 241 | processor.login(EMAIL, PASSWORD, TOKEN_NAME) | 242 | processor.login(EMAIL, PASSWORD, TOKEN_NAME) |
532 | 242 | self.mocker.result(TOKEN) | 243 | self.mocker.result(TOKEN) |
533 | @@ -262,7 +263,7 @@ | |||
534 | 262 | 263 | ||
535 | 263 | def test_login_error_get_token_name(self): | 264 | def test_login_error_get_token_name(self): |
536 | 264 | """The login method fails as expected when get_token_name fails.""" | 265 | """The login method fails as expected when get_token_name fails.""" |
538 | 265 | d = Deferred() | 266 | d = defer.Deferred() |
539 | 266 | self.create_mock_processor() | 267 | self.create_mock_processor() |
540 | 267 | self.patch(ubuntu_sso.main.linux, "blocking", fake_err_blocking) | 268 | self.patch(ubuntu_sso.main.linux, "blocking", fake_err_blocking) |
541 | 268 | 269 | ||
542 | @@ -290,7 +291,7 @@ | |||
543 | 290 | 291 | ||
544 | 291 | def test_login_error_set_credentials(self): | 292 | def test_login_error_set_credentials(self): |
545 | 292 | """The login method fails as expected when set_credentials fails.""" | 293 | """The login method fails as expected when set_credentials fails.""" |
547 | 293 | d = Deferred() | 294 | d = defer.Deferred() |
548 | 294 | processor = self.create_mock_processor() | 295 | processor = self.create_mock_processor() |
549 | 295 | processor.login(EMAIL, PASSWORD, TOKEN_NAME) | 296 | processor.login(EMAIL, PASSWORD, TOKEN_NAME) |
550 | 296 | self.mocker.result(TOKEN) | 297 | self.mocker.result(TOKEN) |
551 | @@ -324,7 +325,7 @@ | |||
552 | 324 | 325 | ||
553 | 325 | def test_validate_email(self): | 326 | def test_validate_email(self): |
554 | 326 | """Test that the validate_email method works ok.""" | 327 | """Test that the validate_email method works ok.""" |
556 | 327 | d = Deferred() | 328 | d = defer.Deferred() |
557 | 328 | self.create_mock_processor().validate_email(EMAIL, PASSWORD, | 329 | self.create_mock_processor().validate_email(EMAIL, PASSWORD, |
558 | 329 | EMAIL_TOKEN, TOKEN_NAME) | 330 | EMAIL_TOKEN, TOKEN_NAME) |
559 | 330 | self.mocker.result(TOKEN) | 331 | self.mocker.result(TOKEN) |
560 | @@ -347,7 +348,7 @@ | |||
561 | 347 | 348 | ||
562 | 348 | def test_validate_email_error(self): | 349 | def test_validate_email_error(self): |
563 | 349 | """Test that the validate_email method fails as expected.""" | 350 | """Test that the validate_email method fails as expected.""" |
565 | 350 | d = Deferred() | 351 | d = defer.Deferred() |
566 | 351 | self.create_mock_processor() | 352 | self.create_mock_processor() |
567 | 352 | self.patch(ubuntu_sso.main.linux, "blocking", fake_err_blocking) | 353 | self.patch(ubuntu_sso.main.linux, "blocking", fake_err_blocking) |
568 | 353 | 354 | ||
569 | @@ -374,7 +375,7 @@ | |||
570 | 374 | 375 | ||
571 | 375 | def test_request_password_reset_token(self): | 376 | def test_request_password_reset_token(self): |
572 | 376 | """Test that the request_password_reset_token method works ok.""" | 377 | """Test that the request_password_reset_token method works ok.""" |
574 | 377 | d = Deferred() | 378 | d = defer.Deferred() |
575 | 378 | processor = self.create_mock_processor() | 379 | processor = self.create_mock_processor() |
576 | 379 | processor.request_password_reset_token(EMAIL) | 380 | processor.request_password_reset_token(EMAIL) |
577 | 380 | self.patch(ubuntu_sso.main, "thread_execute", fake_ok_blocking) | 381 | self.patch(ubuntu_sso.main, "thread_execute", fake_ok_blocking) |
578 | @@ -396,7 +397,7 @@ | |||
579 | 396 | 397 | ||
580 | 397 | def test_request_password_reset_token_error(self): | 398 | def test_request_password_reset_token_error(self): |
581 | 398 | """Test the request_password_reset_token method fails as expected.""" | 399 | """Test the request_password_reset_token method fails as expected.""" |
583 | 399 | d = Deferred() | 400 | d = defer.Deferred() |
584 | 400 | 401 | ||
585 | 401 | self.create_mock_processor().request_password_reset_token(EMAIL) | 402 | self.create_mock_processor().request_password_reset_token(EMAIL) |
586 | 402 | self.mocker.result(EMAIL) | 403 | self.mocker.result(EMAIL) |
587 | @@ -418,7 +419,7 @@ | |||
588 | 418 | 419 | ||
589 | 419 | def test_set_new_password(self): | 420 | def test_set_new_password(self): |
590 | 420 | """Test that the set_new_password method works ok.""" | 421 | """Test that the set_new_password method works ok.""" |
592 | 421 | d = Deferred() | 422 | d = defer.Deferred() |
593 | 422 | self.create_mock_processor().set_new_password(EMAIL, EMAIL_TOKEN, | 423 | self.create_mock_processor().set_new_password(EMAIL, EMAIL_TOKEN, |
594 | 423 | PASSWORD) | 424 | PASSWORD) |
595 | 424 | self.mocker.result(EMAIL) | 425 | self.mocker.result(EMAIL) |
596 | @@ -440,7 +441,7 @@ | |||
597 | 440 | 441 | ||
598 | 441 | def test_set_new_password_error(self): | 442 | def test_set_new_password_error(self): |
599 | 442 | """Test that the set_new_password method fails as expected.""" | 443 | """Test that the set_new_password method fails as expected.""" |
601 | 443 | d = Deferred() | 444 | d = defer.Deferred() |
602 | 444 | expected_result = "expected result" | 445 | expected_result = "expected result" |
603 | 445 | 446 | ||
604 | 446 | self.create_mock_processor().set_new_password(EMAIL, EMAIL_TOKEN, | 447 | self.create_mock_processor().set_new_password(EMAIL, EMAIL_TOKEN, |
605 | @@ -470,7 +471,7 @@ | |||
606 | 470 | 471 | ||
607 | 471 | def test_blocking(self): | 472 | def test_blocking(self): |
608 | 472 | """Test the normal behaviour.""" | 473 | """Test the normal behaviour.""" |
610 | 473 | d = Deferred() | 474 | d = defer.Deferred() |
611 | 474 | expected_result = "expected result" | 475 | expected_result = "expected result" |
612 | 475 | 476 | ||
613 | 476 | def f(): | 477 | def f(): |
614 | @@ -488,7 +489,7 @@ | |||
615 | 488 | 489 | ||
616 | 489 | def test_blocking_error(self): | 490 | def test_blocking_error(self): |
617 | 490 | """Test the behaviour when an Exception is raised.""" | 491 | """Test the behaviour when an Exception is raised.""" |
619 | 491 | d = Deferred() | 492 | d = defer.Deferred() |
620 | 492 | expected_error_message = "expected error message" | 493 | expected_error_message = "expected error message" |
621 | 493 | 494 | ||
622 | 494 | def f(): | 495 | def f(): |
623 | @@ -559,150 +560,6 @@ | |||
624 | 559 | self.assertEqual(result["errtype"], e.__class__.__name__) | 560 | self.assertEqual(result["errtype"], e.__class__.__name__) |
625 | 560 | 561 | ||
626 | 561 | 562 | ||
627 | 562 | class RegisterSampleException(Exception): | ||
628 | 563 | """A mock exception thrown just when testing.""" | ||
629 | 564 | |||
630 | 565 | |||
631 | 566 | class ApplicationCredentialsTestCase(TestCase, MockerTestCase): | ||
632 | 567 | """Tests for the ApplicationCredentials related DBus methods.""" | ||
633 | 568 | |||
634 | 569 | timeout = 5 | ||
635 | 570 | |||
636 | 571 | def setUp(self): | ||
637 | 572 | MockerTestCase.setUp(self) | ||
638 | 573 | |||
639 | 574 | self.client = SSOCredentials(self.mocker.mock()) | ||
640 | 575 | |||
641 | 576 | mock_class = self.mocker.replace("ubuntu_sso.credentials.Credentials") | ||
642 | 577 | mock_class(app_name=APP_NAME) | ||
643 | 578 | self.creds_obj = self.mocker.mock() | ||
644 | 579 | self.mocker.result(self.creds_obj) | ||
645 | 580 | |||
646 | 581 | @inlineCallbacks | ||
647 | 582 | def test_find_credentials(self): | ||
648 | 583 | """find_credentials immediately returns the token when found.""" | ||
649 | 584 | expected_creds = "expected creds" | ||
650 | 585 | self.creds_obj.find_credentials() | ||
651 | 586 | self.mocker.result(defer.succeed(expected_creds)) | ||
652 | 587 | self.mocker.replay() | ||
653 | 588 | |||
654 | 589 | d = Deferred() | ||
655 | 590 | self.client.find_credentials(APP_NAME, d.callback, d.errback) | ||
656 | 591 | creds = yield d | ||
657 | 592 | self.assertEqual(creds, expected_creds) | ||
658 | 593 | |||
659 | 594 | @inlineCallbacks | ||
660 | 595 | def test_credentials_not_found(self): | ||
661 | 596 | """find_credentials immediately returns {} when no creds found.""" | ||
662 | 597 | expected_creds = {} | ||
663 | 598 | self.creds_obj.find_credentials() | ||
664 | 599 | self.mocker.result(defer.succeed(expected_creds)) | ||
665 | 600 | self.mocker.replay() | ||
666 | 601 | |||
667 | 602 | d = Deferred() | ||
668 | 603 | self.client.find_credentials(APP_NAME, d.callback, d.errback) | ||
669 | 604 | creds = yield d | ||
670 | 605 | self.assertEqual(creds, expected_creds) | ||
671 | 606 | |||
672 | 607 | |||
673 | 608 | class ApplicationCredentialsGUITestCase(TestCase, MockerTestCase): | ||
674 | 609 | """Tests for the ApplicationCredentials register/login DBus method.""" | ||
675 | 610 | |||
676 | 611 | app_name = APP_NAME | ||
677 | 612 | ping_url = None | ||
678 | 613 | |||
679 | 614 | def setUp(self): | ||
680 | 615 | MockerTestCase.setUp(self) | ||
681 | 616 | self.client = SSOCredentials(self.mocker.mock()) | ||
682 | 617 | self.args = {PING_URL_KEY: self.ping_url, | ||
683 | 618 | TC_URL_KEY: TC_URL, HELP_TEXT_KEY: HELP_TEXT, | ||
684 | 619 | WINDOW_ID_KEY: WINDOW_ID, | ||
685 | 620 | SUCCESS_CB_KEY: self.client.CredentialsFound, | ||
686 | 621 | ERROR_CB_KEY: self.client._process_error, | ||
687 | 622 | DENIAL_CB_KEY: self.client.AuthorizationDenied} | ||
688 | 623 | |||
689 | 624 | def test_login_or_register(self): | ||
690 | 625 | """login_or_register is correct.""" | ||
691 | 626 | self.args[UI_MODULE_KEY] = MATCH(lambda x: isinstance(x, str)) | ||
692 | 627 | mock_class = self.mocker.replace("ubuntu_sso.credentials.Credentials") | ||
693 | 628 | mock_class(app_name=self.app_name, **self.args) | ||
694 | 629 | creds_obj = self.mocker.mock() | ||
695 | 630 | self.mocker.result(creds_obj) | ||
696 | 631 | |||
697 | 632 | creds_obj.register() | ||
698 | 633 | self.mocker.replay() | ||
699 | 634 | |||
700 | 635 | args = (self.app_name, TC_URL, HELP_TEXT, WINDOW_ID) | ||
701 | 636 | self.client.login_or_register_to_get_credentials(*args) | ||
702 | 637 | |||
703 | 638 | def test_login_only(self): | ||
704 | 639 | """login_or_register is correct.""" | ||
705 | 640 | self.args[TC_URL_KEY] = None | ||
706 | 641 | self.args[UI_MODULE_KEY] = MATCH(lambda x: isinstance(x, str)) | ||
707 | 642 | mock_class = self.mocker.replace("ubuntu_sso.credentials.Credentials") | ||
708 | 643 | mock_class(app_name=self.app_name, **self.args) | ||
709 | 644 | creds_obj = self.mocker.mock() | ||
710 | 645 | self.mocker.result(creds_obj) | ||
711 | 646 | |||
712 | 647 | creds_obj.login() | ||
713 | 648 | self.mocker.replay() | ||
714 | 649 | |||
715 | 650 | args = (self.app_name, HELP_TEXT, WINDOW_ID) | ||
716 | 651 | self.client.login_to_get_credentials(*args) | ||
717 | 652 | |||
718 | 653 | |||
719 | 654 | class ApplicationCredentialsU1TestCase(ApplicationCredentialsGUITestCase): | ||
720 | 655 | """Tests for the ApplicationCredentials register/login DBus method. | ||
721 | 656 | |||
722 | 657 | Specifically for APP_NAME == U1_APP_NAME. | ||
723 | 658 | |||
724 | 659 | """ | ||
725 | 660 | |||
726 | 661 | app_name = U1_APP_NAME | ||
727 | 662 | ping_url = U1_PING_URL | ||
728 | 663 | |||
729 | 664 | |||
730 | 665 | class ApplicationCredentialsClearTokenTestCase(TestCase, MockerTestCase): | ||
731 | 666 | """Tests for the ApplicationCredentials related DBus methods.""" | ||
732 | 667 | |||
733 | 668 | def test_clear_token(self): | ||
734 | 669 | """Check that clear_token tries removing the correct token.""" | ||
735 | 670 | mock_class = self.mocker.replace("ubuntu_sso.credentials.Credentials") | ||
736 | 671 | mock_class(app_name=APP_NAME) | ||
737 | 672 | creds_obj = self.mocker.mock() | ||
738 | 673 | self.mocker.result(creds_obj) | ||
739 | 674 | |||
740 | 675 | creds_obj.clear_credentials() | ||
741 | 676 | self.mocker.result(defer.succeed(None)) | ||
742 | 677 | self.mocker.replay() | ||
743 | 678 | |||
744 | 679 | client = SSOCredentials(self.mocker.mock()) | ||
745 | 680 | client.clear_token(APP_NAME) | ||
746 | 681 | |||
747 | 682 | |||
748 | 683 | class EnvironOverridesTestCase(TestCase): | ||
749 | 684 | """Some URLs can be set from the environment for testing/QA purposes.""" | ||
750 | 685 | |||
751 | 686 | def test_override_ping_url(self): | ||
752 | 687 | """The ping url can be set from the environ via USSOC_PING_URL.""" | ||
753 | 688 | fake_url = 'this is not really a URL' | ||
754 | 689 | old_url = os.environ.get('USSOC_PING_URL') | ||
755 | 690 | os.environ['USSOC_PING_URL'] = fake_url | ||
756 | 691 | try: | ||
757 | 692 | creds = SSOCredentials(None) | ||
758 | 693 | self.assertEqual(creds.root.ping_url, fake_url) | ||
759 | 694 | finally: | ||
760 | 695 | if old_url: | ||
761 | 696 | os.environ['USSOC_PING_URL'] = old_url | ||
762 | 697 | else: | ||
763 | 698 | del os.environ['USSOC_PING_URL'] | ||
764 | 699 | |||
765 | 700 | def test_no_override_ping_url(self): | ||
766 | 701 | """If the environ is unset, the default ping url is used.""" | ||
767 | 702 | creds = SSOCredentials(None) | ||
768 | 703 | self.assertEqual(creds.root.ping_url, U1_PING_URL) | ||
769 | 704 | |||
770 | 705 | |||
771 | 706 | class CredentialsManagementTestCase(TestCase): | 563 | class CredentialsManagementTestCase(TestCase): |
772 | 707 | """Tests for the CredentialsManagement DBus interface.""" | 564 | """Tests for the CredentialsManagement DBus interface.""" |
773 | 708 | 565 | ||
774 | @@ -776,7 +633,7 @@ | |||
775 | 776 | 633 | ||
776 | 777 | def test_find_credentials(self): | 634 | def test_find_credentials(self): |
777 | 778 | """Keep proper track of on going requests.""" | 635 | """Keep proper track of on going requests.""" |
779 | 779 | d = Deferred() | 636 | d = defer.Deferred() |
780 | 780 | 637 | ||
781 | 781 | def verify(*args): | 638 | def verify(*args): |
782 | 782 | """Make the check.""" | 639 | """Make the check.""" |
783 | @@ -790,7 +647,7 @@ | |||
784 | 790 | 647 | ||
785 | 791 | def test_clear_credentials(self): | 648 | def test_clear_credentials(self): |
786 | 792 | """Keep proper track of on going requests.""" | 649 | """Keep proper track of on going requests.""" |
788 | 793 | d = Deferred() | 650 | d = defer.Deferred() |
789 | 794 | 651 | ||
790 | 795 | def verify(*args): | 652 | def verify(*args): |
791 | 796 | """Make the check.""" | 653 | """Make the check.""" |
792 | @@ -804,7 +661,7 @@ | |||
793 | 804 | 661 | ||
794 | 805 | def test_store_credentials(self): | 662 | def test_store_credentials(self): |
795 | 806 | """Keep proper track of on going requests.""" | 663 | """Keep proper track of on going requests.""" |
797 | 807 | d = Deferred() | 664 | d = defer.Deferred() |
798 | 808 | 665 | ||
799 | 809 | def verify(*args): | 666 | def verify(*args): |
800 | 810 | """Make the check.""" | 667 | """Make the check.""" |
801 | @@ -1004,7 +861,7 @@ | |||
802 | 1004 | If the creds are found, CredentialsFound is emitted. | 861 | If the creds are found, CredentialsFound is emitted. |
803 | 1005 | 862 | ||
804 | 1006 | """ | 863 | """ |
806 | 1007 | d = Deferred() | 864 | d = defer.Deferred() |
807 | 1008 | 865 | ||
808 | 1009 | def verify(app_name, creds): | 866 | def verify(app_name, creds): |
809 | 1010 | """The actual test.""" | 867 | """The actual test.""" |
810 | @@ -1032,7 +889,7 @@ | |||
811 | 1032 | If the creds are not found, CredentialsNotFound is emitted. | 889 | If the creds are not found, CredentialsNotFound is emitted. |
812 | 1033 | 890 | ||
813 | 1034 | """ | 891 | """ |
815 | 1035 | d = Deferred() | 892 | d = defer.Deferred() |
816 | 1036 | 893 | ||
817 | 1037 | def verify(app_name): | 894 | def verify(app_name): |
818 | 1038 | """The actual test.""" | 895 | """The actual test.""" |
819 | @@ -1056,7 +913,7 @@ | |||
820 | 1056 | 913 | ||
821 | 1057 | def test_find_credentials_error(self): | 914 | def test_find_credentials_error(self): |
822 | 1058 | """If find_credentials fails, CredentialsError is sent.""" | 915 | """If find_credentials fails, CredentialsError is sent.""" |
824 | 1059 | d = Deferred() | 916 | d = defer.Deferred() |
825 | 1060 | 917 | ||
826 | 1061 | def verify(app_name, errdict): | 918 | def verify(app_name, errdict): |
827 | 1062 | """The actual test.""" | 919 | """The actual test.""" |
828 | @@ -1091,7 +948,7 @@ | |||
829 | 1091 | 948 | ||
830 | 1092 | def test_clear_credentials_does_not_block(self): | 949 | def test_clear_credentials_does_not_block(self): |
831 | 1093 | """Calling clear_credentials does not block but return thru signals.""" | 950 | """Calling clear_credentials does not block but return thru signals.""" |
833 | 1094 | d = Deferred() | 951 | d = defer.Deferred() |
834 | 1095 | 952 | ||
835 | 1096 | def verify(app_name): | 953 | def verify(app_name): |
836 | 1097 | """The actual test.""" | 954 | """The actual test.""" |
837 | @@ -1115,7 +972,7 @@ | |||
838 | 1115 | 972 | ||
839 | 1116 | def test_clear_credentials_error(self): | 973 | def test_clear_credentials_error(self): |
840 | 1117 | """If clear_credentials fails, CredentialsError is sent.""" | 974 | """If clear_credentials fails, CredentialsError is sent.""" |
842 | 1118 | d = Deferred() | 975 | d = defer.Deferred() |
843 | 1119 | 976 | ||
844 | 1120 | def verify(app_name, errdict): | 977 | def verify(app_name, errdict): |
845 | 1121 | """The actual test.""" | 978 | """The actual test.""" |
846 | @@ -1152,7 +1009,7 @@ | |||
847 | 1152 | If the creds are stored, CredentialsStored is emitted. | 1009 | If the creds are stored, CredentialsStored is emitted. |
848 | 1153 | 1010 | ||
849 | 1154 | """ | 1011 | """ |
851 | 1155 | d = Deferred() | 1012 | d = defer.Deferred() |
852 | 1156 | 1013 | ||
853 | 1157 | def verify(app_name): | 1014 | def verify(app_name): |
854 | 1158 | """The actual test.""" | 1015 | """The actual test.""" |
855 | @@ -1176,7 +1033,7 @@ | |||
856 | 1176 | 1033 | ||
857 | 1177 | def test_store_credentials_error(self): | 1034 | def test_store_credentials_error(self): |
858 | 1178 | """If store_credentials fails, CredentialsError is sent.""" | 1035 | """If store_credentials fails, CredentialsError is sent.""" |
860 | 1179 | d = Deferred() | 1036 | d = defer.Deferred() |
861 | 1180 | 1037 | ||
862 | 1181 | def verify(app_name, errdict): | 1038 | def verify(app_name, errdict): |
863 | 1182 | """The actual test.""" | 1039 | """The actual test.""" |
864 | 1183 | 1040 | ||
865 | === modified file 'ubuntu_sso/main/tests/test_windows.py' | |||
866 | --- ubuntu_sso/main/tests/test_windows.py 2011-09-14 18:21:11 +0000 | |||
867 | +++ ubuntu_sso/main/tests/test_windows.py 2011-09-27 21:50:39 +0000 | |||
868 | @@ -37,8 +37,6 @@ | |||
869 | 37 | CredentialsManagementClient, | 37 | CredentialsManagementClient, |
870 | 38 | LOCALHOST, | 38 | LOCALHOST, |
871 | 39 | SignalBroadcaster, | 39 | SignalBroadcaster, |
872 | 40 | SSOCredentials, | ||
873 | 41 | SSOCredentialsClient, | ||
874 | 42 | SSOLogin, | 40 | SSOLogin, |
875 | 43 | SSOLoginClient, | 41 | SSOLoginClient, |
876 | 44 | UbuntuSSORoot, | 42 | UbuntuSSORoot, |
877 | @@ -269,7 +267,7 @@ | |||
878 | 269 | self.root = self.mocker.mock() | 267 | self.root = self.mocker.mock() |
879 | 270 | self.login = SSOLogin(None) | 268 | self.login = SSOLogin(None) |
880 | 271 | # start pb | 269 | # start pb |
882 | 272 | self.sso_root = UbuntuSSORoot(self.login, None, None) | 270 | self.sso_root = UbuntuSSORoot(sso_login=self.login) |
883 | 273 | self.server_factory = SaveProtocolServerFactory(self.sso_root) | 271 | self.server_factory = SaveProtocolServerFactory(self.sso_root) |
884 | 274 | # pylint: disable=E1101 | 272 | # pylint: disable=E1101 |
885 | 275 | port = get_sso_pb_port() | 273 | port = get_sso_pb_port() |
886 | @@ -542,191 +540,6 @@ | |||
887 | 542 | self.mocker.verify() | 540 | self.mocker.verify() |
888 | 543 | 541 | ||
889 | 544 | 542 | ||
890 | 545 | class SSOCredentialsTestCase(TestCase): | ||
891 | 546 | """Test the credentials class.""" | ||
892 | 547 | |||
893 | 548 | @defer.inlineCallbacks | ||
894 | 549 | def setUp(self): | ||
895 | 550 | """Set up tests.""" | ||
896 | 551 | yield super(SSOCredentialsTestCase, self).setUp() | ||
897 | 552 | self.mocker = Mocker() | ||
898 | 553 | self.root = self.mocker.mock() | ||
899 | 554 | self.except_to_errdict = self.mocker.replace( | ||
900 | 555 | 'ubuntu_sso.main.except_to_errdict') | ||
901 | 556 | self.creds = SSOCredentials(None) | ||
902 | 557 | self.creds.root = self.root | ||
903 | 558 | # start pb | ||
904 | 559 | self.sso_root = UbuntuSSORoot(None, self.creds, None) | ||
905 | 560 | self.server_factory = SaveProtocolServerFactory(self.sso_root) | ||
906 | 561 | # pylint: disable=E1101 | ||
907 | 562 | port = get_sso_pb_port() | ||
908 | 563 | self.listener = reactor.listenTCP(port, self.server_factory) | ||
909 | 564 | self.client_factory = PBClientFactory() | ||
910 | 565 | self.connector = reactor.connectTCP(LOCALHOST, port, | ||
911 | 566 | self.client_factory) | ||
912 | 567 | self.client = yield self._get_client() | ||
913 | 568 | # pylint: enable=E1101 | ||
914 | 569 | |||
915 | 570 | def tearDown(self): | ||
916 | 571 | """Clean reactor.""" | ||
917 | 572 | if self.server_factory.protocolInstance is not None: | ||
918 | 573 | self.server_factory.protocolInstance.transport.loseConnection() | ||
919 | 574 | return defer.gatherResults([self._tearDownServer(), | ||
920 | 575 | self._tearDownClient()]) | ||
921 | 576 | |||
922 | 577 | def _tearDownServer(self): | ||
923 | 578 | """Teardown the server.""" | ||
924 | 579 | return defer.maybeDeferred(self.listener.stopListening) | ||
925 | 580 | |||
926 | 581 | def _tearDownClient(self): | ||
927 | 582 | """Tear down the client.""" | ||
928 | 583 | self.connector.disconnect() | ||
929 | 584 | return defer.succeed(None) | ||
930 | 585 | |||
931 | 586 | @defer.inlineCallbacks | ||
932 | 587 | def _get_client(self): | ||
933 | 588 | """Get the client.""" | ||
934 | 589 | # request the remote object and create a client | ||
935 | 590 | root = yield self.client_factory.getRootObject() | ||
936 | 591 | remote = yield root.callRemote('get_sso_credentials') | ||
937 | 592 | client = SSOCredentialsClient(remote) | ||
938 | 593 | yield client.register_to_signals() | ||
939 | 594 | # set the cb | ||
940 | 595 | for signal_name in ['on_authorization_denied_cb', | ||
941 | 596 | 'on_credentials_found_cb', | ||
942 | 597 | 'on_credentials_error_cb']: | ||
943 | 598 | setattr(client, signal_name, self.mocker.mock()) | ||
944 | 599 | defer.returnValue(client) | ||
945 | 600 | |||
946 | 601 | @defer.inlineCallbacks | ||
947 | 602 | def test_emit_authorization_denied(self): | ||
948 | 603 | """Test that the cb is executed.""" | ||
949 | 604 | app_name = 'app' | ||
950 | 605 | |||
951 | 606 | self.client.on_authorization_denied_cb(app_name) | ||
952 | 607 | self.mocker.replay() | ||
953 | 608 | self.creds.emit_authorization_denied(app_name) | ||
954 | 609 | yield self.client.unregister_to_signals() | ||
955 | 610 | self.mocker.verify() | ||
956 | 611 | |||
957 | 612 | @defer.inlineCallbacks | ||
958 | 613 | def test_emit_credentials_found(self): | ||
959 | 614 | """Test that the cb was executed.""" | ||
960 | 615 | app_name = 'app' | ||
961 | 616 | credentials = 'cred' | ||
962 | 617 | |||
963 | 618 | self.client.on_credentials_found_cb(app_name, credentials) | ||
964 | 619 | self.mocker.replay() | ||
965 | 620 | self.creds.emit_credentials_found(app_name, credentials) | ||
966 | 621 | yield self.client.unregister_to_signals() | ||
967 | 622 | self.mocker.verify() | ||
968 | 623 | |||
969 | 624 | @defer.inlineCallbacks | ||
970 | 625 | def test_emit_credentials_error(self): | ||
971 | 626 | """Test that the cb was executed.""" | ||
972 | 627 | app_name = 'app' | ||
973 | 628 | raised_error = 'error' | ||
974 | 629 | detail = 'detail' | ||
975 | 630 | |||
976 | 631 | self.client.on_credentials_error_cb(app_name, raised_error, detail) | ||
977 | 632 | self.mocker.replay() | ||
978 | 633 | self.creds.emit_credentials_error(app_name, raised_error, detail) | ||
979 | 634 | yield self.client.unregister_to_signals() | ||
980 | 635 | self.mocker.verify() | ||
981 | 636 | |||
982 | 637 | @defer.inlineCallbacks | ||
983 | 638 | def test_find_credentials_no_kword(self): | ||
984 | 639 | """Ensure that the root is called.""" | ||
985 | 640 | app_name = 'app' | ||
986 | 641 | callback = lambda: None | ||
987 | 642 | errback = lambda: None | ||
988 | 643 | |||
989 | 644 | self.root.find_credentials(app_name, MATCH(callable), | ||
990 | 645 | MATCH(callable)) | ||
991 | 646 | self.mocker.replay() | ||
992 | 647 | yield self.client.find_credentials(app_name, callback, errback) | ||
993 | 648 | yield self.client.unregister_to_signals() | ||
994 | 649 | |||
995 | 650 | @defer.inlineCallbacks | ||
996 | 651 | def test_find_credentials_(self): | ||
997 | 652 | """Ensure that the root is called.""" | ||
998 | 653 | app_name = 'app' | ||
999 | 654 | callback = lambda: None | ||
1000 | 655 | errback = lambda: None | ||
1001 | 656 | |||
1002 | 657 | self.root.find_credentials(app_name, MATCH(callable), | ||
1003 | 658 | MATCH(callable)) | ||
1004 | 659 | self.mocker.replay() | ||
1005 | 660 | yield self.client.find_credentials(app_name, callback=callback, | ||
1006 | 661 | errback=errback) | ||
1007 | 662 | yield self.client.unregister_to_signals() | ||
1008 | 663 | |||
1009 | 664 | @defer.inlineCallbacks | ||
1010 | 665 | def test_login_or_register_to_get_credentials(self): | ||
1011 | 666 | """Ensure that the root is called.""" | ||
1012 | 667 | app_name = 'app' | ||
1013 | 668 | terms = 'terms' | ||
1014 | 669 | help_txt = 'help' | ||
1015 | 670 | window_id = 'window_id' | ||
1016 | 671 | |||
1017 | 672 | # pylint: disable=W0212 | ||
1018 | 673 | self.root.login_or_register_to_get_credentials(app_name, terms, | ||
1019 | 674 | help_txt, window_id, | ||
1020 | 675 | self.creds.emit_credentials_found, | ||
1021 | 676 | self.creds._process_error, | ||
1022 | 677 | self.creds.emit_authorization_denied, | ||
1023 | 678 | ui_module='ubuntu_sso.qt.gui') | ||
1024 | 679 | # pylint: enable=W0212 | ||
1025 | 680 | self.mocker.replay() | ||
1026 | 681 | yield self.client.login_or_register_to_get_credentials(app_name, terms, | ||
1027 | 682 | help_txt, window_id) | ||
1028 | 683 | yield self.client.unregister_to_signals() | ||
1029 | 684 | |||
1030 | 685 | @defer.inlineCallbacks | ||
1031 | 686 | def test_login_to_get_credentials(self): | ||
1032 | 687 | """Ensure that the root is called.""" | ||
1033 | 688 | app_name = 'app' | ||
1034 | 689 | help_txt = 'help' | ||
1035 | 690 | window_id = 'window_id' | ||
1036 | 691 | |||
1037 | 692 | # pylint: disable=W0212 | ||
1038 | 693 | self.root.login_to_get_credentials(app_name, help_txt, window_id, | ||
1039 | 694 | self.creds.emit_credentials_found, | ||
1040 | 695 | self.creds._process_error, | ||
1041 | 696 | self.creds.emit_authorization_denied, | ||
1042 | 697 | ui_module='ubuntu_sso.qt.gui') | ||
1043 | 698 | # pylint: enable=W0212 | ||
1044 | 699 | self.mocker.replay() | ||
1045 | 700 | yield self.client.login_to_get_credentials(app_name, help_txt, | ||
1046 | 701 | window_id) | ||
1047 | 702 | yield self.client.unregister_to_signals() | ||
1048 | 703 | |||
1049 | 704 | @defer.inlineCallbacks | ||
1050 | 705 | def test_clear_token_no_kword(self): | ||
1051 | 706 | """Ensure that the root is called.""" | ||
1052 | 707 | app_name = 'app' | ||
1053 | 708 | callback = lambda: None | ||
1054 | 709 | errback = lambda: None | ||
1055 | 710 | |||
1056 | 711 | self.root.clear_token(app_name, MATCH(callable), MATCH(callable)) | ||
1057 | 712 | self.mocker.replay() | ||
1058 | 713 | yield self.client.clear_token(app_name, callback, errback) | ||
1059 | 714 | yield self.client.unregister_to_signals() | ||
1060 | 715 | |||
1061 | 716 | @defer.inlineCallbacks | ||
1062 | 717 | def test_clear_token(self): | ||
1063 | 718 | """Ensure that the root is called.""" | ||
1064 | 719 | app_name = 'app' | ||
1065 | 720 | callback = lambda: None | ||
1066 | 721 | errback = lambda: None | ||
1067 | 722 | |||
1068 | 723 | self.root.clear_token(app_name, MATCH(callable), MATCH(callable)) | ||
1069 | 724 | self.mocker.replay() | ||
1070 | 725 | yield self.client.clear_token(app_name, callback=callback, | ||
1071 | 726 | errback=errback) | ||
1072 | 727 | yield self.client.unregister_to_signals() | ||
1073 | 728 | |||
1074 | 729 | |||
1075 | 730 | class CredentialsManagementTestCase(TestCase): | 543 | class CredentialsManagementTestCase(TestCase): |
1076 | 731 | """Test the management class.""" | 544 | """Test the management class.""" |
1077 | 732 | 545 | ||
1078 | @@ -741,7 +554,7 @@ | |||
1079 | 741 | self.creds = CredentialsManagement(None, None) | 554 | self.creds = CredentialsManagement(None, None) |
1080 | 742 | self.creds.root = self.root | 555 | self.creds.root = self.root |
1081 | 743 | # start pb | 556 | # start pb |
1083 | 744 | self.sso_root = UbuntuSSORoot(None, None, self.creds) | 557 | self.sso_root = UbuntuSSORoot(cred_manager=self.creds) |
1084 | 745 | self.server_factory = SaveProtocolServerFactory(self.sso_root) | 558 | self.server_factory = SaveProtocolServerFactory(self.sso_root) |
1085 | 746 | # pylint: disable=E1101 | 559 | # pylint: disable=E1101 |
1086 | 747 | port = get_sso_pb_port() | 560 | port = get_sso_pb_port() |
1087 | 748 | 561 | ||
1088 | === modified file 'ubuntu_sso/main/windows.py' | |||
1089 | --- ubuntu_sso/main/windows.py 2011-09-14 20:59:39 +0000 | |||
1090 | +++ ubuntu_sso/main/windows.py 2011-09-27 21:50:39 +0000 | |||
1091 | @@ -17,8 +17,6 @@ | |||
1092 | 17 | # with this program. If not, see <http://www.gnu.org/licenses/>. | 17 | # with this program. If not, see <http://www.gnu.org/licenses/>. |
1093 | 18 | """Main implementation on windows.""" | 18 | """Main implementation on windows.""" |
1094 | 19 | 19 | ||
1095 | 20 | import warnings | ||
1096 | 21 | |||
1097 | 22 | from functools import wraps | 20 | from functools import wraps |
1098 | 23 | 21 | ||
1099 | 24 | # pylint: disable=F0401 | 22 | # pylint: disable=F0401 |
1100 | @@ -36,14 +34,11 @@ | |||
1101 | 36 | Root, | 34 | Root, |
1102 | 37 | ) | 35 | ) |
1103 | 38 | 36 | ||
1104 | 39 | from ubuntu_sso import NO_OP | ||
1105 | 40 | from ubuntu_sso.account import Account | 37 | from ubuntu_sso.account import Account |
1106 | 41 | from ubuntu_sso.credentials import ERROR_KEY, ERROR_DETAIL_KEY | ||
1107 | 42 | from ubuntu_sso.logger import setup_logging | 38 | from ubuntu_sso.logger import setup_logging |
1108 | 43 | from ubuntu_sso.main import ( | 39 | from ubuntu_sso.main import ( |
1109 | 44 | CredentialsManagementRoot, | 40 | CredentialsManagementRoot, |
1110 | 45 | SSOLoginRoot, | 41 | SSOLoginRoot, |
1111 | 46 | SSOCredentialsRoot, | ||
1112 | 47 | except_to_errdict, | 42 | except_to_errdict, |
1113 | 48 | ) | 43 | ) |
1114 | 49 | from ubuntu_sso.utils.tcpactivation import ActivationConfig, ActivationClient | 44 | from ubuntu_sso.utils.tcpactivation import ActivationConfig, ActivationClient |
1115 | @@ -334,100 +329,6 @@ | |||
1116 | 334 | self.emit_password_change_error) | 329 | self.emit_password_change_error) |
1117 | 335 | 330 | ||
1118 | 336 | 331 | ||
1119 | 337 | class SSOCredentials(Referenceable, SignalBroadcaster): | ||
1120 | 338 | """DBus object that gets credentials, and login/registers if needed.""" | ||
1121 | 339 | |||
1122 | 340 | __metaclass__ = RemoteMeta | ||
1123 | 341 | |||
1124 | 342 | # calls that will be accessible remotely | ||
1125 | 343 | remote_calls = [ | ||
1126 | 344 | 'find_credentials', | ||
1127 | 345 | 'login_or_register_to_get_credentials', | ||
1128 | 346 | 'login_to_get_credentials', | ||
1129 | 347 | 'clear_token', | ||
1130 | 348 | ] | ||
1131 | 349 | |||
1132 | 350 | def __init__(self, *args, **kwargs): | ||
1133 | 351 | super(SSOCredentials, self).__init__() | ||
1134 | 352 | self.root = SSOCredentialsRoot() | ||
1135 | 353 | |||
1136 | 354 | def _process_error(self, app_name, error_dict): | ||
1137 | 355 | """Process the 'error_dict' and emit CredentialsError.""" | ||
1138 | 356 | msg = error_dict.get(ERROR_KEY, 'No error message given.') | ||
1139 | 357 | detail = error_dict.get(ERROR_DETAIL_KEY, 'No detailed error given.') | ||
1140 | 358 | self.emit_credentials_error(app_name, msg, detail) | ||
1141 | 359 | |||
1142 | 360 | def emit_authorization_denied(self, app_name): | ||
1143 | 361 | """Signal thrown when the user denies the authorization.""" | ||
1144 | 362 | logger.info('SSOCredentials: emitting AuthorizationDenied with ' | ||
1145 | 363 | 'app_name "%s"', app_name) | ||
1146 | 364 | self.emit_signal('on_authorization_denied', app_name) | ||
1147 | 365 | |||
1148 | 366 | def emit_credentials_found(self, app_name, credentials): | ||
1149 | 367 | """Signal thrown when the credentials are found.""" | ||
1150 | 368 | logger.info('SSOCredentials: emitting CredentialsFound with ' | ||
1151 | 369 | 'app_name "%s"', app_name) | ||
1152 | 370 | self.emit_signal('on_credentials_found', app_name, credentials) | ||
1153 | 371 | |||
1154 | 372 | def emit_credentials_error(self, app_name, error_message, detailed_error): | ||
1155 | 373 | """Signal thrown when there is a problem finding the credentials.""" | ||
1156 | 374 | logger.error('SSOCredentials: emitting CredentialsError with app_name ' | ||
1157 | 375 | '"%s" and error_message %r', app_name, error_message) | ||
1158 | 376 | self.emit_signal('on_credentials_error', app_name, error_message, | ||
1159 | 377 | detailed_error) | ||
1160 | 378 | |||
1161 | 379 | def find_credentials(self, app_name, callback=NO_OP, errback=NO_OP): | ||
1162 | 380 | """Get the credentials from the keyring or {} if not there.""" | ||
1163 | 381 | self.root.find_credentials(app_name, remote_handler(callback), | ||
1164 | 382 | remote_handler(errback)) | ||
1165 | 383 | |||
1166 | 384 | def login_or_register_to_get_credentials(self, app_name, | ||
1167 | 385 | terms_and_conditions_url, | ||
1168 | 386 | help_text, window_id, | ||
1169 | 387 | ui_module='ubuntu_sso.qt.gui'): | ||
1170 | 388 | """Get credentials if found else prompt GUI to login or register. | ||
1171 | 389 | |||
1172 | 390 | 'app_name' will be displayed in the GUI. | ||
1173 | 391 | 'terms_and_conditions_url' will be the URL pointing to T&C. | ||
1174 | 392 | 'help_text' is an explanatory text for the end-users, will be shown | ||
1175 | 393 | below the headers. | ||
1176 | 394 | 'window_id' is the id of the window which will be set as a parent of | ||
1177 | 395 | the GUI. If 0, no parent will be set. | ||
1178 | 396 | |||
1179 | 397 | """ | ||
1180 | 398 | self.root.login_or_register_to_get_credentials(app_name, | ||
1181 | 399 | terms_and_conditions_url, | ||
1182 | 400 | help_text, window_id, | ||
1183 | 401 | self.emit_credentials_found, | ||
1184 | 402 | self._process_error, | ||
1185 | 403 | self.emit_authorization_denied, | ||
1186 | 404 | ui_module=ui_module) | ||
1187 | 405 | |||
1188 | 406 | def login_to_get_credentials(self, app_name, help_text, window_id): | ||
1189 | 407 | """Get credentials if found else prompt GUI just to login | ||
1190 | 408 | |||
1191 | 409 | 'app_name' will be displayed in the GUI. | ||
1192 | 410 | 'help_text' is an explanatory text for the end-users, will be shown | ||
1193 | 411 | before the login fields. | ||
1194 | 412 | 'window_id' is the id of the window which will be set as a parent of | ||
1195 | 413 | the GUI. If 0, no parent will be set. | ||
1196 | 414 | |||
1197 | 415 | """ | ||
1198 | 416 | self.root.login_to_get_credentials(app_name, help_text, window_id, | ||
1199 | 417 | self.emit_credentials_found, | ||
1200 | 418 | self._process_error, | ||
1201 | 419 | self.emit_authorization_denied, | ||
1202 | 420 | ui_module='ubuntu_sso.qt.gui') | ||
1203 | 421 | |||
1204 | 422 | def clear_token(self, app_name, callback=NO_OP, errback=NO_OP): | ||
1205 | 423 | """Clear the token for an application from the keyring. | ||
1206 | 424 | |||
1207 | 425 | 'app_name' is the name of the application. | ||
1208 | 426 | """ | ||
1209 | 427 | self.root.clear_token(app_name, remote_handler(callback), | ||
1210 | 428 | remote_handler(errback)) | ||
1211 | 429 | |||
1212 | 430 | |||
1213 | 431 | class CredentialsManagement(Referenceable, SignalBroadcaster): | 332 | class CredentialsManagement(Referenceable, SignalBroadcaster): |
1214 | 432 | """Object that manages credentials. | 333 | """Object that manages credentials. |
1215 | 433 | 334 | ||
1216 | @@ -595,24 +496,19 @@ | |||
1217 | 595 | # calls that will be accessible remotely | 496 | # calls that will be accessible remotely |
1218 | 596 | remote_calls = [ | 497 | remote_calls = [ |
1219 | 597 | 'get_sso_login', | 498 | 'get_sso_login', |
1222 | 598 | 'get_sso_credentials', | 499 | 'get_cred_manager', |
1223 | 599 | 'get_cred_manager'] | 500 | ] |
1224 | 600 | 501 | ||
1226 | 601 | def __init__(self, sso_login, sso_credentials, cred_manager): | 502 | def __init__(self, sso_login=None, cred_manager=None): |
1227 | 602 | """Create a new instance that will expose the objects.""" | 503 | """Create a new instance that will expose the objects.""" |
1228 | 603 | super(UbuntuSSORoot, self).__init__() | 504 | super(UbuntuSSORoot, self).__init__() |
1229 | 604 | self._sso_login = sso_login | 505 | self._sso_login = sso_login |
1230 | 605 | self._sso_credentials = sso_credentials | ||
1231 | 606 | self._cred_manager = cred_manager | 506 | self._cred_manager = cred_manager |
1232 | 607 | 507 | ||
1233 | 608 | def get_sso_login(self): | 508 | def get_sso_login(self): |
1234 | 609 | """Return the sso_login.""" | 509 | """Return the sso_login.""" |
1235 | 610 | return self._sso_login | 510 | return self._sso_login |
1236 | 611 | 511 | ||
1237 | 612 | def get_sso_credentials(self): | ||
1238 | 613 | """Return the sso credentials.""" | ||
1239 | 614 | return self._sso_credentials | ||
1240 | 615 | |||
1241 | 616 | def get_cred_manager(self): | 512 | def get_cred_manager(self): |
1242 | 617 | """Return the credentials manager.""" | 513 | """Return the credentials manager.""" |
1243 | 618 | return self._cred_manager | 514 | return self._cred_manager |
1244 | @@ -807,80 +703,6 @@ | |||
1245 | 807 | """Call the matching method in the processor.""" | 703 | """Call the matching method in the processor.""" |
1246 | 808 | 704 | ||
1247 | 809 | 705 | ||
1248 | 810 | class SSOCredentialsClient(RemoteClient, Referenceable): | ||
1249 | 811 | """Deprecated client for the remote SSOCredentials object. | ||
1250 | 812 | |||
1251 | 813 | This class is deprecated! | ||
1252 | 814 | """ | ||
1253 | 815 | |||
1254 | 816 | __metaclass__ = RemoteMeta | ||
1255 | 817 | |||
1256 | 818 | # calls that will be accessible remotely | ||
1257 | 819 | remote_calls = [ | ||
1258 | 820 | 'on_authorization_denied', | ||
1259 | 821 | 'on_credentials_found', | ||
1260 | 822 | 'on_credentials_error', | ||
1261 | 823 | ] | ||
1262 | 824 | |||
1263 | 825 | def __init__(self, remote_login): | ||
1264 | 826 | """Create a client for the cred API.""" | ||
1265 | 827 | warnings.warn("SSOCredentialsClient is deprecated.", | ||
1266 | 828 | DeprecationWarning) | ||
1267 | 829 | super(SSOCredentialsClient, self).__init__(remote_login) | ||
1268 | 830 | |||
1269 | 831 | @signal | ||
1270 | 832 | def on_authorization_denied(self, app_name): | ||
1271 | 833 | """Signal thrown when the user denies the authorization.""" | ||
1272 | 834 | |||
1273 | 835 | @signal | ||
1274 | 836 | def on_credentials_found(self, app_name, credentials): | ||
1275 | 837 | """Signal thrown when the credentials are found.""" | ||
1276 | 838 | |||
1277 | 839 | @signal | ||
1278 | 840 | def on_credentials_error(self, app_name, error_message, detailed_error): | ||
1279 | 841 | """Signal thrown when there is a problem finding the credentials.""" | ||
1280 | 842 | |||
1281 | 843 | @callbacks(callbacks_names=[('callback', 2), ('errback', 3)]) | ||
1282 | 844 | @remote | ||
1283 | 845 | def find_credentials(self, app_name, callback=NO_OP, errback=NO_OP): | ||
1284 | 846 | """Get the credentials from the keyring or {} if not there.""" | ||
1285 | 847 | |||
1286 | 848 | @remote | ||
1287 | 849 | def login_or_register_to_get_credentials(self, app_name, | ||
1288 | 850 | terms_and_conditions_url, | ||
1289 | 851 | help_text, window_id): | ||
1290 | 852 | """Get credentials if found else prompt GUI to login or register. | ||
1291 | 853 | |||
1292 | 854 | 'app_name' will be displayed in the GUI. | ||
1293 | 855 | 'terms_and_conditions_url' will be the URL pointing to T&C. | ||
1294 | 856 | 'help_text' is an explanatory text for the end-users, will be shown | ||
1295 | 857 | below the headers. | ||
1296 | 858 | 'window_id' is the id of the window which will be set as a parent of | ||
1297 | 859 | the GUI. If 0, no parent will be set. | ||
1298 | 860 | |||
1299 | 861 | """ | ||
1300 | 862 | |||
1301 | 863 | @remote | ||
1302 | 864 | def login_to_get_credentials(self, app_name, help_text, window_id): | ||
1303 | 865 | """Get credentials if found else prompt GUI just to login | ||
1304 | 866 | |||
1305 | 867 | 'app_name' will be displayed in the GUI. | ||
1306 | 868 | 'help_text' is an explanatory text for the end-users, will be shown | ||
1307 | 869 | before the login fields. | ||
1308 | 870 | 'window_id' is the id of the window which will be set as a parent of | ||
1309 | 871 | the GUI. If 0, no parent will be set. | ||
1310 | 872 | |||
1311 | 873 | """ | ||
1312 | 874 | |||
1313 | 875 | @callbacks(callbacks_names=[('callback', 2), ('errback', 3)]) | ||
1314 | 876 | @remote | ||
1315 | 877 | def clear_token(self, app_name, callback=NO_OP, errback=NO_OP): | ||
1316 | 878 | """Clear the token for an application from the keyring. | ||
1317 | 879 | |||
1318 | 880 | 'app_name' is the name of the application. | ||
1319 | 881 | """ | ||
1320 | 882 | |||
1321 | 883 | |||
1322 | 884 | class CredentialsManagementClient(RemoteClient, Referenceable): | 706 | class CredentialsManagementClient(RemoteClient, Referenceable): |
1323 | 885 | """Client that can perform calls to the remote CredManagement object.""" | 707 | """Client that can perform calls to the remote CredManagement object.""" |
1324 | 886 | 708 | ||
1325 | 887 | 709 | ||
1326 | === modified file 'ubuntu_sso/qt/controllers.py' | |||
1327 | --- ubuntu_sso/qt/controllers.py 2011-09-21 21:41:04 +0000 | |||
1328 | +++ ubuntu_sso/qt/controllers.py 2011-09-27 21:50:39 +0000 | |||
1329 | @@ -77,9 +77,6 @@ | |||
1330 | 77 | logger = setup_logging('ubuntu_sso.controllers') | 77 | logger = setup_logging('ubuntu_sso.controllers') |
1331 | 78 | FAKE_URL = '<a href="http://one.ubuntu.com">%s</a>' | 78 | FAKE_URL = '<a href="http://one.ubuntu.com">%s</a>' |
1332 | 79 | 79 | ||
1333 | 80 | # pylint: disable=W0511 | ||
1334 | 81 | # disabled warnings about TODO comments | ||
1335 | 82 | |||
1336 | 83 | 80 | ||
1337 | 84 | # Based on the gtk implementation | 81 | # Based on the gtk implementation |
1338 | 85 | def _build_general_error_message(errordict): | 82 | def _build_general_error_message(errordict): |
1339 | @@ -916,7 +913,6 @@ | |||
1340 | 916 | logger.debug('UbuntuSSOWizardController.on_registration_success') | 913 | logger.debug('UbuntuSSOWizardController.on_registration_success') |
1341 | 917 | result = yield self.registration_success_callback(unicode(app_name), | 914 | result = yield self.registration_success_callback(unicode(app_name), |
1342 | 918 | unicode(email)) | 915 | unicode(email)) |
1343 | 919 | # TODO: what to do? | ||
1344 | 920 | logger.debug('Result from callback is %s', result) | 916 | logger.debug('Result from callback is %s', result) |
1345 | 921 | if result == 0: | 917 | if result == 0: |
1346 | 922 | logger.info('Success in calling the given registration_callback') | 918 | logger.info('Success in calling the given registration_callback') |
+1