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_redirected_to login_path(:cookie_test => true, :referer => "/history")
359 assert_response :success
360 assert_template "sessions/new"
361 post auth_path(:provider => "openid", :openid_url => "http://localhost:1123/john.doe", :origin => "/login?referer=%2Fhistory", :referer => "/history")
362 assert_redirected_to auth_success_path(:provider => "openid", :openid_url => "http://localhost:1123/john.doe", :origin => "/login?referer=%2Fhistory", :referer => "/history")
364 assert_response :redirect
366 assert_response :success
367 assert_template "changesets/history"
368 assert_select "span.username", user.display_name
371 def test_login_openid_pending
372 user = create(:user, :pending, :auth_provider => "openid", :auth_uid => "http://example.com/john.doe")
373 OmniAuth.config.add_mock(:openid, :uid => user.auth_uid)
375 get "/login", :params => { :referer => "/history" }
376 assert_redirected_to login_path(:cookie_test => true, :referer => "/history")
378 assert_response :success
379 assert_template "sessions/new"
380 post auth_path(:provider => "openid", :openid_url => "http://localhost:1123/john.doe", :origin => "/login?referer=%2Fhistory", :referer => "/history")
381 assert_redirected_to auth_success_path(:provider => "openid", :openid_url => "http://localhost:1123/john.doe", :origin => "/login?referer=%2Fhistory", :referer => "/history")
383 assert_response :redirect
385 assert_response :success
386 assert_template "confirm"
389 def test_login_openid_suspended
390 user = create(:user, :suspended, :auth_provider => "openid", :auth_uid => "http://example.com/john.doe")
391 OmniAuth.config.add_mock(:openid, :uid => user.auth_uid)
393 get "/login", :params => { :referer => "/history" }
394 assert_redirected_to login_path(:cookie_test => true, :referer => "/history")
396 assert_response :success
397 assert_template "sessions/new"
398 post auth_path(:provider => "openid", :openid_url => "http://localhost:1123/john.doe", :origin => "/login?referer=%2Fhistory", :referer => "/history")
399 assert_redirected_to auth_success_path(:provider => "openid", :openid_url => "http://localhost:1123/john.doe", :origin => "/login?referer=%2Fhistory", :referer => "/history")
401 assert_response :redirect
403 assert_response :success
404 assert_template "sessions/new"
405 assert_select "span.username", false
406 assert_select "div.alert.alert-danger", /your account has been suspended/ do
407 assert_select "a[href='mailto:openstreetmap@example.com']", "support"
411 def test_login_openid_blocked
412 user = create(:user, :auth_provider => "openid", :auth_uid => "http://example.com/john.doe")
413 create(:user_block, :needs_view, :user => user)
414 OmniAuth.config.add_mock(:openid, :uid => user.auth_uid)
416 get "/login", :params => { :referer => "/history" }
417 assert_redirected_to login_path(:cookie_test => true, :referer => "/history")
419 assert_response :success
420 assert_template "sessions/new"
421 post auth_path(:provider => "openid", :openid_url => "http://localhost:1123/john.doe", :origin => "/login?referer=%2Fhistory", :referer => "/history")
422 assert_redirected_to auth_success_path(:provider => "openid", :openid_url => "http://localhost:1123/john.doe", :origin => "/login?referer=%2Fhistory", :referer => "/history")
424 assert_response :redirect
426 assert_response :success
427 assert_template "user_blocks/show"
428 assert_select "span.username", user.display_name
431 def test_login_openid_connection_failed
432 user = create(:user, :auth_provider => "openid", :auth_uid => "http://example.com/john.doe")
433 OmniAuth.config.mock_auth[:openid] = :connection_failed
435 get "/login", :params => { :referer => "/history" }
436 assert_redirected_to login_path(:cookie_test => true, :referer => "/history")
438 assert_response :success
439 assert_template "sessions/new"
440 post auth_path(:provider => "openid", :openid_url => user.auth_uid, :origin => "/login?referer=%2Fhistory", :referer => "/history")
441 assert_redirected_to auth_success_path(:provider => "openid", :openid_url => user.auth_uid, :origin => "/login?referer=%2Fhistory", :referer => "/history")
443 assert_redirected_to auth_failure_path(:strategy => "openid", :message => "connection_failed", :origin => "/login?referer=%2Fhistory")
445 assert_response :redirect
447 assert_response :success
448 assert_template "sessions/new"
449 assert_select "div.alert.alert-danger", "Connection to authentication provider failed"
450 assert_select "span.username", false
453 def test_login_openid_invalid_credentials
454 user = create(:user, :auth_provider => "openid", :auth_uid => "http://example.com/john.doe")
455 OmniAuth.config.mock_auth[:openid] = :invalid_credentials
457 get "/login", :params => { :referer => "/history" }
458 assert_redirected_to login_path(:cookie_test => true, :referer => "/history")
460 assert_response :success
461 assert_template "sessions/new"
462 post auth_path(:provider => "openid", :openid_url => user.auth_uid, :origin => "/login?referer=%2Fhistory", :referer => "/history")
463 assert_redirected_to auth_success_path(:provider => "openid", :openid_url => user.auth_uid, :origin => "/login?referer=%2Fhistory", :referer => "/history")
465 assert_redirected_to auth_failure_path(:strategy => "openid", :message => "invalid_credentials", :origin => "/login?referer=%2Fhistory")
467 assert_response :redirect
469 assert_response :success
470 assert_template "sessions/new"
471 assert_select "div.alert.alert-danger", "Invalid authentication credentials"
472 assert_select "span.username", false
475 def test_login_openid_unknown
476 OmniAuth.config.add_mock(:openid, :uid => "http://localhost:1123/fred.bloggs")
478 get "/login", :params => { :referer => "/history" }
479 assert_redirected_to login_path(:cookie_test => true, :referer => "/history")
481 assert_response :success
482 assert_template "sessions/new"
483 post auth_path(:provider => "openid", :openid_url => "http://localhost:1123/fred.bloggs", :origin => "/login?referer=%2Fhistory", :referer => "/history")
484 assert_redirected_to auth_success_path(:provider => "openid", :openid_url => "http://localhost:1123/fred.bloggs", :origin => "/login?referer=%2Fhistory", :referer => "/history")
486 assert_response :redirect
488 assert_response :success
489 assert_template "users/new"
490 assert_select "span.username", false
493 def test_login_google_success
494 user = create(:user, :auth_provider => "google", :auth_uid => "1234567890")
495 OmniAuth.config.add_mock(:google, :uid => user.auth_uid, :extra => {
496 :id_info => { "openid_id" => "http://localhost:1123/fred.bloggs" }
499 get "/login", :params => { :referer => "/history" }
500 assert_redirected_to login_path("cookie_test" => "true", "referer" => "/history")
502 assert_response :success
503 assert_template "sessions/new"
504 post auth_path(:provider => "google", :origin => "/login?referer=%2Fhistory", :referer => "/history")
505 assert_redirected_to auth_success_path(:provider => "google")
507 assert_response :redirect
509 assert_response :success
510 assert_template "changesets/history"
511 assert_select "span.username", user.display_name
514 def test_login_google_pending
515 user = create(:user, :pending, :auth_provider => "google", :auth_uid => "1234567890")
516 OmniAuth.config.add_mock(:google, :uid => user.auth_uid, :extra => {
517 :id_info => { "openid_id" => "http://localhost:1123/fred.bloggs" }
520 get "/login", :params => { :referer => "/history" }
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_redirected_to auth_success_path(:provider => "google")
528 assert_response :redirect
530 assert_response :success
531 assert_template "confirm"
534 def test_login_google_suspended
535 user = create(:user, :suspended, :auth_provider => "google", :auth_uid => "1234567890")
536 OmniAuth.config.add_mock(:google, :uid => user.auth_uid, :extra => {
537 :id_info => { "openid_id" => "http://localhost:1123/fred.bloggs" }
540 get "/login", :params => { :referer => "/history" }
541 assert_redirected_to login_path("cookie_test" => "true", "referer" => "/history")
543 assert_response :success
544 assert_template "sessions/new"
545 post auth_path(:provider => "google", :origin => "/login?referer=%2Fhistory", :referer => "/history")
546 assert_redirected_to auth_success_path(:provider => "google")
548 assert_response :redirect
550 assert_response :success
551 assert_template "sessions/new"
552 assert_select "span.username", false
553 assert_select "div.alert.alert-danger", /your account has been suspended/ do
554 assert_select "a[href='mailto:openstreetmap@example.com']", "support"
558 def test_login_google_blocked
559 user = create(:user, :auth_provider => "google", :auth_uid => "1234567890")
560 create(:user_block, :needs_view, :user => user)
561 OmniAuth.config.add_mock(:google, :uid => user.auth_uid, :extra => {
562 :id_info => { "openid_id" => "http://localhost:1123/fred.bloggs" }
565 get "/login", :params => { :referer => "/history" }
566 assert_redirected_to login_path("cookie_test" => "true", "referer" => "/history")
568 assert_response :success
569 assert_template "sessions/new"
570 post auth_path(:provider => "google", :origin => "/login?referer=%2Fhistory", :referer => "/history")
571 assert_redirected_to auth_success_path(:provider => "google")
573 assert_response :redirect
575 assert_response :success
576 assert_template "user_blocks/show"
577 assert_select "span.username", user.display_name
580 def test_login_google_connection_failed
581 OmniAuth.config.mock_auth[:google] = :connection_failed
583 get "/login", :params => { :referer => "/history" }
584 assert_redirected_to login_path("cookie_test" => "true", "referer" => "/history")
586 assert_response :success
587 assert_template "sessions/new"
588 post auth_path(:provider => "google", :origin => "/login?referer=%2Fhistory", :referer => "/history")
589 assert_redirected_to auth_success_path(:provider => "google")
591 assert_redirected_to auth_failure_path(:strategy => "google", :message => "connection_failed", :origin => "/login?referer=%2Fhistory")
593 assert_response :redirect
595 assert_response :success
596 assert_template "sessions/new"
597 assert_select "div.alert.alert-danger", "Connection to authentication provider failed"
598 assert_select "span.username", false
601 def test_login_google_invalid_credentials
602 OmniAuth.config.mock_auth[:google] = :invalid_credentials
604 get "/login", :params => { :referer => "/history" }
605 assert_redirected_to login_path("cookie_test" => "true", "referer" => "/history")
607 assert_response :success
608 assert_template "sessions/new"
609 post auth_path(:provider => "google", :origin => "/login?referer=%2Fhistory", :referer => "/history")
610 assert_redirected_to auth_success_path(:provider => "google")
612 assert_redirected_to auth_failure_path(:strategy => "google", :message => "invalid_credentials", :origin => "/login?referer=%2Fhistory")
614 assert_response :redirect
616 assert_response :success
617 assert_template "sessions/new"
618 assert_select "div.alert.alert-danger", "Invalid authentication credentials"
619 assert_select "span.username", false
622 def test_login_google_unknown
623 OmniAuth.config.add_mock(:google, :uid => "987654321", :extra => {
624 :id_info => { "openid_id" => "http://localhost:1123/fred.bloggs" }
627 get "/login", :params => { :referer => "/history" }
628 assert_redirected_to login_path("cookie_test" => "true", "referer" => "/history")
630 assert_response :success
631 assert_template "sessions/new"
632 post auth_path(:provider => "google", :origin => "/login?referer=%2Fhistory", :referer => "/history")
633 assert_redirected_to auth_success_path(:provider => "google")
635 assert_response :redirect
637 assert_response :success
638 assert_template "users/new"
639 assert_select "span.username", false
642 def test_login_google_upgrade
643 user = create(:user, :auth_provider => "openid", :auth_uid => "http://example.com/john.doe")
644 OmniAuth.config.add_mock(:google, :uid => "987654321", :extra => {
645 :id_info => { "openid_id" => user.auth_uid }
648 get "/login", :params => { :referer => "/history" }
649 assert_redirected_to login_path("cookie_test" => "true", "referer" => "/history")
651 assert_response :success
652 assert_template "sessions/new"
653 post auth_path(:provider => "google", :origin => "/login?referer=%2Fhistory", :referer => "/history")
654 assert_redirected_to auth_success_path(:provider => "google")
656 assert_response :redirect
658 assert_response :success
659 assert_template "changesets/history"
660 assert_select "span.username", user.display_name
662 u = User.find_by(:display_name => user.display_name)
663 assert_equal "google", u.auth_provider
664 assert_equal "987654321", u.auth_uid
667 def test_login_facebook_success
668 user = create(:user, :auth_provider => "facebook", :auth_uid => "1234567890")
669 OmniAuth.config.add_mock(:facebook, :uid => user.auth_uid)
671 get "/login", :params => { :referer => "/history" }
672 assert_redirected_to login_path("cookie_test" => "true", "referer" => "/history")
674 assert_response :success
675 assert_template "sessions/new"
676 post auth_path(:provider => "facebook", :origin => "/login?referer=%2Fhistory", :referer => "/history")
677 assert_redirected_to auth_success_path(:provider => "facebook")
679 assert_response :redirect
681 assert_response :success
682 assert_template "changesets/history"
683 assert_select "span.username", user.display_name
686 def test_login_facebook_pending
687 user = create(:user, :pending, :auth_provider => "facebook", :auth_uid => "1234567890")
688 OmniAuth.config.add_mock(:facebook, :uid => user.auth_uid)
690 get "/login", :params => { :referer => "/history" }
691 assert_redirected_to login_path("cookie_test" => "true", "referer" => "/history")
693 assert_response :success
694 assert_template "sessions/new"
695 post auth_path(:provider => "facebook", :origin => "/login?referer=%2Fhistory", :referer => "/history")
696 assert_redirected_to auth_success_path(:provider => "facebook")
698 assert_response :redirect
700 assert_response :success
701 assert_template "confirm"
704 def test_login_facebook_suspended
705 user = create(:user, :suspended, :auth_provider => "facebook", :auth_uid => "1234567890")
706 OmniAuth.config.add_mock(:facebook, :uid => user.auth_uid)
708 get "/login", :params => { :referer => "/history" }
709 assert_redirected_to login_path("cookie_test" => "true", "referer" => "/history")
711 assert_response :success
712 assert_template "sessions/new"
713 post auth_path(:provider => "facebook", :origin => "/login?referer=%2Fhistory", :referer => "/history")
714 assert_redirected_to auth_success_path(:provider => "facebook")
716 assert_response :redirect
718 assert_response :success
719 assert_template "sessions/new"
720 assert_select "span.username", false
721 assert_select "div.alert.alert-danger", /your account has been suspended/ do
722 assert_select "a[href='mailto:openstreetmap@example.com']", "support"
726 def test_login_facebook_blocked
727 user = create(:user, :auth_provider => "facebook", :auth_uid => "1234567890")
728 create(:user_block, :needs_view, :user => user)
729 OmniAuth.config.add_mock(:facebook, :uid => user.auth_uid)
731 get "/login", :params => { :referer => "/history" }
732 assert_redirected_to login_path("cookie_test" => "true", "referer" => "/history")
734 assert_response :success
735 assert_template "sessions/new"
736 post auth_path(:provider => "facebook", :origin => "/login?referer=%2Fhistory", :referer => "/history")
737 assert_redirected_to auth_success_path(:provider => "facebook")
739 assert_response :redirect
741 assert_response :success
742 assert_template "user_blocks/show"
743 assert_select "span.username", user.display_name
746 def test_login_facebook_connection_failed
747 OmniAuth.config.mock_auth[:facebook] = :connection_failed
749 get "/login", :params => { :referer => "/history" }
750 assert_redirected_to login_path("cookie_test" => "true", "referer" => "/history")
752 assert_response :success
753 assert_template "sessions/new"
754 post auth_path(:provider => "facebook", :origin => "/login?referer=%2Fhistory", :referer => "/history")
755 assert_redirected_to auth_success_path(:provider => "facebook")
757 assert_redirected_to auth_failure_path(:strategy => "facebook", :message => "connection_failed", :origin => "/login?referer=%2Fhistory")
759 assert_response :redirect
761 assert_response :success
762 assert_template "sessions/new"
763 assert_select "div.alert.alert-danger", "Connection to authentication provider failed"
764 assert_select "span.username", false
767 def test_login_facebook_invalid_credentials
768 OmniAuth.config.mock_auth[:facebook] = :invalid_credentials
770 get "/login", :params => { :referer => "/history" }
771 assert_redirected_to login_path("cookie_test" => "true", "referer" => "/history")
773 assert_response :success
774 assert_template "sessions/new"
775 post auth_path(:provider => "facebook", :origin => "/login?referer=%2Fhistory", :referer => "/history")
776 assert_redirected_to auth_success_path(:provider => "facebook")
778 assert_redirected_to auth_failure_path(:strategy => "facebook", :message => "invalid_credentials", :origin => "/login?referer=%2Fhistory")
780 assert_response :redirect
782 assert_response :success
783 assert_template "sessions/new"
784 assert_select "div.alert.alert-danger", "Invalid authentication credentials"
785 assert_select "span.username", false
788 def test_login_facebook_unknown
789 OmniAuth.config.add_mock(:facebook, :uid => "987654321")
791 get "/login", :params => { :referer => "/history" }
792 assert_redirected_to login_path("cookie_test" => "true", "referer" => "/history")
794 assert_response :success
795 assert_template "sessions/new"
796 post auth_path(:provider => "facebook", :origin => "/login?referer=%2Fhistory", :referer => "/history")
797 assert_redirected_to auth_success_path(:provider => "facebook")
799 assert_response :redirect
801 assert_response :success
802 assert_template "users/new"
803 assert_select "span.username", false
806 def test_login_microsoft_success
807 user = create(:user, :auth_provider => "microsoft", :auth_uid => "1234567890")
808 OmniAuth.config.add_mock(:microsoft, :uid => user.auth_uid)
810 get "/login", :params => { :referer => "/history" }
811 assert_redirected_to login_path("cookie_test" => "true", "referer" => "/history")
813 assert_response :success
814 assert_template "sessions/new"
815 post auth_path(:provider => "microsoft", :origin => "/login?referer=%2Fhistory", :referer => "/history")
816 assert_redirected_to auth_success_path(:provider => "microsoft")
818 assert_response :redirect
820 assert_response :success
821 assert_template "changesets/history"
822 assert_select "span.username", user.display_name
825 def test_login_microsoft_pending
826 user = create(:user, :pending, :auth_provider => "microsoft", :auth_uid => "1234567890")
827 OmniAuth.config.add_mock(:microsoft, :uid => user.auth_uid)
829 get "/login", :params => { :referer => "/history" }
830 assert_redirected_to login_path("cookie_test" => "true", "referer" => "/history")
832 assert_response :success
833 assert_template "sessions/new"
834 post auth_path(:provider => "microsoft", :origin => "/login?referer=%2Fhistory", :referer => "/history")
835 assert_redirected_to auth_success_path(:provider => "microsoft")
837 assert_response :redirect
839 assert_response :success
840 assert_template "confirm"
843 def test_login_microsoft_suspended
844 user = create(:user, :suspended, :auth_provider => "microsoft", :auth_uid => "1234567890")
845 OmniAuth.config.add_mock(:microsoft, :uid => user.auth_uid)
847 get "/login", :params => { :referer => "/history" }
848 assert_redirected_to login_path("cookie_test" => "true", "referer" => "/history")
850 assert_response :success
851 assert_template "sessions/new"
852 post auth_path(:provider => "microsoft", :origin => "/login?referer=%2Fhistory", :referer => "/history")
853 assert_redirected_to auth_success_path(:provider => "microsoft")
855 assert_response :redirect
857 assert_response :success
858 assert_template "sessions/new"
859 assert_select "span.username", false
860 assert_select "div.alert.alert-danger", /your account has been suspended/ do
861 assert_select "a[href='mailto:openstreetmap@example.com']", "support"
865 def test_login_microsoft_blocked
866 user = create(:user, :auth_provider => "microsoft", :auth_uid => "1234567890")
867 create(:user_block, :needs_view, :user => user)
868 OmniAuth.config.add_mock(:microsoft, :uid => user.auth_uid)
870 get "/login", :params => { :referer => "/history" }
871 assert_redirected_to login_path("cookie_test" => "true", "referer" => "/history")
873 assert_response :success
874 assert_template "sessions/new"
875 post auth_path(:provider => "microsoft", :origin => "/login?referer=%2Fhistory", :referer => "/history")
876 assert_redirected_to auth_success_path(:provider => "microsoft")
878 assert_response :redirect
880 assert_response :success
881 assert_template "user_blocks/show"
882 assert_select "span.username", user.display_name
885 def test_login_microsoft_connection_failed
886 OmniAuth.config.mock_auth[:microsoft] = :connection_failed
888 get "/login", :params => { :referer => "/history" }
889 assert_redirected_to login_path("cookie_test" => "true", "referer" => "/history")
891 assert_response :success
892 assert_template "sessions/new"
893 post auth_path(:provider => "microsoft", :origin => "/login?referer=%2Fhistory", :referer => "/history")
894 assert_redirected_to auth_success_path(:provider => "microsoft")
896 assert_redirected_to auth_failure_path(:strategy => "microsoft", :message => "connection_failed", :origin => "/login?referer=%2Fhistory")
898 assert_response :redirect
900 assert_response :success
901 assert_template "sessions/new"
902 assert_select "div.alert.alert-danger", "Connection to authentication provider failed"
903 assert_select "span.username", false
906 def test_login_microsoft_invalid_credentials
907 OmniAuth.config.mock_auth[:microsoft] = :invalid_credentials
909 get "/login", :params => { :referer => "/history" }
910 assert_redirected_to login_path("cookie_test" => "true", "referer" => "/history")
912 assert_response :success
913 assert_template "sessions/new"
914 post auth_path(:provider => "microsoft", :origin => "/login?referer=%2Fhistory", :referer => "/history")
915 assert_redirected_to auth_success_path(:provider => "microsoft")
917 assert_redirected_to auth_failure_path(:strategy => "microsoft", :message => "invalid_credentials", :origin => "/login?referer=%2Fhistory")
919 assert_response :redirect
921 assert_response :success
922 assert_template "sessions/new"
923 assert_select "div.alert.alert-danger", "Invalid authentication credentials"
924 assert_select "span.username", false
927 def test_login_microsoft_unknown
928 OmniAuth.config.add_mock(:microsoft, :uid => "987654321")
930 get "/login", :params => { :referer => "/history" }
931 assert_redirected_to login_path("cookie_test" => "true", "referer" => "/history")
933 assert_response :success
934 assert_template "sessions/new"
935 post auth_path(:provider => "microsoft", :origin => "/login?referer=%2Fhistory", :referer => "/history")
936 assert_redirected_to auth_success_path(:provider => "microsoft")
938 assert_response :redirect
940 assert_response :success
941 assert_template "users/new"
942 assert_select "span.username", false
945 def test_login_github_success
946 user = create(:user, :auth_provider => "github", :auth_uid => "1234567890")
947 OmniAuth.config.add_mock(:github, :uid => user.auth_uid)
949 get "/login", :params => { :referer => "/history" }
950 assert_redirected_to login_path("cookie_test" => "true", "referer" => "/history")
952 assert_response :success
953 assert_template "sessions/new"
954 post auth_path(:provider => "github", :origin => "/login?referer=%2Fhistory", :referer => "/history")
955 assert_redirected_to auth_success_path(:provider => "github")
957 assert_response :redirect
959 assert_response :success
960 assert_template "changesets/history"
961 assert_select "span.username", user.display_name
964 def test_login_github_pending
965 user = create(:user, :pending, :auth_provider => "github", :auth_uid => "1234567890")
966 OmniAuth.config.add_mock(:github, :uid => user.auth_uid)
968 get "/login", :params => { :referer => "/history" }
969 assert_redirected_to login_path("cookie_test" => "true", "referer" => "/history")
971 assert_response :success
972 assert_template "sessions/new"
973 post auth_path(:provider => "github", :origin => "/login?referer=%2Fhistory", :referer => "/history")
974 assert_redirected_to auth_success_path(:provider => "github")
976 assert_response :redirect
978 assert_response :success
979 assert_template "confirm"
982 def test_login_github_suspended
983 user = create(:user, :suspended, :auth_provider => "github", :auth_uid => "1234567890")
984 OmniAuth.config.add_mock(:github, :uid => user.auth_uid)
986 get "/login", :params => { :referer => "/history" }
987 assert_redirected_to login_path("cookie_test" => "true", "referer" => "/history")
989 assert_response :success
990 assert_template "sessions/new"
991 post auth_path(:provider => "github", :origin => "/login?referer=%2Fhistory", :referer => "/history")
992 assert_redirected_to auth_success_path(:provider => "github")
994 assert_response :redirect
996 assert_response :success
997 assert_template "sessions/new"
998 assert_select "span.username", false
999 assert_select "div.alert.alert-danger", /your account has been suspended/ do
1000 assert_select "a[href='mailto:openstreetmap@example.com']", "support"
1004 def test_login_github_blocked
1005 user = create(:user, :auth_provider => "github", :auth_uid => "1234567890")
1006 create(:user_block, :needs_view, :user => user)
1007 OmniAuth.config.add_mock(:github, :uid => user.auth_uid)
1009 get "/login", :params => { :referer => "/history" }
1010 assert_redirected_to login_path("cookie_test" => "true", "referer" => "/history")
1012 assert_response :success
1013 assert_template "sessions/new"
1014 post auth_path(:provider => "github", :origin => "/login?referer=%2Fhistory", :referer => "/history")
1015 assert_redirected_to auth_success_path(:provider => "github")
1017 assert_response :redirect
1019 assert_response :success
1020 assert_template "user_blocks/show"
1021 assert_select "span.username", user.display_name
1024 def test_login_github_connection_failed
1025 OmniAuth.config.mock_auth[:github] = :connection_failed
1027 get "/login", :params => { :referer => "/history" }
1028 assert_redirected_to login_path("cookie_test" => "true", "referer" => "/history")
1030 assert_response :success
1031 assert_template "sessions/new"
1032 post auth_path(:provider => "github", :origin => "/login?referer=%2Fhistory", :referer => "/history")
1033 assert_redirected_to auth_success_path(:provider => "github")
1035 assert_redirected_to auth_failure_path(:strategy => "github", :message => "connection_failed", :origin => "/login?referer=%2Fhistory")
1037 assert_response :redirect
1039 assert_response :success
1040 assert_template "sessions/new"
1041 assert_select "div.alert.alert-danger", "Connection to authentication provider failed"
1042 assert_select "span.username", false
1045 def test_login_github_invalid_credentials
1046 OmniAuth.config.mock_auth[:github] = :invalid_credentials
1048 get "/login", :params => { :referer => "/history" }
1049 assert_redirected_to login_path("cookie_test" => "true", "referer" => "/history")
1051 assert_response :success
1052 assert_template "sessions/new"
1053 post auth_path(:provider => "github", :origin => "/login?referer=%2Fhistory", :referer => "/history")
1054 assert_redirected_to auth_success_path(:provider => "github")
1056 assert_redirected_to auth_failure_path(:strategy => "github", :message => "invalid_credentials", :origin => "/login?referer=%2Fhistory")
1058 assert_response :redirect
1060 assert_response :success
1061 assert_template "sessions/new"
1062 assert_select "div.alert.alert-danger", "Invalid authentication credentials"
1063 assert_select "span.username", false
1066 def test_login_github_unknown
1067 OmniAuth.config.add_mock(:github, :uid => "987654321")
1069 get "/login", :params => { :referer => "/history" }
1070 assert_redirected_to login_path("cookie_test" => "true", "referer" => "/history")
1072 assert_response :success
1073 assert_template "sessions/new"
1074 post auth_path(:provider => "github", :origin => "/login?referer=%2Fhistory", :referer => "/history")
1075 assert_redirected_to auth_success_path(:provider => "github")
1077 assert_response :redirect
1079 assert_response :success
1080 assert_template "users/new"
1081 assert_select "span.username", false
1084 def test_login_wikipedia_success
1085 user = create(:user, :auth_provider => "wikipedia", :auth_uid => "1234567890")
1086 OmniAuth.config.add_mock(:wikipedia, :uid => user.auth_uid)
1088 get "/login", :params => { :referer => "/history" }
1089 assert_redirected_to login_path("cookie_test" => "true", "referer" => "/history")
1091 assert_response :success
1092 assert_template "sessions/new"
1093 post auth_path(:provider => "wikipedia", :origin => "/login?referer=%2Fhistory", :referer => "/history")
1094 assert_redirected_to auth_success_path(:provider => "wikipedia", :origin => "/login?referer=%2Fhistory", :referer => "/history")
1096 assert_response :redirect
1098 assert_response :success
1099 assert_template "changesets/history"
1100 assert_select "span.username", user.display_name
1103 def test_login_wikipedia_pending
1104 user = create(:user, :pending, :auth_provider => "wikipedia", :auth_uid => "1234567890")
1105 OmniAuth.config.add_mock(:wikipedia, :uid => user.auth_uid)
1107 get "/login", :params => { :referer => "/history" }
1108 assert_redirected_to login_path("cookie_test" => "true", "referer" => "/history")
1110 assert_response :success
1111 assert_template "sessions/new"
1112 post auth_path(:provider => "wikipedia", :origin => "/login?referer=%2Fhistory", :referer => "/history")
1113 assert_redirected_to auth_success_path(:provider => "wikipedia", :origin => "/login?referer=%2Fhistory", :referer => "/history")
1115 assert_response :redirect
1117 assert_response :success
1118 assert_template "confirm"
1121 def test_login_wikipedia_suspended
1122 user = create(:user, :suspended, :auth_provider => "wikipedia", :auth_uid => "1234567890")
1123 OmniAuth.config.add_mock(:wikipedia, :uid => user.auth_uid)
1125 get "/login", :params => { :referer => "/history" }
1126 assert_redirected_to login_path("cookie_test" => "true", "referer" => "/history")
1128 assert_response :success
1129 assert_template "sessions/new"
1130 post auth_path(:provider => "wikipedia", :origin => "/login?referer=%2Fhistory", :referer => "/history")
1131 assert_redirected_to auth_success_path(:provider => "wikipedia", :origin => "/login?referer=%2Fhistory", :referer => "/history")
1133 assert_response :redirect
1135 assert_response :success
1136 assert_template "sessions/new"
1137 assert_select "span.username", false
1138 assert_select "div.alert.alert-danger", /your account has been suspended/ do
1139 assert_select "a[href='mailto:openstreetmap@example.com']", "support"
1143 def test_login_wikipedia_blocked
1144 user = create(:user, :auth_provider => "wikipedia", :auth_uid => "1234567890")
1145 create(:user_block, :needs_view, :user => user)
1146 OmniAuth.config.add_mock(:wikipedia, :uid => user.auth_uid)
1148 get "/login", :params => { :referer => "/history" }
1149 assert_redirected_to login_path("cookie_test" => "true", "referer" => "/history")
1151 assert_response :success
1152 assert_template "sessions/new"
1153 post auth_path(:provider => "wikipedia", :origin => "/login?referer=%2Fhistory", :referer => "/history")
1154 assert_redirected_to auth_success_path(:provider => "wikipedia", :origin => "/login?referer=%2Fhistory", :referer => "/history")
1156 assert_response :redirect
1158 assert_response :success
1159 assert_template "user_blocks/show"
1160 assert_select "span.username", user.display_name
1163 def test_login_wikipedia_connection_failed
1164 OmniAuth.config.mock_auth[:wikipedia] = :connection_failed
1166 get "/login", :params => { :referer => "/history" }
1167 assert_redirected_to login_path("cookie_test" => "true", "referer" => "/history")
1169 assert_response :success
1170 assert_template "sessions/new"
1171 post auth_path(:provider => "wikipedia", :origin => "/login?referer=%2Fhistory", :referer => "/history")
1172 assert_redirected_to auth_success_path(:provider => "wikipedia", :origin => "/login?referer=%2Fhistory", :referer => "/history")
1174 assert_redirected_to auth_failure_path(:strategy => "wikipedia", :message => "connection_failed", :origin => "/login?referer=%2Fhistory")
1176 assert_response :redirect
1178 assert_response :success
1179 assert_template "sessions/new"
1180 assert_select "div.alert.alert-danger", "Connection to authentication provider failed"
1181 assert_select "span.username", false
1184 def test_login_wikipedia_invalid_credentials
1185 OmniAuth.config.mock_auth[:wikipedia] = :invalid_credentials
1187 get "/login", :params => { :referer => "/history" }
1188 assert_redirected_to login_path("cookie_test" => "true", "referer" => "/history")
1190 assert_response :success
1191 assert_template "sessions/new"
1192 post auth_path(:provider => "wikipedia", :origin => "/login?referer=%2Fhistory", :referer => "/history")
1193 assert_redirected_to auth_success_path(:provider => "wikipedia", :origin => "/login?referer=%2Fhistory", :referer => "/history")
1195 assert_redirected_to auth_failure_path(:strategy => "wikipedia", :message => "invalid_credentials", :origin => "/login?referer=%2Fhistory")
1197 assert_response :redirect
1199 assert_response :success
1200 assert_template "sessions/new"
1201 assert_select "div.alert.alert-danger", "Invalid authentication credentials"
1202 assert_select "span.username", false
1205 def test_login_wikipedia_unknown
1206 OmniAuth.config.add_mock(:wikipedia, :uid => "987654321")
1208 get "/login", :params => { :referer => "/history" }
1209 assert_redirected_to login_path("cookie_test" => "true", "referer" => "/history")
1211 assert_response :success
1212 assert_template "sessions/new"
1213 post auth_path(:provider => "wikipedia", :origin => "/login?referer=%2Fhistory", :referer => "/history")
1214 assert_redirected_to auth_success_path(:provider => "wikipedia", :origin => "/login?referer=%2Fhistory", :referer => "/history")
1216 assert_response :redirect
1218 assert_response :success
1219 assert_template "users/new"
1220 assert_select "span.username", false
1225 def try_password_login(username, password, remember_me = nil)
1227 assert_redirected_to login_path(:cookie_test => true)
1229 assert_response :success
1230 assert_template "sessions/new"
1231 assert_select "input#username", 1 do
1232 assert_select "[value]", false
1234 assert_select "input#password", 1 do
1235 assert_select "[value=?]", ""
1237 assert_select "input#remember_me", 1 do
1238 assert_select "[checked]", false
1241 post "/login", :params => { :username => username, :password => "wrong", :remember_me => remember_me, :referer => "/history" }
1242 assert_response :redirect
1244 assert_response :success
1245 assert_template "sessions/new"
1246 assert_select "input#username", 1 do
1247 assert_select "[value=?]", username
1249 assert_select "input#password", 1 do
1250 assert_select "[value=?]", ""
1252 assert_select "input#remember_me", 1 do
1253 assert_select "[checked]", remember_me == "yes"
1256 post "/login", :params => { :username => username, :password => password, :remember_me => remember_me, :referer => "/history" }
1257 assert_response :redirect
1259 assert_response :success