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", :extra => {
976 :id_info => { "openid_id" => "http://localhost:1123/fred.bloggs" }
979 get "/login", :referer => "/history"
980 assert_response :redirect
981 assert_redirected_to "controller" => "user", "action" => "login", "cookie_test" => "true", "referer" => "/history"
983 assert_response :success
984 assert_template "user/login"
985 get auth_path(:provider => "facebook", :origin => "/login")
986 assert_response :redirect
987 assert_redirected_to auth_success_path(:provider => "facebook")
989 assert_response :redirect
991 assert_response :success
992 assert_template "changeset/history"
993 assert_select "span.username", "facebookuser"
996 def test_login_facebook_connection_failed
997 OmniAuth.config.mock_auth[:facebook] = :connection_failed
999 get "/login", :referer => "/history"
1000 assert_response :redirect
1001 assert_redirected_to "controller" => "user", "action" => "login", "cookie_test" => "true", "referer" => "/history"
1003 assert_response :success
1004 assert_template "user/login"
1005 get auth_path(:provider => "facebook", :origin => "/login")
1006 assert_response :redirect
1007 assert_redirected_to auth_success_path(:provider => "facebook")
1009 assert_response :redirect
1010 assert_redirected_to auth_failure_path(:strategy => "facebook", :message => "connection_failed", :origin => "/login")
1012 assert_response :redirect
1014 assert_response :success
1015 assert_template "login"
1016 assert_select "div.flash.error", "Connection to authentication provider failed"
1017 assert_select "span.username", false
1020 def test_login_facebook_invalid_credentials
1021 OmniAuth.config.mock_auth[:facebook] = :invalid_credentials
1023 get "/login", :referer => "/history"
1024 assert_response :redirect
1025 assert_redirected_to "controller" => "user", "action" => "login", "cookie_test" => "true", "referer" => "/history"
1027 assert_response :success
1028 assert_template "user/login"
1029 get auth_path(:provider => "facebook", :origin => "/login")
1030 assert_response :redirect
1031 assert_redirected_to auth_success_path(:provider => "facebook")
1033 assert_response :redirect
1034 assert_redirected_to auth_failure_path(:strategy => "facebook", :message => "invalid_credentials", :origin => "/login")
1036 assert_response :redirect
1038 assert_response :success
1039 assert_template "login"
1040 assert_select "div.flash.error", "Invalid authentication credentials"
1041 assert_select "span.username", false
1044 def test_login_facebook_unknown
1045 OmniAuth.config.add_mock(:facebook, :uid => "987654321", :extra => {
1046 :id_info => { "openid_id" => "http://localhost:1123/fred.bloggs" }
1049 get "/login", :referer => "/history"
1050 assert_response :redirect
1051 assert_redirected_to "controller" => "user", "action" => "login", "cookie_test" => "true", "referer" => "/history"
1053 assert_response :success
1054 assert_template "user/login"
1055 get auth_path(:provider => "facebook", :origin => "/login")
1056 assert_response :redirect
1057 assert_redirected_to auth_success_path(:provider => "facebook")
1059 assert_response :redirect
1061 assert_response :success
1062 assert_template "user/new"
1063 assert_select "span.username", false
1066 def test_login_windowslive_success
1067 OmniAuth.config.add_mock(:windowslive, :uid => "123456789", :extra => {
1068 :id_info => { "openid_id" => "http://localhost:1123/fred.bloggs" }
1071 get "/login", :referer => "/history"
1072 assert_response :redirect
1073 assert_redirected_to "controller" => "user", "action" => "login", "cookie_test" => "true", "referer" => "/history"
1075 assert_response :success
1076 assert_template "user/login"
1077 get auth_path(:provider => "windowslive", :origin => "/login")
1078 assert_response :redirect
1079 assert_redirected_to auth_success_path(:provider => "windowslive")
1081 assert_response :redirect
1083 assert_response :success
1084 assert_template "changeset/history"
1085 assert_select "span.username", "windowsliveuser"
1088 def test_login_windowslive_connection_failed
1089 OmniAuth.config.mock_auth[:windowslive] = :connection_failed
1091 get "/login", :referer => "/history"
1092 assert_response :redirect
1093 assert_redirected_to "controller" => "user", "action" => "login", "cookie_test" => "true", "referer" => "/history"
1095 assert_response :success
1096 assert_template "user/login"
1097 get auth_path(:provider => "windowslive", :origin => "/login")
1098 assert_response :redirect
1099 assert_redirected_to auth_success_path(:provider => "windowslive")
1101 assert_response :redirect
1102 assert_redirected_to auth_failure_path(:strategy => "windowslive", :message => "connection_failed", :origin => "/login")
1104 assert_response :redirect
1106 assert_response :success
1107 assert_template "login"
1108 assert_select "div.flash.error", "Connection to authentication provider failed"
1109 assert_select "span.username", false
1112 def test_login_windowslive_invalid_credentials
1113 OmniAuth.config.mock_auth[:windowslive] = :invalid_credentials
1115 get "/login", :referer => "/history"
1116 assert_response :redirect
1117 assert_redirected_to "controller" => "user", "action" => "login", "cookie_test" => "true", "referer" => "/history"
1119 assert_response :success
1120 assert_template "user/login"
1121 get auth_path(:provider => "windowslive", :origin => "/login")
1122 assert_response :redirect
1123 assert_redirected_to auth_success_path(:provider => "windowslive")
1125 assert_response :redirect
1126 assert_redirected_to auth_failure_path(:strategy => "windowslive", :message => "invalid_credentials", :origin => "/login")
1128 assert_response :redirect
1130 assert_response :success
1131 assert_template "login"
1132 assert_select "div.flash.error", "Invalid authentication credentials"
1133 assert_select "span.username", false
1136 def test_login_windowslive_unknown
1137 OmniAuth.config.add_mock(:windowslive, :uid => "987654321", :extra => {
1138 :id_info => { "openid_id" => "http://localhost:1123/fred.bloggs" }
1141 get "/login", :referer => "/history"
1142 assert_response :redirect
1143 assert_redirected_to "controller" => "user", "action" => "login", "cookie_test" => "true", "referer" => "/history"
1145 assert_response :success
1146 assert_template "user/login"
1147 get auth_path(:provider => "windowslive", :origin => "/login")
1148 assert_response :redirect
1149 assert_redirected_to auth_success_path(:provider => "windowslive")
1151 assert_response :redirect
1153 assert_response :success
1154 assert_template "user/new"
1155 assert_select "span.username", false