3 class UserLoginTest < ActionDispatch::IntegrationTest
4 fixtures :users, :user_blocks
7 OmniAuth.config.test_mode = true
11 OmniAuth.config.mock_auth[:openid] = nil
12 OmniAuth.config.mock_auth[:google] = nil
13 OmniAuth.config.mock_auth[:facebook] = nil
14 OmniAuth.config.mock_auth[:windowslive] = nil
15 OmniAuth.config.test_mode = false
18 def test_login_email_password_normal
19 user = users(:normal_user)
22 assert_response :redirect
23 assert_redirected_to :controller => :user, :action => :login, :cookie_test => true
25 assert_response :success
27 post "/login", :username => user.email, :password => "wrong", :referer => "/history"
28 assert_response :redirect
30 assert_response :success
31 assert_template "login"
33 post "/login", :username => user.email, :password => "test", :referer => "/history"
34 assert_response :redirect
36 assert_response :success
37 assert_template "changeset/history"
38 assert_select "span.username", "test"
41 def test_login_email_password_normal_upcase
42 user = users(:normal_user)
45 assert_response :redirect
46 assert_redirected_to :controller => :user, :action => :login, :cookie_test => true
48 assert_response :success
50 post "/login", :username => user.email.upcase, :password => "wrong", :referer => "/history"
51 assert_response :redirect
53 assert_response :success
54 assert_template "login"
56 post "/login", :username => user.email.upcase, :password => "test", :referer => "/history"
57 assert_response :redirect
59 assert_response :success
60 assert_template "changeset/history"
61 assert_select "span.username", "TEST"
64 def test_login_email_password_normal_titlecase
65 user = users(:normal_user)
68 assert_response :redirect
69 assert_redirected_to :controller => :user, :action => :login, :cookie_test => true
71 assert_response :success
73 post "/login", :username => user.email.titlecase, :password => "wrong", :referer => "/history"
74 assert_response :redirect
76 assert_response :success
77 assert_template "login"
79 post "/login", :username => user.email.titlecase, :password => "test", :referer => "/history"
80 assert_response :redirect
82 assert_response :success
83 assert_template "login"
84 assert_select "span.username", false
87 def test_login_email_password_public
88 user = users(:public_user)
91 assert_response :redirect
92 assert_redirected_to :controller => :user, :action => :login, :cookie_test => true
94 assert_response :success
96 post "/login", :username => user.email, :password => "wrong", :referer => "/history"
97 assert_response :redirect
99 assert_response :success
100 assert_template "login"
102 post "/login", :username => user.email, :password => "test", :referer => "/history"
103 assert_response :redirect
105 assert_response :success
106 assert_template "changeset/history"
107 assert_select "span.username", "test2"
110 def test_login_email_password_public_upcase
111 user = users(:public_user)
114 assert_response :redirect
115 assert_redirected_to :controller => :user, :action => :login, :cookie_test => true
117 assert_response :success
119 post "/login", :username => user.email.upcase, :password => "wrong", :referer => "/history"
120 assert_response :redirect
122 assert_response :success
123 assert_template "login"
125 post "/login", :username => user.email.upcase, :password => "test", :referer => "/history"
126 assert_response :redirect
128 assert_response :success
129 assert_template "changeset/history"
130 assert_select "span.username", "test2"
133 def test_login_email_password_public_titlecase
134 user = users(:public_user)
137 assert_response :redirect
138 assert_redirected_to :controller => :user, :action => :login, :cookie_test => true
140 assert_response :success
142 post "/login", :username => user.email.titlecase, :password => "wrong", :referer => "/history"
143 assert_response :redirect
145 assert_response :success
146 assert_template "login"
148 post "/login", :username => user.email.titlecase, :password => "test", :referer => "/history"
149 assert_response :redirect
151 assert_response :success
152 assert_template "changeset/history"
153 assert_select "span.username", "test2"
156 def test_login_email_password_inactive
157 user = users(:inactive_user)
160 assert_response :redirect
161 assert_redirected_to :controller => :user, :action => :login, :cookie_test => true
163 assert_response :success
165 post "/login", :username => user.email, :password => "wrong", :referer => "/history"
166 assert_response :redirect
168 assert_response :success
169 assert_template "login"
171 post "/login", :username => user.email, :password => "test2", :referer => "/history"
172 assert_response :redirect
174 assert_response :success
175 assert_template "confirm"
178 def test_login_email_password_inactive_upcase
179 user = users(:inactive_user)
182 assert_response :redirect
183 assert_redirected_to :controller => :user, :action => :login, :cookie_test => true
185 assert_response :success
187 post "/login", :username => user.email.upcase, :password => "wrong", :referer => "/history"
188 assert_response :redirect
190 assert_response :success
191 assert_template "login"
193 post "/login", :username => user.email.upcase, :password => "test2", :referer => "/history"
194 assert_response :redirect
196 assert_response :success
197 assert_template "confirm"
200 def test_login_email_password_inactive_titlecase
201 user = users(:inactive_user)
204 assert_response :redirect
205 assert_redirected_to :controller => :user, :action => :login, :cookie_test => true
207 assert_response :success
209 post "/login", :username => user.email.titlecase, :password => "wrong", :referer => "/history"
210 assert_response :redirect
212 assert_response :success
213 assert_template "login"
215 post "/login", :username => user.email.titlecase, :password => "test2", :referer => "/history"
216 assert_response :redirect
218 assert_response :success
219 assert_template "confirm"
222 def test_login_email_password_suspended
223 user = users(:suspended_user)
226 assert_response :redirect
227 assert_redirected_to :controller => :user, :action => :login, :cookie_test => true
229 assert_response :success
231 post "/login", :username => user.email, :password => "wrong", :referer => "/history"
232 assert_response :redirect
234 assert_response :success
235 assert_template "login"
237 post "/login", :username => user.email, :password => "test", :referer => "/history"
238 assert_response :redirect
240 assert_response :success
241 assert_template "login"
242 assert_select "div.flash.error", /your account has been suspended/
245 def test_login_email_password_suspended_upcase
246 user = users(:suspended_user)
249 assert_response :redirect
250 assert_redirected_to :controller => :user, :action => :login, :cookie_test => true
252 assert_response :success
254 post "/login", :username => user.email.upcase, :password => "wrong", :referer => "/history"
255 assert_response :redirect
257 assert_response :success
258 assert_template "login"
260 post "/login", :username => user.email.upcase, :password => "test", :referer => "/history"
261 assert_response :redirect
263 assert_response :success
264 assert_template "login"
265 assert_select "div.flash.error", /your account has been suspended/
268 def test_login_email_password_suspended_titlecase
269 user = users(:suspended_user)
272 assert_response :redirect
273 assert_redirected_to :controller => :user, :action => :login, :cookie_test => true
275 assert_response :success
277 post "/login", :username => user.email.titlecase, :password => "wrong", :referer => "/history"
278 assert_response :redirect
280 assert_response :success
281 assert_template "login"
283 post "/login", :username => user.email.titlecase, :password => "test", :referer => "/history"
284 assert_response :redirect
286 assert_response :success
287 assert_template "login"
288 assert_select "div.flash.error", /your account has been suspended/
291 def test_login_email_password_blocked
292 user = users(:blocked_user)
295 assert_response :redirect
296 assert_redirected_to :controller => :user, :action => :login, :cookie_test => true
298 assert_response :success
300 post "/login", :username => user.email, :password => "wrong", :referer => "/history"
301 assert_response :redirect
303 assert_response :success
304 assert_template "login"
306 post "/login", :username => user.email, :password => "test", :referer => "/history"
307 assert_response :redirect
309 assert_response :success
310 assert_template "user_blocks/show"
313 def test_login_email_password_blocked_upcase
314 user = users(:blocked_user)
317 assert_response :redirect
318 assert_redirected_to :controller => :user, :action => :login, :cookie_test => true
320 assert_response :success
322 post "/login", :username => user.email.upcase, :password => "wrong", :referer => "/history"
323 assert_response :redirect
325 assert_response :success
326 assert_template "login"
328 post "/login", :username => user.email.upcase, :password => "test", :referer => "/history"
329 assert_response :redirect
331 assert_response :success
332 assert_template "user_blocks/show"
335 def test_login_email_password_blocked_titlecase
336 user = users(:blocked_user)
339 assert_response :redirect
340 assert_redirected_to :controller => :user, :action => :login, :cookie_test => true
342 assert_response :success
344 post "/login", :username => user.email.titlecase, :password => "wrong", :referer => "/history"
345 assert_response :redirect
347 assert_response :success
348 assert_template "login"
350 post "/login", :username => user.email.titlecase, :password => "test", :referer => "/history"
351 assert_response :redirect
353 assert_response :success
354 assert_template "user_blocks/show"
357 def test_login_username_password_normal
358 user = users(:normal_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", "test"
380 def test_login_username_password_normal_upcase
381 user = users(:normal_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", "TEST"
403 def test_login_username_password_normal_titlecase
404 user = users(:normal_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 "login"
423 assert_select "span.username", false
426 def test_login_username_password_public
427 user = users(:public_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 => "test", :referer => "/history"
442 assert_response :redirect
444 assert_response :success
445 assert_template "changeset/history"
446 assert_select "span.username", "test2"
449 def test_login_username_password_public_upcase
450 user = users(:public_user)
453 assert_response :redirect
454 assert_redirected_to :controller => :user, :action => :login, :cookie_test => true
456 assert_response :success
458 post "/login", :username => user.display_name.upcase, :password => "wrong", :referer => "/history"
459 assert_response :redirect
461 assert_response :success
462 assert_template "login"
464 post "/login", :username => user.display_name.upcase, :password => "test", :referer => "/history"
465 assert_response :redirect
467 assert_response :success
468 assert_template "changeset/history"
469 assert_select "span.username", "test2"
472 def test_login_username_password_public_titlecase
473 user = users(:public_user)
476 assert_response :redirect
477 assert_redirected_to :controller => :user, :action => :login, :cookie_test => true
479 assert_response :success
481 post "/login", :username => user.display_name.titlecase, :password => "wrong", :referer => "/history"
482 assert_response :redirect
484 assert_response :success
485 assert_template "login"
487 post "/login", :username => user.display_name.titlecase, :password => "test", :referer => "/history"
488 assert_response :redirect
490 assert_response :success
491 assert_template "changeset/history"
492 assert_select "span.username", "test2"
495 def test_login_username_password_inactive
496 user = users(:inactive_user)
499 assert_response :redirect
500 assert_redirected_to :controller => :user, :action => :login, :cookie_test => true
502 assert_response :success
504 post "/login", :username => user.display_name, :password => "wrong", :referer => "/history"
505 assert_response :redirect
507 assert_response :success
508 assert_template "login"
510 post "/login", :username => user.display_name, :password => "test2", :referer => "/history"
511 assert_response :redirect
513 assert_response :success
514 assert_template "confirm"
517 def test_login_username_password_inactive_upcase
518 user = users(:inactive_user)
521 assert_response :redirect
522 assert_redirected_to :controller => :user, :action => :login, :cookie_test => true
524 assert_response :success
526 post "/login", :username => user.display_name.upcase, :password => "wrong", :referer => "/history"
527 assert_response :redirect
529 assert_response :success
530 assert_template "login"
532 post "/login", :username => user.display_name.upcase, :password => "test2", :referer => "/history"
533 assert_response :redirect
535 assert_response :success
536 assert_template "confirm"
539 def test_login_username_password_inactive_titlecase
540 user = users(:inactive_user)
543 assert_response :redirect
544 assert_redirected_to :controller => :user, :action => :login, :cookie_test => true
546 assert_response :success
548 post "/login", :username => user.display_name.titlecase, :password => "wrong", :referer => "/history"
549 assert_response :redirect
551 assert_response :success
552 assert_template "login"
554 post "/login", :username => user.display_name.titlecase, :password => "test2", :referer => "/history"
555 assert_response :redirect
557 assert_response :success
558 assert_template "confirm"
561 def test_login_username_password_suspended
562 user = users(:suspended_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.display_name, :password => "wrong", :referer => "/history"
571 assert_response :redirect
573 assert_response :success
574 assert_template "login"
576 post "/login", :username => user.display_name, :password => "test", :referer => "/history"
577 assert_response :redirect
579 assert_response :success
580 assert_template "login"
581 assert_select "div.flash.error", /your account has been suspended/
584 def test_login_username_password_suspended_upcase
585 user = users(:suspended_user)
588 assert_response :redirect
589 assert_redirected_to :controller => :user, :action => :login, :cookie_test => true
591 assert_response :success
593 post "/login", :username => user.display_name.upcase, :password => "wrong", :referer => "/history"
594 assert_response :redirect
596 assert_response :success
597 assert_template "login"
599 post "/login", :username => user.display_name.upcase, :password => "test", :referer => "/history"
600 assert_response :redirect
602 assert_response :success
603 assert_template "login"
604 assert_select "div.flash.error", /your account has been suspended/
607 def test_login_username_password_suspended_titlecase
608 user = users(:suspended_user)
611 assert_response :redirect
612 assert_redirected_to :controller => :user, :action => :login, :cookie_test => true
614 assert_response :success
616 post "/login", :username => user.display_name.titlecase, :password => "wrong", :referer => "/history"
617 assert_response :redirect
619 assert_response :success
620 assert_template "login"
622 post "/login", :username => user.display_name.titlecase, :password => "test", :referer => "/history"
623 assert_response :redirect
625 assert_response :success
626 assert_template "login"
627 assert_select "div.flash.error", /your account has been suspended/
630 def test_login_username_password_blocked
631 user = users(:blocked_user)
634 assert_response :redirect
635 assert_redirected_to :controller => :user, :action => :login, :cookie_test => true
637 assert_response :success
639 post "/login", :username => user.display_name, :password => "wrong", :referer => "/history"
640 assert_response :redirect
642 assert_response :success
643 assert_template "login"
645 post "/login", :username => user.display_name, :password => "test", :referer => "/history"
646 assert_response :redirect
648 assert_response :success
649 assert_template "user_blocks/show"
652 def test_login_username_password_blocked_upcase
653 user = users(:blocked_user)
656 assert_response :redirect
657 assert_redirected_to :controller => :user, :action => :login, :cookie_test => true
659 assert_response :success
661 post "/login", :username => user.display_name.upcase, :password => "wrong", :referer => "/history"
662 assert_response :redirect
664 assert_response :success
665 assert_template "login"
667 post "/login", :username => user.display_name.upcase, :password => "test", :referer => "/history"
668 assert_response :redirect
670 assert_response :success
671 assert_template "user_blocks/show"
674 def test_login_username_password_blocked_titlecase
675 user = users(:blocked_user)
678 assert_response :redirect
679 assert_redirected_to :controller => :user, :action => :login, :cookie_test => true
681 assert_response :success
683 post "/login", :username => user.display_name.titlecase, :password => "wrong", :referer => "/history"
684 assert_response :redirect
686 assert_response :success
687 assert_template "login"
689 post "/login", :username => user.display_name.titlecase, :password => "test", :referer => "/history"
690 assert_response :redirect
692 assert_response :success
693 assert_template "user_blocks/show"
696 def test_login_email_password_remember_me
697 user = users(:normal_user)
700 assert_response :redirect
701 assert_redirected_to :controller => :user, :action => :login, :cookie_test => true
703 assert_response :success
705 post "/login", :username => user.email, :password => "test", :remember_me => true, :referer => "/history"
706 assert_response :redirect
708 assert_response :success
709 assert_template "changeset/history"
710 assert_select "span.username", "test"
711 assert session.key?(:_remember_for)
714 def test_login_username_password_remember_me
715 user = users(:normal_user)
718 assert_response :redirect
719 assert_redirected_to :controller => :user, :action => :login, :cookie_test => true
721 assert_response :success
723 post "/login", :username => user.display_name, :password => "test", :remember_me => true, :referer => "/history"
724 assert_response :redirect
726 assert_response :success
727 assert_template "changeset/history"
728 assert_select "span.username", "test"
729 assert session.key?(:_remember_for)
732 def test_login_openid_success
733 OmniAuth.config.add_mock(:openid, :uid => "http://localhost:1123/john.doe")
735 get "/login", :referer => "/history"
736 assert_response :redirect
737 assert_redirected_to :controller => :user, :action => :login, :cookie_test => true, :referer => "/history"
739 assert_response :success
740 assert_template "user/login"
741 post "/login", :openid_url => "http://localhost:1123/john.doe", :referer => "/history"
742 assert_response :redirect
743 assert_redirected_to auth_path(:provider => "openid", :openid_url => "http://localhost:1123/john.doe", :origin => "/login")
745 assert_response :redirect
746 assert_redirected_to auth_success_path(:provider => "openid", :openid_url => "http://localhost:1123/john.doe", :origin => "/login")
748 assert_response :redirect
750 assert_response :success
751 assert_template "changeset/history"
752 assert_select "span.username", "openIDuser"
755 def test_login_openid_remember_me
756 OmniAuth.config.add_mock(:openid, :uid => "http://localhost:1123/john.doe")
758 get "/login", :referer => "/history"
759 assert_response :redirect
760 assert_redirected_to :controller => :user, :action => :login, :cookie_test => true, :referer => "/history"
762 assert_response :success
763 assert_template "user/login"
764 post "/login", :openid_url => "http://localhost:1123/john.doe", :remember_me_openid => true, :referer => "/history"
765 assert_response :redirect
766 assert_redirected_to auth_path(:provider => "openid", :openid_url => "http://localhost:1123/john.doe", :origin => "/login")
768 assert_response :redirect
769 assert_redirected_to auth_success_path(:provider => "openid", :openid_url => "http://localhost:1123/john.doe", :origin => "/login")
771 assert_response :redirect
773 assert_response :success
774 assert_template "changeset/history"
775 assert_select "span.username", "openIDuser"
776 assert session.key?(:_remember_for)
779 def test_login_openid_connection_failed
780 OmniAuth.config.mock_auth[:openid] = :connection_failed
782 get "/login", :referer => "/history"
783 assert_response :redirect
784 assert_redirected_to :controller => :user, :action => :login, :cookie_test => true, :referer => "/history"
786 assert_response :success
787 assert_template "user/login"
788 post "/login", :openid_url => "http://localhost:1123/john.doe", :referer => "/history"
789 assert_response :redirect
790 assert_redirected_to auth_path(:provider => "openid", :openid_url => "http://localhost:1123/john.doe", :origin => "/login")
792 assert_response :redirect
793 assert_redirected_to auth_success_path(:provider => "openid", :openid_url => "http://localhost:1123/john.doe", :origin => "/login")
795 assert_response :redirect
796 assert_redirected_to auth_failure_path(:strategy => "openid", :message => "connection_failed", :origin => "/login")
798 assert_response :redirect
800 assert_response :success
801 assert_template "login"
802 assert_select "div.flash.error", "Connection to authentication provider failed"
803 assert_select "span.username", false
806 def test_login_openid_invalid_credentials
807 OmniAuth.config.mock_auth[:openid] = :invalid_credentials
809 get "/login", :referer => "/history"
810 assert_response :redirect
811 assert_redirected_to :controller => :user, :action => :login, :cookie_test => true, :referer => "/history"
813 assert_response :success
814 assert_template "user/login"
815 post "/login", :openid_url => "http://localhost:1123/john.doe", :referer => "/history"
816 assert_response :redirect
817 assert_redirected_to auth_path(:provider => "openid", :openid_url => "http://localhost:1123/john.doe", :origin => "/login")
819 assert_response :redirect
820 assert_redirected_to auth_success_path(:provider => "openid", :openid_url => "http://localhost:1123/john.doe", :origin => "/login")
822 assert_response :redirect
823 assert_redirected_to auth_failure_path(:strategy => "openid", :message => "invalid_credentials", :origin => "/login")
825 assert_response :redirect
827 assert_response :success
828 assert_template "login"
829 assert_select "div.flash.error", "Invalid authentication credentials"
830 assert_select "span.username", false
833 def test_login_openid_unknown
834 OmniAuth.config.add_mock(:openid, :uid => "http://localhost:1123/fred.bloggs")
836 get "/login", :referer => "/history"
837 assert_response :redirect
838 assert_redirected_to :controller => :user, :action => :login, :cookie_test => true, :referer => "/history"
840 assert_response :success
841 assert_template "user/login"
842 post "/login", :openid_url => "http://localhost:1123/fred.bloggs", :referer => "/history"
843 assert_response :redirect
844 assert_redirected_to auth_path(:provider => "openid", :openid_url => "http://localhost:1123/fred.bloggs", :origin => "/login")
846 assert_response :redirect
847 assert_redirected_to auth_success_path(:provider => "openid", :openid_url => "http://localhost:1123/fred.bloggs", :origin => "/login")
849 assert_response :redirect
851 assert_response :success
852 assert_template "user/new"
853 assert_select "span.username", false
856 def test_login_google_success
857 OmniAuth.config.add_mock(:google, :uid => "123456789", :extra => {
858 :id_info => { "openid_id" => "http://localhost:1123/fred.bloggs" }
861 get "/login", :referer => "/history"
862 assert_response :redirect
863 assert_redirected_to "controller" => "user", "action" => "login", "cookie_test" => "true", "referer" => "/history"
865 assert_response :success
866 assert_template "user/login"
867 get auth_path(:provider => "google", :origin => "/login")
868 assert_response :redirect
869 assert_redirected_to auth_success_path(:provider => "google")
871 assert_response :redirect
873 assert_response :success
874 assert_template "changeset/history"
875 assert_select "span.username", "googleuser"
878 def test_login_google_connection_failed
879 OmniAuth.config.mock_auth[:google] = :connection_failed
881 get "/login", :referer => "/history"
882 assert_response :redirect
883 assert_redirected_to "controller" => "user", "action" => "login", "cookie_test" => "true", "referer" => "/history"
885 assert_response :success
886 assert_template "user/login"
887 get auth_path(:provider => "google", :origin => "/login")
888 assert_response :redirect
889 assert_redirected_to auth_success_path(:provider => "google")
891 assert_response :redirect
892 assert_redirected_to auth_failure_path(:strategy => "google", :message => "connection_failed", :origin => "/login")
894 assert_response :redirect
896 assert_response :success
897 assert_template "login"
898 assert_select "div.flash.error", "Connection to authentication provider failed"
899 assert_select "span.username", false
902 def test_login_google_invalid_credentials
903 OmniAuth.config.mock_auth[:google] = :invalid_credentials
905 get "/login", :referer => "/history"
906 assert_response :redirect
907 assert_redirected_to "controller" => "user", "action" => "login", "cookie_test" => "true", "referer" => "/history"
909 assert_response :success
910 assert_template "user/login"
911 get auth_path(:provider => "google", :origin => "/login")
912 assert_response :redirect
913 assert_redirected_to auth_success_path(:provider => "google")
915 assert_response :redirect
916 assert_redirected_to auth_failure_path(:strategy => "google", :message => "invalid_credentials", :origin => "/login")
918 assert_response :redirect
920 assert_response :success
921 assert_template "login"
922 assert_select "div.flash.error", "Invalid authentication credentials"
923 assert_select "span.username", false
926 def test_login_google_unknown
927 OmniAuth.config.add_mock(:google, :uid => "987654321", :extra => {
928 :id_info => { "openid_id" => "http://localhost:1123/fred.bloggs" }
931 get "/login", :referer => "/history"
932 assert_response :redirect
933 assert_redirected_to "controller" => "user", "action" => "login", "cookie_test" => "true", "referer" => "/history"
935 assert_response :success
936 assert_template "user/login"
937 get auth_path(:provider => "google", :origin => "/login")
938 assert_response :redirect
939 assert_redirected_to auth_success_path(:provider => "google")
941 assert_response :redirect
943 assert_response :success
944 assert_template "user/new"
945 assert_select "span.username", false
948 def test_login_google_upgrade
949 OmniAuth.config.add_mock(:google, :uid => "987654321", :extra => {
950 :id_info => { "openid_id" => "http://localhost:1123/john.doe" }
953 get "/login", :referer => "/history"
954 assert_response :redirect
955 assert_redirected_to "controller" => "user", "action" => "login", "cookie_test" => "true", "referer" => "/history"
957 assert_response :success
958 assert_template "user/login"
959 get auth_path(:provider => "google", :origin => "/login")
960 assert_response :redirect
961 assert_redirected_to auth_success_path(:provider => "google")
963 assert_response :redirect
965 assert_response :success
966 assert_template "changeset/history"
967 assert_select "span.username", "openIDuser"
969 user = User.find_by_display_name("openIDuser")
970 assert_equal "google", user.auth_provider
971 assert_equal "987654321", user.auth_uid
974 def test_login_facebook_success
975 OmniAuth.config.add_mock(:facebook, :uid => "123456789")
977 get "/login", :referer => "/history"
978 assert_response :redirect
979 assert_redirected_to "controller" => "user", "action" => "login", "cookie_test" => "true", "referer" => "/history"
981 assert_response :success
982 assert_template "user/login"
983 get auth_path(:provider => "facebook", :origin => "/login")
984 assert_response :redirect
985 assert_redirected_to auth_success_path(:provider => "facebook")
987 assert_response :redirect
989 assert_response :success
990 assert_template "changeset/history"
991 assert_select "span.username", "facebookuser"
994 def test_login_facebook_connection_failed
995 OmniAuth.config.mock_auth[:facebook] = :connection_failed
997 get "/login", :referer => "/history"
998 assert_response :redirect
999 assert_redirected_to "controller" => "user", "action" => "login", "cookie_test" => "true", "referer" => "/history"
1001 assert_response :success
1002 assert_template "user/login"
1003 get auth_path(:provider => "facebook", :origin => "/login")
1004 assert_response :redirect
1005 assert_redirected_to auth_success_path(:provider => "facebook")
1007 assert_response :redirect
1008 assert_redirected_to auth_failure_path(:strategy => "facebook", :message => "connection_failed", :origin => "/login")
1010 assert_response :redirect
1012 assert_response :success
1013 assert_template "login"
1014 assert_select "div.flash.error", "Connection to authentication provider failed"
1015 assert_select "span.username", false
1018 def test_login_facebook_invalid_credentials
1019 OmniAuth.config.mock_auth[:facebook] = :invalid_credentials
1021 get "/login", :referer => "/history"
1022 assert_response :redirect
1023 assert_redirected_to "controller" => "user", "action" => "login", "cookie_test" => "true", "referer" => "/history"
1025 assert_response :success
1026 assert_template "user/login"
1027 get auth_path(:provider => "facebook", :origin => "/login")
1028 assert_response :redirect
1029 assert_redirected_to auth_success_path(:provider => "facebook")
1031 assert_response :redirect
1032 assert_redirected_to auth_failure_path(:strategy => "facebook", :message => "invalid_credentials", :origin => "/login")
1034 assert_response :redirect
1036 assert_response :success
1037 assert_template "login"
1038 assert_select "div.flash.error", "Invalid authentication credentials"
1039 assert_select "span.username", false
1042 def test_login_facebook_unknown
1043 OmniAuth.config.add_mock(:facebook, :uid => "987654321")
1045 get "/login", :referer => "/history"
1046 assert_response :redirect
1047 assert_redirected_to "controller" => "user", "action" => "login", "cookie_test" => "true", "referer" => "/history"
1049 assert_response :success
1050 assert_template "user/login"
1051 get auth_path(:provider => "facebook", :origin => "/login")
1052 assert_response :redirect
1053 assert_redirected_to auth_success_path(:provider => "facebook")
1055 assert_response :redirect
1057 assert_response :success
1058 assert_template "user/new"
1059 assert_select "span.username", false
1062 def test_login_windowslive_success
1063 OmniAuth.config.add_mock(:windowslive, :uid => "123456789")
1065 get "/login", :referer => "/history"
1066 assert_response :redirect
1067 assert_redirected_to "controller" => "user", "action" => "login", "cookie_test" => "true", "referer" => "/history"
1069 assert_response :success
1070 assert_template "user/login"
1071 get auth_path(:provider => "windowslive", :origin => "/login")
1072 assert_response :redirect
1073 assert_redirected_to auth_success_path(:provider => "windowslive")
1075 assert_response :redirect
1077 assert_response :success
1078 assert_template "changeset/history"
1079 assert_select "span.username", "windowsliveuser"
1082 def test_login_windowslive_connection_failed
1083 OmniAuth.config.mock_auth[:windowslive] = :connection_failed
1085 get "/login", :referer => "/history"
1086 assert_response :redirect
1087 assert_redirected_to "controller" => "user", "action" => "login", "cookie_test" => "true", "referer" => "/history"
1089 assert_response :success
1090 assert_template "user/login"
1091 get auth_path(:provider => "windowslive", :origin => "/login")
1092 assert_response :redirect
1093 assert_redirected_to auth_success_path(:provider => "windowslive")
1095 assert_response :redirect
1096 assert_redirected_to auth_failure_path(:strategy => "windowslive", :message => "connection_failed", :origin => "/login")
1098 assert_response :redirect
1100 assert_response :success
1101 assert_template "login"
1102 assert_select "div.flash.error", "Connection to authentication provider failed"
1103 assert_select "span.username", false
1106 def test_login_windowslive_invalid_credentials
1107 OmniAuth.config.mock_auth[:windowslive] = :invalid_credentials
1109 get "/login", :referer => "/history"
1110 assert_response :redirect
1111 assert_redirected_to "controller" => "user", "action" => "login", "cookie_test" => "true", "referer" => "/history"
1113 assert_response :success
1114 assert_template "user/login"
1115 get auth_path(:provider => "windowslive", :origin => "/login")
1116 assert_response :redirect
1117 assert_redirected_to auth_success_path(:provider => "windowslive")
1119 assert_response :redirect
1120 assert_redirected_to auth_failure_path(:strategy => "windowslive", :message => "invalid_credentials", :origin => "/login")
1122 assert_response :redirect
1124 assert_response :success
1125 assert_template "login"
1126 assert_select "div.flash.error", "Invalid authentication credentials"
1127 assert_select "span.username", false
1130 def test_login_windowslive_unknown
1131 OmniAuth.config.add_mock(:windowslive, :uid => "987654321")
1133 get "/login", :referer => "/history"
1134 assert_response :redirect
1135 assert_redirected_to "controller" => "user", "action" => "login", "cookie_test" => "true", "referer" => "/history"
1137 assert_response :success
1138 assert_template "user/login"
1139 get auth_path(:provider => "windowslive", :origin => "/login")
1140 assert_response :redirect
1141 assert_redirected_to auth_success_path(:provider => "windowslive")
1143 assert_response :redirect
1145 assert_response :success
1146 assert_template "user/new"
1147 assert_select "span.username", false