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/ do
117 assert_select "a[href='mailto:openstreetmap@example.com']", "webmaster"
121 def test_login_email_password_suspended_upcase
122 user = create(:user, :suspended)
124 try_password_login user.email.upcase, "test"
126 assert_template "login"
127 assert_select "span.username", false
128 assert_select "div.flash.error", /your account has been suspended/ do
129 assert_select "a[href='mailto:openstreetmap@example.com']", "webmaster"
133 def test_login_email_password_suspended_titlecase
134 user = create(:user, :suspended)
136 try_password_login user.email.titlecase, "test"
138 assert_template "login"
139 assert_select "span.username", false
140 assert_select "div.flash.error", /your account has been suspended/ do
141 assert_select "a[href='mailto:openstreetmap@example.com']", "webmaster"
145 def test_login_email_password_blocked
147 create(:user_block, :needs_view, :user => user)
149 try_password_login user.email, "test"
151 assert_template "user_blocks/show"
152 assert_select "span.username", user.display_name
155 def test_login_email_password_blocked_upcase
157 create(:user_block, :needs_view, :user => user)
159 try_password_login user.email.upcase, "test"
161 assert_template "user_blocks/show"
162 assert_select "span.username", user.display_name
165 def test_login_email_password_blocked_titlecase
167 create(:user_block, :needs_view, :user => user)
169 try_password_login user.email.titlecase, "test"
171 assert_template "user_blocks/show"
172 assert_select "span.username", user.display_name
175 # As above, it's possible to have multiple accounts in the database with only
176 # differences in display_name case, for hysterical raisins. We need to bypass
177 # the validation checks to create users like this nowadays.
178 def test_login_username_password_duplicate
179 # Attempt to log in as one user, it should work
181 _uppercase_user = build(:user, :display_name => user.display_name.upcase).tap { |u| u.save(:validate => false) }
183 try_password_login user.display_name, "test"
185 assert_template "changeset/history"
186 assert_select "span.username", user.display_name
189 def test_login_username_password_duplicate_upcase
190 # Attempt to log in as the uppercase_user, it should also work
192 uppercase_user = build(:user, :display_name => user.display_name.upcase).tap { |u| u.save(:validate => false) }
194 try_password_login uppercase_user.display_name, "test"
196 assert_template "changeset/history"
197 assert_select "span.username", uppercase_user.display_name
200 def test_login_username_password_duplicate_downcase
201 # When there's no exact match for case, and two possible users, it should fail
203 _uppercase_user = build(:user, :display_name => user.display_name.upcase).tap { |u| u.save(:validate => false) }
205 try_password_login user.display_name.downcase, "test"
207 assert_template "login"
208 assert_select "span.username", false
211 # When there are no duplicate emails, any variation of cases should work
212 def test_login_username_password
215 try_password_login user.display_name, "test"
217 assert_template "changeset/history"
218 assert_select "span.username", user.display_name
221 def test_login_username_password_upcase
224 try_password_login user.display_name.upcase, "test"
226 assert_template "changeset/history"
227 assert_select "span.username", user.display_name
230 def test_login_username_password_downcase
233 try_password_login user.display_name.downcase, "test"
235 assert_template "changeset/history"
236 assert_select "span.username", user.display_name
239 def test_login_username_password_pending
240 user = create(:user, :pending)
242 try_password_login user.display_name, "test"
244 assert_template "confirm"
245 assert_select "span.username", false
248 def test_login_username_password_pending_upcase
249 user = create(:user, :pending)
251 try_password_login user.display_name.upcase, "test"
253 assert_template "confirm"
254 assert_select "span.username", false
257 def test_login_username_password_pending_downcase
258 user = create(:user, :pending)
260 try_password_login user.display_name.downcase, "test"
262 assert_template "confirm"
263 assert_select "span.username", false
266 def test_login_username_password_suspended
267 user = create(:user, :suspended)
269 try_password_login user.display_name, "test"
271 assert_template "login"
272 assert_select "span.username", false
273 assert_select "div.flash.error", /your account has been suspended/ do
274 assert_select "a[href='mailto:openstreetmap@example.com']", "webmaster"
278 def test_login_username_password_suspended_upcase
279 user = create(:user, :suspended)
281 try_password_login user.display_name.upcase, "test"
283 assert_template "login"
284 assert_select "span.username", false
285 assert_select "div.flash.error", /your account has been suspended/ do
286 assert_select "a[href='mailto:openstreetmap@example.com']", "webmaster"
290 def test_login_username_password_suspended_downcase
291 user = create(:user, :suspended)
293 try_password_login user.display_name.downcase, "test"
295 assert_template "login"
296 assert_select "span.username", false
297 assert_select "div.flash.error", /your account has been suspended/ do
298 assert_select "a[href='mailto:openstreetmap@example.com']", "webmaster"
302 def test_login_username_password_blocked
304 create(:user_block, :needs_view, :user => user)
306 try_password_login user.display_name.upcase, "test"
308 assert_template "user_blocks/show"
309 assert_select "span.username", user.display_name
312 def test_login_username_password_blocked_upcase
314 create(:user_block, :needs_view, :user => user)
316 try_password_login user.display_name, "test"
318 assert_template "user_blocks/show"
319 assert_select "span.username", user.display_name
322 def test_login_username_password_blocked_downcase
324 create(:user_block, :needs_view, :user => user)
326 try_password_login user.display_name.downcase, "test"
328 assert_template "user_blocks/show"
329 assert_select "span.username", user.display_name
332 def test_login_email_password_remember_me
335 try_password_login user.email, "test", "yes"
337 assert_template "changeset/history"
338 assert_select "span.username", user.display_name
339 assert session.key?(:_remember_for)
342 def test_login_username_password_remember_me
345 try_password_login user.display_name, "test", "yes"
347 assert_template "changeset/history"
348 assert_select "span.username", user.display_name
349 assert session.key?(:_remember_for)
352 def test_login_openid_success
353 user = create(:user, :auth_provider => "openid", :auth_uid => "http://example.com/john.doe")
354 OmniAuth.config.add_mock(:openid, :uid => user.auth_uid)
356 get "/login", :params => { :referer => "/history" }
357 assert_response :redirect
358 assert_redirected_to :controller => :users, :action => :login, :cookie_test => true, :referer => "/history"
360 assert_response :success
361 assert_template "users/login"
362 post "/login", :params => { :openid_url => "http://localhost:1123/john.doe", :referer => "/history" }
363 assert_response :redirect
364 assert_redirected_to auth_path(:provider => "openid", :openid_url => "http://localhost:1123/john.doe", :origin => "/login?referer=%2Fhistory", :referer => "/history")
366 assert_response :redirect
367 assert_redirected_to auth_success_path(:provider => "openid", :openid_url => "http://localhost:1123/john.doe", :origin => "/login?referer=%2Fhistory", :referer => "/history")
369 assert_response :redirect
371 assert_response :success
372 assert_template "changeset/history"
373 assert_select "span.username", user.display_name
376 def test_login_openid_remember_me
377 user = create(:user, :auth_provider => "openid", :auth_uid => "http://example.com/john.doe")
378 OmniAuth.config.add_mock(:openid, :uid => user.auth_uid)
380 get "/login", :params => { :referer => "/history" }
381 assert_response :redirect
382 assert_redirected_to :controller => :users, :action => :login, :cookie_test => true, :referer => "/history"
384 assert_response :success
385 assert_template "users/login"
386 post "/login", :params => { :openid_url => user.auth_uid, :remember_me_openid => true, :referer => "/history" }
387 assert_response :redirect
388 assert_redirected_to auth_path(:provider => "openid", :openid_url => user.auth_uid, :origin => "/login?referer=%2Fhistory", :referer => "/history")
390 assert_response :redirect
391 assert_redirected_to auth_success_path(:provider => "openid", :openid_url => user.auth_uid, :origin => "/login?referer=%2Fhistory", :referer => "/history")
393 assert_response :redirect
395 assert_response :success
396 assert_template "changeset/history"
397 assert_select "span.username", user.display_name
398 assert session.key?(:_remember_for)
401 def test_login_openid_connection_failed
402 user = create(:user, :auth_provider => "openid", :auth_uid => "http://example.com/john.doe")
403 OmniAuth.config.mock_auth[:openid] = :connection_failed
405 get "/login", :params => { :referer => "/history" }
406 assert_response :redirect
407 assert_redirected_to :controller => :users, :action => :login, :cookie_test => true, :referer => "/history"
409 assert_response :success
410 assert_template "users/login"
411 post "/login", :params => { :openid_url => user.auth_uid, :referer => "/history" }
412 assert_response :redirect
413 assert_redirected_to auth_path(:provider => "openid", :openid_url => user.auth_uid, :origin => "/login?referer=%2Fhistory", :referer => "/history")
415 assert_response :redirect
416 assert_redirected_to auth_success_path(:provider => "openid", :openid_url => user.auth_uid, :origin => "/login?referer=%2Fhistory", :referer => "/history")
418 assert_response :redirect
419 assert_redirected_to auth_failure_path(:strategy => "openid", :message => "connection_failed", :origin => "/login?referer=%2Fhistory")
421 assert_response :redirect
423 assert_response :success
424 assert_template "login"
425 assert_select "div.flash.error", "Connection to authentication provider failed"
426 assert_select "span.username", false
429 def test_login_openid_invalid_credentials
430 user = create(:user, :auth_provider => "openid", :auth_uid => "http://example.com/john.doe")
431 OmniAuth.config.mock_auth[:openid] = :invalid_credentials
433 get "/login", :params => { :referer => "/history" }
434 assert_response :redirect
435 assert_redirected_to :controller => :users, :action => :login, :cookie_test => true, :referer => "/history"
437 assert_response :success
438 assert_template "users/login"
439 post "/login", :params => { :openid_url => user.auth_uid, :referer => "/history" }
440 assert_response :redirect
441 assert_redirected_to auth_path(:provider => "openid", :openid_url => user.auth_uid, :origin => "/login?referer=%2Fhistory", :referer => "/history")
443 assert_response :redirect
444 assert_redirected_to auth_success_path(:provider => "openid", :openid_url => user.auth_uid, :origin => "/login?referer=%2Fhistory", :referer => "/history")
446 assert_response :redirect
447 assert_redirected_to auth_failure_path(:strategy => "openid", :message => "invalid_credentials", :origin => "/login?referer=%2Fhistory")
449 assert_response :redirect
451 assert_response :success
452 assert_template "login"
453 assert_select "div.flash.error", "Invalid authentication credentials"
454 assert_select "span.username", false
457 def test_login_openid_unknown
458 OmniAuth.config.add_mock(:openid, :uid => "http://localhost:1123/fred.bloggs")
460 get "/login", :params => { :referer => "/history" }
461 assert_response :redirect
462 assert_redirected_to :controller => :users, :action => :login, :cookie_test => true, :referer => "/history"
464 assert_response :success
465 assert_template "users/login"
466 post "/login", :params => { :openid_url => "http://localhost:1123/fred.bloggs", :referer => "/history" }
467 assert_response :redirect
468 assert_redirected_to auth_path(:provider => "openid", :openid_url => "http://localhost:1123/fred.bloggs", :origin => "/login?referer=%2Fhistory", :referer => "/history")
470 assert_response :redirect
471 assert_redirected_to auth_success_path(:provider => "openid", :openid_url => "http://localhost:1123/fred.bloggs", :origin => "/login?referer=%2Fhistory", :referer => "/history")
473 assert_response :redirect
475 assert_response :success
476 assert_template "users/new"
477 assert_select "span.username", false
480 def test_login_google_success
481 user = create(:user, :auth_provider => "google", :auth_uid => "1234567890")
482 OmniAuth.config.add_mock(:google, :uid => user.auth_uid, :extra => {
483 :id_info => { "openid_id" => "http://localhost:1123/fred.bloggs" }
486 get "/login", :params => { :referer => "/history" }
487 assert_response :redirect
488 assert_redirected_to "controller" => "users", "action" => "login", "cookie_test" => "true", "referer" => "/history"
490 assert_response :success
491 assert_template "users/login"
492 get auth_path(:provider => "google", :origin => "/login?referer=%2Fhistory", :referer => "/history")
493 assert_response :redirect
494 assert_redirected_to auth_success_path(:provider => "google")
496 assert_response :redirect
498 assert_response :success
499 assert_template "changeset/history"
500 assert_select "span.username", user.display_name
503 def test_login_google_connection_failed
504 OmniAuth.config.mock_auth[:google] = :connection_failed
506 get "/login", :params => { :referer => "/history" }
507 assert_response :redirect
508 assert_redirected_to "controller" => "users", "action" => "login", "cookie_test" => "true", "referer" => "/history"
510 assert_response :success
511 assert_template "users/login"
512 get auth_path(:provider => "google", :origin => "/login?referer=%2Fhistory", :referer => "/history")
513 assert_response :redirect
514 assert_redirected_to auth_success_path(:provider => "google")
516 assert_response :redirect
517 assert_redirected_to auth_failure_path(:strategy => "google", :message => "connection_failed", :origin => "/login?referer=%2Fhistory")
519 assert_response :redirect
521 assert_response :success
522 assert_template "login"
523 assert_select "div.flash.error", "Connection to authentication provider failed"
524 assert_select "span.username", false
527 def test_login_google_invalid_credentials
528 OmniAuth.config.mock_auth[:google] = :invalid_credentials
530 get "/login", :params => { :referer => "/history" }
531 assert_response :redirect
532 assert_redirected_to "controller" => "users", "action" => "login", "cookie_test" => "true", "referer" => "/history"
534 assert_response :success
535 assert_template "users/login"
536 get auth_path(:provider => "google", :origin => "/login?referer=%2Fhistory", :referer => "/history")
537 assert_response :redirect
538 assert_redirected_to auth_success_path(:provider => "google")
540 assert_response :redirect
541 assert_redirected_to auth_failure_path(:strategy => "google", :message => "invalid_credentials", :origin => "/login?referer=%2Fhistory")
543 assert_response :redirect
545 assert_response :success
546 assert_template "login"
547 assert_select "div.flash.error", "Invalid authentication credentials"
548 assert_select "span.username", false
551 def test_login_google_unknown
552 OmniAuth.config.add_mock(:google, :uid => "987654321", :extra => {
553 :id_info => { "openid_id" => "http://localhost:1123/fred.bloggs" }
556 get "/login", :params => { :referer => "/history" }
557 assert_response :redirect
558 assert_redirected_to "controller" => "users", "action" => "login", "cookie_test" => "true", "referer" => "/history"
560 assert_response :success
561 assert_template "users/login"
562 get auth_path(:provider => "google", :origin => "/login?referer=%2Fhistory", :referer => "/history")
563 assert_response :redirect
564 assert_redirected_to auth_success_path(:provider => "google")
566 assert_response :redirect
568 assert_response :success
569 assert_template "users/new"
570 assert_select "span.username", false
573 def test_login_google_upgrade
574 user = create(:user, :auth_provider => "openid", :auth_uid => "http://example.com/john.doe")
575 OmniAuth.config.add_mock(:google, :uid => "987654321", :extra => {
576 :id_info => { "openid_id" => user.auth_uid }
579 get "/login", :params => { :referer => "/history" }
580 assert_response :redirect
581 assert_redirected_to "controller" => "users", "action" => "login", "cookie_test" => "true", "referer" => "/history"
583 assert_response :success
584 assert_template "users/login"
585 get auth_path(:provider => "google", :origin => "/login?referer=%2Fhistory", :referer => "/history")
586 assert_response :redirect
587 assert_redirected_to auth_success_path(:provider => "google")
589 assert_response :redirect
591 assert_response :success
592 assert_template "changeset/history"
593 assert_select "span.username", user.display_name
595 u = User.find_by(:display_name => user.display_name)
596 assert_equal "google", u.auth_provider
597 assert_equal "987654321", u.auth_uid
600 def test_login_facebook_success
601 user = create(:user, :auth_provider => "facebook", :auth_uid => "1234567890")
602 OmniAuth.config.add_mock(:facebook, :uid => user.auth_uid)
604 get "/login", :params => { :referer => "/history" }
605 assert_response :redirect
606 assert_redirected_to "controller" => "users", "action" => "login", "cookie_test" => "true", "referer" => "/history"
608 assert_response :success
609 assert_template "users/login"
610 get auth_path(:provider => "facebook", :origin => "/login?referer=%2Fhistory", :referer => "/history")
611 assert_response :redirect
612 assert_redirected_to auth_success_path(:provider => "facebook")
614 assert_response :redirect
616 assert_response :success
617 assert_template "changeset/history"
618 assert_select "span.username", user.display_name
621 def test_login_facebook_connection_failed
622 OmniAuth.config.mock_auth[:facebook] = :connection_failed
624 get "/login", :params => { :referer => "/history" }
625 assert_response :redirect
626 assert_redirected_to "controller" => "users", "action" => "login", "cookie_test" => "true", "referer" => "/history"
628 assert_response :success
629 assert_template "users/login"
630 get auth_path(:provider => "facebook", :origin => "/login?referer=%2Fhistory", :referer => "/history")
631 assert_response :redirect
632 assert_redirected_to auth_success_path(:provider => "facebook")
634 assert_response :redirect
635 assert_redirected_to auth_failure_path(:strategy => "facebook", :message => "connection_failed", :origin => "/login?referer=%2Fhistory")
637 assert_response :redirect
639 assert_response :success
640 assert_template "login"
641 assert_select "div.flash.error", "Connection to authentication provider failed"
642 assert_select "span.username", false
645 def test_login_facebook_invalid_credentials
646 OmniAuth.config.mock_auth[:facebook] = :invalid_credentials
648 get "/login", :params => { :referer => "/history" }
649 assert_response :redirect
650 assert_redirected_to "controller" => "users", "action" => "login", "cookie_test" => "true", "referer" => "/history"
652 assert_response :success
653 assert_template "users/login"
654 get auth_path(:provider => "facebook", :origin => "/login?referer=%2Fhistory", :referer => "/history")
655 assert_response :redirect
656 assert_redirected_to auth_success_path(:provider => "facebook")
658 assert_response :redirect
659 assert_redirected_to auth_failure_path(:strategy => "facebook", :message => "invalid_credentials", :origin => "/login?referer=%2Fhistory")
661 assert_response :redirect
663 assert_response :success
664 assert_template "login"
665 assert_select "div.flash.error", "Invalid authentication credentials"
666 assert_select "span.username", false
669 def test_login_facebook_unknown
670 OmniAuth.config.add_mock(:facebook, :uid => "987654321")
672 get "/login", :params => { :referer => "/history" }
673 assert_response :redirect
674 assert_redirected_to "controller" => "users", "action" => "login", "cookie_test" => "true", "referer" => "/history"
676 assert_response :success
677 assert_template "users/login"
678 get auth_path(:provider => "facebook", :origin => "/login?referer=%2Fhistory", :referer => "/history")
679 assert_response :redirect
680 assert_redirected_to auth_success_path(:provider => "facebook")
682 assert_response :redirect
684 assert_response :success
685 assert_template "users/new"
686 assert_select "span.username", false
689 def test_login_windowslive_success
690 user = create(:user, :auth_provider => "windowslive", :auth_uid => "1234567890")
691 OmniAuth.config.add_mock(:windowslive, :uid => user.auth_uid)
693 get "/login", :params => { :referer => "/history" }
694 assert_response :redirect
695 assert_redirected_to "controller" => "users", "action" => "login", "cookie_test" => "true", "referer" => "/history"
697 assert_response :success
698 assert_template "users/login"
699 get auth_path(:provider => "windowslive", :origin => "/login?referer=%2Fhistory", :referer => "/history")
700 assert_response :redirect
701 assert_redirected_to auth_success_path(:provider => "windowslive")
703 assert_response :redirect
705 assert_response :success
706 assert_template "changeset/history"
707 assert_select "span.username", user.display_name
710 def test_login_windowslive_connection_failed
711 OmniAuth.config.mock_auth[:windowslive] = :connection_failed
713 get "/login", :params => { :referer => "/history" }
714 assert_response :redirect
715 assert_redirected_to "controller" => "users", "action" => "login", "cookie_test" => "true", "referer" => "/history"
717 assert_response :success
718 assert_template "users/login"
719 get auth_path(:provider => "windowslive", :origin => "/login?referer=%2Fhistory", :referer => "/history")
720 assert_response :redirect
721 assert_redirected_to auth_success_path(:provider => "windowslive")
723 assert_response :redirect
724 assert_redirected_to auth_failure_path(:strategy => "windowslive", :message => "connection_failed", :origin => "/login?referer=%2Fhistory")
726 assert_response :redirect
728 assert_response :success
729 assert_template "login"
730 assert_select "div.flash.error", "Connection to authentication provider failed"
731 assert_select "span.username", false
734 def test_login_windowslive_invalid_credentials
735 OmniAuth.config.mock_auth[:windowslive] = :invalid_credentials
737 get "/login", :params => { :referer => "/history" }
738 assert_response :redirect
739 assert_redirected_to "controller" => "users", "action" => "login", "cookie_test" => "true", "referer" => "/history"
741 assert_response :success
742 assert_template "users/login"
743 get auth_path(:provider => "windowslive", :origin => "/login?referer=%2Fhistory", :referer => "/history")
744 assert_response :redirect
745 assert_redirected_to auth_success_path(:provider => "windowslive")
747 assert_response :redirect
748 assert_redirected_to auth_failure_path(:strategy => "windowslive", :message => "invalid_credentials", :origin => "/login?referer=%2Fhistory")
750 assert_response :redirect
752 assert_response :success
753 assert_template "login"
754 assert_select "div.flash.error", "Invalid authentication credentials"
755 assert_select "span.username", false
758 def test_login_windowslive_unknown
759 OmniAuth.config.add_mock(:windowslive, :uid => "987654321")
761 get "/login", :params => { :referer => "/history" }
762 assert_response :redirect
763 assert_redirected_to "controller" => "users", "action" => "login", "cookie_test" => "true", "referer" => "/history"
765 assert_response :success
766 assert_template "users/login"
767 get auth_path(:provider => "windowslive", :origin => "/login?referer=%2Fhistory", :referer => "/history")
768 assert_response :redirect
769 assert_redirected_to auth_success_path(:provider => "windowslive")
771 assert_response :redirect
773 assert_response :success
774 assert_template "users/new"
775 assert_select "span.username", false
778 def test_login_github_success
779 user = create(:user, :auth_provider => "github", :auth_uid => "1234567890")
780 OmniAuth.config.add_mock(:github, :uid => user.auth_uid)
782 get "/login", :params => { :referer => "/history" }
783 assert_response :redirect
784 assert_redirected_to "controller" => "users", "action" => "login", "cookie_test" => "true", "referer" => "/history"
786 assert_response :success
787 assert_template "users/login"
788 get auth_path(:provider => "github", :origin => "/login?referer=%2Fhistory", :referer => "/history")
789 assert_response :redirect
790 assert_redirected_to auth_success_path(:provider => "github")
792 assert_response :redirect
794 assert_response :success
795 assert_template "changeset/history"
796 assert_select "span.username", user.display_name
799 def test_login_github_connection_failed
800 OmniAuth.config.mock_auth[:github] = :connection_failed
802 get "/login", :params => { :referer => "/history" }
803 assert_response :redirect
804 assert_redirected_to "controller" => "users", "action" => "login", "cookie_test" => "true", "referer" => "/history"
806 assert_response :success
807 assert_template "users/login"
808 get auth_path(:provider => "github", :origin => "/login?referer=%2Fhistory", :referer => "/history")
809 assert_response :redirect
810 assert_redirected_to auth_success_path(:provider => "github")
812 assert_response :redirect
813 assert_redirected_to auth_failure_path(:strategy => "github", :message => "connection_failed", :origin => "/login?referer=%2Fhistory")
815 assert_response :redirect
817 assert_response :success
818 assert_template "login"
819 assert_select "div.flash.error", "Connection to authentication provider failed"
820 assert_select "span.username", false
823 def test_login_github_invalid_credentials
824 OmniAuth.config.mock_auth[:github] = :invalid_credentials
826 get "/login", :params => { :referer => "/history" }
827 assert_response :redirect
828 assert_redirected_to "controller" => "users", "action" => "login", "cookie_test" => "true", "referer" => "/history"
830 assert_response :success
831 assert_template "users/login"
832 get auth_path(:provider => "github", :origin => "/login?referer=%2Fhistory", :referer => "/history")
833 assert_response :redirect
834 assert_redirected_to auth_success_path(:provider => "github")
836 assert_response :redirect
837 assert_redirected_to auth_failure_path(:strategy => "github", :message => "invalid_credentials", :origin => "/login?referer=%2Fhistory")
839 assert_response :redirect
841 assert_response :success
842 assert_template "login"
843 assert_select "div.flash.error", "Invalid authentication credentials"
844 assert_select "span.username", false
847 def test_login_github_unknown
848 OmniAuth.config.add_mock(:github, :uid => "987654321")
850 get "/login", :params => { :referer => "/history" }
851 assert_response :redirect
852 assert_redirected_to "controller" => "users", "action" => "login", "cookie_test" => "true", "referer" => "/history"
854 assert_response :success
855 assert_template "users/login"
856 get auth_path(:provider => "github", :origin => "/login?referer=%2Fhistory", :referer => "/history")
857 assert_response :redirect
858 assert_redirected_to auth_success_path(:provider => "github")
860 assert_response :redirect
862 assert_response :success
863 assert_template "users/new"
864 assert_select "span.username", false
867 def test_login_wikipedia_success
868 user = create(:user, :auth_provider => "wikipedia", :auth_uid => "1234567890")
869 OmniAuth.config.add_mock(:wikipedia, :uid => user.auth_uid)
871 get "/login", :params => { :referer => "/history" }
872 assert_response :redirect
873 assert_redirected_to "controller" => "users", "action" => "login", "cookie_test" => "true", "referer" => "/history"
875 assert_response :success
876 assert_template "users/login"
877 get auth_path(:provider => "wikipedia", :origin => "/login?referer=%2Fhistory", :referer => "/history")
878 assert_response :redirect
879 assert_redirected_to auth_success_path(:provider => "wikipedia", :origin => "/login?referer=%2Fhistory", :referer => "/history")
881 assert_response :redirect
883 assert_response :success
884 assert_template "changeset/history"
885 assert_select "span.username", user.display_name
888 def test_login_wikipedia_connection_failed
889 OmniAuth.config.mock_auth[:wikipedia] = :connection_failed
891 get "/login", :params => { :referer => "/history" }
892 assert_response :redirect
893 assert_redirected_to "controller" => "users", "action" => "login", "cookie_test" => "true", "referer" => "/history"
895 assert_response :success
896 assert_template "users/login"
897 get auth_path(:provider => "wikipedia", :origin => "/login?referer=%2Fhistory", :referer => "/history")
898 assert_response :redirect
899 assert_redirected_to auth_success_path(:provider => "wikipedia", :origin => "/login?referer=%2Fhistory", :referer => "/history")
901 assert_response :redirect
902 assert_redirected_to auth_failure_path(:strategy => "wikipedia", :message => "connection_failed", :origin => "/login?referer=%2Fhistory")
904 assert_response :redirect
906 assert_response :success
907 assert_template "login"
908 assert_select "div.flash.error", "Connection to authentication provider failed"
909 assert_select "span.username", false
912 def test_login_wikipedia_invalid_credentials
913 OmniAuth.config.mock_auth[:wikipedia] = :invalid_credentials
915 get "/login", :params => { :referer => "/history" }
916 assert_response :redirect
917 assert_redirected_to "controller" => "users", "action" => "login", "cookie_test" => "true", "referer" => "/history"
919 assert_response :success
920 assert_template "users/login"
921 get auth_path(:provider => "wikipedia", :origin => "/login?referer=%2Fhistory", :referer => "/history")
922 assert_response :redirect
923 assert_redirected_to auth_success_path(:provider => "wikipedia", :origin => "/login?referer=%2Fhistory", :referer => "/history")
925 assert_response :redirect
926 assert_redirected_to auth_failure_path(:strategy => "wikipedia", :message => "invalid_credentials", :origin => "/login?referer=%2Fhistory")
928 assert_response :redirect
930 assert_response :success
931 assert_template "login"
932 assert_select "div.flash.error", "Invalid authentication credentials"
933 assert_select "span.username", false
936 def test_login_wikipedia_unknown
937 OmniAuth.config.add_mock(:wikipedia, :uid => "987654321")
939 get "/login", :params => { :referer => "/history" }
940 assert_response :redirect
941 assert_redirected_to "controller" => "users", "action" => "login", "cookie_test" => "true", "referer" => "/history"
943 assert_response :success
944 assert_template "users/login"
945 get auth_path(:provider => "wikipedia", :origin => "/login?referer=%2Fhistory", :referer => "/history")
946 assert_response :redirect
947 assert_redirected_to auth_success_path(:provider => "wikipedia", :origin => "/login?referer=%2Fhistory", :referer => "/history")
949 assert_response :redirect
951 assert_response :success
952 assert_template "users/new"
953 assert_select "span.username", false
958 def try_password_login(username, password, remember_me = nil)
960 assert_response :redirect
961 assert_redirected_to :controller => :users, :action => :login, :cookie_test => true
963 assert_response :success
964 assert_template "login"
965 assert_select "input#username", 1 do
966 assert_select "[value]", false
968 assert_select "input#password", 1 do
969 assert_select "[value=?]", ""
971 assert_select "input#remember_me", 1 do
972 assert_select "[checked]", false
975 post "/login", :params => { :username => username, :password => "wrong", :remember_me => remember_me, :referer => "/history" }
976 assert_response :redirect
978 assert_response :success
979 assert_template "login"
980 assert_select "input#username", 1 do
981 assert_select "[value=?]", username
983 assert_select "input#password", 1 do
984 assert_select "[value=?]", ""
986 assert_select "input#remember_me", 1 do
987 assert_select "[checked]", remember_me == "yes"
990 post "/login", :params => { :username => username, :password => password, :remember_me => remember_me, :referer => "/history" }
991 assert_response :redirect
993 assert_response :success