3 class UserLoginTest < ActionDispatch::IntegrationTest
5 OmniAuth.config.test_mode = true
9 OmniAuth.config.mock_auth[:openid] = nil
10 OmniAuth.config.mock_auth[:google] = nil
11 OmniAuth.config.mock_auth[:facebook] = nil
12 OmniAuth.config.mock_auth[:windowslive] = nil
13 OmniAuth.config.mock_auth[:github] = nil
14 OmniAuth.config.mock_auth[:wikipedia] = nil
15 OmniAuth.config.test_mode = false
18 # It's possible to have multiple accounts in the database with only differences
19 # in email case, for hysterical raisins. We need to bypass the validation checks to
20 # create users like this nowadays.
21 def test_login_email_password_duplicate
22 # Attempt to log in as one user, it should work
24 _uppercase_user = build(:user, :email => user.email.upcase).tap { |u| u.save(:validate => false) }
26 try_password_login user.email, "test"
28 assert_template "changeset/history"
29 assert_select "span.username", user.display_name
32 def test_login_email_password_duplicate_upcase
33 # Attempt to log in as the uppercase_user, it should also work
35 uppercase_user = build(:user, :email => user.email.upcase).tap { |u| u.save(:validate => false) }
37 try_password_login uppercase_user.email, "test"
39 assert_template "changeset/history"
40 assert_select "span.username", uppercase_user.display_name
43 def test_login_email_password_duplicate_titlecase
44 # When there's no exact match for case, and two possible users, it should fail
46 _uppercase_user = build(:user, :email => user.email.upcase).tap { |u| u.save(:validate => false) }
48 try_password_login user.email.titlecase, "test"
50 assert_template "login"
51 assert_select "span.username", false
54 # When there are no duplicate emails, any variation of cases should work
55 def test_login_email_password
58 try_password_login user.email, "test"
60 assert_template "changeset/history"
61 assert_select "span.username", user.display_name
64 def test_login_email_password_upcase
67 try_password_login user.email.upcase, "test"
69 assert_template "changeset/history"
70 assert_select "span.username", user.display_name
73 def test_login_email_password_titlecase
76 try_password_login user.email.titlecase, "test"
78 assert_template "changeset/history"
79 assert_select "span.username", user.display_name
82 def test_login_email_password_pending
83 user = create(:user, :pending)
85 try_password_login user.email, "test"
87 assert_template "confirm"
88 assert_select "span.username", false
91 def test_login_email_password_pending_upcase
92 user = create(:user, :pending)
94 try_password_login user.email.upcase, "test"
96 assert_template "confirm"
97 assert_select "span.username", false
100 def test_login_email_password_pending_titlecase
101 user = create(:user, :pending)
103 try_password_login user.email.titlecase, "test"
105 assert_template "confirm"
106 assert_select "span.username", false
109 def test_login_email_password_suspended
110 user = create(:user, :suspended)
112 try_password_login user.email, "test"
114 assert_template "login"
115 assert_select "span.username", false
116 assert_select "div.flash.error", /your account has been suspended/
119 def test_login_email_password_suspended_upcase
120 user = create(:user, :suspended)
122 try_password_login user.email.upcase, "test"
124 assert_template "login"
125 assert_select "span.username", false
126 assert_select "div.flash.error", /your account has been suspended/
129 def test_login_email_password_suspended_titlecase
130 user = create(:user, :suspended)
132 try_password_login user.email.titlecase, "test"
134 assert_template "login"
135 assert_select "span.username", false
136 assert_select "div.flash.error", /your account has been suspended/
139 def test_login_email_password_blocked
141 create(:user_block, :needs_view, :user => user)
143 try_password_login user.email, "test"
145 assert_template "user_blocks/show"
146 assert_select "span.username", user.display_name
149 def test_login_email_password_blocked_upcase
151 create(:user_block, :needs_view, :user => user)
153 try_password_login user.email.upcase, "test"
155 assert_template "user_blocks/show"
156 assert_select "span.username", user.display_name
159 def test_login_email_password_blocked_titlecase
161 create(:user_block, :needs_view, :user => user)
163 try_password_login user.email.titlecase, "test"
165 assert_template "user_blocks/show"
166 assert_select "span.username", user.display_name
169 # As above, it's possible to have multiple accounts in the database with only
170 # differences in display_name case, for hysterical raisins. We need to bypass
171 # the validation checks to create users like this nowadays.
172 def test_login_username_password_duplicate
173 # Attempt to log in as one user, it should work
175 _uppercase_user = build(:user, :display_name => user.display_name.upcase).tap { |u| u.save(:validate => false) }
177 try_password_login user.display_name, "test"
179 assert_template "changeset/history"
180 assert_select "span.username", user.display_name
183 def test_login_username_password_duplicate_upcase
184 # Attempt to log in as the uppercase_user, it should also work
186 uppercase_user = build(:user, :display_name => user.display_name.upcase).tap { |u| u.save(:validate => false) }
188 try_password_login uppercase_user.display_name, "test"
190 assert_template "changeset/history"
191 assert_select "span.username", uppercase_user.display_name
194 def test_login_username_password_duplicate_downcase
195 # When there's no exact match for case, and two possible users, it should fail
197 _uppercase_user = build(:user, :display_name => user.display_name.upcase).tap { |u| u.save(:validate => false) }
199 try_password_login user.display_name.downcase, "test"
201 assert_template "login"
202 assert_select "span.username", false
205 # When there are no duplicate emails, any variation of cases should work
206 def test_login_username_password
209 try_password_login user.display_name, "test"
211 assert_template "changeset/history"
212 assert_select "span.username", user.display_name
215 def test_login_username_password_upcase
218 try_password_login user.display_name.upcase, "test"
220 assert_template "changeset/history"
221 assert_select "span.username", user.display_name
224 def test_login_username_password_downcase
227 try_password_login user.display_name.downcase, "test"
229 assert_template "changeset/history"
230 assert_select "span.username", user.display_name
233 def test_login_username_password_pending
234 user = create(:user, :pending)
236 try_password_login user.display_name, "test"
238 assert_template "confirm"
239 assert_select "span.username", false
242 def test_login_username_password_pending_upcase
243 user = create(:user, :pending)
245 try_password_login user.display_name.upcase, "test"
247 assert_template "confirm"
248 assert_select "span.username", false
251 def test_login_username_password_pending_downcase
252 user = create(:user, :pending)
254 try_password_login user.display_name.downcase, "test"
256 assert_template "confirm"
257 assert_select "span.username", false
260 def test_login_username_password_suspended
261 user = create(:user, :suspended)
263 try_password_login user.display_name, "test"
265 assert_template "login"
266 assert_select "span.username", false
267 assert_select "div.flash.error", /your account has been suspended/
270 def test_login_username_password_suspended_upcase
271 user = create(:user, :suspended)
273 try_password_login user.display_name.upcase, "test"
275 assert_template "login"
276 assert_select "span.username", false
277 assert_select "div.flash.error", /your account has been suspended/
280 def test_login_username_password_suspended_downcase
281 user = create(:user, :suspended)
283 try_password_login user.display_name.downcase, "test"
285 assert_template "login"
286 assert_select "span.username", false
287 assert_select "div.flash.error", /your account has been suspended/
290 def test_login_username_password_blocked
292 create(:user_block, :needs_view, :user => user)
294 try_password_login user.display_name.upcase, "test"
296 assert_template "user_blocks/show"
297 assert_select "span.username", user.display_name
300 def test_login_username_password_blocked_upcase
302 create(:user_block, :needs_view, :user => user)
304 try_password_login user.display_name, "test"
306 assert_template "user_blocks/show"
307 assert_select "span.username", user.display_name
310 def test_login_username_password_blocked_downcase
312 create(:user_block, :needs_view, :user => user)
314 try_password_login user.display_name.downcase, "test"
316 assert_template "user_blocks/show"
317 assert_select "span.username", user.display_name
320 def test_login_email_password_remember_me
323 try_password_login user.email, "test", "yes"
325 assert_template "changeset/history"
326 assert_select "span.username", user.display_name
327 assert session.key?(:_remember_for)
330 def test_login_username_password_remember_me
333 try_password_login user.display_name, "test", "yes"
335 assert_template "changeset/history"
336 assert_select "span.username", user.display_name
337 assert session.key?(:_remember_for)
340 def test_login_openid_success
341 user = create(:user, :auth_provider => "openid", :auth_uid => "http://example.com/john.doe")
342 OmniAuth.config.add_mock(:openid, :uid => user.auth_uid)
344 get "/login", :referer => "/history"
345 assert_response :redirect
346 assert_redirected_to :controller => :user, :action => :login, :cookie_test => true, :referer => "/history"
348 assert_response :success
349 assert_template "user/login"
350 post "/login", :openid_url => "http://localhost:1123/john.doe", :referer => "/history"
351 assert_response :redirect
352 assert_redirected_to auth_path(:provider => "openid", :openid_url => "http://localhost:1123/john.doe", :origin => "/login?referer=%2Fhistory", :referer => "/history")
354 assert_response :redirect
355 assert_redirected_to auth_success_path(:provider => "openid", :openid_url => "http://localhost:1123/john.doe", :origin => "/login?referer=%2Fhistory", :referer => "/history")
357 assert_response :redirect
359 assert_response :success
360 assert_template "changeset/history"
361 assert_select "span.username", user.display_name
364 def test_login_openid_remember_me
365 user = create(:user, :auth_provider => "openid", :auth_uid => "http://example.com/john.doe")
366 OmniAuth.config.add_mock(:openid, :uid => user.auth_uid)
368 get "/login", :referer => "/history"
369 assert_response :redirect
370 assert_redirected_to :controller => :user, :action => :login, :cookie_test => true, :referer => "/history"
372 assert_response :success
373 assert_template "user/login"
374 post "/login", :openid_url => user.auth_uid, :remember_me_openid => true, :referer => "/history"
375 assert_response :redirect
376 assert_redirected_to auth_path(:provider => "openid", :openid_url => user.auth_uid, :origin => "/login?referer=%2Fhistory", :referer => "/history")
378 assert_response :redirect
379 assert_redirected_to auth_success_path(:provider => "openid", :openid_url => user.auth_uid, :origin => "/login?referer=%2Fhistory", :referer => "/history")
381 assert_response :redirect
383 assert_response :success
384 assert_template "changeset/history"
385 assert_select "span.username", user.display_name
386 assert session.key?(:_remember_for)
389 def test_login_openid_connection_failed
390 user = create(:user, :auth_provider => "openid", :auth_uid => "http://example.com/john.doe")
391 OmniAuth.config.mock_auth[:openid] = :connection_failed
393 get "/login", :referer => "/history"
394 assert_response :redirect
395 assert_redirected_to :controller => :user, :action => :login, :cookie_test => true, :referer => "/history"
397 assert_response :success
398 assert_template "user/login"
399 post "/login", :openid_url => user.auth_uid, :referer => "/history"
400 assert_response :redirect
401 assert_redirected_to auth_path(:provider => "openid", :openid_url => user.auth_uid, :origin => "/login?referer=%2Fhistory", :referer => "/history")
403 assert_response :redirect
404 assert_redirected_to auth_success_path(:provider => "openid", :openid_url => user.auth_uid, :origin => "/login?referer=%2Fhistory", :referer => "/history")
406 assert_response :redirect
407 assert_redirected_to auth_failure_path(:strategy => "openid", :message => "connection_failed", :origin => "/login?referer=%2Fhistory")
409 assert_response :redirect
411 assert_response :success
412 assert_template "login"
413 assert_select "div.flash.error", "Connection to authentication provider failed"
414 assert_select "span.username", false
417 def test_login_openid_invalid_credentials
418 user = create(:user, :auth_provider => "openid", :auth_uid => "http://example.com/john.doe")
419 OmniAuth.config.mock_auth[:openid] = :invalid_credentials
421 get "/login", :referer => "/history"
422 assert_response :redirect
423 assert_redirected_to :controller => :user, :action => :login, :cookie_test => true, :referer => "/history"
425 assert_response :success
426 assert_template "user/login"
427 post "/login", :openid_url => user.auth_uid, :referer => "/history"
428 assert_response :redirect
429 assert_redirected_to auth_path(:provider => "openid", :openid_url => user.auth_uid, :origin => "/login?referer=%2Fhistory", :referer => "/history")
431 assert_response :redirect
432 assert_redirected_to auth_success_path(:provider => "openid", :openid_url => user.auth_uid, :origin => "/login?referer=%2Fhistory", :referer => "/history")
434 assert_response :redirect
435 assert_redirected_to auth_failure_path(:strategy => "openid", :message => "invalid_credentials", :origin => "/login?referer=%2Fhistory")
437 assert_response :redirect
439 assert_response :success
440 assert_template "login"
441 assert_select "div.flash.error", "Invalid authentication credentials"
442 assert_select "span.username", false
445 def test_login_openid_unknown
446 OmniAuth.config.add_mock(:openid, :uid => "http://localhost:1123/fred.bloggs")
448 get "/login", :referer => "/history"
449 assert_response :redirect
450 assert_redirected_to :controller => :user, :action => :login, :cookie_test => true, :referer => "/history"
452 assert_response :success
453 assert_template "user/login"
454 post "/login", :openid_url => "http://localhost:1123/fred.bloggs", :referer => "/history"
455 assert_response :redirect
456 assert_redirected_to auth_path(:provider => "openid", :openid_url => "http://localhost:1123/fred.bloggs", :origin => "/login?referer=%2Fhistory", :referer => "/history")
458 assert_response :redirect
459 assert_redirected_to auth_success_path(:provider => "openid", :openid_url => "http://localhost:1123/fred.bloggs", :origin => "/login?referer=%2Fhistory", :referer => "/history")
461 assert_response :redirect
463 assert_response :success
464 assert_template "user/new"
465 assert_select "span.username", false
468 def test_login_google_success
469 user = create(:user, :auth_provider => "google", :auth_uid => "1234567890")
470 OmniAuth.config.add_mock(:google, :uid => user.auth_uid, :extra => {
471 :id_info => { "openid_id" => "http://localhost:1123/fred.bloggs" }
474 get "/login", :referer => "/history"
475 assert_response :redirect
476 assert_redirected_to "controller" => "user", "action" => "login", "cookie_test" => "true", "referer" => "/history"
478 assert_response :success
479 assert_template "user/login"
480 get auth_path(:provider => "google", :origin => "/login?referer=%2Fhistory", :referer => "/history")
481 assert_response :redirect
482 assert_redirected_to auth_success_path(:provider => "google")
484 assert_response :redirect
486 assert_response :success
487 assert_template "changeset/history"
488 assert_select "span.username", user.display_name
491 def test_login_google_connection_failed
492 OmniAuth.config.mock_auth[:google] = :connection_failed
494 get "/login", :referer => "/history"
495 assert_response :redirect
496 assert_redirected_to "controller" => "user", "action" => "login", "cookie_test" => "true", "referer" => "/history"
498 assert_response :success
499 assert_template "user/login"
500 get auth_path(:provider => "google", :origin => "/login?referer=%2Fhistory", :referer => "/history")
501 assert_response :redirect
502 assert_redirected_to auth_success_path(:provider => "google")
504 assert_response :redirect
505 assert_redirected_to auth_failure_path(:strategy => "google", :message => "connection_failed", :origin => "/login?referer=%2Fhistory")
507 assert_response :redirect
509 assert_response :success
510 assert_template "login"
511 assert_select "div.flash.error", "Connection to authentication provider failed"
512 assert_select "span.username", false
515 def test_login_google_invalid_credentials
516 OmniAuth.config.mock_auth[:google] = :invalid_credentials
518 get "/login", :referer => "/history"
519 assert_response :redirect
520 assert_redirected_to "controller" => "user", "action" => "login", "cookie_test" => "true", "referer" => "/history"
522 assert_response :success
523 assert_template "user/login"
524 get auth_path(:provider => "google", :origin => "/login?referer=%2Fhistory", :referer => "/history")
525 assert_response :redirect
526 assert_redirected_to auth_success_path(:provider => "google")
528 assert_response :redirect
529 assert_redirected_to auth_failure_path(:strategy => "google", :message => "invalid_credentials", :origin => "/login?referer=%2Fhistory")
531 assert_response :redirect
533 assert_response :success
534 assert_template "login"
535 assert_select "div.flash.error", "Invalid authentication credentials"
536 assert_select "span.username", false
539 def test_login_google_unknown
540 OmniAuth.config.add_mock(:google, :uid => "987654321", :extra => {
541 :id_info => { "openid_id" => "http://localhost:1123/fred.bloggs" }
544 get "/login", :referer => "/history"
545 assert_response :redirect
546 assert_redirected_to "controller" => "user", "action" => "login", "cookie_test" => "true", "referer" => "/history"
548 assert_response :success
549 assert_template "user/login"
550 get auth_path(:provider => "google", :origin => "/login?referer=%2Fhistory", :referer => "/history")
551 assert_response :redirect
552 assert_redirected_to auth_success_path(:provider => "google")
554 assert_response :redirect
556 assert_response :success
557 assert_template "user/new"
558 assert_select "span.username", false
561 def test_login_google_upgrade
562 user = create(:user, :auth_provider => "openid", :auth_uid => "http://example.com/john.doe")
563 OmniAuth.config.add_mock(:google, :uid => "987654321", :extra => {
564 :id_info => { "openid_id" => user.auth_uid }
567 get "/login", :referer => "/history"
568 assert_response :redirect
569 assert_redirected_to "controller" => "user", "action" => "login", "cookie_test" => "true", "referer" => "/history"
571 assert_response :success
572 assert_template "user/login"
573 get auth_path(:provider => "google", :origin => "/login?referer=%2Fhistory", :referer => "/history")
574 assert_response :redirect
575 assert_redirected_to auth_success_path(:provider => "google")
577 assert_response :redirect
579 assert_response :success
580 assert_template "changeset/history"
581 assert_select "span.username", user.display_name
583 u = User.find_by(:display_name => user.display_name)
584 assert_equal "google", u.auth_provider
585 assert_equal "987654321", u.auth_uid
588 def test_login_facebook_success
589 user = create(:user, :auth_provider => "facebook", :auth_uid => "1234567890")
590 OmniAuth.config.add_mock(:facebook, :uid => user.auth_uid)
592 get "/login", :referer => "/history"
593 assert_response :redirect
594 assert_redirected_to "controller" => "user", "action" => "login", "cookie_test" => "true", "referer" => "/history"
596 assert_response :success
597 assert_template "user/login"
598 get auth_path(:provider => "facebook", :origin => "/login?referer=%2Fhistory", :referer => "/history")
599 assert_response :redirect
600 assert_redirected_to auth_success_path(:provider => "facebook")
602 assert_response :redirect
604 assert_response :success
605 assert_template "changeset/history"
606 assert_select "span.username", user.display_name
609 def test_login_facebook_connection_failed
610 OmniAuth.config.mock_auth[:facebook] = :connection_failed
612 get "/login", :referer => "/history"
613 assert_response :redirect
614 assert_redirected_to "controller" => "user", "action" => "login", "cookie_test" => "true", "referer" => "/history"
616 assert_response :success
617 assert_template "user/login"
618 get auth_path(:provider => "facebook", :origin => "/login?referer=%2Fhistory", :referer => "/history")
619 assert_response :redirect
620 assert_redirected_to auth_success_path(:provider => "facebook")
622 assert_response :redirect
623 assert_redirected_to auth_failure_path(:strategy => "facebook", :message => "connection_failed", :origin => "/login?referer=%2Fhistory")
625 assert_response :redirect
627 assert_response :success
628 assert_template "login"
629 assert_select "div.flash.error", "Connection to authentication provider failed"
630 assert_select "span.username", false
633 def test_login_facebook_invalid_credentials
634 OmniAuth.config.mock_auth[:facebook] = :invalid_credentials
636 get "/login", :referer => "/history"
637 assert_response :redirect
638 assert_redirected_to "controller" => "user", "action" => "login", "cookie_test" => "true", "referer" => "/history"
640 assert_response :success
641 assert_template "user/login"
642 get auth_path(:provider => "facebook", :origin => "/login?referer=%2Fhistory", :referer => "/history")
643 assert_response :redirect
644 assert_redirected_to auth_success_path(:provider => "facebook")
646 assert_response :redirect
647 assert_redirected_to auth_failure_path(:strategy => "facebook", :message => "invalid_credentials", :origin => "/login?referer=%2Fhistory")
649 assert_response :redirect
651 assert_response :success
652 assert_template "login"
653 assert_select "div.flash.error", "Invalid authentication credentials"
654 assert_select "span.username", false
657 def test_login_facebook_unknown
658 OmniAuth.config.add_mock(:facebook, :uid => "987654321")
660 get "/login", :referer => "/history"
661 assert_response :redirect
662 assert_redirected_to "controller" => "user", "action" => "login", "cookie_test" => "true", "referer" => "/history"
664 assert_response :success
665 assert_template "user/login"
666 get auth_path(:provider => "facebook", :origin => "/login?referer=%2Fhistory", :referer => "/history")
667 assert_response :redirect
668 assert_redirected_to auth_success_path(:provider => "facebook")
670 assert_response :redirect
672 assert_response :success
673 assert_template "user/new"
674 assert_select "span.username", false
677 def test_login_windowslive_success
678 user = create(:user, :auth_provider => "windowslive", :auth_uid => "1234567890")
679 OmniAuth.config.add_mock(:windowslive, :uid => user.auth_uid)
681 get "/login", :referer => "/history"
682 assert_response :redirect
683 assert_redirected_to "controller" => "user", "action" => "login", "cookie_test" => "true", "referer" => "/history"
685 assert_response :success
686 assert_template "user/login"
687 get auth_path(:provider => "windowslive", :origin => "/login?referer=%2Fhistory", :referer => "/history")
688 assert_response :redirect
689 assert_redirected_to auth_success_path(:provider => "windowslive")
691 assert_response :redirect
693 assert_response :success
694 assert_template "changeset/history"
695 assert_select "span.username", user.display_name
698 def test_login_windowslive_connection_failed
699 OmniAuth.config.mock_auth[:windowslive] = :connection_failed
701 get "/login", :referer => "/history"
702 assert_response :redirect
703 assert_redirected_to "controller" => "user", "action" => "login", "cookie_test" => "true", "referer" => "/history"
705 assert_response :success
706 assert_template "user/login"
707 get auth_path(:provider => "windowslive", :origin => "/login?referer=%2Fhistory", :referer => "/history")
708 assert_response :redirect
709 assert_redirected_to auth_success_path(:provider => "windowslive")
711 assert_response :redirect
712 assert_redirected_to auth_failure_path(:strategy => "windowslive", :message => "connection_failed", :origin => "/login?referer=%2Fhistory")
714 assert_response :redirect
716 assert_response :success
717 assert_template "login"
718 assert_select "div.flash.error", "Connection to authentication provider failed"
719 assert_select "span.username", false
722 def test_login_windowslive_invalid_credentials
723 OmniAuth.config.mock_auth[:windowslive] = :invalid_credentials
725 get "/login", :referer => "/history"
726 assert_response :redirect
727 assert_redirected_to "controller" => "user", "action" => "login", "cookie_test" => "true", "referer" => "/history"
729 assert_response :success
730 assert_template "user/login"
731 get auth_path(:provider => "windowslive", :origin => "/login?referer=%2Fhistory", :referer => "/history")
732 assert_response :redirect
733 assert_redirected_to auth_success_path(:provider => "windowslive")
735 assert_response :redirect
736 assert_redirected_to auth_failure_path(:strategy => "windowslive", :message => "invalid_credentials", :origin => "/login?referer=%2Fhistory")
738 assert_response :redirect
740 assert_response :success
741 assert_template "login"
742 assert_select "div.flash.error", "Invalid authentication credentials"
743 assert_select "span.username", false
746 def test_login_windowslive_unknown
747 OmniAuth.config.add_mock(:windowslive, :uid => "987654321")
749 get "/login", :referer => "/history"
750 assert_response :redirect
751 assert_redirected_to "controller" => "user", "action" => "login", "cookie_test" => "true", "referer" => "/history"
753 assert_response :success
754 assert_template "user/login"
755 get auth_path(:provider => "windowslive", :origin => "/login?referer=%2Fhistory", :referer => "/history")
756 assert_response :redirect
757 assert_redirected_to auth_success_path(:provider => "windowslive")
759 assert_response :redirect
761 assert_response :success
762 assert_template "user/new"
763 assert_select "span.username", false
766 def test_login_github_success
767 user = create(:user, :auth_provider => "github", :auth_uid => "1234567890")
768 OmniAuth.config.add_mock(:github, :uid => user.auth_uid)
770 get "/login", :referer => "/history"
771 assert_response :redirect
772 assert_redirected_to "controller" => "user", "action" => "login", "cookie_test" => "true", "referer" => "/history"
774 assert_response :success
775 assert_template "user/login"
776 get auth_path(:provider => "github", :origin => "/login?referer=%2Fhistory", :referer => "/history")
777 assert_response :redirect
778 assert_redirected_to auth_success_path(:provider => "github", :origin => "/login?referer=%2Fhistory", :referer => "/history")
780 assert_response :redirect
782 assert_response :success
783 assert_template "changeset/history"
784 assert_select "span.username", user.display_name
787 def test_login_github_connection_failed
788 OmniAuth.config.mock_auth[:github] = :connection_failed
790 get "/login", :referer => "/history"
791 assert_response :redirect
792 assert_redirected_to "controller" => "user", "action" => "login", "cookie_test" => "true", "referer" => "/history"
794 assert_response :success
795 assert_template "user/login"
796 get auth_path(:provider => "github", :origin => "/login?referer=%2Fhistory", :referer => "/history")
797 assert_response :redirect
798 assert_redirected_to auth_success_path(:provider => "github", :origin => "/login?referer=%2Fhistory", :referer => "/history")
800 assert_response :redirect
801 assert_redirected_to auth_failure_path(:strategy => "github", :message => "connection_failed", :origin => "/login?referer=%2Fhistory")
803 assert_response :redirect
805 assert_response :success
806 assert_template "login"
807 assert_select "div.flash.error", "Connection to authentication provider failed"
808 assert_select "span.username", false
811 def test_login_github_invalid_credentials
812 OmniAuth.config.mock_auth[:github] = :invalid_credentials
814 get "/login", :referer => "/history"
815 assert_response :redirect
816 assert_redirected_to "controller" => "user", "action" => "login", "cookie_test" => "true", "referer" => "/history"
818 assert_response :success
819 assert_template "user/login"
820 get auth_path(:provider => "github", :origin => "/login?referer=%2Fhistory", :referer => "/history")
821 assert_response :redirect
822 assert_redirected_to auth_success_path(:provider => "github", :origin => "/login?referer=%2Fhistory", :referer => "/history")
824 assert_response :redirect
825 assert_redirected_to auth_failure_path(:strategy => "github", :message => "invalid_credentials", :origin => "/login?referer=%2Fhistory")
827 assert_response :redirect
829 assert_response :success
830 assert_template "login"
831 assert_select "div.flash.error", "Invalid authentication credentials"
832 assert_select "span.username", false
835 def test_login_github_unknown
836 OmniAuth.config.add_mock(:github, :uid => "987654321")
838 get "/login", :referer => "/history"
839 assert_response :redirect
840 assert_redirected_to "controller" => "user", "action" => "login", "cookie_test" => "true", "referer" => "/history"
842 assert_response :success
843 assert_template "user/login"
844 get auth_path(:provider => "github", :origin => "/login?referer=%2Fhistory", :referer => "/history")
845 assert_response :redirect
846 assert_redirected_to auth_success_path(:provider => "github", :origin => "/login?referer=%2Fhistory", :referer => "/history")
848 assert_response :redirect
850 assert_response :success
851 assert_template "user/new"
852 assert_select "span.username", false
855 def test_login_wikipedia_success
856 user = create(:user, :auth_provider => "wikipedia", :auth_uid => "1234567890")
857 OmniAuth.config.add_mock(:wikipedia, :uid => user.auth_uid)
859 get "/login", :referer => "/history"
860 assert_response :redirect
861 assert_redirected_to "controller" => "user", "action" => "login", "cookie_test" => "true", "referer" => "/history"
863 assert_response :success
864 assert_template "user/login"
865 get auth_path(:provider => "wikipedia", :origin => "/login?referer=%2Fhistory", :referer => "/history")
866 assert_response :redirect
867 assert_redirected_to auth_success_path(:provider => "wikipedia", :origin => "/login?referer=%2Fhistory", :referer => "/history")
869 assert_response :redirect
871 assert_response :success
872 assert_template "changeset/history"
873 assert_select "span.username", user.display_name
876 def test_login_wikipedia_connection_failed
877 OmniAuth.config.mock_auth[:wikipedia] = :connection_failed
879 get "/login", :referer => "/history"
880 assert_response :redirect
881 assert_redirected_to "controller" => "user", "action" => "login", "cookie_test" => "true", "referer" => "/history"
883 assert_response :success
884 assert_template "user/login"
885 get auth_path(:provider => "wikipedia", :origin => "/login?referer=%2Fhistory", :referer => "/history")
886 assert_response :redirect
887 assert_redirected_to auth_success_path(:provider => "wikipedia", :origin => "/login?referer=%2Fhistory", :referer => "/history")
889 assert_response :redirect
890 assert_redirected_to auth_failure_path(:strategy => "wikipedia", :message => "connection_failed", :origin => "/login?referer=%2Fhistory")
892 assert_response :redirect
894 assert_response :success
895 assert_template "login"
896 assert_select "div.flash.error", "Connection to authentication provider failed"
897 assert_select "span.username", false
900 def test_login_wikipedia_invalid_credentials
901 OmniAuth.config.mock_auth[:wikipedia] = :invalid_credentials
903 get "/login", :referer => "/history"
904 assert_response :redirect
905 assert_redirected_to "controller" => "user", "action" => "login", "cookie_test" => "true", "referer" => "/history"
907 assert_response :success
908 assert_template "user/login"
909 get auth_path(:provider => "wikipedia", :origin => "/login?referer=%2Fhistory", :referer => "/history")
910 assert_response :redirect
911 assert_redirected_to auth_success_path(:provider => "wikipedia", :origin => "/login?referer=%2Fhistory", :referer => "/history")
913 assert_response :redirect
914 assert_redirected_to auth_failure_path(:strategy => "wikipedia", :message => "invalid_credentials", :origin => "/login?referer=%2Fhistory")
916 assert_response :redirect
918 assert_response :success
919 assert_template "login"
920 assert_select "div.flash.error", "Invalid authentication credentials"
921 assert_select "span.username", false
924 def test_login_wikipedia_unknown
925 OmniAuth.config.add_mock(:wikipedia, :uid => "987654321")
927 get "/login", :referer => "/history"
928 assert_response :redirect
929 assert_redirected_to "controller" => "user", "action" => "login", "cookie_test" => "true", "referer" => "/history"
931 assert_response :success
932 assert_template "user/login"
933 get auth_path(:provider => "wikipedia", :origin => "/login?referer=%2Fhistory", :referer => "/history")
934 assert_response :redirect
935 assert_redirected_to auth_success_path(:provider => "wikipedia", :origin => "/login?referer=%2Fhistory", :referer => "/history")
937 assert_response :redirect
939 assert_response :success
940 assert_template "user/new"
941 assert_select "span.username", false
946 def try_password_login(username, password, remember_me = nil)
948 assert_response :redirect
949 assert_redirected_to :controller => :user, :action => :login, :cookie_test => true
951 assert_response :success
952 assert_template "login"
953 assert_select "input#username", 1 do
954 assert_select "[value]", false
956 assert_select "input#password", 1 do
957 assert_select "[value=?]", ""
959 assert_select "input#remember_me", 1 do
960 assert_select "[checked]", false
963 post "/login", :username => username, :password => "wrong", :remember_me => remember_me, :referer => "/history"
964 assert_response :redirect
966 assert_response :success
967 assert_template "login"
968 assert_select "input#username", 1 do
969 assert_select "[value=?]", username
971 assert_select "input#password", 1 do
972 assert_select "[value=?]", ""
974 assert_select "input#remember_me", 1 do
975 assert_select "[checked]", remember_me == "yes"
978 post "/login", :username => username, :password => password, :remember_me => remember_me, :referer => "/history"
979 assert_response :redirect
981 assert_response :success