Merge lp:~nataliabidart/ubuntu-sso-client/ping-server into lp:ubuntu-sso-client

Proposed by Natalia Bidart
Status: Merged
Approved by: Natalia Bidart
Approved revision: 589
Merged at revision: 584
Proposed branch: lp:~nataliabidart/ubuntu-sso-client/ping-server
Merge into: lp:ubuntu-sso-client
Diff against target: 1406 lines (+311/-224)
4 files modified
ubuntu_sso/gui.py (+57/-46)
ubuntu_sso/main.py (+80/-69)
ubuntu_sso/tests/test_gui.py (+46/-44)
ubuntu_sso/tests/test_main.py (+128/-65)
To merge this branch: bzr merge lp:~nataliabidart/ubuntu-sso-client/ping-server
Reviewer Review Type Date Requested Status
Rodrigo Moya (community) Approve
John Lenton (community) Approve
Review via email: mp+33474@code.launchpad.net

Commit message

Ping an URL when the login was successful (LP: #621226).
Signals propagates the app_name to be later check by the GUI so only those belonging to it will be processed (LP: #621377).

Description of the change

Ping an URL when the login was successful.
Also, signals propagates the app_name to be later check by the GUI so only those belonging to it will be processed.

To post a comment you must log in.
589. By Natalia Bidart

Removing an unneeded change.

Revision history for this message
John Lenton (chipaca) wrote :

The branch looks good. It has some kind of a segfault issue, but it looks like it's in trunk also; nessita will be looking into it more.

review: Approve
Revision history for this message
Rodrigo Moya (rodrigo-moya) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'ubuntu_sso/gui.py'
2--- ubuntu_sso/gui.py 2010-08-23 13:32:24 +0000
3+++ ubuntu_sso/gui.py 2010-08-24 00:02:39 +0000
4@@ -57,10 +57,10 @@
5 SIG_USER_CANCELATION = 'user-cancelation'
6
7 SIGNAL_ARGUMENTS = [
8- (SIG_LOGIN_FAILED, (gobject.TYPE_STRING,)),
9- (SIG_LOGIN_SUCCEEDED, (gobject.TYPE_STRING,)),
10- (SIG_REGISTRATION_FAILED, (gobject.TYPE_STRING,)),
11- (SIG_REGISTRATION_SUCCEEDED, (gobject.TYPE_STRING,)),
12+ (SIG_LOGIN_FAILED, (gobject.TYPE_STRING, gobject.TYPE_STRING)),
13+ (SIG_LOGIN_SUCCEEDED, (gobject.TYPE_STRING, gobject.TYPE_STRING,)),
14+ (SIG_REGISTRATION_FAILED, (gobject.TYPE_STRING, gobject.TYPE_STRING)),
15+ (SIG_REGISTRATION_SUCCEEDED, (gobject.TYPE_STRING, gobject.TYPE_STRING,)),
16 (SIG_USER_CANCELATION, (gobject.TYPE_STRING,)),
17 ]
18
19@@ -100,6 +100,18 @@
20 return os.path.join(get_data_dir(), filename)
21
22
23+def log_call(f):
24+ """Decorator to log call funtions."""
25+
26+ @wraps(f)
27+ def inner(*args, **kwargs):
28+ """Execute 'f' logging the call as INFO."""
29+ logger.info('%s: args %r, kwargs %r.', f.__name__, args, kwargs)
30+ return f(*args, **kwargs)
31+
32+ return inner
33+
34+
35 class LabeledEntry(gtk.Entry):
36 """An entry that displays the label within itself ina grey color."""
37
38@@ -472,7 +484,7 @@
39 logger.info('Calling generate_captcha with filename path at %r',
40 self._captcha_filename)
41 f = self.backend.generate_captcha
42- f(self._captcha_filename,
43+ f(self.app_name, self._captcha_filename,
44 reply_handler=NO_OP, error_handler=NO_OP)
45
46 return self.enter_details_vbox
47@@ -669,7 +681,7 @@
48 ' captcha_id %r and captcha_solution %r.', email1,
49 self._captcha_id, captcha_solution)
50 f = self.backend.register_user
51- f(email1, password1, self._captcha_id, captcha_solution,
52+ f(self.app_name, email1, password1, self._captcha_id, captcha_solution,
53 reply_handler=NO_OP, error_handler=NO_OP)
54
55 def on_tc_button_clicked(self, *args, **kwargs):
56@@ -690,7 +702,7 @@
57 ', app_name %r and email_token %r.', email,
58 self.app_name, email_token)
59 f = self.backend.validate_email
60- f(email, password, self.app_name, email_token,
61+ f(self.app_name, email, password, email_token,
62 reply_handler=NO_OP, error_handler=NO_OP)
63
64 self._set_current_page(self.processing_vbox)
65@@ -725,7 +737,7 @@
66 self._clear_warnings()
67
68 f = self.backend.login
69- f(email, password, self.app_name,
70+ f(self.app_name, email, password,
71 reply_handler=NO_OP, error_handler=NO_OP)
72
73 self._set_current_page(self.processing_vbox)
74@@ -744,7 +756,7 @@
75
76 logger.info('Calling request_password_reset_token with %r.', email)
77 f = self.backend.request_password_reset_token
78- f(email, reply_handler=NO_OP, error_handler=NO_OP)
79+ f(self.app_name, email, reply_handler=NO_OP, error_handler=NO_OP)
80
81 self._set_current_page(self.processing_vbox)
82
83@@ -778,7 +790,8 @@
84 logger.info('Calling set_new_password with email %r, token %r and ' \
85 'new password: <hidden>.', email, token)
86 f = self.backend.set_new_password
87- f(email, token, password1, reply_handler=NO_OP, error_handler=NO_OP)
88+ f(self.app_name, email, token, password1,
89+ reply_handler=NO_OP, error_handler=NO_OP)
90
91 self._set_current_page(self.processing_vbox)
92
93@@ -800,83 +813,81 @@
94
95 # backend callbacks
96
97- def on_captcha_generated(self, captcha_id, *args, **kwargs):
98+ @log_call
99+ def on_captcha_generated(self, app_name, captcha_id, *args, **kwargs):
100 """Captcha image has been generated and is available to be shown."""
101 assert captcha_id is not None
102 self._captcha_id = captcha_id
103 self._set_captcha_image()
104
105- def on_captcha_generation_error(self, *args, **kwargs):
106+ @log_call
107+ def on_captcha_generation_error(self, app_name, error, *args, **kwargs):
108 """Captcha image generation failed."""
109- logger.warning('on_captcha_generation_error: args %r, kwargs %r',
110- args, kwargs)
111
112- def on_user_registered(self, *args, **kwargs):
113+ @log_call
114+ def on_user_registered(self, app_name, email, *args, **kwargs):
115 """Registration can go on, user needs to verify email."""
116- logger.info('on_user_registered: user was successfully registered! ' \
117- 'args %r, kwargs %r.', args, kwargs)
118 self._set_current_page(self.verify_email_vbox)
119
120- def on_user_registration_error(self, *args, **kwargs):
121+ @log_call
122+ def on_user_registration_error(self, app_name, error, *args, **kwargs):
123 """Captcha image generation failed."""
124- logger.warning('on_user_registration_error: args %r, kwargs %r',
125- args, kwargs)
126 self._set_current_page(self.enter_details_vbox,
127 warning_text=self.UNKNOWN_ERROR)
128- self._gtk_signal_log.append((SIG_REGISTRATION_FAILED, self.app_name))
129+ self._gtk_signal_log.append((SIG_REGISTRATION_FAILED, self.app_name,
130+ error))
131
132- def on_email_validated(self, app_name, *args, **kwargs):
133+ @log_call
134+ def on_email_validated(self, app_name, email, *args, **kwargs):
135 """User email was successfully verified."""
136- logger.info('on_email_validated: email was successfully validated! ' \
137- 'app_name %r, args %r, kwargs %r.', app_name, args, kwargs)
138 self._set_current_page(self.success_vbox)
139- self._gtk_signal_log.append((SIG_REGISTRATION_SUCCEEDED, app_name))
140+ self._gtk_signal_log.append((SIG_REGISTRATION_SUCCEEDED, self.app_name,
141+ email))
142
143- def on_email_validation_error(self, *args, **kwargs):
144+ @log_call
145+ def on_email_validation_error(self, app_name, error, *args, **kwargs):
146 """User email validation failed."""
147- logger.warning('on_email_validation_error: args %r, kwargs %r',
148- args, kwargs)
149 self._set_current_page(self.verify_email_vbox,
150 warning_text=self.UNKNOWN_ERROR)
151- self._gtk_signal_log.append((SIG_REGISTRATION_FAILED, self.app_name))
152+ self._gtk_signal_log.append((SIG_REGISTRATION_FAILED, self.app_name,
153+ error))
154
155- def on_logged_in(self, app_name, *args, **kwargs):
156+ @log_call
157+ def on_logged_in(self, app_name, email, *args, **kwargs):
158 """User was successfully logged in."""
159- logger.info('on_logged_in: user was successfully logged in! '
160- 'args %r, kwargs %r', args, kwargs)
161 self._set_current_page(self.success_vbox)
162- self._gtk_signal_log.append((SIG_LOGIN_SUCCEEDED, app_name))
163+ self._gtk_signal_log.append((SIG_LOGIN_SUCCEEDED, self.app_name,
164+ email))
165
166- def on_login_error(self, *args, **kwargs):
167+ @log_call
168+ def on_login_error(self, app_name, error, *args, **kwargs):
169 """User was not successfully logged in."""
170- logger.warning('on_login_error: args %r, kwargs %r',
171- args, kwargs)
172 self._set_current_page(self.login_vbox,
173 warning_text=self.UNKNOWN_ERROR)
174- self._gtk_signal_log.append((SIG_LOGIN_FAILED, self.app_name))
175+ self._gtk_signal_log.append((SIG_LOGIN_FAILED, self.app_name,
176+ error))
177
178- def on_password_reset_token_sent(self, email, *args, **kwargs):
179+ @log_call
180+ def on_password_reset_token_sent(self, app_name, email, *args, **kwargs):
181 """Password reset token was successfully sent."""
182- email = self.reset_email_entry.get_text()
183 msg = self.SET_NEW_PASSWORD_LABEL % {'email': email}
184 self.set_new_password_vbox.help_text = msg
185 self._set_current_page(self.set_new_password_vbox)
186
187- def on_password_reset_error(self, *args, **kwargs):
188+ @log_call
189+ def on_password_reset_error(self, app_name, error, *args, **kwargs):
190 """Password reset failed."""
191- logger.warning('on_password_reset_error: args %r, kwargs %r',
192- args, kwargs)
193 self._set_current_page(self.login_vbox,
194 warning_text=self.UNKNOWN_ERROR)
195
196- def on_password_changed(self, email, *args, **kwargs):
197+ @log_call
198+ def on_password_changed(self, app_name, email, *args, **kwargs):
199 """Password was successfully changed."""
200 self._set_current_page(self.login_vbox,
201 warning_text=self.PASSWORD_CHANGED)
202
203- def on_password_change_error(self, *args, **kwargs):
204+ @log_call
205+ def on_password_change_error(self, app_name, error, *args, **kwargs):
206 """Password reset failed."""
207- logger.warning('on_password_change_error: args %r, kwargs %r',
208- args, kwargs)
209 self._set_current_page(self.request_password_token_vbox,
210 warning_text=self.UNKNOWN_ERROR)
211
212=== modified file 'ubuntu_sso/main.py'
213--- ubuntu_sso/main.py 2010-08-23 19:23:40 +0000
214+++ ubuntu_sso/main.py 2010-08-24 00:02:39 +0000
215@@ -59,6 +59,7 @@
216
217 OLD_KEY_NAME = "UbuntuOne token for https://ubuntuone.com"
218 U1_APP_NAME = "Ubuntu One"
219+PING_URL = "http://one.ubuntu.com/oauth/sso-finished-so-get-tokens/"
220
221
222 class NoDefaultConfigError(Exception):
223@@ -199,17 +200,16 @@
224 elif result['status'] != 'ok':
225 raise RegistrationError('Received unknown status: %s' % result)
226 else:
227- return True
228+ return email
229
230- def login(self, email, password, app_name):
231+ def login(self, email, password, token_name):
232 """Login a user with 'email' and 'password'."""
233- logger.debug('login: email: %r password: <hidden>, app_name: %r',
234- email, app_name)
235+ logger.debug('login: email: %r password: <hidden>, token_name: %r',
236+ email, token_name)
237 basic = BasicHttpAuthorizer(email, password)
238 sso_service = self.sso_service_class(basic, self.service_url)
239 service = sso_service.authentications.authenticate
240
241- token_name = get_token_name(app_name)
242 try:
243 credentials = service(token_name=token_name)
244 except HTTPError:
245@@ -218,16 +218,15 @@
246
247 logger.debug('login: authentication successful! consumer_key: %r, ' \
248 'token_name: %r', credentials['consumer_key'], token_name)
249- keyring_store_credentials(app_name, credentials)
250 return credentials
251
252- def validate_email(self, email, password, app_name, email_token):
253+ def validate_email(self, email, password, email_token, token_name):
254 """Validate an email token for user with 'email' and 'password'."""
255 logger.debug('validate_email: email: %r password: <hidden>, '
256- 'app_name: %r, email_token: %r',
257- email, app_name, email_token)
258+ 'email_token: %r, token_name: %r.',
259+ email, email_token, token_name)
260 token = self.login(email=email, password=password,
261- app_name=app_name)
262+ token_name=token_name)
263
264 oauth_token = OAuthToken(token['token'], token['token_secret'])
265 authorizer = OAuthAuthorizer(token['consumer_key'],
266@@ -239,7 +238,7 @@
267 if 'errors' in result:
268 raise EmailTokenError(result['errors'])
269 elif 'email' in result:
270- return True
271+ return result['email']
272 else:
273 raise EmailTokenError('Received invalid reply: %s' % result)
274
275@@ -254,7 +253,7 @@
276 raise ResetPasswordTokenError(e.content)
277
278 if result['status'] == 'ok':
279- return True
280+ return email
281 else:
282 raise ResetPasswordTokenError('Received invalid reply: %s' %
283 result)
284@@ -276,7 +275,7 @@
285 raise NewPasswordError(e.content)
286
287 if result['status'] == 'ok':
288- return True
289+ return email
290 else:
291 raise NewPasswordError('Received invalid reply: %s' % result)
292
293@@ -289,16 +288,16 @@
294 }
295
296
297-def blocking(f, result_cb, error_cb):
298+def blocking(f, app_name, result_cb, error_cb):
299 """Run f in a thread; return or throw an exception thru the callbacks."""
300 def _in_thread():
301 """The part that runs inside the thread."""
302 try:
303- result_cb(f())
304+ result_cb(app_name, f())
305 except Exception, e:
306 msg = "Exception while running DBus blocking code in a thread."""
307 logger.exception(msg)
308- error_cb(except_to_errdict(e))
309+ error_cb(app_name, except_to_errdict(e))
310 threading.Thread(target=_in_thread).start()
311
312
313@@ -320,119 +319,123 @@
314 sso_service_class=self.sso_service_class)
315
316 # generate_capcha signals
317- @dbus.service.signal(DBUS_IFACE_USER_NAME, signature="s")
318- def CaptchaGenerated(self, result):
319+ @dbus.service.signal(DBUS_IFACE_USER_NAME, signature="ss")
320+ def CaptchaGenerated(self, app_name, result):
321 """Signal thrown after the captcha is generated."""
322
323- @dbus.service.signal(DBUS_IFACE_USER_NAME, signature="a{ss}")
324- def CaptchaGenerationError(self, error):
325+ @dbus.service.signal(DBUS_IFACE_USER_NAME, signature="sa{ss}")
326+ def CaptchaGenerationError(self, app_name, error):
327 """Signal thrown when there's a problem generating the captcha."""
328
329 @dbus.service.method(dbus_interface=DBUS_IFACE_USER_NAME,
330- in_signature='s')
331- def generate_captcha(self, filename):
332+ in_signature='ss')
333+ def generate_captcha(self, app_name, filename):
334 """Call the matching method in the processor."""
335 def f():
336 """Inner function that will be run in a thread."""
337 return self.processor().generate_captcha(filename)
338- blocking(f, self.CaptchaGenerated, self.CaptchaGenerationError)
339+ blocking(f, app_name, self.CaptchaGenerated,
340+ self.CaptchaGenerationError)
341
342 # register_user signals
343- @dbus.service.signal(DBUS_IFACE_USER_NAME, signature="b")
344- def UserRegistered(self, result):
345+ @dbus.service.signal(DBUS_IFACE_USER_NAME, signature="ss")
346+ def UserRegistered(self, app_name, result):
347 """Signal thrown when the user is registered."""
348
349- @dbus.service.signal(DBUS_IFACE_USER_NAME, signature="a{ss}")
350- def UserRegistrationError(self, error):
351+ @dbus.service.signal(DBUS_IFACE_USER_NAME, signature="sa{ss}")
352+ def UserRegistrationError(self, app_name, error):
353 """Signal thrown when there's a problem registering the user."""
354
355 @dbus.service.method(dbus_interface=DBUS_IFACE_USER_NAME,
356- in_signature='ssss')
357- def register_user(self, email, password, captcha_id, captcha_solution):
358+ in_signature='sssss')
359+ def register_user(self, app_name, email, password,
360+ captcha_id, captcha_solution):
361 """Call the matching method in the processor."""
362 def f():
363 """Inner function that will be run in a thread."""
364 return self.processor().register_user(email, password,
365- captcha_id, captcha_solution)
366- blocking(f, self.UserRegistered, self.UserRegistrationError)
367+ captcha_id, captcha_solution)
368+ blocking(f, app_name, self.UserRegistered, self.UserRegistrationError)
369
370 # login signals
371- @dbus.service.signal(DBUS_IFACE_USER_NAME, signature="s")
372- def LoggedIn(self, result):
373+ @dbus.service.signal(DBUS_IFACE_USER_NAME, signature="ss")
374+ def LoggedIn(self, app_name, result):
375 """Signal thrown when the user is logged in."""
376
377- @dbus.service.signal(DBUS_IFACE_USER_NAME, signature="a{ss}")
378- def LoginError(self, error):
379+ @dbus.service.signal(DBUS_IFACE_USER_NAME, signature="sa{ss}")
380+ def LoginError(self, app_name, error):
381 """Signal thrown when there is a problem in the login."""
382
383 @dbus.service.method(dbus_interface=DBUS_IFACE_USER_NAME,
384 in_signature='sss')
385- def login(self, email, password, app_name):
386+ def login(self, app_name, email, password):
387 """Call the matching method in the processor."""
388 def f():
389 """Inner function that will be run in a thread."""
390- credentials = self.processor().login(email, password, app_name)
391+ token_name = get_token_name(app_name)
392+ credentials = self.processor().login(email, password, token_name)
393 assert credentials is not None
394- return app_name
395- blocking(f, self.LoggedIn, self.LoginError)
396+ keyring_store_credentials(app_name, credentials)
397+ return email
398+ blocking(f, app_name, self.LoggedIn, self.LoginError)
399
400 # validate_email signals
401- @dbus.service.signal(DBUS_IFACE_USER_NAME, signature="s")
402- def EmailValidated(self, app_name):
403+ @dbus.service.signal(DBUS_IFACE_USER_NAME, signature="ss")
404+ def EmailValidated(self, app_name, result):
405 """Signal thrown after the email is validated."""
406
407- @dbus.service.signal(DBUS_IFACE_USER_NAME, signature="a{ss}")
408- def EmailValidationError(self, error):
409+ @dbus.service.signal(DBUS_IFACE_USER_NAME, signature="sa{ss}")
410+ def EmailValidationError(self, app_name, error):
411 """Signal thrown when there's a problem validating the email."""
412
413 @dbus.service.method(dbus_interface=DBUS_IFACE_USER_NAME,
414 in_signature='ssss')
415- def validate_email(self, email, password, app_name, email_token):
416+ def validate_email(self, app_name, email, password, email_token):
417 """Call the matching method in the processor."""
418 def f():
419 """Inner function that will be run in a thread."""
420- self.processor().validate_email(email, password,
421- app_name, email_token)
422- return app_name
423- blocking(f, self.EmailValidated, self.EmailValidationError)
424+ token_name = get_token_name(app_name)
425+ return self.processor().validate_email(email, password,
426+ email_token, token_name)
427+ blocking(f, app_name, self.EmailValidated, self.EmailValidationError)
428
429 # request_password_reset_token signals
430- @dbus.service.signal(DBUS_IFACE_USER_NAME, signature="s")
431- def PasswordResetTokenSent(self, email):
432+ @dbus.service.signal(DBUS_IFACE_USER_NAME, signature="ss")
433+ def PasswordResetTokenSent(self, app_name, email):
434 """Signal thrown when the token is succesfully sent."""
435
436- @dbus.service.signal(DBUS_IFACE_USER_NAME, signature="a{ss}")
437- def PasswordResetError(self, error):
438+ @dbus.service.signal(DBUS_IFACE_USER_NAME, signature="sa{ss}")
439+ def PasswordResetError(self, app_name, error):
440 """Signal thrown when there's a problem sending the token."""
441
442 @dbus.service.method(dbus_interface=DBUS_IFACE_USER_NAME,
443- in_signature='s')
444- def request_password_reset_token(self, email):
445+ in_signature='ss')
446+ def request_password_reset_token(self, app_name, email):
447 """Call the matching method in the processor."""
448 def f():
449 """Inner function that will be run in a thread."""
450- self.processor().request_password_reset_token(email)
451- return email
452- blocking(f, self.PasswordResetTokenSent, self.PasswordResetError)
453+ return self.processor().request_password_reset_token(email)
454+ blocking(f, app_name, self.PasswordResetTokenSent,
455+ self.PasswordResetError)
456
457 # set_new_password signals
458- @dbus.service.signal(DBUS_IFACE_USER_NAME, signature="s")
459- def PasswordChanged(self, email):
460+ @dbus.service.signal(DBUS_IFACE_USER_NAME, signature="ss")
461+ def PasswordChanged(self, app_name, email):
462 """Signal thrown when the token is succesfully sent."""
463
464- @dbus.service.signal(DBUS_IFACE_USER_NAME, signature="a{ss}")
465- def PasswordChangeError(self, error):
466+ @dbus.service.signal(DBUS_IFACE_USER_NAME, signature="sa{ss}")
467+ def PasswordChangeError(self, app_name, error):
468 """Signal thrown when there's a problem sending the token."""
469
470 @dbus.service.method(dbus_interface=DBUS_IFACE_USER_NAME,
471- in_signature='sss')
472- def set_new_password(self, email, token, new_password):
473+ in_signature='ssss')
474+ def set_new_password(self, app_name, email, token, new_password):
475 """Call the matching method in the processor."""
476 def f():
477 """Inner function that will be run in a thread."""
478- self.processor().set_new_password(email, token, new_password)
479- return email
480- blocking(f, self.PasswordChanged, self.PasswordChangeError)
481+ return self.processor().set_new_password(email, token,
482+ new_password)
483+ blocking(f, app_name, self.PasswordChanged, self.PasswordChangeError)
484
485
486 class SSOCredentials(dbus.service.Object):
487@@ -460,8 +463,9 @@
488 else:
489 return token
490
491- def _login_success_cb(self, dialog, app_name):
492+ def _login_success_cb(self, dialog, app_name, email):
493 """Handles the response from the UI dialog."""
494+ logger.info('Login successful for app %r, email %r', app_name, email)
495 try:
496 creds = keyring_get_credentials(app_name)
497 self.CredentialsFound(app_name, creds)
498@@ -470,16 +474,21 @@
499 logger.exception(msg)
500 self.CredentialsError(app_name, msg, traceback.format_exc())
501
502- def _login_error_cb(self, dialog, app_name):
503+ def _login_error_cb(self, dialog, app_name, error):
504 """Handles a problem in the UI."""
505+ logger.info('Login unsuccessful for app %r, error %r', app_name, error)
506 msg = "Problem getting the credentials from the keyring."
507 self.CredentialsError(app_name, msg, "no more info available")
508- logger.error(msg)
509
510 def _login_auth_denied_cb(self, dialog, app_name):
511 """The user decides not to allow the registration or login."""
512 self.AuthorizationDenied(app_name)
513
514+ def _ping_url(self, dialog, app_name, email):
515+ """Ping the given url."""
516+ if app_name == U1_APP_NAME:
517+ urllib2.urlopen(PING_URL + email)
518+
519 def _show_login_or_register_ui(self, app_name, tc_url, help_text,
520 win_id, login_only=False):
521 """Shows the UI so the user can login or register."""
522@@ -487,9 +496,11 @@
523 gui_app = gui.UbuntuSSOClientGUI(app_name, tc_url,
524 help_text, win_id, login_only)
525 gui_app.connect(gui.SIG_LOGIN_SUCCEEDED, self._login_success_cb)
526+ gui_app.connect(gui.SIG_LOGIN_SUCCEEDED, self._ping_url)
527 gui_app.connect(gui.SIG_LOGIN_FAILED, self._login_error_cb)
528 gui_app.connect(gui.SIG_REGISTRATION_SUCCEEDED,
529 self._login_success_cb)
530+ gui_app.connect(gui.SIG_REGISTRATION_SUCCEEDED, self._ping_url)
531 gui_app.connect(gui.SIG_REGISTRATION_FAILED, self._login_error_cb)
532 gui_app.connect(gui.SIG_USER_CANCELATION,
533 self._login_auth_denied_cb)
534
535=== modified file 'ubuntu_sso/tests/test_gui.py'
536--- ubuntu_sso/tests/test_gui.py 2010-08-23 13:32:24 +0000
537+++ ubuntu_sso/tests/test_gui.py 2010-08-24 00:02:39 +0000
538@@ -44,6 +44,7 @@
539 CAPTCHA_SOLUTION = 'william Byrd'
540 EMAIL = 'test@example.com'
541 EMAIL_TOKEN = 'B2Pgtf'
542+ERROR = 'Something bad happened!'
543 NAME = 'Juanito Pérez'
544 PASSWORD = 'h3lloWorld'
545 RESET_PASSWORD_TOKEN = '8G5Wtq'
546@@ -358,7 +359,7 @@
547
548 def click_join_with_valid_data(self):
549 """Move to the next page after entering details."""
550- self.ui.on_captcha_generated(captcha_id=CAPTCHA_ID) # we have captcha!
551+ self.ui.on_captcha_generated(app_name=APP_NAME, captcha_id=CAPTCHA_ID)
552
553 self.ui.name_entry.set_text(NAME)
554 # match emails
555@@ -598,7 +599,8 @@
556 expected = 'register_user'
557 self.assertIn(expected, self.ui.backend._called)
558 self.assertEqual(self.ui.backend._called[expected],
559- ((EMAIL, PASSWORD, CAPTCHA_ID, CAPTCHA_SOLUTION),
560+ ((APP_NAME, EMAIL, PASSWORD, CAPTCHA_ID,
561+ CAPTCHA_SOLUTION),
562 dict(reply_handler=gui.NO_OP,
563 error_handler=gui.NO_OP)))
564
565@@ -678,18 +680,18 @@
566
567 def test_join_ok_button_is_enabled_when_captcha_is_available(self):
568 """The join_ok_button is sensitive when captcha is available."""
569- self.ui.on_captcha_generated(captcha_id=CAPTCHA_ID)
570+ self.ui.on_captcha_generated(app_name=APP_NAME, captcha_id=CAPTCHA_ID)
571 self.assertTrue(self.ui.join_ok_button.is_sensitive())
572
573 def test_captcha_loading_is_hid_when_captcha_is_available(self):
574 """The captcha_loading is hid when captcha is available."""
575- self.ui.on_captcha_generated(captcha_id=CAPTCHA_ID)
576+ self.ui.on_captcha_generated(app_name=APP_NAME, captcha_id=CAPTCHA_ID)
577 self.assertFalse(self.ui.captcha_loading.get_property('visible'),
578 'captcha_loading is not visible.')
579
580 def test_captcha_id_is_stored_when_captcha_is_available(self):
581 """The captcha_id is stored when captcha is available."""
582- self.ui.on_captcha_generated(captcha_id=CAPTCHA_ID)
583+ self.ui.on_captcha_generated(app_name=APP_NAME, captcha_id=CAPTCHA_ID)
584 self.assertEqual(CAPTCHA_ID, self.ui._captcha_id)
585
586 def test_captcha_image_is_requested_as_startup(self):
587@@ -698,14 +700,14 @@
588 expected = 'generate_captcha'
589 self.assertIn(expected, self.ui.backend._called)
590 self.assertEqual(self.ui.backend._called[expected],
591- ((self.ui._captcha_filename,),
592+ ((APP_NAME, self.ui._captcha_filename),
593 dict(reply_handler=gui.NO_OP,
594 error_handler=gui.NO_OP)))
595
596 def test_captcha_is_shown_when_available(self):
597 """The captcha image is shown when available."""
598 self.patch(self.ui.captcha_image, 'set_from_file', self._set_called)
599- self.ui.on_captcha_generated(captcha_id=CAPTCHA_ID)
600+ self.ui.on_captcha_generated(app_name=APP_NAME, captcha_id=CAPTCHA_ID)
601 self.assertTrue(self.ui.captcha_image.get_property('visible'))
602 self.assertEqual(self._called, ((self.ui._captcha_filename,), {}))
603
604@@ -770,7 +772,7 @@
605 """Init."""
606 super(UserRegistrationErrorTestCase, self).setUp()
607 self.click_join_with_valid_data()
608- self.ui.on_user_registration_error()
609+ self.ui.on_user_registration_error(app_name=APP_NAME, error=ERROR)
610
611 def test_previous_page_is_shown(self):
612 """On UserRegistrationError the previous page is shown."""
613@@ -788,6 +790,7 @@
614 def setUp(self):
615 """Init."""
616 super(VerifyEmailTestCase, self).setUp()
617+ self.ui.on_user_registered(app_name=APP_NAME, email=EMAIL)
618 self.click_verify_email_with_valid_data()
619
620 def test_verify_email_image_is_correct(self):
621@@ -798,12 +801,11 @@
622
623 def test_registration_successful_shows_verify_email_vbox(self):
624 """Receiving 'registration_successful' shows the verify email vbox."""
625- self.ui.on_user_registered()
626+ self.ui.on_user_registered(app_name=APP_NAME, email=EMAIL)
627 self.assert_pages_visibility(verify_email=True)
628
629 def test_help_label_display_correct_wording(self):
630 """The help_label display VERIFY_EMAIL_LABEL."""
631- self.ui.on_user_registered()
632 msg = 'help_label must read "%s" (got "%s" instead).'
633 actual = self.ui.help_label.get_text()
634 expected = self.ui.VERIFY_EMAIL_LABEL
635@@ -815,7 +817,7 @@
636 expected = 'validate_email'
637 self.assertIn(expected, self.ui.backend._called)
638 self.assertEqual(self.ui.backend._called[expected],
639- ((EMAIL, PASSWORD, APP_NAME, EMAIL_TOKEN),
640+ ((APP_NAME, EMAIL, PASSWORD, EMAIL_TOKEN),
641 dict(reply_handler=gui.NO_OP,
642 error_handler=gui.NO_OP)))
643
644@@ -832,18 +834,18 @@
645
646 def test_on_email_validated_shows_success_page(self):
647 """On email validated the success page is shown."""
648- self.ui.on_email_validated(APP_NAME)
649+ self.ui.on_email_validated(app_name=APP_NAME, email=EMAIL)
650 self.assert_pages_visibility(success=True)
651
652 def test_on_email_validated_clears_the_help_text(self):
653 """On email validated the help text is removed."""
654- self.ui.on_email_validated(APP_NAME)
655+ self.ui.on_email_validated(app_name=APP_NAME, email=EMAIL)
656 self.assertEqual('', self.ui.help_label.get_text())
657 test_on_email_validated_clears_the_help_text.skip = 'Maybe this is wrong.'
658
659 def test_on_email_validation_error_verify_email_is_shown(self):
660 """On email validation error, the verify_email page is shown."""
661- self.ui.on_email_validation_error()
662+ self.ui.on_email_validation_error(app_name=APP_NAME, error=ERROR)
663 self.assert_pages_visibility(verify_email=True)
664 self.assert_correct_warning(self.ui.warning_label,
665 self.ui.UNKNOWN_ERROR)
666@@ -1033,7 +1035,7 @@
667 expected = 'login'
668 self.assertIn(expected, self.ui.backend._called)
669 self.assertEqual(self.ui.backend._called[expected],
670- ((EMAIL, PASSWORD, APP_NAME),
671+ ((APP_NAME, EMAIL, PASSWORD),
672 dict(reply_handler=gui.NO_OP,
673 error_handler=gui.NO_OP)))
674
675@@ -1045,26 +1047,26 @@
676 def test_on_logged_in_morphs_to_success_page(self):
677 """When user logged in the success page is shown."""
678 self.click_connect_with_valid_data()
679- self.ui.on_logged_in(APP_NAME)
680+ self.ui.on_logged_in(app_name=APP_NAME, email=EMAIL)
681 self.assert_pages_visibility(success=True)
682
683 def test_on_login_error_morphs_to_login_page(self):
684 """On user login error, the previous page is shown."""
685 self.click_connect_with_valid_data()
686- self.ui.on_login_error()
687+ self.ui.on_login_error(app_name=APP_NAME, error=ERROR)
688 self.assert_pages_visibility(login=True)
689
690 def test_on_login_error_a_warning_is_shown(self):
691 """On user login error, a warning is shown with proper wording."""
692 self.click_connect_with_valid_data()
693- self.ui.on_login_error()
694+ self.ui.on_login_error(app_name=APP_NAME, error=ERROR)
695 self.assert_correct_warning(self.ui.warning_label,
696 self.ui.UNKNOWN_ERROR)
697
698 def test_back_to_registration_hides_warning(self):
699 """After user login error, warning is hidden when clicking 'Back'."""
700 self.click_connect_with_valid_data()
701- self.ui.on_login_error()
702+ self.ui.on_login_error(app_name=APP_NAME, error=ERROR)
703 self.ui.login_back_button.clicked()
704 self.assertFalse(self.ui.warning_label.get_property('visible'))
705
706@@ -1188,20 +1190,20 @@
707 expected = 'request_password_reset_token'
708 self.assertIn(expected, self.ui.backend._called)
709 self.assertEqual(self.ui.backend._called[expected],
710- ((EMAIL,),
711+ ((APP_NAME, EMAIL),
712 dict(reply_handler=gui.NO_OP,
713 error_handler=gui.NO_OP)))
714
715 def test_on_password_reset_token_sent_morphs_window(self):
716 """When the reset token was sent, the reset password page is shown."""
717 self.click_request_password_token_with_valid_data()
718- self.ui.on_password_reset_token_sent(email=EMAIL)
719+ self.ui.on_password_reset_token_sent(app_name=APP_NAME, email=EMAIL)
720 self.assert_pages_visibility(set_new_password=True)
721
722 def test_on_password_reset_token_sent_help_text(self):
723 """Clicking request_password_token_ok_button changes the help text."""
724 self.click_request_password_token_with_valid_data()
725- self.ui.on_password_reset_token_sent(email=EMAIL)
726+ self.ui.on_password_reset_token_sent(app_name=APP_NAME, email=EMAIL)
727
728 self.assertEqual(self.ui.help_label.get_text(),
729 self.ui.SET_NEW_PASSWORD_LABEL % {'email': EMAIL})
730@@ -1209,14 +1211,14 @@
731 def test_on_password_reset_token_sent_ok_button(self):
732 """After request_password_token_ok_button the ok button is updated."""
733 self.click_request_password_token_with_valid_data()
734- self.ui.on_password_reset_token_sent(email=EMAIL)
735+ self.ui.on_password_reset_token_sent(app_name=APP_NAME, email=EMAIL)
736
737 self.assertEqual(self.ui.set_new_password_ok_button.get_label(),
738 self.ui.RESET_PASSWORD)
739
740 def test_on_password_reset_error_shows_login_page(self):
741 """When reset token wasn't successfuly sent the login page is shown."""
742- self.ui.on_password_reset_error()
743+ self.ui.on_password_reset_error(app_name=APP_NAME, error=ERROR)
744 self.assert_correct_warning(self.ui.warning_label,
745 self.ui.UNKNOWN_ERROR)
746 self.assert_pages_visibility(login=True)
747@@ -1229,7 +1231,7 @@
748 """Init."""
749 super(SetNewPasswordTestCase, self).setUp()
750 self.click_request_password_token_with_valid_data()
751- self.ui.on_password_reset_token_sent(email=EMAIL)
752+ self.ui.on_password_reset_token_sent(app_name=APP_NAME, email=EMAIL)
753
754 def test_on_set_new_password_ok_button_disabled(self):
755 """The set_new_password_ok_button is disabled until values added."""
756@@ -1260,20 +1262,20 @@
757 expected = 'set_new_password'
758 self.assertIn(expected, self.ui.backend._called)
759 self.assertEqual(self.ui.backend._called[expected],
760- ((EMAIL, RESET_PASSWORD_TOKEN, PASSWORD),
761+ ((APP_NAME, EMAIL, RESET_PASSWORD_TOKEN, PASSWORD),
762 dict(reply_handler=gui.NO_OP,
763 error_handler=gui.NO_OP)))
764
765 def test_on_password_changed_shows_success_page(self):
766 """When password was successfuly changed the success page is shown."""
767- self.ui.on_password_changed(EMAIL)
768+ self.ui.on_password_changed(app_name=APP_NAME, email=EMAIL)
769 self.assert_correct_warning(self.ui.warning_label,
770 self.ui.PASSWORD_CHANGED)
771 self.assert_pages_visibility(login=True)
772
773 def test_on_password_change_error_shows_login_page(self):
774 """When password wasn't changed the reset password page is shown."""
775- self.ui.on_password_change_error()
776+ self.ui.on_password_change_error(app_name=APP_NAME, error=ERROR)
777 self.assert_correct_warning(self.ui.warning_label,
778 self.ui.UNKNOWN_ERROR)
779 self.assert_pages_visibility(request_password_token=True)
780@@ -1353,46 +1355,46 @@
781
782 def test_on_user_registration_error_proper_signal_is_emitted(self):
783 """On UserRegistrationError, 'registration-failed' signal is sent."""
784- self.ui.on_user_registration_error()
785+ self.ui.on_user_registration_error(app_name=APP_NAME, error=ERROR)
786 self.ui.on_close_clicked()
787- self.assertEqual((self.ui.window, (APP_NAME,), {}),
788+ self.assertEqual((self.ui.window, (APP_NAME, ERROR), {}),
789 self._called[gui.SIG_REGISTRATION_FAILED])
790
791 def test_on_email_validated_proper_signals_is_emitted(self):
792 """On EmailValidated, 'registration-succeeded' signal is sent."""
793- self.ui.on_email_validated(APP_NAME)
794+ self.ui.on_email_validated(app_name=APP_NAME, email=EMAIL)
795 self.ui.on_close_clicked()
796- self.assertEqual((self.ui.window, (APP_NAME,), {}),
797+ self.assertEqual((self.ui.window, (APP_NAME, EMAIL), {}),
798 self._called[gui.SIG_REGISTRATION_SUCCEEDED])
799
800 def test_on_email_validation_error_proper_signals_is_emitted(self):
801 """On EmailValidationError, 'registration-failed' signal is sent."""
802- self.ui.on_email_validation_error()
803+ self.ui.on_email_validation_error(app_name=APP_NAME, error=ERROR)
804 self.ui.on_close_clicked()
805- self.assertEqual((self.ui.window, (APP_NAME,), {}),
806+ self.assertEqual((self.ui.window, (APP_NAME, ERROR), {}),
807 self._called[gui.SIG_REGISTRATION_FAILED])
808
809 def test_on_logged_in_proper_signals_is_emitted(self):
810 """On LoggedIn, 'login-succeeded' signal is sent."""
811- self.ui.on_logged_in(APP_NAME)
812+ self.ui.on_logged_in(app_name=APP_NAME, email=EMAIL)
813 self.ui.on_close_clicked()
814- self.assertEqual((self.ui.window, (APP_NAME,), {}),
815+ self.assertEqual((self.ui.window, (APP_NAME, EMAIL), {}),
816 self._called[gui.SIG_LOGIN_SUCCEEDED])
817
818 def test_on_login_error_proper_signals_is_emitted(self):
819 """On LoginError, 'login-failed' signal is sent."""
820 self.click_connect_with_valid_data()
821- self.ui.on_login_error()
822+ self.ui.on_login_error(app_name=APP_NAME, error=ERROR)
823 self.ui.on_close_clicked()
824- self.assertEqual((self.ui.window, (APP_NAME,), {}),
825+ self.assertEqual((self.ui.window, (APP_NAME, ERROR), {}),
826 self._called[gui.SIG_LOGIN_FAILED])
827
828 def test_registration_successfull_even_if_prior_registration_error(self):
829 """Only one signal is sent with the final outcome."""
830 self.click_join_with_valid_data()
831- self.ui.on_user_registration_error()
832+ self.ui.on_user_registration_error(app_name=APP_NAME, error=ERROR)
833 self.click_join_with_valid_data()
834- self.ui.on_email_validated(APP_NAME)
835+ self.ui.on_email_validated(app_name=APP_NAME, email=EMAIL)
836 self.ui.on_close_clicked()
837
838 self.assertEqual(len(self._called), 1)
839@@ -1401,9 +1403,9 @@
840 def test_login_successfull_even_if_prior_login_error(self):
841 """Only one signal is sent with the final outcome."""
842 self.click_connect_with_valid_data()
843- self.ui.on_login_error()
844+ self.ui.on_login_error(app_name=APP_NAME, error=ERROR)
845 self.click_connect_with_valid_data()
846- self.ui.on_logged_in(APP_NAME)
847+ self.ui.on_logged_in(app_name=APP_NAME, email=EMAIL)
848 self.ui.on_close_clicked()
849
850 self.assertEqual(len(self._called), 1)
851@@ -1412,7 +1414,7 @@
852 def test_user_cancelation_even_if_prior_registration_error(self):
853 """Only one signal is sent with the final outcome."""
854 self.click_join_with_valid_data()
855- self.ui.on_user_registration_error()
856+ self.ui.on_user_registration_error(app_name=APP_NAME, error=ERROR)
857 self.ui.join_cancel_button.clicked()
858
859 self.assertEqual(len(self._called), 1)
860@@ -1421,7 +1423,7 @@
861 def test_user_cancelation_even_if_prior_login_error(self):
862 """Only one signal is sent with the final outcome."""
863 self.click_connect_with_valid_data()
864- self.ui.on_login_error()
865+ self.ui.on_login_error(app_name=APP_NAME, error=ERROR)
866 self.ui.login_cancel_button.clicked()
867
868 self.assertEqual(len(self._called), 1)
869
870=== modified file 'ubuntu_sso/tests/test_main.py'
871--- ubuntu_sso/tests/test_main.py 2010-08-23 19:23:40 +0000
872+++ ubuntu_sso/tests/test_main.py 2010-08-24 00:02:39 +0000
873@@ -22,6 +22,7 @@
874 import logging
875 import os
876 import StringIO
877+import urllib2
878
879 import gobject
880
881@@ -36,10 +37,13 @@
882 from ubuntu_sso import config, gui
883 from ubuntu_sso.main import (
884 AuthenticationError, BadRealmError, blocking, EmailTokenError,
885- InvalidEmailError, InvalidPasswordError, SSOLogin, SSOCredentials,
886- get_token_name, keyring_get_credentials, keyring_store_credentials, logger,
887- LoginProcessor, NewPasswordError, SSOLoginProcessor, RegistrationError,
888- ResetPasswordTokenError, OLD_KEY_NAME, U1_APP_NAME, except_to_errdict)
889+ except_to_errdict, get_token_name,
890+ InvalidEmailError, InvalidPasswordError,
891+ keyring_get_credentials, keyring_store_credentials, logger,
892+ LoginProcessor, NewPasswordError, OLD_KEY_NAME, PING_URL,
893+ RegistrationError, ResetPasswordTokenError,
894+ SSOCredentials, SSOLogin, SSOLoginProcessor,
895+ U1_APP_NAME)
896
897
898 APP_NAME = 'The Coolest App Ever'
899@@ -60,15 +64,17 @@
900 u'name': u'test',
901 u'token': u'GkInOfSMGwTXAUoVQwLUoPxElEEUdhsLVNTPhxHJDUIeHCPNEo',
902 u'token_secret': u'qFYImEtlczPbsCnYyuwLoPDlPEnvNcIktZphPQklAWrvyfFMV'}
903+TOKEN_NAME = get_token_name(APP_NAME)
904 STATUS_UNKNOWN = {'status': 'yadda-yadda'}
905 STATUS_ERROR = {'status': 'error', 'errors': {'something': ['Bla', 'Ble']}}
906 STATUS_OK = {'status': 'ok'}
907 STATUS_EMAIL_UNKNOWN = {'status': 'yadda-yadda'}
908 STATUS_EMAIL_ERROR = {'errors': {'email_token': ['Error1', 'Error2']}}
909-STATUS_EMAIL_OK = {'email': 'okmail@okserver.okdomain'}
910+STATUS_EMAIL_OK = {'email': EMAIL}
911 TC_URL = 'tcurl'
912 WINDOW_ID = 5
913
914+NO_OP = lambda *args, **kwargs: None
915 LOGIN_OR_REGISTER_ARGS = (APP_NAME, TC_URL, HELP, WINDOW_ID)
916 LOGIN_OR_REGISTER_GUI_ARGS = LOGIN_OR_REGISTER_ARGS + (False,)
917 LOGIN_ONLY_ARGS = (APP_NAME, HELP, WINDOW_ID)
918@@ -120,7 +126,7 @@
919
920 def authenticate(self, token_name):
921 """Fake authenticate. Return a fix result."""
922- if not token_name.startswith(get_token_name(APP_NAME)):
923+ if not token_name.startswith(TOKEN_NAME):
924 raise HTTPError(response=None, content=None)
925 else:
926 return TOKEN
927@@ -159,13 +165,7 @@
928 captcha_id=CAPTCHA_ID,
929 captcha_solution=CAPTCHA_SOLUTION)
930 self.login_kwargs = dict(email=EMAIL, password=PASSWORD,
931- app_name=APP_NAME)
932-
933- def ksc(k, v):
934- self.assertEqual(k, APP_NAME)
935- self.assertEqual(v, TOKEN)
936-
937- self.patch(ubuntu_sso.main, "keyring_store_credentials", ksc)
938+ token_name=TOKEN_NAME)
939
940 def tearDown(self):
941 """Clean up."""
942@@ -215,7 +215,7 @@
943 def test_register_user_if_status_ok(self):
944 """A user is succesfuy registered into the SSO server."""
945 result = self.processor.register_user(**self.register_kwargs)
946- self.assertTrue(result, 'registration was successful.')
947+ self.assertEqual(EMAIL, result, 'registration was successful.')
948
949 def test_register_user_if_status_error(self):
950 """Proper error is raised if register fails."""
951@@ -238,7 +238,7 @@
952
953 def test_login_if_http_error(self):
954 """Proper error is raised if authentication fails."""
955- self.login_kwargs['app_name'] = APP_NAME * 2 # invalid token name
956+ self.login_kwargs['token_name'] = APP_NAME * 2 # invalid token name
957 self.assertRaises(AuthenticationError,
958 self.processor.login, **self.login_kwargs)
959
960@@ -253,7 +253,7 @@
961 """A email is succesfuy validated in the SSO server."""
962 self.login_kwargs['email_token'] = EMAIL_TOKEN # valid email token
963 result = self.processor.validate_email(**self.login_kwargs)
964- self.assertTrue(result, 'email validation was successful.')
965+ self.assertEqual(EMAIL, result, 'email validation was successful.')
966
967 def test_validate_email_if_status_error(self):
968 """Proper error is raised if email validation fails."""
969@@ -276,7 +276,8 @@
970 def test_request_password_reset_token_if_status_ok(self):
971 """A reset password token is succesfuly sent."""
972 result = self.processor.request_password_reset_token(email=EMAIL)
973- self.assertTrue(result, 'password reset token must be successful.')
974+ self.assertEqual(EMAIL, result,
975+ 'password reset token must be successful.')
976
977 def test_request_password_reset_token_if_http_error(self):
978 """Proper error is raised if password token request fails."""
979@@ -297,7 +298,8 @@
980 result = self.processor.set_new_password(email=EMAIL,
981 token=RESET_PASSWORD_TOKEN,
982 new_password=PASSWORD)
983- self.assertTrue(result, 'new password must be set successfully.')
984+ self.assertEqual(EMAIL, result,
985+ 'new password must be set successfully.')
986
987 def test_set_new_password_if_http_error(self):
988 """Proper error is raised if setting a new password fails."""
989@@ -399,19 +401,26 @@
990 self.mocker.result(mockbus)
991 mockbus._register_object_path(ARGS)
992
993+ def ksc(k, v):
994+ """Assert over token and app_name."""
995+ self.assertEqual(k, APP_NAME)
996+ self.assertEqual(v, TOKEN)
997+
998+ self.patch(ubuntu_sso.main, "keyring_store_credentials", ksc)
999+
1000 def tearDown(self):
1001 """Verify the mocking bus and shut it down."""
1002 self.mocker.verify()
1003 self.mocker.restore()
1004
1005- def fake_ok_blocking(self, f, cb, eb):
1006+ def fake_ok_blocking(self, f, a, cb, eb):
1007 """A fake blocking function that succeeds."""
1008- cb(f())
1009+ cb(a, f())
1010
1011- def fake_err_blocking(self, f, cb, eb):
1012+ def fake_err_blocking(self, f, a, cb, eb):
1013 """A fake blocking function that fails."""
1014 f()
1015- eb(except_to_errdict(BlockingSampleException()))
1016+ eb(a, except_to_errdict(BlockingSampleException()))
1017
1018 def test_creation(self):
1019 """Test that the object creation is successful."""
1020@@ -436,15 +445,16 @@
1021 self.patch(ubuntu_sso.main, "blocking", self.fake_ok_blocking)
1022 self.mocker.replay()
1023
1024- def verify(result):
1025+ def verify(app_name, result):
1026 self.assertEqual(result, expected_result)
1027+ self.assertEqual(app_name, APP_NAME)
1028 d.callback(result)
1029
1030 client = SSOLogin(self.mockbusname,
1031 sso_login_processor_class=self.mockprocessorclass)
1032 self.patch(client, "CaptchaGenerated", verify)
1033 self.patch(client, "CaptchaGenerationError", d.errback)
1034- client.generate_captcha(filename)
1035+ client.generate_captcha(APP_NAME, filename)
1036 return d
1037
1038 def test_generate_captcha_error(self):
1039@@ -457,15 +467,16 @@
1040 self.patch(ubuntu_sso.main, "blocking", self.fake_err_blocking)
1041 self.mocker.replay()
1042
1043- def verify(errdict):
1044+ def verify(app_name, errdict):
1045 self.assertEqual(errdict["errtype"], "BlockingSampleException")
1046+ self.assertEqual(app_name, APP_NAME)
1047 d.callback("Ok")
1048
1049 client = SSOLogin(self.mockbusname,
1050 sso_login_processor_class=self.mockprocessorclass)
1051 self.patch(client, "CaptchaGenerated", d.errback)
1052 self.patch(client, "CaptchaGenerationError", verify)
1053- client.generate_captcha(filename)
1054+ client.generate_captcha(APP_NAME, filename)
1055 return d
1056
1057 def test_register_user(self):
1058@@ -478,15 +489,17 @@
1059 self.patch(ubuntu_sso.main, "blocking", self.fake_ok_blocking)
1060 self.mocker.replay()
1061
1062- def verify(result):
1063+ def verify(app_name, result):
1064 self.assertEqual(result, expected_result)
1065+ self.assertEqual(app_name, APP_NAME)
1066 d.callback(result)
1067
1068 client = SSOLogin(self.mockbusname,
1069 sso_login_processor_class=self.mockprocessorclass)
1070 self.patch(client, "UserRegistered", verify)
1071 self.patch(client, "UserRegistrationError", d.errback)
1072- client.register_user(EMAIL, PASSWORD, CAPTCHA_ID, CAPTCHA_SOLUTION)
1073+ client.register_user(APP_NAME, EMAIL, PASSWORD, CAPTCHA_ID,
1074+ CAPTCHA_SOLUTION)
1075 return d
1076
1077 def test_register_user_error(self):
1078@@ -499,47 +512,49 @@
1079 self.patch(ubuntu_sso.main, "blocking", self.fake_err_blocking)
1080 self.mocker.replay()
1081
1082- def verify(errdict):
1083+ def verify(app_name, errdict):
1084 self.assertEqual(errdict["errtype"], "BlockingSampleException")
1085+ self.assertEqual(app_name, APP_NAME)
1086 d.callback("Ok")
1087
1088 client = SSOLogin(self.mockbusname,
1089 sso_login_processor_class=self.mockprocessorclass)
1090 self.patch(client, "UserRegistered", d.errback)
1091 self.patch(client, "UserRegistrationError", verify)
1092- client.register_user(EMAIL, PASSWORD, CAPTCHA_ID, CAPTCHA_SOLUTION)
1093+ client.register_user(APP_NAME, EMAIL, PASSWORD, CAPTCHA_ID,
1094+ CAPTCHA_SOLUTION)
1095 return d
1096
1097 def test_login(self):
1098 """Test that the login method works ok."""
1099 d = Deferred()
1100- sample_result = {"sample": "tokens"}
1101- self.create_mock_processor().login(EMAIL, PASSWORD, APP_NAME)
1102- self.mocker.result(sample_result)
1103+ self.create_mock_processor().login(EMAIL, PASSWORD, TOKEN_NAME)
1104+ self.mocker.result(TOKEN)
1105 self.patch(ubuntu_sso.main, "blocking", self.fake_ok_blocking)
1106 self.mocker.replay()
1107
1108- def verify(result):
1109- self.assertEqual(result, APP_NAME)
1110+ def verify(app_name, result):
1111+ self.assertEqual(result, EMAIL)
1112+ self.assertEqual(app_name, APP_NAME)
1113 d.callback(result)
1114
1115 client = SSOLogin(self.mockbusname,
1116 sso_login_processor_class=self.mockprocessorclass)
1117 self.patch(client, "LoggedIn", verify)
1118 self.patch(client, "LoginError", d.errback)
1119- client.login(EMAIL, PASSWORD, APP_NAME)
1120+ client.login(APP_NAME, EMAIL, PASSWORD)
1121 return d
1122
1123 def test_login_error(self):
1124 """Test that the login method fails as expected."""
1125 d = Deferred()
1126- expected_result = "expected result"
1127- self.create_mock_processor().login(EMAIL, PASSWORD, APP_NAME)
1128- self.mocker.result(expected_result)
1129+ self.create_mock_processor().login(EMAIL, PASSWORD, TOKEN_NAME)
1130+ self.mocker.result(TOKEN)
1131 self.patch(ubuntu_sso.main, "blocking", self.fake_err_blocking)
1132 self.mocker.replay()
1133
1134- def verify(errdict):
1135+ def verify(app_name, errdict):
1136+ self.assertEqual(app_name, APP_NAME)
1137 self.assertEqual(errdict["errtype"], "BlockingSampleException")
1138 d.callback("Ok")
1139
1140@@ -547,27 +562,28 @@
1141 sso_login_processor_class=self.mockprocessorclass)
1142 self.patch(client, "LoggedIn", d.errback)
1143 self.patch(client, "LoginError", verify)
1144- client.login(EMAIL, PASSWORD, APP_NAME)
1145+ client.login(APP_NAME, EMAIL, PASSWORD)
1146 return d
1147
1148 def test_validate_email(self):
1149 """Test that the validate_email method works ok."""
1150 d = Deferred()
1151 self.create_mock_processor().validate_email(EMAIL, PASSWORD,
1152- APP_NAME, EMAIL_TOKEN)
1153- self.mocker.result(APP_NAME)
1154+ EMAIL_TOKEN, TOKEN_NAME)
1155+ self.mocker.result(EMAIL)
1156 self.patch(ubuntu_sso.main, "blocking", self.fake_ok_blocking)
1157 self.mocker.replay()
1158
1159- def verify(result):
1160- self.assertEqual(result, APP_NAME)
1161+ def verify(app_name, result):
1162+ self.assertEqual(result, EMAIL)
1163+ self.assertEqual(app_name, APP_NAME)
1164 d.callback(result)
1165
1166 client = SSOLogin(self.mockbusname,
1167 sso_login_processor_class=self.mockprocessorclass)
1168 self.patch(client, "EmailValidated", verify)
1169 self.patch(client, "EmailValidationError", d.errback)
1170- client.validate_email(EMAIL, PASSWORD, APP_NAME, EMAIL_TOKEN)
1171+ client.validate_email(APP_NAME, EMAIL, PASSWORD, EMAIL_TOKEN)
1172 return d
1173
1174 def test_validate_email_error(self):
1175@@ -576,12 +592,13 @@
1176 expected_result = "expected result"
1177
1178 self.create_mock_processor().validate_email(EMAIL, PASSWORD,
1179- APP_NAME, EMAIL_TOKEN)
1180+ EMAIL_TOKEN, TOKEN_NAME)
1181 self.mocker.result(expected_result)
1182 self.patch(ubuntu_sso.main, "blocking", self.fake_err_blocking)
1183 self.mocker.replay()
1184
1185- def verify(errdict):
1186+ def verify(app_name, errdict):
1187+ self.assertEqual(app_name, APP_NAME)
1188 self.assertEqual(errdict["errtype"], "BlockingSampleException")
1189 d.callback("Ok")
1190
1191@@ -589,7 +606,7 @@
1192 sso_login_processor_class=self.mockprocessorclass)
1193 self.patch(client, "EmailValidated", d.errback)
1194 self.patch(client, "EmailValidationError", verify)
1195- client.validate_email(EMAIL, PASSWORD, APP_NAME, EMAIL_TOKEN)
1196+ client.validate_email(APP_NAME, EMAIL, PASSWORD, EMAIL_TOKEN)
1197 return d
1198
1199 def test_request_password_reset_token(self):
1200@@ -598,17 +615,19 @@
1201 processor = self.create_mock_processor()
1202 processor.request_password_reset_token(EMAIL)
1203 self.patch(ubuntu_sso.main, "blocking", self.fake_ok_blocking)
1204+ self.mocker.result(EMAIL)
1205 self.mocker.replay()
1206
1207- def verify(result):
1208+ def verify(app_name, result):
1209 self.assertEqual(result, EMAIL)
1210+ self.assertEqual(app_name, APP_NAME)
1211 d.callback(result)
1212
1213 client = SSOLogin(self.mockbusname,
1214 sso_login_processor_class=self.mockprocessorclass)
1215 self.patch(client, "PasswordResetTokenSent", verify)
1216 self.patch(client, "PasswordResetError", d.errback)
1217- client.request_password_reset_token(EMAIL)
1218+ client.request_password_reset_token(APP_NAME, EMAIL)
1219 return d
1220
1221 def test_request_password_reset_token_error(self):
1222@@ -616,19 +635,20 @@
1223 d = Deferred()
1224
1225 self.create_mock_processor().request_password_reset_token(EMAIL)
1226- self.mocker.result(True)
1227+ self.mocker.result(EMAIL)
1228 self.patch(ubuntu_sso.main, "blocking", self.fake_err_blocking)
1229 self.mocker.replay()
1230
1231- def verify(errdict):
1232+ def verify(app_name, errdict):
1233 self.assertEqual(errdict["errtype"], "BlockingSampleException")
1234+ self.assertEqual(app_name, APP_NAME)
1235 d.callback("Ok")
1236
1237 client = SSOLogin(self.mockbusname,
1238 sso_login_processor_class=self.mockprocessorclass)
1239 self.patch(client, "PasswordResetTokenSent", d.errback)
1240 self.patch(client, "PasswordResetError", verify)
1241- client.request_password_reset_token(EMAIL)
1242+ client.request_password_reset_token(APP_NAME, EMAIL)
1243 return d
1244
1245 def test_set_new_password(self):
1246@@ -640,15 +660,16 @@
1247 self.patch(ubuntu_sso.main, "blocking", self.fake_ok_blocking)
1248 self.mocker.replay()
1249
1250- def verify(result):
1251+ def verify(app_name, result):
1252 self.assertEqual(result, EMAIL)
1253+ self.assertEqual(app_name, APP_NAME)
1254 d.callback(result)
1255
1256 client = SSOLogin(self.mockbusname,
1257 sso_login_processor_class=self.mockprocessorclass)
1258 self.patch(client, "PasswordChanged", verify)
1259 self.patch(client, "PasswordChangeError", d.errback)
1260- client.set_new_password(EMAIL, EMAIL_TOKEN, PASSWORD)
1261+ client.set_new_password(APP_NAME, EMAIL, EMAIL_TOKEN, PASSWORD)
1262 return d
1263
1264 def test_set_new_password_error(self):
1265@@ -662,20 +683,22 @@
1266 self.patch(ubuntu_sso.main, "blocking", self.fake_err_blocking)
1267 self.mocker.replay()
1268
1269- def verify(errdict):
1270+ def verify(app_name, errdict):
1271 self.assertEqual(errdict["errtype"], "BlockingSampleException")
1272+ self.assertEqual(app_name, APP_NAME)
1273 d.callback("Ok")
1274
1275 client = SSOLogin(self.mockbusname,
1276 sso_login_processor_class=self.mockprocessorclass)
1277 self.patch(client, "PasswordChanged", d.errback)
1278 self.patch(client, "PasswordChangeError", verify)
1279- client.set_new_password(EMAIL, EMAIL_TOKEN, PASSWORD)
1280+ client.set_new_password(APP_NAME, EMAIL, EMAIL_TOKEN, PASSWORD)
1281 return d
1282
1283
1284 class BlockingFunctionTestCase(TestCase):
1285 """Tests for the "blocking" function."""
1286+
1287 timeout = 5
1288
1289 def test_blocking(self):
1290@@ -686,11 +709,12 @@
1291 def f():
1292 return expected_result
1293
1294- def verify(result):
1295+ def verify(app_name, result):
1296 self.assertEqual(result, expected_result)
1297+ self.assertEqual(app_name, APP_NAME)
1298 d.callback(result)
1299
1300- blocking(f, verify, d.errback)
1301+ blocking(f, APP_NAME, verify, d.errback)
1302 return d
1303
1304 def test_blocking_error(self):
1305@@ -701,12 +725,13 @@
1306 def f():
1307 raise BlockingSampleException(expected_error_message)
1308
1309- def verify(errdict):
1310+ def verify(app_name, errdict):
1311+ self.assertEqual(app_name, APP_NAME)
1312 self.assertEqual(errdict["errtype"], "BlockingSampleException")
1313 self.assertEqual(errdict["message"], expected_error_message)
1314 d.callback("Ok")
1315
1316- blocking(f, d.errback, verify)
1317+ blocking(f, APP_NAME, d.errback, verify)
1318 return d
1319
1320
1321@@ -971,7 +996,7 @@
1322 client = SSOCredentials(self.mocker.mock())
1323 self.patch(client, "CredentialsError", verify)
1324
1325- client._login_error_cb(None, APP_NAME)
1326+ client._login_error_cb(None, APP_NAME, 'some error')
1327 return d
1328
1329 def test_show_login_or_register_ui_error(self):
1330@@ -1008,7 +1033,7 @@
1331 client = SSOCredentials(self.mocker.mock())
1332 self.patch(client, "CredentialsFound", verify)
1333
1334- client._login_success_cb(None, APP_NAME)
1335+ client._login_success_cb(None, APP_NAME, EMAIL)
1336 return d
1337
1338 def test_login_success_cb_error(self):
1339@@ -1026,7 +1051,7 @@
1340 client = SSOCredentials(self.mocker.mock())
1341 self.patch(client, "CredentialsError", verify)
1342
1343- client._login_success_cb(None, APP_NAME)
1344+ client._login_success_cb(None, APP_NAME, EMAIL)
1345 return d
1346
1347 def test_auth_denied_cb(self):
1348@@ -1114,8 +1139,10 @@
1349
1350 expected = [
1351 (gui.SIG_LOGIN_SUCCEEDED, self.client._login_success_cb),
1352+ (gui.SIG_LOGIN_SUCCEEDED, self.client._ping_url),
1353 (gui.SIG_LOGIN_FAILED, self.client._login_error_cb),
1354 (gui.SIG_REGISTRATION_SUCCEEDED, self.client._login_success_cb),
1355+ (gui.SIG_REGISTRATION_SUCCEEDED, self.client._ping_url),
1356 (gui.SIG_REGISTRATION_FAILED, self.client._login_error_cb),
1357 (gui.SIG_USER_CANCELATION, self.client._login_auth_denied_cb),
1358 ]
1359@@ -1174,11 +1201,47 @@
1360
1361 expected = [
1362 (gui.SIG_LOGIN_SUCCEEDED, self.client._login_success_cb),
1363+ (gui.SIG_LOGIN_SUCCEEDED, self.client._ping_url),
1364 (gui.SIG_LOGIN_FAILED, self.client._login_error_cb),
1365 (gui.SIG_REGISTRATION_SUCCEEDED, self.client._login_success_cb),
1366+ (gui.SIG_REGISTRATION_SUCCEEDED, self.client._ping_url),
1367 (gui.SIG_REGISTRATION_FAILED, self.client._login_error_cb),
1368 (gui.SIG_USER_CANCELATION, self.client._login_auth_denied_cb),
1369 ]
1370 self.patch(gui, "UbuntuSSOClientGUI", FakedUbuntuSSOClientGUI)
1371 self.login_only(*LOGIN_ONLY_ARGS)
1372 self.assertEqual(self.signals, expected)
1373+
1374+ def test_on_registration_successful_u1_server_is_pinged(self):
1375+ """When a registration is successful, the PING_URL is pinged."""
1376+ self.args = None
1377+ self.kwargs = None
1378+
1379+ def fake_it(*args, **kwargs):
1380+ """Fake a call."""
1381+ self.args = args
1382+ self.kwargs = kwargs
1383+
1384+ self.patch(urllib2, 'urlopen', fake_it)
1385+
1386+ self.client._ping_url(None, U1_APP_NAME, EMAIL)
1387+
1388+ self.assertEqual(self.args, (PING_URL + EMAIL,))
1389+ self.assertEqual(self.kwargs, {})
1390+
1391+ def test_on_registration_successful_no_server_is_pinged(self):
1392+ """When a registration is successful, the PING_URL is not pinged."""
1393+ self.args = None
1394+ self.kwargs = None
1395+
1396+ def fake_it(*args, **kwargs):
1397+ """Fake a call."""
1398+ self.args = args
1399+ self.kwargs = kwargs
1400+
1401+ self.patch(urllib2, 'urlopen', fake_it)
1402+
1403+ self.client._ping_url(None, APP_NAME, EMAIL)
1404+
1405+ self.assertEqual(self.args, None)
1406+ self.assertEqual(self.kwargs, None)

Subscribers

People subscribed via source and target branches