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[:microsoft] = 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.alert.alert-danger", /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.alert.alert-danger", /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.alert.alert-danger", /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.alert.alert-danger", /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.alert.alert-danger", /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.alert.alert-danger", /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_pending
374 user = create(:user, :pending, :auth_provider => "openid", :auth_uid => "http://example.com/john.doe")
375 OmniAuth.config.add_mock(:openid, :uid => user.auth_uid)
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 => "http://localhost:1123/john.doe", :origin => "/login?referer=%2Fhistory", :referer => "/history")
384 assert_response :redirect
385 assert_redirected_to auth_success_path(:provider => "openid", :openid_url => "http://localhost:1123/john.doe", :origin => "/login?referer=%2Fhistory", :referer => "/history")
387 assert_response :redirect
389 assert_response :success
390 assert_template "confirm"
393 def test_login_openid_suspended
394 user = create(:user, :suspended, :auth_provider => "openid", :auth_uid => "http://example.com/john.doe")
395 OmniAuth.config.add_mock(:openid, :uid => user.auth_uid)
397 get "/login", :params => { :referer => "/history" }
398 assert_response :redirect
399 assert_redirected_to login_path(:cookie_test => true, :referer => "/history")
401 assert_response :success
402 assert_template "sessions/new"
403 post auth_path(:provider => "openid", :openid_url => "http://localhost:1123/john.doe", :origin => "/login?referer=%2Fhistory", :referer => "/history")
404 assert_response :redirect
405 assert_redirected_to auth_success_path(:provider => "openid", :openid_url => "http://localhost:1123/john.doe", :origin => "/login?referer=%2Fhistory", :referer => "/history")
407 assert_response :redirect
409 assert_response :success
410 assert_template "sessions/new"
411 assert_select "span.username", false
412 assert_select "div.alert.alert-danger", /your account has been suspended/ do
413 assert_select "a[href='mailto:openstreetmap@example.com']", "support"
417 def test_login_openid_blocked
418 user = create(:user, :auth_provider => "openid", :auth_uid => "http://example.com/john.doe")
419 create(:user_block, :needs_view, :user => user)
420 OmniAuth.config.add_mock(:openid, :uid => user.auth_uid)
422 get "/login", :params => { :referer => "/history" }
423 assert_response :redirect
424 assert_redirected_to login_path(:cookie_test => true, :referer => "/history")
426 assert_response :success
427 assert_template "sessions/new"
428 post auth_path(:provider => "openid", :openid_url => "http://localhost:1123/john.doe", :origin => "/login?referer=%2Fhistory", :referer => "/history")
429 assert_response :redirect
430 assert_redirected_to auth_success_path(:provider => "openid", :openid_url => "http://localhost:1123/john.doe", :origin => "/login?referer=%2Fhistory", :referer => "/history")
432 assert_response :redirect
434 assert_response :success
435 assert_template "user_blocks/show"
436 assert_select "span.username", user.display_name
439 def test_login_openid_connection_failed
440 user = create(:user, :auth_provider => "openid", :auth_uid => "http://example.com/john.doe")
441 OmniAuth.config.mock_auth[:openid] = :connection_failed
443 get "/login", :params => { :referer => "/history" }
444 assert_response :redirect
445 assert_redirected_to login_path(:cookie_test => true, :referer => "/history")
447 assert_response :success
448 assert_template "sessions/new"
449 post auth_path(:provider => "openid", :openid_url => user.auth_uid, :origin => "/login?referer=%2Fhistory", :referer => "/history")
450 assert_response :redirect
451 assert_redirected_to auth_success_path(:provider => "openid", :openid_url => user.auth_uid, :origin => "/login?referer=%2Fhistory", :referer => "/history")
453 assert_response :redirect
454 assert_redirected_to auth_failure_path(:strategy => "openid", :message => "connection_failed", :origin => "/login?referer=%2Fhistory")
456 assert_response :redirect
458 assert_response :success
459 assert_template "sessions/new"
460 assert_select "div.alert.alert-danger", "Connection to authentication provider failed"
461 assert_select "span.username", false
464 def test_login_openid_invalid_credentials
465 user = create(:user, :auth_provider => "openid", :auth_uid => "http://example.com/john.doe")
466 OmniAuth.config.mock_auth[:openid] = :invalid_credentials
468 get "/login", :params => { :referer => "/history" }
469 assert_response :redirect
470 assert_redirected_to login_path(:cookie_test => true, :referer => "/history")
472 assert_response :success
473 assert_template "sessions/new"
474 post auth_path(:provider => "openid", :openid_url => user.auth_uid, :origin => "/login?referer=%2Fhistory", :referer => "/history")
475 assert_response :redirect
476 assert_redirected_to auth_success_path(:provider => "openid", :openid_url => user.auth_uid, :origin => "/login?referer=%2Fhistory", :referer => "/history")
478 assert_response :redirect
479 assert_redirected_to auth_failure_path(:strategy => "openid", :message => "invalid_credentials", :origin => "/login?referer=%2Fhistory")
481 assert_response :redirect
483 assert_response :success
484 assert_template "sessions/new"
485 assert_select "div.alert.alert-danger", "Invalid authentication credentials"
486 assert_select "span.username", false
489 def test_login_openid_unknown
490 OmniAuth.config.add_mock(:openid, :uid => "http://localhost:1123/fred.bloggs")
492 get "/login", :params => { :referer => "/history" }
493 assert_response :redirect
494 assert_redirected_to login_path(:cookie_test => true, :referer => "/history")
496 assert_response :success
497 assert_template "sessions/new"
498 post auth_path(:provider => "openid", :openid_url => "http://localhost:1123/fred.bloggs", :origin => "/login?referer=%2Fhistory", :referer => "/history")
499 assert_response :redirect
500 assert_redirected_to auth_success_path(:provider => "openid", :openid_url => "http://localhost:1123/fred.bloggs", :origin => "/login?referer=%2Fhistory", :referer => "/history")
502 assert_response :redirect
504 assert_response :success
505 assert_template "users/new"
506 assert_select "span.username", false
509 def test_login_google_success
510 user = create(:user, :auth_provider => "google", :auth_uid => "1234567890")
511 OmniAuth.config.add_mock(:google, :uid => user.auth_uid, :extra => {
512 :id_info => { "openid_id" => "http://localhost:1123/fred.bloggs" }
515 get "/login", :params => { :referer => "/history" }
516 assert_response :redirect
517 assert_redirected_to login_path("cookie_test" => "true", "referer" => "/history")
519 assert_response :success
520 assert_template "sessions/new"
521 post auth_path(:provider => "google", :origin => "/login?referer=%2Fhistory", :referer => "/history")
522 assert_response :redirect
523 assert_redirected_to auth_success_path(:provider => "google")
525 assert_response :redirect
527 assert_response :success
528 assert_template "changesets/history"
529 assert_select "span.username", user.display_name
532 def test_login_google_pending
533 user = create(:user, :pending, :auth_provider => "google", :auth_uid => "1234567890")
534 OmniAuth.config.add_mock(:google, :uid => user.auth_uid, :extra => {
535 :id_info => { "openid_id" => "http://localhost:1123/fred.bloggs" }
538 get "/login", :params => { :referer => "/history" }
539 assert_response :redirect
540 assert_redirected_to login_path("cookie_test" => "true", "referer" => "/history")
542 assert_response :success
543 assert_template "sessions/new"
544 post auth_path(:provider => "google", :origin => "/login?referer=%2Fhistory", :referer => "/history")
545 assert_response :redirect
546 assert_redirected_to auth_success_path(:provider => "google")
548 assert_response :redirect
550 assert_response :success
551 assert_template "confirm"
554 def test_login_google_suspended
555 user = create(:user, :suspended, :auth_provider => "google", :auth_uid => "1234567890")
556 OmniAuth.config.add_mock(:google, :uid => user.auth_uid, :extra => {
557 :id_info => { "openid_id" => "http://localhost:1123/fred.bloggs" }
560 get "/login", :params => { :referer => "/history" }
561 assert_response :redirect
562 assert_redirected_to login_path("cookie_test" => "true", "referer" => "/history")
564 assert_response :success
565 assert_template "sessions/new"
566 post auth_path(:provider => "google", :origin => "/login?referer=%2Fhistory", :referer => "/history")
567 assert_response :redirect
568 assert_redirected_to auth_success_path(:provider => "google")
570 assert_response :redirect
572 assert_response :success
573 assert_template "sessions/new"
574 assert_select "span.username", false
575 assert_select "div.alert.alert-danger", /your account has been suspended/ do
576 assert_select "a[href='mailto:openstreetmap@example.com']", "support"
580 def test_login_google_blocked
581 user = create(:user, :auth_provider => "google", :auth_uid => "1234567890")
582 create(:user_block, :needs_view, :user => user)
583 OmniAuth.config.add_mock(:google, :uid => user.auth_uid, :extra => {
584 :id_info => { "openid_id" => "http://localhost:1123/fred.bloggs" }
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 => "google", :origin => "/login?referer=%2Fhistory", :referer => "/history")
594 assert_response :redirect
595 assert_redirected_to auth_success_path(:provider => "google")
597 assert_response :redirect
599 assert_response :success
600 assert_template "user_blocks/show"
601 assert_select "span.username", user.display_name
604 def test_login_google_connection_failed
605 OmniAuth.config.mock_auth[:google] = :connection_failed
607 get "/login", :params => { :referer => "/history" }
608 assert_response :redirect
609 assert_redirected_to login_path("cookie_test" => "true", "referer" => "/history")
611 assert_response :success
612 assert_template "sessions/new"
613 post auth_path(:provider => "google", :origin => "/login?referer=%2Fhistory", :referer => "/history")
614 assert_response :redirect
615 assert_redirected_to auth_success_path(:provider => "google")
617 assert_response :redirect
618 assert_redirected_to auth_failure_path(:strategy => "google", :message => "connection_failed", :origin => "/login?referer=%2Fhistory")
620 assert_response :redirect
622 assert_response :success
623 assert_template "sessions/new"
624 assert_select "div.alert.alert-danger", "Connection to authentication provider failed"
625 assert_select "span.username", false
628 def test_login_google_invalid_credentials
629 OmniAuth.config.mock_auth[:google] = :invalid_credentials
631 get "/login", :params => { :referer => "/history" }
632 assert_response :redirect
633 assert_redirected_to login_path("cookie_test" => "true", "referer" => "/history")
635 assert_response :success
636 assert_template "sessions/new"
637 post auth_path(:provider => "google", :origin => "/login?referer=%2Fhistory", :referer => "/history")
638 assert_response :redirect
639 assert_redirected_to auth_success_path(:provider => "google")
641 assert_response :redirect
642 assert_redirected_to auth_failure_path(:strategy => "google", :message => "invalid_credentials", :origin => "/login?referer=%2Fhistory")
644 assert_response :redirect
646 assert_response :success
647 assert_template "sessions/new"
648 assert_select "div.alert.alert-danger", "Invalid authentication credentials"
649 assert_select "span.username", false
652 def test_login_google_unknown
653 OmniAuth.config.add_mock(:google, :uid => "987654321", :extra => {
654 :id_info => { "openid_id" => "http://localhost:1123/fred.bloggs" }
657 get "/login", :params => { :referer => "/history" }
658 assert_response :redirect
659 assert_redirected_to login_path("cookie_test" => "true", "referer" => "/history")
661 assert_response :success
662 assert_template "sessions/new"
663 post auth_path(:provider => "google", :origin => "/login?referer=%2Fhistory", :referer => "/history")
664 assert_response :redirect
665 assert_redirected_to auth_success_path(:provider => "google")
667 assert_response :redirect
669 assert_response :success
670 assert_template "users/new"
671 assert_select "span.username", false
674 def test_login_google_upgrade
675 user = create(:user, :auth_provider => "openid", :auth_uid => "http://example.com/john.doe")
676 OmniAuth.config.add_mock(:google, :uid => "987654321", :extra => {
677 :id_info => { "openid_id" => user.auth_uid }
680 get "/login", :params => { :referer => "/history" }
681 assert_response :redirect
682 assert_redirected_to login_path("cookie_test" => "true", "referer" => "/history")
684 assert_response :success
685 assert_template "sessions/new"
686 post auth_path(:provider => "google", :origin => "/login?referer=%2Fhistory", :referer => "/history")
687 assert_response :redirect
688 assert_redirected_to auth_success_path(:provider => "google")
690 assert_response :redirect
692 assert_response :success
693 assert_template "changesets/history"
694 assert_select "span.username", user.display_name
696 u = User.find_by(:display_name => user.display_name)
697 assert_equal "google", u.auth_provider
698 assert_equal "987654321", u.auth_uid
701 def test_login_facebook_success
702 user = create(:user, :auth_provider => "facebook", :auth_uid => "1234567890")
703 OmniAuth.config.add_mock(:facebook, :uid => user.auth_uid)
705 get "/login", :params => { :referer => "/history" }
706 assert_response :redirect
707 assert_redirected_to login_path("cookie_test" => "true", "referer" => "/history")
709 assert_response :success
710 assert_template "sessions/new"
711 post auth_path(:provider => "facebook", :origin => "/login?referer=%2Fhistory", :referer => "/history")
712 assert_response :redirect
713 assert_redirected_to auth_success_path(:provider => "facebook")
715 assert_response :redirect
717 assert_response :success
718 assert_template "changesets/history"
719 assert_select "span.username", user.display_name
722 def test_login_facebook_pending
723 user = create(:user, :pending, :auth_provider => "facebook", :auth_uid => "1234567890")
724 OmniAuth.config.add_mock(:facebook, :uid => user.auth_uid)
726 get "/login", :params => { :referer => "/history" }
727 assert_response :redirect
728 assert_redirected_to login_path("cookie_test" => "true", "referer" => "/history")
730 assert_response :success
731 assert_template "sessions/new"
732 post auth_path(:provider => "facebook", :origin => "/login?referer=%2Fhistory", :referer => "/history")
733 assert_response :redirect
734 assert_redirected_to auth_success_path(:provider => "facebook")
736 assert_response :redirect
738 assert_response :success
739 assert_template "confirm"
742 def test_login_facebook_suspended
743 user = create(:user, :suspended, :auth_provider => "facebook", :auth_uid => "1234567890")
744 OmniAuth.config.add_mock(:facebook, :uid => user.auth_uid)
746 get "/login", :params => { :referer => "/history" }
747 assert_response :redirect
748 assert_redirected_to login_path("cookie_test" => "true", "referer" => "/history")
750 assert_response :success
751 assert_template "sessions/new"
752 post auth_path(:provider => "facebook", :origin => "/login?referer=%2Fhistory", :referer => "/history")
753 assert_response :redirect
754 assert_redirected_to auth_success_path(:provider => "facebook")
756 assert_response :redirect
758 assert_response :success
759 assert_template "sessions/new"
760 assert_select "span.username", false
761 assert_select "div.alert.alert-danger", /your account has been suspended/ do
762 assert_select "a[href='mailto:openstreetmap@example.com']", "support"
766 def test_login_facebook_blocked
767 user = create(:user, :auth_provider => "facebook", :auth_uid => "1234567890")
768 create(:user_block, :needs_view, :user => user)
769 OmniAuth.config.add_mock(:facebook, :uid => user.auth_uid)
771 get "/login", :params => { :referer => "/history" }
772 assert_response :redirect
773 assert_redirected_to login_path("cookie_test" => "true", "referer" => "/history")
775 assert_response :success
776 assert_template "sessions/new"
777 post auth_path(:provider => "facebook", :origin => "/login?referer=%2Fhistory", :referer => "/history")
778 assert_response :redirect
779 assert_redirected_to auth_success_path(:provider => "facebook")
781 assert_response :redirect
783 assert_response :success
784 assert_template "user_blocks/show"
785 assert_select "span.username", user.display_name
788 def test_login_facebook_connection_failed
789 OmniAuth.config.mock_auth[:facebook] = :connection_failed
791 get "/login", :params => { :referer => "/history" }
792 assert_response :redirect
793 assert_redirected_to login_path("cookie_test" => "true", "referer" => "/history")
795 assert_response :success
796 assert_template "sessions/new"
797 post auth_path(:provider => "facebook", :origin => "/login?referer=%2Fhistory", :referer => "/history")
798 assert_response :redirect
799 assert_redirected_to auth_success_path(:provider => "facebook")
801 assert_response :redirect
802 assert_redirected_to auth_failure_path(:strategy => "facebook", :message => "connection_failed", :origin => "/login?referer=%2Fhistory")
804 assert_response :redirect
806 assert_response :success
807 assert_template "sessions/new"
808 assert_select "div.alert.alert-danger", "Connection to authentication provider failed"
809 assert_select "span.username", false
812 def test_login_facebook_invalid_credentials
813 OmniAuth.config.mock_auth[:facebook] = :invalid_credentials
815 get "/login", :params => { :referer => "/history" }
816 assert_response :redirect
817 assert_redirected_to login_path("cookie_test" => "true", "referer" => "/history")
819 assert_response :success
820 assert_template "sessions/new"
821 post auth_path(:provider => "facebook", :origin => "/login?referer=%2Fhistory", :referer => "/history")
822 assert_response :redirect
823 assert_redirected_to auth_success_path(:provider => "facebook")
825 assert_response :redirect
826 assert_redirected_to auth_failure_path(:strategy => "facebook", :message => "invalid_credentials", :origin => "/login?referer=%2Fhistory")
828 assert_response :redirect
830 assert_response :success
831 assert_template "sessions/new"
832 assert_select "div.alert.alert-danger", "Invalid authentication credentials"
833 assert_select "span.username", false
836 def test_login_facebook_unknown
837 OmniAuth.config.add_mock(:facebook, :uid => "987654321")
839 get "/login", :params => { :referer => "/history" }
840 assert_response :redirect
841 assert_redirected_to login_path("cookie_test" => "true", "referer" => "/history")
843 assert_response :success
844 assert_template "sessions/new"
845 post auth_path(:provider => "facebook", :origin => "/login?referer=%2Fhistory", :referer => "/history")
846 assert_response :redirect
847 assert_redirected_to auth_success_path(:provider => "facebook")
849 assert_response :redirect
851 assert_response :success
852 assert_template "users/new"
853 assert_select "span.username", false
856 def test_login_microsoft_success
857 user = create(:user, :auth_provider => "microsoft", :auth_uid => "1234567890")
858 OmniAuth.config.add_mock(:microsoft, :uid => user.auth_uid)
860 get "/login", :params => { :referer => "/history" }
861 assert_response :redirect
862 assert_redirected_to login_path("cookie_test" => "true", "referer" => "/history")
864 assert_response :success
865 assert_template "sessions/new"
866 post auth_path(:provider => "microsoft", :origin => "/login?referer=%2Fhistory", :referer => "/history")
867 assert_response :redirect
868 assert_redirected_to auth_success_path(:provider => "microsoft")
870 assert_response :redirect
872 assert_response :success
873 assert_template "changesets/history"
874 assert_select "span.username", user.display_name
877 def test_login_microsoft_pending
878 user = create(:user, :pending, :auth_provider => "microsoft", :auth_uid => "1234567890")
879 OmniAuth.config.add_mock(:microsoft, :uid => user.auth_uid)
881 get "/login", :params => { :referer => "/history" }
882 assert_response :redirect
883 assert_redirected_to login_path("cookie_test" => "true", "referer" => "/history")
885 assert_response :success
886 assert_template "sessions/new"
887 post auth_path(:provider => "microsoft", :origin => "/login?referer=%2Fhistory", :referer => "/history")
888 assert_response :redirect
889 assert_redirected_to auth_success_path(:provider => "microsoft")
891 assert_response :redirect
893 assert_response :success
894 assert_template "confirm"
897 def test_login_microsoft_suspended
898 user = create(:user, :suspended, :auth_provider => "microsoft", :auth_uid => "1234567890")
899 OmniAuth.config.add_mock(:microsoft, :uid => user.auth_uid)
901 get "/login", :params => { :referer => "/history" }
902 assert_response :redirect
903 assert_redirected_to login_path("cookie_test" => "true", "referer" => "/history")
905 assert_response :success
906 assert_template "sessions/new"
907 post auth_path(:provider => "microsoft", :origin => "/login?referer=%2Fhistory", :referer => "/history")
908 assert_response :redirect
909 assert_redirected_to auth_success_path(:provider => "microsoft")
911 assert_response :redirect
913 assert_response :success
914 assert_template "sessions/new"
915 assert_select "span.username", false
916 assert_select "div.alert.alert-danger", /your account has been suspended/ do
917 assert_select "a[href='mailto:openstreetmap@example.com']", "support"
921 def test_login_microsoft_blocked
922 user = create(:user, :auth_provider => "microsoft", :auth_uid => "1234567890")
923 create(:user_block, :needs_view, :user => user)
924 OmniAuth.config.add_mock(:microsoft, :uid => user.auth_uid)
926 get "/login", :params => { :referer => "/history" }
927 assert_response :redirect
928 assert_redirected_to login_path("cookie_test" => "true", "referer" => "/history")
930 assert_response :success
931 assert_template "sessions/new"
932 post auth_path(:provider => "microsoft", :origin => "/login?referer=%2Fhistory", :referer => "/history")
933 assert_response :redirect
934 assert_redirected_to auth_success_path(:provider => "microsoft")
936 assert_response :redirect
938 assert_response :success
939 assert_template "user_blocks/show"
940 assert_select "span.username", user.display_name
943 def test_login_microsoft_connection_failed
944 OmniAuth.config.mock_auth[:microsoft] = :connection_failed
946 get "/login", :params => { :referer => "/history" }
947 assert_response :redirect
948 assert_redirected_to login_path("cookie_test" => "true", "referer" => "/history")
950 assert_response :success
951 assert_template "sessions/new"
952 post auth_path(:provider => "microsoft", :origin => "/login?referer=%2Fhistory", :referer => "/history")
953 assert_response :redirect
954 assert_redirected_to auth_success_path(:provider => "microsoft")
956 assert_response :redirect
957 assert_redirected_to auth_failure_path(:strategy => "microsoft", :message => "connection_failed", :origin => "/login?referer=%2Fhistory")
959 assert_response :redirect
961 assert_response :success
962 assert_template "sessions/new"
963 assert_select "div.alert.alert-danger", "Connection to authentication provider failed"
964 assert_select "span.username", false
967 def test_login_microsoft_invalid_credentials
968 OmniAuth.config.mock_auth[:microsoft] = :invalid_credentials
970 get "/login", :params => { :referer => "/history" }
971 assert_response :redirect
972 assert_redirected_to login_path("cookie_test" => "true", "referer" => "/history")
974 assert_response :success
975 assert_template "sessions/new"
976 post auth_path(:provider => "microsoft", :origin => "/login?referer=%2Fhistory", :referer => "/history")
977 assert_response :redirect
978 assert_redirected_to auth_success_path(:provider => "microsoft")
980 assert_response :redirect
981 assert_redirected_to auth_failure_path(:strategy => "microsoft", :message => "invalid_credentials", :origin => "/login?referer=%2Fhistory")
983 assert_response :redirect
985 assert_response :success
986 assert_template "sessions/new"
987 assert_select "div.alert.alert-danger", "Invalid authentication credentials"
988 assert_select "span.username", false
991 def test_login_microsoft_unknown
992 OmniAuth.config.add_mock(:microsoft, :uid => "987654321")
994 get "/login", :params => { :referer => "/history" }
995 assert_response :redirect
996 assert_redirected_to login_path("cookie_test" => "true", "referer" => "/history")
998 assert_response :success
999 assert_template "sessions/new"
1000 post auth_path(:provider => "microsoft", :origin => "/login?referer=%2Fhistory", :referer => "/history")
1001 assert_response :redirect
1002 assert_redirected_to auth_success_path(:provider => "microsoft")
1004 assert_response :redirect
1006 assert_response :success
1007 assert_template "users/new"
1008 assert_select "span.username", false
1011 def test_login_github_success
1012 user = create(:user, :auth_provider => "github", :auth_uid => "1234567890")
1013 OmniAuth.config.add_mock(:github, :uid => user.auth_uid)
1015 get "/login", :params => { :referer => "/history" }
1016 assert_response :redirect
1017 assert_redirected_to login_path("cookie_test" => "true", "referer" => "/history")
1019 assert_response :success
1020 assert_template "sessions/new"
1021 post auth_path(:provider => "github", :origin => "/login?referer=%2Fhistory", :referer => "/history")
1022 assert_response :redirect
1023 assert_redirected_to auth_success_path(:provider => "github")
1025 assert_response :redirect
1027 assert_response :success
1028 assert_template "changesets/history"
1029 assert_select "span.username", user.display_name
1032 def test_login_github_pending
1033 user = create(:user, :pending, :auth_provider => "github", :auth_uid => "1234567890")
1034 OmniAuth.config.add_mock(:github, :uid => user.auth_uid)
1036 get "/login", :params => { :referer => "/history" }
1037 assert_response :redirect
1038 assert_redirected_to login_path("cookie_test" => "true", "referer" => "/history")
1040 assert_response :success
1041 assert_template "sessions/new"
1042 post auth_path(:provider => "github", :origin => "/login?referer=%2Fhistory", :referer => "/history")
1043 assert_response :redirect
1044 assert_redirected_to auth_success_path(:provider => "github")
1046 assert_response :redirect
1048 assert_response :success
1049 assert_template "confirm"
1052 def test_login_github_suspended
1053 user = create(:user, :suspended, :auth_provider => "github", :auth_uid => "1234567890")
1054 OmniAuth.config.add_mock(:github, :uid => user.auth_uid)
1056 get "/login", :params => { :referer => "/history" }
1057 assert_response :redirect
1058 assert_redirected_to login_path("cookie_test" => "true", "referer" => "/history")
1060 assert_response :success
1061 assert_template "sessions/new"
1062 post auth_path(:provider => "github", :origin => "/login?referer=%2Fhistory", :referer => "/history")
1063 assert_response :redirect
1064 assert_redirected_to auth_success_path(:provider => "github")
1066 assert_response :redirect
1068 assert_response :success
1069 assert_template "sessions/new"
1070 assert_select "span.username", false
1071 assert_select "div.alert.alert-danger", /your account has been suspended/ do
1072 assert_select "a[href='mailto:openstreetmap@example.com']", "support"
1076 def test_login_github_blocked
1077 user = create(:user, :auth_provider => "github", :auth_uid => "1234567890")
1078 create(:user_block, :needs_view, :user => user)
1079 OmniAuth.config.add_mock(:github, :uid => user.auth_uid)
1081 get "/login", :params => { :referer => "/history" }
1082 assert_response :redirect
1083 assert_redirected_to login_path("cookie_test" => "true", "referer" => "/history")
1085 assert_response :success
1086 assert_template "sessions/new"
1087 post auth_path(:provider => "github", :origin => "/login?referer=%2Fhistory", :referer => "/history")
1088 assert_response :redirect
1089 assert_redirected_to auth_success_path(:provider => "github")
1091 assert_response :redirect
1093 assert_response :success
1094 assert_template "user_blocks/show"
1095 assert_select "span.username", user.display_name
1098 def test_login_github_connection_failed
1099 OmniAuth.config.mock_auth[:github] = :connection_failed
1101 get "/login", :params => { :referer => "/history" }
1102 assert_response :redirect
1103 assert_redirected_to login_path("cookie_test" => "true", "referer" => "/history")
1105 assert_response :success
1106 assert_template "sessions/new"
1107 post auth_path(:provider => "github", :origin => "/login?referer=%2Fhistory", :referer => "/history")
1108 assert_response :redirect
1109 assert_redirected_to auth_success_path(:provider => "github")
1111 assert_response :redirect
1112 assert_redirected_to auth_failure_path(:strategy => "github", :message => "connection_failed", :origin => "/login?referer=%2Fhistory")
1114 assert_response :redirect
1116 assert_response :success
1117 assert_template "sessions/new"
1118 assert_select "div.alert.alert-danger", "Connection to authentication provider failed"
1119 assert_select "span.username", false
1122 def test_login_github_invalid_credentials
1123 OmniAuth.config.mock_auth[:github] = :invalid_credentials
1125 get "/login", :params => { :referer => "/history" }
1126 assert_response :redirect
1127 assert_redirected_to login_path("cookie_test" => "true", "referer" => "/history")
1129 assert_response :success
1130 assert_template "sessions/new"
1131 post auth_path(:provider => "github", :origin => "/login?referer=%2Fhistory", :referer => "/history")
1132 assert_response :redirect
1133 assert_redirected_to auth_success_path(:provider => "github")
1135 assert_response :redirect
1136 assert_redirected_to auth_failure_path(:strategy => "github", :message => "invalid_credentials", :origin => "/login?referer=%2Fhistory")
1138 assert_response :redirect
1140 assert_response :success
1141 assert_template "sessions/new"
1142 assert_select "div.alert.alert-danger", "Invalid authentication credentials"
1143 assert_select "span.username", false
1146 def test_login_github_unknown
1147 OmniAuth.config.add_mock(:github, :uid => "987654321")
1149 get "/login", :params => { :referer => "/history" }
1150 assert_response :redirect
1151 assert_redirected_to login_path("cookie_test" => "true", "referer" => "/history")
1153 assert_response :success
1154 assert_template "sessions/new"
1155 post auth_path(:provider => "github", :origin => "/login?referer=%2Fhistory", :referer => "/history")
1156 assert_response :redirect
1157 assert_redirected_to auth_success_path(:provider => "github")
1159 assert_response :redirect
1161 assert_response :success
1162 assert_template "users/new"
1163 assert_select "span.username", false
1166 def test_login_wikipedia_success
1167 user = create(:user, :auth_provider => "wikipedia", :auth_uid => "1234567890")
1168 OmniAuth.config.add_mock(:wikipedia, :uid => user.auth_uid)
1170 get "/login", :params => { :referer => "/history" }
1171 assert_response :redirect
1172 assert_redirected_to login_path("cookie_test" => "true", "referer" => "/history")
1174 assert_response :success
1175 assert_template "sessions/new"
1176 post auth_path(:provider => "wikipedia", :origin => "/login?referer=%2Fhistory", :referer => "/history")
1177 assert_response :redirect
1178 assert_redirected_to auth_success_path(:provider => "wikipedia", :origin => "/login?referer=%2Fhistory", :referer => "/history")
1180 assert_response :redirect
1182 assert_response :success
1183 assert_template "changesets/history"
1184 assert_select "span.username", user.display_name
1187 def test_login_wikipedia_pending
1188 user = create(:user, :pending, :auth_provider => "wikipedia", :auth_uid => "1234567890")
1189 OmniAuth.config.add_mock(:wikipedia, :uid => user.auth_uid)
1191 get "/login", :params => { :referer => "/history" }
1192 assert_response :redirect
1193 assert_redirected_to login_path("cookie_test" => "true", "referer" => "/history")
1195 assert_response :success
1196 assert_template "sessions/new"
1197 post auth_path(:provider => "wikipedia", :origin => "/login?referer=%2Fhistory", :referer => "/history")
1198 assert_response :redirect
1199 assert_redirected_to auth_success_path(:provider => "wikipedia", :origin => "/login?referer=%2Fhistory", :referer => "/history")
1201 assert_response :redirect
1203 assert_response :success
1204 assert_template "confirm"
1207 def test_login_wikipedia_suspended
1208 user = create(:user, :suspended, :auth_provider => "wikipedia", :auth_uid => "1234567890")
1209 OmniAuth.config.add_mock(:wikipedia, :uid => user.auth_uid)
1211 get "/login", :params => { :referer => "/history" }
1212 assert_response :redirect
1213 assert_redirected_to login_path("cookie_test" => "true", "referer" => "/history")
1215 assert_response :success
1216 assert_template "sessions/new"
1217 post auth_path(:provider => "wikipedia", :origin => "/login?referer=%2Fhistory", :referer => "/history")
1218 assert_response :redirect
1219 assert_redirected_to auth_success_path(:provider => "wikipedia", :origin => "/login?referer=%2Fhistory", :referer => "/history")
1221 assert_response :redirect
1223 assert_response :success
1224 assert_template "sessions/new"
1225 assert_select "span.username", false
1226 assert_select "div.alert.alert-danger", /your account has been suspended/ do
1227 assert_select "a[href='mailto:openstreetmap@example.com']", "support"
1231 def test_login_wikipedia_blocked
1232 user = create(:user, :auth_provider => "wikipedia", :auth_uid => "1234567890")
1233 create(:user_block, :needs_view, :user => user)
1234 OmniAuth.config.add_mock(:wikipedia, :uid => user.auth_uid)
1236 get "/login", :params => { :referer => "/history" }
1237 assert_response :redirect
1238 assert_redirected_to login_path("cookie_test" => "true", "referer" => "/history")
1240 assert_response :success
1241 assert_template "sessions/new"
1242 post auth_path(:provider => "wikipedia", :origin => "/login?referer=%2Fhistory", :referer => "/history")
1243 assert_response :redirect
1244 assert_redirected_to auth_success_path(:provider => "wikipedia", :origin => "/login?referer=%2Fhistory", :referer => "/history")
1246 assert_response :redirect
1248 assert_response :success
1249 assert_template "user_blocks/show"
1250 assert_select "span.username", user.display_name
1253 def test_login_wikipedia_connection_failed
1254 OmniAuth.config.mock_auth[:wikipedia] = :connection_failed
1256 get "/login", :params => { :referer => "/history" }
1257 assert_response :redirect
1258 assert_redirected_to login_path("cookie_test" => "true", "referer" => "/history")
1260 assert_response :success
1261 assert_template "sessions/new"
1262 post auth_path(:provider => "wikipedia", :origin => "/login?referer=%2Fhistory", :referer => "/history")
1263 assert_response :redirect
1264 assert_redirected_to auth_success_path(:provider => "wikipedia", :origin => "/login?referer=%2Fhistory", :referer => "/history")
1266 assert_response :redirect
1267 assert_redirected_to auth_failure_path(:strategy => "wikipedia", :message => "connection_failed", :origin => "/login?referer=%2Fhistory")
1269 assert_response :redirect
1271 assert_response :success
1272 assert_template "sessions/new"
1273 assert_select "div.alert.alert-danger", "Connection to authentication provider failed"
1274 assert_select "span.username", false
1277 def test_login_wikipedia_invalid_credentials
1278 OmniAuth.config.mock_auth[:wikipedia] = :invalid_credentials
1280 get "/login", :params => { :referer => "/history" }
1281 assert_response :redirect
1282 assert_redirected_to login_path("cookie_test" => "true", "referer" => "/history")
1284 assert_response :success
1285 assert_template "sessions/new"
1286 post auth_path(:provider => "wikipedia", :origin => "/login?referer=%2Fhistory", :referer => "/history")
1287 assert_response :redirect
1288 assert_redirected_to auth_success_path(:provider => "wikipedia", :origin => "/login?referer=%2Fhistory", :referer => "/history")
1290 assert_response :redirect
1291 assert_redirected_to auth_failure_path(:strategy => "wikipedia", :message => "invalid_credentials", :origin => "/login?referer=%2Fhistory")
1293 assert_response :redirect
1295 assert_response :success
1296 assert_template "sessions/new"
1297 assert_select "div.alert.alert-danger", "Invalid authentication credentials"
1298 assert_select "span.username", false
1301 def test_login_wikipedia_unknown
1302 OmniAuth.config.add_mock(:wikipedia, :uid => "987654321")
1304 get "/login", :params => { :referer => "/history" }
1305 assert_response :redirect
1306 assert_redirected_to login_path("cookie_test" => "true", "referer" => "/history")
1308 assert_response :success
1309 assert_template "sessions/new"
1310 post auth_path(:provider => "wikipedia", :origin => "/login?referer=%2Fhistory", :referer => "/history")
1311 assert_response :redirect
1312 assert_redirected_to auth_success_path(:provider => "wikipedia", :origin => "/login?referer=%2Fhistory", :referer => "/history")
1314 assert_response :redirect
1316 assert_response :success
1317 assert_template "users/new"
1318 assert_select "span.username", false
1323 def try_password_login(username, password, remember_me = nil)
1325 assert_response :redirect
1326 assert_redirected_to login_path(:cookie_test => true)
1328 assert_response :success
1329 assert_template "sessions/new"
1330 assert_select "input#username", 1 do
1331 assert_select "[value]", false
1333 assert_select "input#password", 1 do
1334 assert_select "[value=?]", ""
1336 assert_select "input#remember_me", 1 do
1337 assert_select "[checked]", false
1340 post "/login", :params => { :username => username, :password => "wrong", :remember_me => remember_me, :referer => "/history" }
1341 assert_response :redirect
1343 assert_response :success
1344 assert_template "sessions/new"
1345 assert_select "input#username", 1 do
1346 assert_select "[value=?]", username
1348 assert_select "input#password", 1 do
1349 assert_select "[value=?]", ""
1351 assert_select "input#remember_me", 1 do
1352 assert_select "[checked]", remember_me == "yes"
1355 post "/login", :params => { :username => username, :password => password, :remember_me => remember_me, :referer => "/history" }
1356 assert_response :redirect
1358 assert_response :success