3 class UserLoginTest < ActionDispatch::IntegrationTest
7 OmniAuth.config.test_mode = true
11 OmniAuth.config.mock_auth[:openid] = nil
12 OmniAuth.config.test_mode = false
15 def test_login_email_password_normal
16 user = users(:normal_user)
19 assert_response :redirect
20 assert_redirected_to :controller => :user, :action => :login, :cookie_test => true
22 assert_response :success
24 post "/login", :username => user.email, :password => "wrong", :referer => "/history"
25 assert_response :redirect
27 assert_response :success
28 assert_template "login"
30 post "/login", :username => user.email, :password => "test", :referer => "/history"
31 assert_response :redirect
33 assert_response :success
34 assert_template "changeset/history"
35 assert_select "span.username", "test"
38 def test_login_email_password_normal_upcase
39 user = users(:normal_user)
42 assert_response :redirect
43 assert_redirected_to :controller => :user, :action => :login, :cookie_test => true
45 assert_response :success
47 post "/login", :username => user.email.upcase, :password => "wrong", :referer => "/history"
48 assert_response :redirect
50 assert_response :success
51 assert_template "login"
53 post "/login", :username => user.email.upcase, :password => "test", :referer => "/history"
54 assert_response :redirect
56 assert_response :success
57 assert_template "changeset/history"
58 assert_select "span.username", "TEST"
61 def test_login_email_password_normal_titlecase
62 user = users(:normal_user)
65 assert_response :redirect
66 assert_redirected_to :controller => :user, :action => :login, :cookie_test => true
68 assert_response :success
70 post "/login", :username => user.email.titlecase, :password => "wrong", :referer => "/history"
71 assert_response :redirect
73 assert_response :success
74 assert_template "login"
76 post "/login", :username => user.email.titlecase, :password => "test", :referer => "/history"
77 assert_response :redirect
79 assert_response :success
80 assert_template "login"
81 assert_select "span.username", false
84 def test_login_email_password_public
85 user = users(:public_user)
88 assert_response :redirect
89 assert_redirected_to :controller => :user, :action => :login, :cookie_test => true
91 assert_response :success
93 post "/login", :username => user.email, :password => "wrong", :referer => "/history"
94 assert_response :redirect
96 assert_response :success
97 assert_template "login"
99 post "/login", :username => user.email, :password => "test", :referer => "/history"
100 assert_response :redirect
102 assert_response :success
103 assert_template "changeset/history"
104 assert_select "span.username", "test2"
107 def test_login_email_password_public_upcase
108 user = users(:public_user)
111 assert_response :redirect
112 assert_redirected_to :controller => :user, :action => :login, :cookie_test => true
114 assert_response :success
116 post "/login", :username => user.email.upcase, :password => "wrong", :referer => "/history"
117 assert_response :redirect
119 assert_response :success
120 assert_template "login"
122 post "/login", :username => user.email.upcase, :password => "test", :referer => "/history"
123 assert_response :redirect
125 assert_response :success
126 assert_template "changeset/history"
127 assert_select "span.username", "test2"
130 def test_login_email_password_public_titlecase
131 user = users(:public_user)
134 assert_response :redirect
135 assert_redirected_to :controller => :user, :action => :login, :cookie_test => true
137 assert_response :success
139 post "/login", :username => user.email.titlecase, :password => "wrong", :referer => "/history"
140 assert_response :redirect
142 assert_response :success
143 assert_template "login"
145 post "/login", :username => user.email.titlecase, :password => "test", :referer => "/history"
146 assert_response :redirect
148 assert_response :success
149 assert_template "changeset/history"
150 assert_select "span.username", "test2"
153 def test_login_email_password_inactive
154 user = users(:inactive_user)
157 assert_response :redirect
158 assert_redirected_to :controller => :user, :action => :login, :cookie_test => true
160 assert_response :success
162 post "/login", :username => user.email, :password => "wrong", :referer => "/history"
163 assert_response :redirect
165 assert_response :success
166 assert_template "login"
168 post "/login", :username => user.email, :password => "test2", :referer => "/history"
169 assert_response :redirect
171 assert_response :success
172 assert_template "confirm"
175 def test_login_email_password_inactive_upcase
176 user = users(:inactive_user)
179 assert_response :redirect
180 assert_redirected_to :controller => :user, :action => :login, :cookie_test => true
182 assert_response :success
184 post "/login", :username => user.email.upcase, :password => "wrong", :referer => "/history"
185 assert_response :redirect
187 assert_response :success
188 assert_template "login"
190 post "/login", :username => user.email.upcase, :password => "test2", :referer => "/history"
191 assert_response :redirect
193 assert_response :success
194 assert_template "confirm"
197 def test_login_email_password_inactive_titlecase
198 user = users(:inactive_user)
201 assert_response :redirect
202 assert_redirected_to :controller => :user, :action => :login, :cookie_test => true
204 assert_response :success
206 post "/login", :username => user.email.titlecase, :password => "wrong", :referer => "/history"
207 assert_response :redirect
209 assert_response :success
210 assert_template "login"
212 post "/login", :username => user.email.titlecase, :password => "test2", :referer => "/history"
213 assert_response :redirect
215 assert_response :success
216 assert_template "confirm"
219 def test_login_email_password_suspended
220 user = users(:suspended_user)
223 assert_response :redirect
224 assert_redirected_to :controller => :user, :action => :login, :cookie_test => true
226 assert_response :success
228 post "/login", :username => user.email, :password => "wrong", :referer => "/history"
229 assert_response :redirect
231 assert_response :success
232 assert_template "login"
234 post "/login", :username => user.email, :password => "test", :referer => "/history"
235 assert_response :redirect
237 assert_response :success
238 assert_template "login"
239 assert_select "div.flash.error", /your account has been suspended/
242 def test_login_email_password_suspended_upcase
243 user = users(:suspended_user)
246 assert_response :redirect
247 assert_redirected_to :controller => :user, :action => :login, :cookie_test => true
249 assert_response :success
251 post "/login", :username => user.email.upcase, :password => "wrong", :referer => "/history"
252 assert_response :redirect
254 assert_response :success
255 assert_template "login"
257 post "/login", :username => user.email.upcase, :password => "test", :referer => "/history"
258 assert_response :redirect
260 assert_response :success
261 assert_template "login"
262 assert_select "div.flash.error", /your account has been suspended/
265 def test_login_email_password_suspended_titlecase
266 user = users(:suspended_user)
269 assert_response :redirect
270 assert_redirected_to :controller => :user, :action => :login, :cookie_test => true
272 assert_response :success
274 post "/login", :username => user.email.titlecase, :password => "wrong", :referer => "/history"
275 assert_response :redirect
277 assert_response :success
278 assert_template "login"
280 post "/login", :username => user.email.titlecase, :password => "test", :referer => "/history"
281 assert_response :redirect
283 assert_response :success
284 assert_template "login"
285 assert_select "div.flash.error", /your account has been suspended/
288 def test_login_username_password_normal
289 user = users(:normal_user)
292 assert_response :redirect
293 assert_redirected_to :controller => :user, :action => :login, :cookie_test => true
295 assert_response :success
297 post "/login", :username => user.display_name, :password => "wrong", :referer => "/history"
298 assert_response :redirect
300 assert_response :success
301 assert_template "login"
303 post "/login", :username => user.display_name, :password => "test", :referer => "/history"
304 assert_response :redirect
306 assert_response :success
307 assert_template "changeset/history"
308 assert_select "span.username", "test"
311 def test_login_username_password_normal_upcase
312 user = users(:normal_user)
315 assert_response :redirect
316 assert_redirected_to :controller => :user, :action => :login, :cookie_test => true
318 assert_response :success
320 post "/login", :username => user.display_name.upcase, :password => "wrong", :referer => "/history"
321 assert_response :redirect
323 assert_response :success
324 assert_template "login"
326 post "/login", :username => user.display_name.upcase, :password => "test", :referer => "/history"
327 assert_response :redirect
329 assert_response :success
330 assert_template "changeset/history"
331 assert_select "span.username", "TEST"
334 def test_login_username_password_normal_titlecase
335 user = users(:normal_user)
338 assert_response :redirect
339 assert_redirected_to :controller => :user, :action => :login, :cookie_test => true
341 assert_response :success
343 post "/login", :username => user.display_name.titlecase, :password => "wrong", :referer => "/history"
344 assert_response :redirect
346 assert_response :success
347 assert_template "login"
349 post "/login", :username => user.display_name.titlecase, :password => "test", :referer => "/history"
350 assert_response :redirect
352 assert_response :success
353 assert_template "login"
354 assert_select "span.username", false
357 def test_login_username_password_public
358 user = users(:public_user)
361 assert_response :redirect
362 assert_redirected_to :controller => :user, :action => :login, :cookie_test => true
364 assert_response :success
366 post "/login", :username => user.display_name, :password => "wrong", :referer => "/history"
367 assert_response :redirect
369 assert_response :success
370 assert_template "login"
372 post "/login", :username => user.display_name, :password => "test", :referer => "/history"
373 assert_response :redirect
375 assert_response :success
376 assert_template "changeset/history"
377 assert_select "span.username", "test2"
380 def test_login_username_password_public_upcase
381 user = users(:public_user)
384 assert_response :redirect
385 assert_redirected_to :controller => :user, :action => :login, :cookie_test => true
387 assert_response :success
389 post "/login", :username => user.display_name.upcase, :password => "wrong", :referer => "/history"
390 assert_response :redirect
392 assert_response :success
393 assert_template "login"
395 post "/login", :username => user.display_name.upcase, :password => "test", :referer => "/history"
396 assert_response :redirect
398 assert_response :success
399 assert_template "changeset/history"
400 assert_select "span.username", "test2"
403 def test_login_username_password_public_titlecase
404 user = users(:public_user)
407 assert_response :redirect
408 assert_redirected_to :controller => :user, :action => :login, :cookie_test => true
410 assert_response :success
412 post "/login", :username => user.display_name.titlecase, :password => "wrong", :referer => "/history"
413 assert_response :redirect
415 assert_response :success
416 assert_template "login"
418 post "/login", :username => user.display_name.titlecase, :password => "test", :referer => "/history"
419 assert_response :redirect
421 assert_response :success
422 assert_template "changeset/history"
423 assert_select "span.username", "test2"
426 def test_login_username_password_inactive
427 user = users(:inactive_user)
430 assert_response :redirect
431 assert_redirected_to :controller => :user, :action => :login, :cookie_test => true
433 assert_response :success
435 post "/login", :username => user.display_name, :password => "wrong", :referer => "/history"
436 assert_response :redirect
438 assert_response :success
439 assert_template "login"
441 post "/login", :username => user.display_name, :password => "test2", :referer => "/history"
442 assert_response :redirect
444 assert_response :success
445 assert_template "confirm"
448 def test_login_username_password_inactive_upcase
449 user = users(:inactive_user)
452 assert_response :redirect
453 assert_redirected_to :controller => :user, :action => :login, :cookie_test => true
455 assert_response :success
457 post "/login", :username => user.display_name.upcase, :password => "wrong", :referer => "/history"
458 assert_response :redirect
460 assert_response :success
461 assert_template "login"
463 post "/login", :username => user.display_name.upcase, :password => "test2", :referer => "/history"
464 assert_response :redirect
466 assert_response :success
467 assert_template "confirm"
470 def test_login_username_password_inactive_titlecase
471 user = users(:inactive_user)
474 assert_response :redirect
475 assert_redirected_to :controller => :user, :action => :login, :cookie_test => true
477 assert_response :success
479 post "/login", :username => user.display_name.titlecase, :password => "wrong", :referer => "/history"
480 assert_response :redirect
482 assert_response :success
483 assert_template "login"
485 post "/login", :username => user.display_name.titlecase, :password => "test2", :referer => "/history"
486 assert_response :redirect
488 assert_response :success
489 assert_template "confirm"
492 def test_login_username_password_suspended
493 user = users(:suspended_user)
496 assert_response :redirect
497 assert_redirected_to :controller => :user, :action => :login, :cookie_test => true
499 assert_response :success
501 post "/login", :username => user.display_name, :password => "wrong", :referer => "/history"
502 assert_response :redirect
504 assert_response :success
505 assert_template "login"
507 post "/login", :username => user.display_name, :password => "test", :referer => "/history"
508 assert_response :redirect
510 assert_response :success
511 assert_template "login"
512 assert_select "div.flash.error", /your account has been suspended/
515 def test_login_username_password_suspended_upcase
516 user = users(:suspended_user)
519 assert_response :redirect
520 assert_redirected_to :controller => :user, :action => :login, :cookie_test => true
522 assert_response :success
524 post "/login", :username => user.display_name.upcase, :password => "wrong", :referer => "/history"
525 assert_response :redirect
527 assert_response :success
528 assert_template "login"
530 post "/login", :username => user.display_name.upcase, :password => "test", :referer => "/history"
531 assert_response :redirect
533 assert_response :success
534 assert_template "login"
535 assert_select "div.flash.error", /your account has been suspended/
538 def test_login_username_password_suspended_titlecase
539 user = users(:suspended_user)
542 assert_response :redirect
543 assert_redirected_to :controller => :user, :action => :login, :cookie_test => true
545 assert_response :success
547 post "/login", :username => user.display_name.titlecase, :password => "wrong", :referer => "/history"
548 assert_response :redirect
550 assert_response :success
551 assert_template "login"
553 post "/login", :username => user.display_name.titlecase, :password => "test", :referer => "/history"
554 assert_response :redirect
556 assert_response :success
557 assert_template "login"
558 assert_select "div.flash.error", /your account has been suspended/
561 def test_login_email_password_remember_me
562 user = users(:normal_user)
565 assert_response :redirect
566 assert_redirected_to :controller => :user, :action => :login, :cookie_test => true
568 assert_response :success
570 post "/login", :username => user.email, :password => "test", :remember_me => true, :referer => "/history"
571 assert_response :redirect
573 assert_response :success
574 assert_template "changeset/history"
575 assert_select "span.username", "test"
576 assert session.key?(:_remember_for)
579 def test_login_username_password_remember_me
580 user = users(:normal_user)
583 assert_response :redirect
584 assert_redirected_to :controller => :user, :action => :login, :cookie_test => true
586 assert_response :success
588 post "/login", :username => user.display_name, :password => "test", :remember_me => true, :referer => "/history"
589 assert_response :redirect
591 assert_response :success
592 assert_template "changeset/history"
593 assert_select "span.username", "test"
594 assert session.key?(:_remember_for)
597 def test_login_openid_success
598 OmniAuth.config.add_mock(:openid, :uid => "http://localhost:1123/john.doe")
601 assert_response :redirect
602 assert_redirected_to :controller => :user, :action => :login, :cookie_test => true
604 assert_response :success
605 post "/login", :openid_url => "http://localhost:1123/john.doe", :referer => "/history"
606 assert_response :redirect
607 assert_redirected_to auth_path(:provider => "openid", :openid_url => "http://localhost:1123/john.doe", :origin => "/login")
609 assert_response :redirect
610 assert_redirected_to auth_success_path(:provider => "openid", :openid_url => "http://localhost:1123/john.doe", :origin => "/login")
612 assert_response :redirect
614 assert_response :success
615 assert_template "changeset/history"
616 assert_select "span.username", "openIDuser"
619 def test_login_openid_remember_me
620 OmniAuth.config.add_mock(:openid, :uid => "http://localhost:1123/john.doe")
623 assert_response :redirect
624 assert_redirected_to :controller => :user, :action => :login, :cookie_test => true
626 assert_response :success
627 post "/login", :openid_url => "http://localhost:1123/john.doe", :remember_me_openid => true, :referer => "/history"
628 assert_response :redirect
629 assert_redirected_to auth_path(:provider => "openid", :openid_url => "http://localhost:1123/john.doe", :origin => "/login")
631 assert_response :redirect
632 assert_redirected_to auth_success_path(:provider => "openid", :openid_url => "http://localhost:1123/john.doe", :origin => "/login")
634 assert_response :redirect
636 assert_response :success
637 assert_template "changeset/history"
638 assert_select "span.username", "openIDuser"
639 assert session.key?(:_remember_for)
642 def test_login_openid_connection_failed
643 OmniAuth.config.mock_auth[:openid] = :connection_failed
646 assert_response :redirect
647 assert_redirected_to :controller => :user, :action => :login, :cookie_test => true
649 assert_response :success
650 post "/login", :openid_url => "http://localhost:1123/john.doe", :referer => "/history"
651 assert_response :redirect
652 assert_redirected_to auth_path(:provider => "openid", :openid_url => "http://localhost:1123/john.doe", :origin => "/login")
654 assert_response :redirect
655 assert_redirected_to auth_success_path(:provider => "openid", :openid_url => "http://localhost:1123/john.doe", :origin => "/login")
657 assert_response :redirect
658 assert_redirected_to auth_failure_path(:strategy => "openid", :message => "connection_failed", :origin => "/login")
660 assert_response :redirect
662 assert_response :success
663 assert_template "login"
664 assert_select "div.flash.error", "Connection to authentication provider failed"
665 assert_select "span.username", false
668 def test_login_openid_invalid_credentials
669 OmniAuth.config.mock_auth[:openid] = :invalid_credentials
672 assert_response :redirect
673 assert_redirected_to :controller => :user, :action => :login, :cookie_test => true
675 assert_response :success
676 post "/login", :openid_url => "http://localhost:1123/john.doe", :referer => "/history"
677 assert_response :redirect
678 assert_redirected_to auth_path(:provider => "openid", :openid_url => "http://localhost:1123/john.doe", :origin => "/login")
680 assert_response :redirect
681 assert_redirected_to auth_success_path(:provider => "openid", :openid_url => "http://localhost:1123/john.doe", :origin => "/login")
683 assert_response :redirect
684 assert_redirected_to auth_failure_path(:strategy => "openid", :message => "invalid_credentials", :origin => "/login")
686 assert_response :redirect
688 assert_response :success
689 assert_template "login"
690 assert_select "div.flash.error", "Invalid authentication credentials"
691 assert_select "span.username", false
694 def test_login_openid_unknown
695 OmniAuth.config.add_mock(:openid, :uid => "http://localhost:1123/fred.bloggs")
698 assert_response :redirect
699 assert_redirected_to :controller => :user, :action => :login, :cookie_test => true
701 assert_response :success
702 post "/login", :openid_url => "http://localhost:1123/fred.bloggs", :referer => "/diary"
703 assert_response :redirect
704 assert_redirected_to auth_path(:provider => "openid", :openid_url => "http://localhost:1123/fred.bloggs", :origin => "/login")
706 assert_response :redirect
707 assert_redirected_to auth_success_path(:provider => "openid", :openid_url => "http://localhost:1123/fred.bloggs", :origin => "/login")
709 assert_response :redirect
711 assert_response :success
712 assert_template "user/new"
713 assert_select "span.username", false