Merge lp:~nataliabidart/ubuntu-sso-client/validate-all-pages into lp:ubuntu-sso-client

Proposed by Natalia Bidart
Status: Merged
Approved by: Natalia Bidart
Approved revision: 607
Merged at revision: 604
Proposed branch: lp:~nataliabidart/ubuntu-sso-client/validate-all-pages
Merge into: lp:ubuntu-sso-client
Diff against target: 770 lines (+315/-110)
3 files modified
data/ui.glade (+38/-22)
ubuntu_sso/gui.py (+98/-61)
ubuntu_sso/tests/test_gui.py (+179/-27)
To merge this branch: bzr merge lp:~nataliabidart/ubuntu-sso-client/validate-all-pages
Reviewer Review Type Date Requested Status
Alejandro J. Cura (community) Approve
John Lenton (community) Approve
Vincenzo Di Somma (community) Approve
Review via email: mp+33958@code.launchpad.net

Commit message

* Validate form data for verify token page, request password token and set new password (LP: #625361).
* Validate password strength on reset password page (LP: #616528).
* Labels are not as wide as the parent windowm but a little bit less wide (LP: #625009).

Description of the change

Validate form data for verify token page, request password token and set new password (LP: #625361).
Validate password strength on reset password page (LP: #616528).

To post a comment you must log in.
Revision history for this message
Vincenzo Di Somma (vds) :
review: Approve
605. By Natalia Bidart

Removed unneeded code. Clarified error setting.

606. By Natalia Bidart

Labels are not as wide as the parent windowm but a little bit less wide (LP:
#625009).

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

+1 from alecu and me :)

review: Approve
607. By Natalia Bidart

Merged trunk in.

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

I just did some functional testing of this branch and it works ok.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'data/ui.glade'
2--- data/ui.glade 2010-08-26 00:56:39 +0000
3+++ data/ui.glade 2010-08-27 21:46:39 +0000
4@@ -60,6 +60,12 @@
5 <property name="visible">True</property>
6 <property name="spacing">10</property>
7 <child>
8+ <placeholder/>
9+ </child>
10+ <child>
11+ <placeholder/>
12+ </child>
13+ <child>
14 <object class="GtkHBox" id="emails_hbox">
15 <property name="visible">True</property>
16 <property name="spacing">5</property>
17@@ -77,9 +83,6 @@
18 </packing>
19 </child>
20 <child>
21- <placeholder/>
22- </child>
23- <child>
24 <object class="GtkHBox" id="passwords_hbox">
25 <property name="visible">True</property>
26 <property name="spacing">5</property>
27@@ -107,9 +110,6 @@
28 </packing>
29 </child>
30 <child>
31- <placeholder/>
32- </child>
33- <child>
34 <object class="GtkHBox" id="hbox1">
35 <property name="visible">True</property>
36 <child>
37@@ -585,27 +585,43 @@
38 <property name="visible">True</property>
39 <property name="spacing">10</property>
40 <child>
41- <object class="GtkAlignment" id="alignment1">
42+ <object class="GtkVBox" id="vbox2">
43 <property name="visible">True</property>
44- <property name="xscale">0</property>
45- <property name="yscale">0</property>
46- <child>
47- <object class="GtkVBox" id="set_new_password_details_vbox">
48- <property name="visible">True</property>
49- <property name="spacing">5</property>
50- <child>
51- <placeholder/>
52- </child>
53- <child>
54- <placeholder/>
55- </child>
56- <child>
57- <placeholder/>
58- </child>
59+ <child>
60+ <object class="GtkAlignment" id="alignment1">
61+ <property name="visible">True</property>
62+ <property name="xscale">0</property>
63+ <property name="yscale">0</property>
64+ <child>
65+ <object class="GtkVBox" id="set_new_password_details_vbox">
66+ <property name="visible">True</property>
67+ <property name="spacing">5</property>
68+ <child>
69+ <placeholder/>
70+ </child>
71+ <child>
72+ <placeholder/>
73+ </child>
74+ <child>
75+ <placeholder/>
76+ </child>
77+ </object>
78+ </child>
79+ </object>
80+ <packing>
81+ <property name="position">0</property>
82+ </packing>
83+ </child>
84+ <child>
85+ <object class="GtkLabel" id="reset_password_help_label">
86+ <property name="visible">True</property>
87+ <property name="label" translatable="yes">label</property>
88+ <property name="wrap">True</property>
89 </object>
90 </child>
91 </object>
92 <packing>
93+ <property name="padding">5</property>
94 <property name="position">0</property>
95 </packing>
96 </child>
97
98=== modified file 'ubuntu_sso/gui.py'
99--- ubuntu_sso/gui.py 2010-08-27 15:26:27 +0000
100+++ ubuntu_sso/gui.py 2010-08-27 21:46:39 +0000
101@@ -319,22 +319,26 @@
102 self._append_page(self._build_request_password_token_page())
103 self._append_page(self._build_set_new_password_page())
104
105+ window_size = None
106 if not login_only:
107+ window_size = (550, 600)
108 self._append_page(self._build_enter_details_page())
109 self._append_page(self._build_tc_page())
110 self._append_page(self._build_verify_email_page())
111 self.login_button.grab_focus()
112 self._set_current_page(self.enter_details_vbox)
113- self.window.set_size_request(550, 600)
114- size_req = (self.window.get_size_request()[0], -1)
115- for label in self.labels:
116- label.set_size_request(*size_req)
117 else:
118+ window_size = (400, 350)
119 self.login_back_button.hide()
120 self.login_ok_button.grab_focus()
121 self.login_vbox.help_text = help_text
122 self._set_current_page(self.login_vbox)
123
124+ self.window.set_size_request(*window_size)
125+ size_req = (int(window_size[0] * 0.9), -1)
126+ for label in self.labels:
127+ label.set_size_request(*size_req)
128+
129 self._setup_signals()
130 self._gtk_signal_log = []
131
132@@ -501,11 +505,11 @@
133 msg = self.CAPTCHA_RELOAD_TOOLTIP
134 self.captcha_reload_button.set_tooltip_text(msg)
135
136- self.emails_hbox.pack_start(self.email1_entry)
137- self.emails_hbox.pack_start(self.email2_entry)
138+ self.emails_hbox.pack_start(self.email1_entry, expand=False)
139+ self.emails_hbox.pack_start(self.email2_entry, expand=False)
140
141- self.passwords_hbox.pack_start(self.password1_entry)
142- self.passwords_hbox.pack_start(self.password2_entry)
143+ self.passwords_hbox.pack_start(self.password1_entry, expand=False)
144+ self.passwords_hbox.pack_start(self.password2_entry, expand=False)
145 help_msg = '<small>%s</small>' % self.PASSWORD_HELP
146 self.password_help_label.set_markup(help_msg)
147
148@@ -584,7 +588,8 @@
149 self.request_password_token_vbox.help_text = text
150
151 entry = self.reset_email_entry
152- self.request_password_token_details_vbox.pack_start(entry)
153+ self.request_password_token_details_vbox.pack_start(entry,
154+ expand=False)
155 cb = self.on_reset_email_entry_changed
156 self.reset_email_entry.connect('changed', cb)
157 self.request_password_token_ok_button.set_label(self.NEXT)
158@@ -604,19 +609,48 @@
159 for entry in (self.reset_code_entry,
160 self.reset_password1_entry,
161 self.reset_password2_entry):
162- self.set_new_password_details_vbox.pack_start(entry)
163+ self.set_new_password_details_vbox.pack_start(entry, expand=False)
164 entry.connect('activate', cb)
165
166 cb = self.on_set_new_password_entries_changed
167 self.reset_code_entry.connect('changed', cb)
168 self.reset_password1_entry.connect('changed', cb)
169 self.reset_password2_entry.connect('changed', cb)
170+ help_msg = '<small>%s</small>' % self.PASSWORD_HELP
171+ self.reset_password_help_label.set_markup(help_msg)
172
173 self.set_new_password_ok_button.set_label(self.RESET_PASSWORD)
174 self.set_new_password_ok_button.set_sensitive(False)
175
176 return self.set_new_password_vbox
177
178+ def _validate_email(self, email1, email2=None):
179+ """Validate 'email1', return error message if not valid.
180+
181+ If 'email2' is given, must match 'email1'.
182+ """
183+ if email2 is not None and email1 != email2:
184+ return self.EMAIL_MISMATCH
185+
186+ if not email1:
187+ return self.FIELD_REQUIRED
188+
189+ if '@' not in email1:
190+ return self.EMAIL_INVALID
191+
192+ def _validate_password(self, password1, password2=None):
193+ """Validate 'password1', return error message if not valid.
194+
195+ If 'password2' is given, must match 'email1'.
196+ """
197+ if password2 is not None and password1 != password2:
198+ return self.PASSWORD_MISMATCH
199+
200+ if (len(password1) < 8 or
201+ re.search('[A-Z]', password1) is None or
202+ re.search('\d+', password1) is None):
203+ return self.PASSWORD_TOO_WEAK
204+
205 # GTK callbacks
206
207 def run(self):
208@@ -673,56 +707,40 @@
209 name = self.name_entry.get_text()
210 if not name:
211 self.name_entry.set_warning(self.FIELD_REQUIRED)
212- error |= True
213+ error = True
214
215 # check email
216 email1 = self.email1_entry.get_text()
217 email2 = self.email2_entry.get_text()
218- if email1 != email2:
219- self.email1_entry.set_warning(self.EMAIL_MISMATCH)
220- self.email2_entry.set_warning(self.EMAIL_MISMATCH)
221- error |= True
222-
223- if '@' not in email1:
224- self.email1_entry.set_warning(self.EMAIL_INVALID)
225- self.email2_entry.set_warning(self.EMAIL_INVALID)
226- error |= True
227-
228- if not email1:
229- self.email1_entry.set_warning(self.FIELD_REQUIRED)
230- self.email2_entry.set_warning(self.FIELD_REQUIRED)
231- error |= True
232+ msg = self._validate_email(email1, email2)
233+ if msg is not None:
234+ self.email1_entry.set_warning(msg)
235+ self.email2_entry.set_warning(msg)
236+ error = True
237
238 # check password
239 password1 = self.password1_entry.get_text()
240 password2 = self.password2_entry.get_text()
241- if password1 != password2:
242- self.password1_entry.set_warning(self.PASSWORD_MISMATCH)
243- self.password2_entry.set_warning(self.PASSWORD_MISMATCH)
244- error |= True
245-
246- if (len(password1) < 8 or
247- re.search('[A-Z]', password1) is None or
248- re.search('\d+', password1) is None):
249- self.password1_entry.set_warning(self.PASSWORD_TOO_WEAK)
250- self.password2_entry.set_warning(self.PASSWORD_TOO_WEAK)
251- error |= True
252+ msg = self._validate_password(password1, password2)
253+ if msg is not None:
254+ self.password1_entry.set_warning(msg)
255+ self.password2_entry.set_warning(msg)
256+ error = True
257
258 # check T&C
259 if not self.yes_to_tc_checkbutton.get_active():
260 self._set_warning_message(self.tc_warning_label,
261 self.TC_NOT_ACCEPTED)
262- error |= True
263+ error = True
264
265 captcha_solution = self.captcha_solution_entry.get_text()
266 if not captcha_solution:
267 self.captcha_solution_entry.set_warning(self.FIELD_REQUIRED)
268- error |= True
269+ error = True
270
271 if error:
272 return
273
274- self._clear_warnings()
275 self._set_current_page(self.processing_vbox)
276
277 logger.info('Calling register_user with email %r, password <hidden>,' \
278@@ -745,14 +763,19 @@
279 if not self.verify_token_button.is_sensitive():
280 return
281
282+ self._clear_warnings()
283+
284+ email_token = self.email_token_entry.get_text()
285+ if not email_token:
286+ self.email_token_entry.set_warning(self.FIELD_REQUIRED)
287+ return
288+
289 email = self.email1_entry.get_text()
290 password = self.password1_entry.get_text()
291- email_token = self.email_token_entry.get_text()
292-
293+ f = self.backend.validate_email
294 logger.info('Calling validate_email with email %r, password <hidden>' \
295- ', app_name %r and email_token %r.', email,
296- self.app_name, email_token)
297- f = self.backend.validate_email
298+ ', app_name %r and email_token %r.', email, self.app_name,
299+ email_token)
300 f(self.app_name, email, password, email_token,
301 reply_handler=NO_OP, error_handler=NO_OP)
302
303@@ -766,27 +789,21 @@
304 self._clear_warnings()
305
306 error = False
307+
308 email = self.login_email_entry.get_text()
309-
310- if '@' not in email:
311- self.login_email_entry.set_warning(self.EMAIL_INVALID)
312- error |= True
313-
314- if not email:
315- self.login_email_entry.set_warning(self.FIELD_REQUIRED)
316- error |= True
317+ msg = self._validate_email(email)
318+ if msg is not None:
319+ self.login_email_entry.set_warning(msg)
320+ error = True
321
322 password = self.login_password_entry.get_text()
323-
324 if not password:
325 self.login_password_entry.set_warning(self.FIELD_REQUIRED)
326- error |= True
327+ error = True
328
329 if error:
330 return
331
332- self._clear_warnings()
333-
334 f = self.backend.login
335 f(self.app_name, email, password,
336 reply_handler=NO_OP, error_handler=NO_OP)
337@@ -806,7 +823,13 @@
338 if not self.request_password_token_ok_button.is_sensitive():
339 return
340
341+ self._clear_warnings()
342+
343 email = self.reset_email_entry.get_text()
344+ msg = self._validate_email(email)
345+ if msg is not None:
346+ self.reset_email_entry.set_warning(msg)
347+ return
348
349 logger.info('Calling request_password_reset_token with %r.', email)
350 f = self.backend.request_password_reset_token
351@@ -837,13 +860,27 @@
352 if not self.set_new_password_ok_button.is_sensitive():
353 return
354
355- email = self.reset_email_entry.get_text()
356+ self._clear_warnings()
357+
358+ error = False
359+
360 token = self.reset_code_entry.get_text()
361- # XXX: validate passwords!
362- # see LP: #616528
363+ if not token:
364+ self.reset_code_entry.set_warning(self.FIELD_REQUIRED)
365+ error = True
366+
367 password1 = self.reset_password1_entry.get_text()
368- #password2 = self.reset_password2_entry.get_text()
369-
370+ password2 = self.reset_password2_entry.get_text()
371+ msg = self._validate_password(password1, password2)
372+ if msg is not None:
373+ self.reset_password1_entry.set_warning(msg)
374+ self.reset_password2_entry.set_warning(msg)
375+ error = True
376+
377+ if error:
378+ return
379+
380+ email = self.reset_email_entry.get_text()
381 logger.info('Calling set_new_password with email %r, token %r and ' \
382 'new password: <hidden>.', email, token)
383 f = self.backend.set_new_password
384
385=== modified file 'ubuntu_sso/tests/test_gui.py'
386--- ubuntu_sso/tests/test_gui.py 2010-08-27 15:09:43 +0000
387+++ ubuntu_sso/tests/test_gui.py 2010-08-27 21:46:39 +0000
388@@ -364,11 +364,13 @@
389 def assert_warnings_visibility(self, visible=False):
390 """Every warning label should be 'visible'."""
391 msg = '"%s" should be %svisible.'
392- warnings = filter(lambda name: 'warning' in name, self.ui.widgets)
393- for name in warnings:
394+ for name in self.ui.widgets:
395 widget = getattr(self.ui, name)
396- self.assertEqual(visible, widget.get_property('visible'),
397- msg % (name, '' if visible else 'not '))
398+ if 'warning' in name:
399+ self.assertEqual(visible, widget.get_property('visible'),
400+ msg % (name, '' if visible else 'not '))
401+ elif 'entry' in name:
402+ self.assertEqual(widget.warning, '')
403
404 def assert_correct_label_warning(self, label, message):
405 """Check that a warning is shown displaying 'message'."""
406@@ -541,7 +543,7 @@
407
408 def test_initial_size_for_labels(self):
409 """Labels have the correct width."""
410- expected = (self.ui.window.get_size_request()[0], -1)
411+ expected = (int(self.ui.window.get_size_request()[0] * 0.9), -1)
412 msg = 'Label %r must have size request %s (got %s instead).'
413 labels = [i for i in self.ui.widgets if 'label' in i]
414 for label in labels:
415@@ -559,7 +561,7 @@
416
417 def test_warning_fields_are_hidden(self):
418 """Every warning label should be not visible."""
419- self.assert_warnings_visibility(visible=False)
420+ self.assert_warnings_visibility()
421
422 def test_cancel_buttons_close_window(self):
423 """Every cancel button should close the window when clicked."""
424@@ -612,7 +614,7 @@
425 self.assertEqual(self._called, ((xid,), {}))
426
427
428-class RegistrationEnterDetailsTestCase(UbuntuSSOClientTestCase):
429+class EnterDetailsTestCase(UbuntuSSOClientTestCase):
430 """Test suite for the user registration (enter details page)."""
431
432 def test_initial_text_for_header_label(self):
433@@ -914,12 +916,12 @@
434 test_tc_browser_opens_the_proper_uri.skip = 'The freaking test wont work.'
435
436
437-class UserRegistrationErrorTestCase(UbuntuSSOClientTestCase):
438+class RegistrationErrorTestCase(UbuntuSSOClientTestCase):
439 """Test suite for the user registration error handling."""
440
441 def setUp(self):
442 """Init."""
443- super(UserRegistrationErrorTestCase, self).setUp()
444+ super(RegistrationErrorTestCase, self).setUp()
445 self.click_join_with_valid_data()
446
447 def test_previous_page_is_shown(self):
448@@ -992,11 +994,11 @@
449 self.click_verify_email_with_valid_data()
450 self.assert_pages_visibility(processing=True)
451
452- def test_no_warning_messages_if_valid_data_on_verify_token(self):
453+ def test_no_warning_messages_if_valid_data(self):
454 """No warning messages are shown if the data is valid."""
455 # this will certainly NOT generate warnings
456 self.click_verify_email_with_valid_data()
457- self.assert_warnings_visibility(visible=False)
458+ self.assert_warnings_visibility()
459
460 def test_on_email_validated_shows_success_page(self):
461 """On email validated the success page is shown."""
462@@ -1060,6 +1062,42 @@
463 self.assertTrue(self._called)
464
465
466+class VerifyEmailValidationTestCase(UbuntuSSOClientTestCase):
467+ """Test suite for the user registration (verify email page)."""
468+
469+ def setUp(self):
470+ """Init."""
471+ super(VerifyEmailValidationTestCase, self).setUp()
472+ self.ui.on_user_registered(app_name=APP_NAME, email=EMAIL)
473+
474+ def test_warning_is_shown_if_empty_email_token(self):
475+ """A warning message is shown if email token is empty."""
476+ self.ui.email_token_entry.set_text('')
477+
478+ self.ui.verify_token_button.clicked()
479+
480+ self.assert_correct_entry_warning(self.ui.email_token_entry,
481+ self.ui.FIELD_REQUIRED)
482+ self.assertNotIn('validate_email', self.ui.backend._called)
483+
484+ def test_no_warning_messages_if_valid_data(self):
485+ """No warning messages are shown if the data is valid."""
486+ # this will certainly NOT generate warnings
487+ self.click_verify_email_with_valid_data()
488+
489+ self.assert_warnings_visibility()
490+
491+ def test_no_warning_messages_if_valid_data_after_invalid_data(self):
492+ """No warnings if the data is valid (with prior invalid data)."""
493+ # this will certainly generate warnings
494+ self.ui.verify_token_button.clicked()
495+
496+ # this will certainly NOT generate warnings
497+ self.click_verify_email_with_valid_data()
498+
499+ self.assert_warnings_visibility()
500+
501+
502 class RegistrationValidationTestCase(UbuntuSSOClientTestCase):
503 """Test suite for the user registration validations."""
504
505@@ -1072,7 +1110,7 @@
506 """A warning message is shown if name is empty."""
507 self.ui.name_entry.set_text('')
508
509- self.ui.join_ok_button.clicked() # submit form
510+ self.ui.join_ok_button.clicked()
511
512 self.assert_correct_entry_warning(self.ui.name_entry,
513 self.ui.FIELD_REQUIRED)
514@@ -1083,7 +1121,7 @@
515 self.ui.email1_entry.set_text('')
516 self.ui.email2_entry.set_text('')
517
518- self.ui.join_ok_button.clicked() # submit form
519+ self.ui.join_ok_button.clicked()
520
521 self.assert_correct_entry_warning(self.ui.email1_entry,
522 self.ui.FIELD_REQUIRED)
523@@ -1096,7 +1134,7 @@
524 self.ui.email1_entry.set_text(EMAIL)
525 self.ui.email2_entry.set_text(EMAIL * 2)
526
527- self.ui.join_ok_button.clicked() # submit form
528+ self.ui.join_ok_button.clicked()
529
530 self.assert_correct_entry_warning(self.ui.email1_entry,
531 self.ui.EMAIL_MISMATCH)
532@@ -1109,7 +1147,7 @@
533 self.ui.email1_entry.set_text('q')
534 self.ui.email2_entry.set_text('q')
535
536- self.ui.join_ok_button.clicked() # submit form
537+ self.ui.join_ok_button.clicked()
538
539 self.assert_correct_entry_warning(self.ui.email1_entry,
540 self.ui.EMAIL_INVALID)
541@@ -1130,7 +1168,7 @@
542 self.ui.password1_entry.set_text(PASSWORD)
543 self.ui.password2_entry.set_text(PASSWORD * 2)
544
545- self.ui.join_ok_button.clicked() # submit form
546+ self.ui.join_ok_button.clicked()
547
548 self.assert_correct_entry_warning(self.ui.password1_entry,
549 self.ui.PASSWORD_MISMATCH)
550@@ -1145,7 +1183,7 @@
551 self.ui.password1_entry.set_text(w)
552 self.ui.password2_entry.set_text(w)
553
554- self.ui.join_ok_button.clicked() # submit form
555+ self.ui.join_ok_button.clicked()
556
557 self.assert_correct_entry_warning(self.ui.password1_entry,
558 self.ui.PASSWORD_TOO_WEAK)
559@@ -1158,7 +1196,7 @@
560 # don't agree to TC
561 self.ui.yes_to_tc_checkbutton.set_active(False)
562
563- self.ui.join_ok_button.clicked() # submit form
564+ self.ui.join_ok_button.clicked()
565
566 self.assert_correct_label_warning(self.ui.tc_warning_label,
567 self.ui.TC_NOT_ACCEPTED)
568@@ -1169,18 +1207,18 @@
569 # captcha solution will be empty
570 self.ui.captcha_solution_entry.set_text('')
571
572- self.ui.join_ok_button.clicked() # submit form
573+ self.ui.join_ok_button.clicked()
574
575 self.assert_correct_entry_warning(self.ui.captcha_solution_entry,
576 self.ui.FIELD_REQUIRED)
577 self.assertNotIn('register_user', self.ui.backend._called)
578
579- def test_no_warning_messages_if_valid_data_on_enter_details(self):
580+ def test_no_warning_messages_if_valid_data(self):
581 """No warning messages are shown if the data is valid."""
582 # this will certainly NOT generate warnings
583 self.click_join_with_valid_data()
584
585- self.assert_warnings_visibility(visible=False)
586+ self.assert_warnings_visibility()
587
588 def test_no_warning_messages_if_valid_data_after_invalid_data(self):
589 """No warnings if the data is valid (with prior invalid data)."""
590@@ -1190,7 +1228,7 @@
591 # this will certainly NOT generate warnings
592 self.click_join_with_valid_data()
593
594- self.assert_warnings_visibility(visible=False)
595+ self.assert_warnings_visibility()
596
597
598 class LoginTestCase(UbuntuSSOClientTestCase):
599@@ -1331,7 +1369,7 @@
600 """A warning message is shown if email is empty."""
601 self.ui.login_email_entry.set_text('')
602
603- self.ui.login_ok_button.clicked() # submit form
604+ self.ui.login_ok_button.clicked()
605
606 self.assert_correct_entry_warning(self.ui.login_email_entry,
607 self.ui.FIELD_REQUIRED)
608@@ -1341,7 +1379,7 @@
609 """A warning message is shown if email is invalid."""
610 self.ui.login_email_entry.set_text('q')
611
612- self.ui.login_ok_button.clicked() # submit form
613+ self.ui.login_ok_button.clicked()
614
615 self.assert_correct_entry_warning(self.ui.login_email_entry,
616 self.ui.EMAIL_INVALID)
617@@ -1351,7 +1389,7 @@
618 """A warning message is shown if password is empty."""
619 self.ui.login_password_entry.set_text('')
620
621- self.ui.login_ok_button.clicked() # submit form
622+ self.ui.login_ok_button.clicked()
623
624 self.assert_correct_entry_warning(self.ui.login_password_entry,
625 self.ui.FIELD_REQUIRED)
626@@ -1362,7 +1400,7 @@
627 # this will certainly NOT generate warnings
628 self.click_connect_with_valid_data()
629
630- self.assert_warnings_visibility(visible=False)
631+ self.assert_warnings_visibility()
632
633 def test_no_warning_messages_if_valid_data_after_invalid_data(self):
634 """No warnings if the data is valid (with prior invalid data)."""
635@@ -1372,7 +1410,7 @@
636 # this will certainly NOT generate warnings
637 self.click_connect_with_valid_data()
638
639- self.assert_warnings_visibility(visible=False)
640+ self.assert_warnings_visibility()
641
642
643 class ResetPasswordTestCase(UbuntuSSOClientTestCase):
644@@ -1503,6 +1541,50 @@
645 self.assertTrue(self._called)
646
647
648+class ResetPasswordValidationTestCase(UbuntuSSOClientTestCase):
649+ """Test suite for the password reset validations."""
650+
651+ def test_warning_is_shown_if_empty_email(self):
652+ """A warning message is shown if emails are empty."""
653+ self.ui.reset_email_entry.set_text(' ')
654+
655+ self.ui.request_password_token_ok_button.set_sensitive(True)
656+ self.ui.request_password_token_ok_button.clicked()
657+
658+ self.assert_correct_entry_warning(self.ui.reset_email_entry,
659+ self.ui.FIELD_REQUIRED)
660+ self.assertNotIn('request_password_reset_token',
661+ self.ui.backend._called)
662+
663+ def test_warning_is_shown_if_invalid_email(self):
664+ """A warning message is shown if email is invalid."""
665+ self.ui.reset_email_entry.set_text('q')
666+
667+ self.ui.request_password_token_ok_button.clicked()
668+
669+ self.assert_correct_entry_warning(self.ui.reset_email_entry,
670+ self.ui.EMAIL_INVALID)
671+ self.assertNotIn('request_password_reset_token',
672+ self.ui.backend._called)
673+
674+ def test_no_warning_messages_if_valid_data(self):
675+ """No warning messages are shown if the data is valid."""
676+ # this will certainly NOT generate warnings
677+ self.click_request_password_token_with_valid_data()
678+
679+ self.assert_warnings_visibility()
680+
681+ def test_no_warning_messages_if_valid_data_after_invalid_data(self):
682+ """No warnings if the data is valid (with prior invalid data)."""
683+ # this will certainly generate warnings
684+ self.ui.request_password_token_ok_button.clicked()
685+
686+ # this will certainly NOT generate warnings
687+ self.click_request_password_token_with_valid_data()
688+
689+ self.assert_warnings_visibility()
690+
691+
692 class SetNewPasswordTestCase(UbuntuSSOClientTestCase):
693 """Test suite for setting a new password functionality."""
694
695@@ -1602,6 +1684,76 @@
696 self.assertTrue(self._called)
697
698
699+class SetNewPasswordValidationTestCase(UbuntuSSOClientTestCase):
700+ """Test suite for validations for setting a new password."""
701+
702+ def test_warning_is_shown_if_reset_code_empty(self):
703+ """A warning message is shown if reset_code is empty."""
704+ self.ui.reset_code_entry.set_text('')
705+
706+ self.ui.set_new_password_ok_button.set_sensitive(True)
707+ self.ui.set_new_password_ok_button.clicked()
708+
709+ self.assert_correct_entry_warning(self.ui.reset_code_entry,
710+ self.ui.FIELD_REQUIRED)
711+ self.assertNotIn('set_new_password', self.ui.backend._called)
712+
713+ def test_password_help_is_always_shown(self):
714+ """Password help text is correctly displayed."""
715+ visible = self.ui.reset_password_help_label.get_property('visible')
716+ self.assertTrue(visible, 'password help text is visible.')
717+ self.assertEqual(self.ui.reset_password_help_label.get_text(),
718+ self.ui.PASSWORD_HELP)
719+ self.assertNotIn('set_new_password', self.ui.backend._called)
720+
721+ def test_warning_is_shown_if_password_mismatch(self):
722+ """A warning message is shown if password doesn't match."""
723+ self.ui.reset_password1_entry.set_text(PASSWORD)
724+ self.ui.reset_password2_entry.set_text(PASSWORD * 2)
725+
726+ self.ui.set_new_password_ok_button.set_sensitive(True)
727+ self.ui.set_new_password_ok_button.clicked()
728+
729+ self.assert_correct_entry_warning(self.ui.reset_password1_entry,
730+ self.ui.PASSWORD_MISMATCH)
731+ self.assert_correct_entry_warning(self.ui.reset_password2_entry,
732+ self.ui.PASSWORD_MISMATCH)
733+ self.assertNotIn('set_new_password', self.ui.backend._called)
734+
735+ def test_warning_is_shown_if_password_too_weak(self):
736+ """A warning message is shown if password is too weak."""
737+ # password will match but will be too weak
738+ for w in ('', 'h3lloWo', PASSWORD.lower(), 'helloWorld'):
739+ self.ui.reset_password1_entry.set_text(w)
740+ self.ui.reset_password2_entry.set_text(w)
741+
742+ self.ui.set_new_password_ok_button.set_sensitive(True)
743+ self.ui.set_new_password_ok_button.clicked()
744+
745+ self.assert_correct_entry_warning(self.ui.reset_password1_entry,
746+ self.ui.PASSWORD_TOO_WEAK)
747+ self.assert_correct_entry_warning(self.ui.reset_password2_entry,
748+ self.ui.PASSWORD_TOO_WEAK)
749+ self.assertNotIn('set_new_password', self.ui.backend._called)
750+
751+ def test_no_warning_messages_if_valid_data(self):
752+ """No warning messages are shown if the data is valid."""
753+ # this will certainly NOT generate warnings
754+ self.click_set_new_password_with_valid_data()
755+
756+ self.assert_warnings_visibility()
757+
758+ def test_no_warning_messages_if_valid_data_after_invalid_data(self):
759+ """No warnings if the data is valid (with prior invalid data)."""
760+ # this will certainly generate warnings
761+ self.ui.set_new_password_ok_button.clicked()
762+
763+ # this will certainly NOT generate warnings
764+ self.click_set_new_password_with_valid_data()
765+
766+ self.assert_warnings_visibility()
767+
768+
769 class DbusTestCase(UbuntuSSOClientTestCase):
770 """Test suite for the dbus calls."""
771

Subscribers

People subscribed via source and target branches