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 "changesets/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 "changesets/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 "sessions/new"
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 "changesets/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 "changesets/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 "changesets/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 "sessions/new"
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']", "support"
121 def test_login_email_password_suspended_upcase
122 user = create(:user, :suspended)
124 try_password_login user.email.upcase, "test"
126 assert_template "sessions/new"
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']", "support"
133 def test_login_email_password_suspended_titlecase
134 user = create(:user, :suspended)
136 try_password_login user.email.titlecase, "test"
138 assert_template "sessions/new"
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']", "support"
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 "changesets/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 "changesets/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 "sessions/new"
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 "changesets/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 "changesets/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 "changesets/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 "sessions/new"
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']", "support"
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 "sessions/new"
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']", "support"
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 "sessions/new"
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']", "support"
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 "changesets/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 "changesets/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 login_path(:cookie_test => true, :referer => "/history")
360 assert_response :success
361 assert_template "sessions/new"
362 post auth_path(:provider => "openid", :openid_url => "http://localhost:1123/john.doe", :origin => "/login?referer=%2Fhistory", :referer => "/history")
363 assert_response :redirect
364 assert_redirected_to auth_success_path(:provider => "openid", :openid_url => "http://localhost:1123/john.doe", :origin => "/login?referer=%2Fhistory", :referer => "/history")
366 assert_response :redirect
368 assert_response :success
369 assert_template "changesets/history"
370 assert_select "span.username", user.display_name
373 def test_login_openid_connection_failed
374 user = create(:user, :auth_provider => "openid", :auth_uid => "http://example.com/john.doe")
375 OmniAuth.config.mock_auth[:openid] = :connection_failed
377 get "/login", :params => { :referer => "/history" }
378 assert_response :redirect
379 assert_redirected_to login_path(:cookie_test => true, :referer => "/history")
381 assert_response :success
382 assert_template "sessions/new"
383 post auth_path(:provider => "openid", :openid_url => user.auth_uid, :origin => "/login?referer=%2Fhistory", :referer => "/history")
384 assert_response :redirect
385 assert_redirected_to auth_success_path(:provider => "openid", :openid_url => user.auth_uid, :origin => "/login?referer=%2Fhistory", :referer => "/history")
387 assert_response :redirect
388 assert_redirected_to auth_failure_path(:strategy => "openid", :message => "connection_failed", :origin => "/login?referer=%2Fhistory")
390 assert_response :redirect
392 assert_response :success
393 assert_template "sessions/new"
394 assert_select "div.flash.error", "Connection to authentication provider failed"
395 assert_select "span.username", false
398 def test_login_openid_invalid_credentials
399 user = create(:user, :auth_provider => "openid", :auth_uid => "http://example.com/john.doe")
400 OmniAuth.config.mock_auth[:openid] = :invalid_credentials
402 get "/login", :params => { :referer => "/history" }
403 assert_response :redirect
404 assert_redirected_to login_path(:cookie_test => true, :referer => "/history")
406 assert_response :success
407 assert_template "sessions/new"
408 post auth_path(:provider => "openid", :openid_url => user.auth_uid, :origin => "/login?referer=%2Fhistory", :referer => "/history")
409 assert_response :redirect
410 assert_redirected_to auth_success_path(:provider => "openid", :openid_url => user.auth_uid, :origin => "/login?referer=%2Fhistory", :referer => "/history")
412 assert_response :redirect
413 assert_redirected_to auth_failure_path(:strategy => "openid", :message => "invalid_credentials", :origin => "/login?referer=%2Fhistory")
415 assert_response :redirect
417 assert_response :success
418 assert_template "sessions/new"
419 assert_select "div.flash.error", "Invalid authentication credentials"
420 assert_select "span.username", false
423 def test_login_openid_unknown
424 OmniAuth.config.add_mock(:openid, :uid => "http://localhost:1123/fred.bloggs")
426 get "/login", :params => { :referer => "/history" }
427 assert_response :redirect
428 assert_redirected_to login_path(:cookie_test => true, :referer => "/history")
430 assert_response :success
431 assert_template "sessions/new"
432 post auth_path(:provider => "openid", :openid_url => "http://localhost:1123/fred.bloggs", :origin => "/login?referer=%2Fhistory", :referer => "/history")
433 assert_response :redirect
434 assert_redirected_to auth_success_path(:provider => "openid", :openid_url => "http://localhost:1123/fred.bloggs", :origin => "/login?referer=%2Fhistory", :referer => "/history")
436 assert_response :redirect
438 assert_response :success
439 assert_template "users/new"
440 assert_select "span.username", false
443 def test_login_google_success
444 user = create(:user, :auth_provider => "google", :auth_uid => "1234567890")
445 OmniAuth.config.add_mock(:google, :uid => user.auth_uid, :extra => {
446 :id_info => { "openid_id" => "http://localhost:1123/fred.bloggs" }
449 get "/login", :params => { :referer => "/history" }
450 assert_response :redirect
451 assert_redirected_to login_path("cookie_test" => "true", "referer" => "/history")
453 assert_response :success
454 assert_template "sessions/new"
455 post auth_path(:provider => "google", :origin => "/login?referer=%2Fhistory", :referer => "/history")
456 assert_response :redirect
457 assert_redirected_to auth_success_path(:provider => "google")
459 assert_response :redirect
461 assert_response :success
462 assert_template "changesets/history"
463 assert_select "span.username", user.display_name
466 def test_login_google_connection_failed
467 OmniAuth.config.mock_auth[:google] = :connection_failed
469 get "/login", :params => { :referer => "/history" }
470 assert_response :redirect
471 assert_redirected_to login_path("cookie_test" => "true", "referer" => "/history")
473 assert_response :success
474 assert_template "sessions/new"
475 post auth_path(:provider => "google", :origin => "/login?referer=%2Fhistory", :referer => "/history")
476 assert_response :redirect
477 assert_redirected_to auth_success_path(:provider => "google")
479 assert_response :redirect
480 assert_redirected_to auth_failure_path(:strategy => "google", :message => "connection_failed", :origin => "/login?referer=%2Fhistory")
482 assert_response :redirect
484 assert_response :success
485 assert_template "sessions/new"
486 assert_select "div.flash.error", "Connection to authentication provider failed"
487 assert_select "span.username", false
490 def test_login_google_invalid_credentials
491 OmniAuth.config.mock_auth[:google] = :invalid_credentials
493 get "/login", :params => { :referer => "/history" }
494 assert_response :redirect
495 assert_redirected_to login_path("cookie_test" => "true", "referer" => "/history")
497 assert_response :success
498 assert_template "sessions/new"
499 post auth_path(:provider => "google", :origin => "/login?referer=%2Fhistory", :referer => "/history")
500 assert_response :redirect
501 assert_redirected_to auth_success_path(:provider => "google")
503 assert_response :redirect
504 assert_redirected_to auth_failure_path(:strategy => "google", :message => "invalid_credentials", :origin => "/login?referer=%2Fhistory")
506 assert_response :redirect
508 assert_response :success
509 assert_template "sessions/new"
510 assert_select "div.flash.error", "Invalid authentication credentials"
511 assert_select "span.username", false
514 def test_login_google_unknown
515 OmniAuth.config.add_mock(:google, :uid => "987654321", :extra => {
516 :id_info => { "openid_id" => "http://localhost:1123/fred.bloggs" }
519 get "/login", :params => { :referer => "/history" }
520 assert_response :redirect
521 assert_redirected_to login_path("cookie_test" => "true", "referer" => "/history")
523 assert_response :success
524 assert_template "sessions/new"
525 post auth_path(:provider => "google", :origin => "/login?referer=%2Fhistory", :referer => "/history")
526 assert_response :redirect
527 assert_redirected_to auth_success_path(:provider => "google")
529 assert_response :redirect
531 assert_response :success
532 assert_template "users/new"
533 assert_select "span.username", false
536 def test_login_google_upgrade
537 user = create(:user, :auth_provider => "openid", :auth_uid => "http://example.com/john.doe")
538 OmniAuth.config.add_mock(:google, :uid => "987654321", :extra => {
539 :id_info => { "openid_id" => user.auth_uid }
542 get "/login", :params => { :referer => "/history" }
543 assert_response :redirect
544 assert_redirected_to login_path("cookie_test" => "true", "referer" => "/history")
546 assert_response :success
547 assert_template "sessions/new"
548 post auth_path(:provider => "google", :origin => "/login?referer=%2Fhistory", :referer => "/history")
549 assert_response :redirect
550 assert_redirected_to auth_success_path(:provider => "google")
552 assert_response :redirect
554 assert_response :success
555 assert_template "changesets/history"
556 assert_select "span.username", user.display_name
558 u = User.find_by(:display_name => user.display_name)
559 assert_equal "google", u.auth_provider
560 assert_equal "987654321", u.auth_uid
563 def test_login_facebook_success
564 user = create(:user, :auth_provider => "facebook", :auth_uid => "1234567890")
565 OmniAuth.config.add_mock(:facebook, :uid => user.auth_uid)
567 get "/login", :params => { :referer => "/history" }
568 assert_response :redirect
569 assert_redirected_to login_path("cookie_test" => "true", "referer" => "/history")
571 assert_response :success
572 assert_template "sessions/new"
573 post auth_path(:provider => "facebook", :origin => "/login?referer=%2Fhistory", :referer => "/history")
574 assert_response :redirect
575 assert_redirected_to auth_success_path(:provider => "facebook")
577 assert_response :redirect
579 assert_response :success
580 assert_template "changesets/history"
581 assert_select "span.username", user.display_name
584 def test_login_facebook_connection_failed
585 OmniAuth.config.mock_auth[:facebook] = :connection_failed
587 get "/login", :params => { :referer => "/history" }
588 assert_response :redirect
589 assert_redirected_to login_path("cookie_test" => "true", "referer" => "/history")
591 assert_response :success
592 assert_template "sessions/new"
593 post auth_path(:provider => "facebook", :origin => "/login?referer=%2Fhistory", :referer => "/history")
594 assert_response :redirect
595 assert_redirected_to auth_success_path(:provider => "facebook")
597 assert_response :redirect
598 assert_redirected_to auth_failure_path(:strategy => "facebook", :message => "connection_failed", :origin => "/login?referer=%2Fhistory")
600 assert_response :redirect
602 assert_response :success
603 assert_template "sessions/new"
604 assert_select "div.flash.error", "Connection to authentication provider failed"
605 assert_select "span.username", false
608 def test_login_facebook_invalid_credentials
609 OmniAuth.config.mock_auth[:facebook] = :invalid_credentials
611 get "/login", :params => { :referer => "/history" }
612 assert_response :redirect
613 assert_redirected_to login_path("cookie_test" => "true", "referer" => "/history")
615 assert_response :success
616 assert_template "sessions/new"
617 post auth_path(:provider => "facebook", :origin => "/login?referer=%2Fhistory", :referer => "/history")
618 assert_response :redirect
619 assert_redirected_to auth_success_path(:provider => "facebook")
621 assert_response :redirect
622 assert_redirected_to auth_failure_path(:strategy => "facebook", :message => "invalid_credentials", :origin => "/login?referer=%2Fhistory")
624 assert_response :redirect
626 assert_response :success
627 assert_template "sessions/new"
628 assert_select "div.flash.error", "Invalid authentication credentials"
629 assert_select "span.username", false
632 def test_login_facebook_unknown
633 OmniAuth.config.add_mock(:facebook, :uid => "987654321")
635 get "/login", :params => { :referer => "/history" }
636 assert_response :redirect
637 assert_redirected_to login_path("cookie_test" => "true", "referer" => "/history")
639 assert_response :success
640 assert_template "sessions/new"
641 post auth_path(:provider => "facebook", :origin => "/login?referer=%2Fhistory", :referer => "/history")
642 assert_response :redirect
643 assert_redirected_to auth_success_path(:provider => "facebook")
645 assert_response :redirect
647 assert_response :success
648 assert_template "users/new"
649 assert_select "span.username", false
652 def test_login_windowslive_success
653 user = create(:user, :auth_provider => "windowslive", :auth_uid => "1234567890")
654 OmniAuth.config.add_mock(:windowslive, :uid => user.auth_uid)
656 get "/login", :params => { :referer => "/history" }
657 assert_response :redirect
658 assert_redirected_to login_path("cookie_test" => "true", "referer" => "/history")
660 assert_response :success
661 assert_template "sessions/new"
662 post auth_path(:provider => "windowslive", :origin => "/login?referer=%2Fhistory", :referer => "/history")
663 assert_response :redirect
664 assert_redirected_to auth_success_path(:provider => "windowslive")
666 assert_response :redirect
668 assert_response :success
669 assert_template "changesets/history"
670 assert_select "span.username", user.display_name
673 def test_login_windowslive_connection_failed
674 OmniAuth.config.mock_auth[:windowslive] = :connection_failed
676 get "/login", :params => { :referer => "/history" }
677 assert_response :redirect
678 assert_redirected_to login_path("cookie_test" => "true", "referer" => "/history")
680 assert_response :success
681 assert_template "sessions/new"
682 post auth_path(:provider => "windowslive", :origin => "/login?referer=%2Fhistory", :referer => "/history")
683 assert_response :redirect
684 assert_redirected_to auth_success_path(:provider => "windowslive")
686 assert_response :redirect
687 assert_redirected_to auth_failure_path(:strategy => "windowslive", :message => "connection_failed", :origin => "/login?referer=%2Fhistory")
689 assert_response :redirect
691 assert_response :success
692 assert_template "sessions/new"
693 assert_select "div.flash.error", "Connection to authentication provider failed"
694 assert_select "span.username", false
697 def test_login_windowslive_invalid_credentials
698 OmniAuth.config.mock_auth[:windowslive] = :invalid_credentials
700 get "/login", :params => { :referer => "/history" }
701 assert_response :redirect
702 assert_redirected_to login_path("cookie_test" => "true", "referer" => "/history")
704 assert_response :success
705 assert_template "sessions/new"
706 post auth_path(:provider => "windowslive", :origin => "/login?referer=%2Fhistory", :referer => "/history")
707 assert_response :redirect
708 assert_redirected_to auth_success_path(:provider => "windowslive")
710 assert_response :redirect
711 assert_redirected_to auth_failure_path(:strategy => "windowslive", :message => "invalid_credentials", :origin => "/login?referer=%2Fhistory")
713 assert_response :redirect
715 assert_response :success
716 assert_template "sessions/new"
717 assert_select "div.flash.error", "Invalid authentication credentials"
718 assert_select "span.username", false
721 def test_login_windowslive_unknown
722 OmniAuth.config.add_mock(:windowslive, :uid => "987654321")
724 get "/login", :params => { :referer => "/history" }
725 assert_response :redirect
726 assert_redirected_to login_path("cookie_test" => "true", "referer" => "/history")
728 assert_response :success
729 assert_template "sessions/new"
730 post auth_path(:provider => "windowslive", :origin => "/login?referer=%2Fhistory", :referer => "/history")
731 assert_response :redirect
732 assert_redirected_to auth_success_path(:provider => "windowslive")
734 assert_response :redirect
736 assert_response :success
737 assert_template "users/new"
738 assert_select "span.username", false
741 def test_login_github_success
742 user = create(:user, :auth_provider => "github", :auth_uid => "1234567890")
743 OmniAuth.config.add_mock(:github, :uid => user.auth_uid)
745 get "/login", :params => { :referer => "/history" }
746 assert_response :redirect
747 assert_redirected_to login_path("cookie_test" => "true", "referer" => "/history")
749 assert_response :success
750 assert_template "sessions/new"
751 post auth_path(:provider => "github", :origin => "/login?referer=%2Fhistory", :referer => "/history")
752 assert_response :redirect
753 assert_redirected_to auth_success_path(:provider => "github")
755 assert_response :redirect
757 assert_response :success
758 assert_template "changesets/history"
759 assert_select "span.username", user.display_name
762 def test_login_github_connection_failed
763 OmniAuth.config.mock_auth[:github] = :connection_failed
765 get "/login", :params => { :referer => "/history" }
766 assert_response :redirect
767 assert_redirected_to login_path("cookie_test" => "true", "referer" => "/history")
769 assert_response :success
770 assert_template "sessions/new"
771 post auth_path(:provider => "github", :origin => "/login?referer=%2Fhistory", :referer => "/history")
772 assert_response :redirect
773 assert_redirected_to auth_success_path(:provider => "github")
775 assert_response :redirect
776 assert_redirected_to auth_failure_path(:strategy => "github", :message => "connection_failed", :origin => "/login?referer=%2Fhistory")
778 assert_response :redirect
780 assert_response :success
781 assert_template "sessions/new"
782 assert_select "div.flash.error", "Connection to authentication provider failed"
783 assert_select "span.username", false
786 def test_login_github_invalid_credentials
787 OmniAuth.config.mock_auth[:github] = :invalid_credentials
789 get "/login", :params => { :referer => "/history" }
790 assert_response :redirect
791 assert_redirected_to login_path("cookie_test" => "true", "referer" => "/history")
793 assert_response :success
794 assert_template "sessions/new"
795 post auth_path(:provider => "github", :origin => "/login?referer=%2Fhistory", :referer => "/history")
796 assert_response :redirect
797 assert_redirected_to auth_success_path(:provider => "github")
799 assert_response :redirect
800 assert_redirected_to auth_failure_path(:strategy => "github", :message => "invalid_credentials", :origin => "/login?referer=%2Fhistory")
802 assert_response :redirect
804 assert_response :success
805 assert_template "sessions/new"
806 assert_select "div.flash.error", "Invalid authentication credentials"
807 assert_select "span.username", false
810 def test_login_github_unknown
811 OmniAuth.config.add_mock(:github, :uid => "987654321")
813 get "/login", :params => { :referer => "/history" }
814 assert_response :redirect
815 assert_redirected_to login_path("cookie_test" => "true", "referer" => "/history")
817 assert_response :success
818 assert_template "sessions/new"
819 post auth_path(:provider => "github", :origin => "/login?referer=%2Fhistory", :referer => "/history")
820 assert_response :redirect
821 assert_redirected_to auth_success_path(:provider => "github")
823 assert_response :redirect
825 assert_response :success
826 assert_template "users/new"
827 assert_select "span.username", false
830 def test_login_wikipedia_success
831 user = create(:user, :auth_provider => "wikipedia", :auth_uid => "1234567890")
832 OmniAuth.config.add_mock(:wikipedia, :uid => user.auth_uid)
834 get "/login", :params => { :referer => "/history" }
835 assert_response :redirect
836 assert_redirected_to login_path("cookie_test" => "true", "referer" => "/history")
838 assert_response :success
839 assert_template "sessions/new"
840 post auth_path(:provider => "wikipedia", :origin => "/login?referer=%2Fhistory", :referer => "/history")
841 assert_response :redirect
842 assert_redirected_to auth_success_path(:provider => "wikipedia", :origin => "/login?referer=%2Fhistory", :referer => "/history")
844 assert_response :redirect
846 assert_response :success
847 assert_template "changesets/history"
848 assert_select "span.username", user.display_name
851 def test_login_wikipedia_connection_failed
852 OmniAuth.config.mock_auth[:wikipedia] = :connection_failed
854 get "/login", :params => { :referer => "/history" }
855 assert_response :redirect
856 assert_redirected_to login_path("cookie_test" => "true", "referer" => "/history")
858 assert_response :success
859 assert_template "sessions/new"
860 post auth_path(:provider => "wikipedia", :origin => "/login?referer=%2Fhistory", :referer => "/history")
861 assert_response :redirect
862 assert_redirected_to auth_success_path(:provider => "wikipedia", :origin => "/login?referer=%2Fhistory", :referer => "/history")
864 assert_response :redirect
865 assert_redirected_to auth_failure_path(:strategy => "wikipedia", :message => "connection_failed", :origin => "/login?referer=%2Fhistory")
867 assert_response :redirect
869 assert_response :success
870 assert_template "sessions/new"
871 assert_select "div.flash.error", "Connection to authentication provider failed"
872 assert_select "span.username", false
875 def test_login_wikipedia_invalid_credentials
876 OmniAuth.config.mock_auth[:wikipedia] = :invalid_credentials
878 get "/login", :params => { :referer => "/history" }
879 assert_response :redirect
880 assert_redirected_to login_path("cookie_test" => "true", "referer" => "/history")
882 assert_response :success
883 assert_template "sessions/new"
884 post auth_path(:provider => "wikipedia", :origin => "/login?referer=%2Fhistory", :referer => "/history")
885 assert_response :redirect
886 assert_redirected_to auth_success_path(:provider => "wikipedia", :origin => "/login?referer=%2Fhistory", :referer => "/history")
888 assert_response :redirect
889 assert_redirected_to auth_failure_path(:strategy => "wikipedia", :message => "invalid_credentials", :origin => "/login?referer=%2Fhistory")
891 assert_response :redirect
893 assert_response :success
894 assert_template "sessions/new"
895 assert_select "div.flash.error", "Invalid authentication credentials"
896 assert_select "span.username", false
899 def test_login_wikipedia_unknown
900 OmniAuth.config.add_mock(:wikipedia, :uid => "987654321")
902 get "/login", :params => { :referer => "/history" }
903 assert_response :redirect
904 assert_redirected_to login_path("cookie_test" => "true", "referer" => "/history")
906 assert_response :success
907 assert_template "sessions/new"
908 post auth_path(:provider => "wikipedia", :origin => "/login?referer=%2Fhistory", :referer => "/history")
909 assert_response :redirect
910 assert_redirected_to auth_success_path(:provider => "wikipedia", :origin => "/login?referer=%2Fhistory", :referer => "/history")
912 assert_response :redirect
914 assert_response :success
915 assert_template "users/new"
916 assert_select "span.username", false
921 def try_password_login(username, password, remember_me = nil)
923 assert_response :redirect
924 assert_redirected_to login_path(:cookie_test => true)
926 assert_response :success
927 assert_template "sessions/new"
928 assert_select "input#username", 1 do
929 assert_select "[value]", false
931 assert_select "input#password", 1 do
932 assert_select "[value=?]", ""
934 assert_select "input#remember_me", 1 do
935 assert_select "[checked]", false
938 post "/login", :params => { :username => username, :password => "wrong", :remember_me => remember_me, :referer => "/history" }
939 assert_response :redirect
941 assert_response :success
942 assert_template "sessions/new"
943 assert_select "input#username", 1 do
944 assert_select "[value=?]", username
946 assert_select "input#password", 1 do
947 assert_select "[value=?]", ""
949 assert_select "input#remember_me", 1 do
950 assert_select "[checked]", remember_me == "yes"
953 post "/login", :params => { :username => username, :password => password, :remember_me => remember_me, :referer => "/history" }
954 assert_response :redirect
956 assert_response :success