3 class UserLoginTest < ActionDispatch::IntegrationTest
4 fixtures :users, :user_roles
7 OmniAuth.config.test_mode = true
11 OmniAuth.config.mock_auth[:openid] = nil
12 OmniAuth.config.mock_auth[:google] = nil
13 OmniAuth.config.mock_auth[:facebook] = nil
14 OmniAuth.config.mock_auth[:windowslive] = nil
15 OmniAuth.config.mock_auth[:github] = nil
16 OmniAuth.config.mock_auth[:wikipedia] = nil
17 OmniAuth.config.test_mode = false
20 def test_login_email_password_normal
21 user = users(:normal_user)
23 try_password_login user.email, "test"
25 assert_template "changeset/history"
26 assert_select "span.username", "test"
29 def test_login_email_password_normal_upcase
30 user = users(:normal_user)
32 try_password_login user.email.upcase, "test"
34 assert_template "changeset/history"
35 assert_select "span.username", "TEST"
38 def test_login_email_password_normal_titlecase
39 user = users(:normal_user)
41 try_password_login user.email.titlecase, "test"
43 assert_template "login"
44 assert_select "span.username", false
47 def test_login_email_password_public
48 user = users(:public_user)
50 try_password_login user.email, "test"
52 assert_template "changeset/history"
53 assert_select "span.username", "test2"
56 def test_login_email_password_public_upcase
57 user = users(:public_user)
59 try_password_login user.email.upcase, "test"
61 assert_template "changeset/history"
62 assert_select "span.username", "test2"
65 def test_login_email_password_public_titlecase
66 user = users(:public_user)
68 try_password_login user.email.titlecase, "test"
70 assert_template "changeset/history"
71 assert_select "span.username", "test2"
74 def test_login_email_password_inactive
75 user = users(:inactive_user)
77 try_password_login user.email, "test2"
79 assert_template "confirm"
80 assert_select "span.username", false
83 def test_login_email_password_inactive_upcase
84 user = users(:inactive_user)
86 try_password_login user.email.upcase, "test2"
88 assert_template "confirm"
89 assert_select "span.username", false
92 def test_login_email_password_inactive_titlecase
93 user = users(:inactive_user)
95 try_password_login user.email.titlecase, "test2"
97 assert_template "confirm"
98 assert_select "span.username", false
101 def test_login_email_password_suspended
102 user = users(:suspended_user)
104 try_password_login user.email, "test"
106 assert_template "login"
107 assert_select "span.username", false
108 assert_select "div.flash.error", /your account has been suspended/
111 def test_login_email_password_suspended_upcase
112 user = users(:suspended_user)
114 try_password_login user.email.upcase, "test"
116 assert_template "login"
117 assert_select "span.username", false
118 assert_select "div.flash.error", /your account has been suspended/
121 def test_login_email_password_suspended_titlecase
122 user = users(:suspended_user)
124 try_password_login user.email.titlecase, "test"
126 assert_template "login"
127 assert_select "span.username", false
128 assert_select "div.flash.error", /your account has been suspended/
131 def test_login_email_password_blocked
132 user = users(:blocked_user)
133 create(:user_block, :needs_view, :user => user)
135 try_password_login user.email, "test"
137 assert_template "user_blocks/show"
138 assert_select "span.username", "blocked"
141 def test_login_email_password_blocked_upcase
142 user = users(:blocked_user)
143 create(:user_block, :needs_view, :user => user)
145 try_password_login user.email.upcase, "test"
147 assert_template "user_blocks/show"
148 assert_select "span.username", "blocked"
151 def test_login_email_password_blocked_titlecase
152 user = users(:blocked_user)
153 create(:user_block, :needs_view, :user => user)
155 try_password_login user.email.titlecase, "test"
157 assert_template "user_blocks/show"
158 assert_select "span.username", "blocked"
161 def test_login_username_password_normal
162 user = users(:normal_user)
164 try_password_login user.display_name, "test"
166 assert_template "changeset/history"
167 assert_select "span.username", "test"
170 def test_login_username_password_normal_upcase
171 user = users(:normal_user)
173 try_password_login user.display_name.upcase, "test"
175 assert_template "changeset/history"
176 assert_select "span.username", "TEST"
179 def test_login_username_password_normal_titlecase
180 user = users(:normal_user)
182 try_password_login user.display_name.titlecase, "test"
184 assert_template "login"
185 assert_select "span.username", false
188 def test_login_username_password_public
189 user = users(:public_user)
191 try_password_login user.display_name, "test"
193 assert_template "changeset/history"
194 assert_select "span.username", "test2"
197 def test_login_username_password_public_upcase
198 user = users(:public_user)
200 try_password_login user.display_name.upcase, "test"
202 assert_template "changeset/history"
203 assert_select "span.username", "test2"
206 def test_login_username_password_public_titlecase
207 user = users(:public_user)
209 try_password_login user.display_name.titlecase, "test"
211 assert_template "changeset/history"
212 assert_select "span.username", "test2"
215 def test_login_username_password_inactive
216 user = users(:inactive_user)
218 try_password_login user.display_name, "test2"
220 assert_template "confirm"
221 assert_select "span.username", false
224 def test_login_username_password_inactive_upcase
225 user = users(:inactive_user)
227 try_password_login user.display_name.upcase, "test2"
229 assert_template "confirm"
230 assert_select "span.username", false
233 def test_login_username_password_inactive_titlecase
234 user = users(:inactive_user)
236 try_password_login user.display_name.titlecase, "test2"
238 assert_template "confirm"
239 assert_select "span.username", false
242 def test_login_username_password_suspended
243 user = users(:suspended_user)
245 try_password_login user.display_name, "test"
247 assert_template "login"
248 assert_select "span.username", false
249 assert_select "div.flash.error", /your account has been suspended/
252 def test_login_username_password_suspended_upcase
253 user = users(:suspended_user)
255 try_password_login user.display_name.upcase, "test"
257 assert_template "login"
258 assert_select "span.username", false
259 assert_select "div.flash.error", /your account has been suspended/
262 def test_login_username_password_suspended_titlecase
263 user = users(:suspended_user)
265 try_password_login user.display_name.titlecase, "test"
267 assert_template "login"
268 assert_select "span.username", false
269 assert_select "div.flash.error", /your account has been suspended/
272 def test_login_username_password_blocked
273 user = users(:blocked_user)
274 create(:user_block, :needs_view, :user => user)
276 try_password_login user.display_name.upcase, "test"
278 assert_template "user_blocks/show"
279 assert_select "span.username", "blocked"
282 def test_login_username_password_blocked_upcase
283 user = users(:blocked_user)
284 create(:user_block, :needs_view, :user => user)
286 try_password_login user.display_name, "test"
288 assert_template "user_blocks/show"
289 assert_select "span.username", "blocked"
292 def test_login_username_password_blocked_titlecase
293 user = users(:blocked_user)
294 create(:user_block, :needs_view, :user => user)
296 try_password_login user.display_name.titlecase, "test"
298 assert_template "user_blocks/show"
299 assert_select "span.username", "blocked"
302 def test_login_email_password_remember_me
303 user = users(:normal_user)
305 try_password_login user.email, "test", "yes"
307 assert_template "changeset/history"
308 assert_select "span.username", "test"
309 assert session.key?(:_remember_for)
312 def test_login_username_password_remember_me
313 user = users(:normal_user)
315 try_password_login user.display_name, "test", "yes"
317 assert_template "changeset/history"
318 assert_select "span.username", "test"
319 assert session.key?(:_remember_for)
322 def test_login_openid_success
323 OmniAuth.config.add_mock(:openid, :uid => "http://localhost:1123/john.doe")
325 get "/login", :referer => "/history"
326 assert_response :redirect
327 assert_redirected_to :controller => :user, :action => :login, :cookie_test => true, :referer => "/history"
329 assert_response :success
330 assert_template "user/login"
331 post "/login", :openid_url => "http://localhost:1123/john.doe", :referer => "/history"
332 assert_response :redirect
333 assert_redirected_to auth_path(:provider => "openid", :openid_url => "http://localhost:1123/john.doe", :origin => "/login?referer=%2Fhistory", :referer => "/history")
335 assert_response :redirect
336 assert_redirected_to auth_success_path(:provider => "openid", :openid_url => "http://localhost:1123/john.doe", :origin => "/login?referer=%2Fhistory", :referer => "/history")
338 assert_response :redirect
340 assert_response :success
341 assert_template "changeset/history"
342 assert_select "span.username", "openIDuser"
345 def test_login_openid_remember_me
346 OmniAuth.config.add_mock(:openid, :uid => "http://localhost:1123/john.doe")
348 get "/login", :referer => "/history"
349 assert_response :redirect
350 assert_redirected_to :controller => :user, :action => :login, :cookie_test => true, :referer => "/history"
352 assert_response :success
353 assert_template "user/login"
354 post "/login", :openid_url => "http://localhost:1123/john.doe", :remember_me_openid => true, :referer => "/history"
355 assert_response :redirect
356 assert_redirected_to auth_path(:provider => "openid", :openid_url => "http://localhost:1123/john.doe", :origin => "/login?referer=%2Fhistory", :referer => "/history")
358 assert_response :redirect
359 assert_redirected_to auth_success_path(:provider => "openid", :openid_url => "http://localhost:1123/john.doe", :origin => "/login?referer=%2Fhistory", :referer => "/history")
361 assert_response :redirect
363 assert_response :success
364 assert_template "changeset/history"
365 assert_select "span.username", "openIDuser"
366 assert session.key?(:_remember_for)
369 def test_login_openid_connection_failed
370 OmniAuth.config.mock_auth[:openid] = :connection_failed
372 get "/login", :referer => "/history"
373 assert_response :redirect
374 assert_redirected_to :controller => :user, :action => :login, :cookie_test => true, :referer => "/history"
376 assert_response :success
377 assert_template "user/login"
378 post "/login", :openid_url => "http://localhost:1123/john.doe", :referer => "/history"
379 assert_response :redirect
380 assert_redirected_to auth_path(:provider => "openid", :openid_url => "http://localhost:1123/john.doe", :origin => "/login?referer=%2Fhistory", :referer => "/history")
382 assert_response :redirect
383 assert_redirected_to auth_success_path(:provider => "openid", :openid_url => "http://localhost:1123/john.doe", :origin => "/login?referer=%2Fhistory", :referer => "/history")
385 assert_response :redirect
386 assert_redirected_to auth_failure_path(:strategy => "openid", :message => "connection_failed", :origin => "/login?referer=%2Fhistory")
388 assert_response :redirect
390 assert_response :success
391 assert_template "login"
392 assert_select "div.flash.error", "Connection to authentication provider failed"
393 assert_select "span.username", false
396 def test_login_openid_invalid_credentials
397 OmniAuth.config.mock_auth[:openid] = :invalid_credentials
399 get "/login", :referer => "/history"
400 assert_response :redirect
401 assert_redirected_to :controller => :user, :action => :login, :cookie_test => true, :referer => "/history"
403 assert_response :success
404 assert_template "user/login"
405 post "/login", :openid_url => "http://localhost:1123/john.doe", :referer => "/history"
406 assert_response :redirect
407 assert_redirected_to auth_path(:provider => "openid", :openid_url => "http://localhost:1123/john.doe", :origin => "/login?referer=%2Fhistory", :referer => "/history")
409 assert_response :redirect
410 assert_redirected_to auth_success_path(:provider => "openid", :openid_url => "http://localhost:1123/john.doe", :origin => "/login?referer=%2Fhistory", :referer => "/history")
412 assert_response :redirect
413 assert_redirected_to auth_failure_path(:strategy => "openid", :message => "invalid_credentials", :origin => "/login?referer=%2Fhistory")
415 assert_response :redirect
417 assert_response :success
418 assert_template "login"
419 assert_select "div.flash.error", "Invalid authentication credentials"
420 assert_select "span.username", false
423 def test_login_openid_unknown
424 OmniAuth.config.add_mock(:openid, :uid => "http://localhost:1123/fred.bloggs")
426 get "/login", :referer => "/history"
427 assert_response :redirect
428 assert_redirected_to :controller => :user, :action => :login, :cookie_test => true, :referer => "/history"
430 assert_response :success
431 assert_template "user/login"
432 post "/login", :openid_url => "http://localhost:1123/fred.bloggs", :referer => "/history"
433 assert_response :redirect
434 assert_redirected_to auth_path(:provider => "openid", :openid_url => "http://localhost:1123/fred.bloggs", :origin => "/login?referer=%2Fhistory", :referer => "/history")
436 assert_response :redirect
437 assert_redirected_to auth_success_path(:provider => "openid", :openid_url => "http://localhost:1123/fred.bloggs", :origin => "/login?referer=%2Fhistory", :referer => "/history")
439 assert_response :redirect
441 assert_response :success
442 assert_template "user/new"
443 assert_select "span.username", false
446 def test_login_google_success
447 OmniAuth.config.add_mock(:google, :uid => "123456789", :extra => {
448 :id_info => { "openid_id" => "http://localhost:1123/fred.bloggs" }
451 get "/login", :referer => "/history"
452 assert_response :redirect
453 assert_redirected_to "controller" => "user", "action" => "login", "cookie_test" => "true", "referer" => "/history"
455 assert_response :success
456 assert_template "user/login"
457 get auth_path(:provider => "google", :origin => "/login?referer=%2Fhistory", :referer => "/history")
458 assert_response :redirect
459 assert_redirected_to auth_success_path(:provider => "google")
461 assert_response :redirect
463 assert_response :success
464 assert_template "changeset/history"
465 assert_select "span.username", "googleuser"
468 def test_login_google_connection_failed
469 OmniAuth.config.mock_auth[:google] = :connection_failed
471 get "/login", :referer => "/history"
472 assert_response :redirect
473 assert_redirected_to "controller" => "user", "action" => "login", "cookie_test" => "true", "referer" => "/history"
475 assert_response :success
476 assert_template "user/login"
477 get auth_path(:provider => "google", :origin => "/login?referer=%2Fhistory", :referer => "/history")
478 assert_response :redirect
479 assert_redirected_to auth_success_path(:provider => "google")
481 assert_response :redirect
482 assert_redirected_to auth_failure_path(:strategy => "google", :message => "connection_failed", :origin => "/login?referer=%2Fhistory")
484 assert_response :redirect
486 assert_response :success
487 assert_template "login"
488 assert_select "div.flash.error", "Connection to authentication provider failed"
489 assert_select "span.username", false
492 def test_login_google_invalid_credentials
493 OmniAuth.config.mock_auth[:google] = :invalid_credentials
495 get "/login", :referer => "/history"
496 assert_response :redirect
497 assert_redirected_to "controller" => "user", "action" => "login", "cookie_test" => "true", "referer" => "/history"
499 assert_response :success
500 assert_template "user/login"
501 get auth_path(:provider => "google", :origin => "/login?referer=%2Fhistory", :referer => "/history")
502 assert_response :redirect
503 assert_redirected_to auth_success_path(:provider => "google")
505 assert_response :redirect
506 assert_redirected_to auth_failure_path(:strategy => "google", :message => "invalid_credentials", :origin => "/login?referer=%2Fhistory")
508 assert_response :redirect
510 assert_response :success
511 assert_template "login"
512 assert_select "div.flash.error", "Invalid authentication credentials"
513 assert_select "span.username", false
516 def test_login_google_unknown
517 OmniAuth.config.add_mock(:google, :uid => "987654321", :extra => {
518 :id_info => { "openid_id" => "http://localhost:1123/fred.bloggs" }
521 get "/login", :referer => "/history"
522 assert_response :redirect
523 assert_redirected_to "controller" => "user", "action" => "login", "cookie_test" => "true", "referer" => "/history"
525 assert_response :success
526 assert_template "user/login"
527 get auth_path(:provider => "google", :origin => "/login?referer=%2Fhistory", :referer => "/history")
528 assert_response :redirect
529 assert_redirected_to auth_success_path(:provider => "google")
531 assert_response :redirect
533 assert_response :success
534 assert_template "user/new"
535 assert_select "span.username", false
538 def test_login_google_upgrade
539 OmniAuth.config.add_mock(:google, :uid => "987654321", :extra => {
540 :id_info => { "openid_id" => "http://localhost:1123/john.doe" }
543 get "/login", :referer => "/history"
544 assert_response :redirect
545 assert_redirected_to "controller" => "user", "action" => "login", "cookie_test" => "true", "referer" => "/history"
547 assert_response :success
548 assert_template "user/login"
549 get auth_path(:provider => "google", :origin => "/login?referer=%2Fhistory", :referer => "/history")
550 assert_response :redirect
551 assert_redirected_to auth_success_path(:provider => "google")
553 assert_response :redirect
555 assert_response :success
556 assert_template "changeset/history"
557 assert_select "span.username", "openIDuser"
559 user = User.find_by(:display_name => "openIDuser")
560 assert_equal "google", user.auth_provider
561 assert_equal "987654321", user.auth_uid
564 def test_login_facebook_success
565 OmniAuth.config.add_mock(:facebook, :uid => "123456789")
567 get "/login", :referer => "/history"
568 assert_response :redirect
569 assert_redirected_to "controller" => "user", "action" => "login", "cookie_test" => "true", "referer" => "/history"
571 assert_response :success
572 assert_template "user/login"
573 get auth_path(:provider => "facebook", :origin => "/login?referer=%2Fhistory", :referer => "/history")
574 assert_response :redirect
575 assert_redirected_to auth_success_path(:provider => "facebook")
577 assert_response :redirect
579 assert_response :success
580 assert_template "changeset/history"
581 assert_select "span.username", "facebookuser"
584 def test_login_facebook_connection_failed
585 OmniAuth.config.mock_auth[:facebook] = :connection_failed
587 get "/login", :referer => "/history"
588 assert_response :redirect
589 assert_redirected_to "controller" => "user", "action" => "login", "cookie_test" => "true", "referer" => "/history"
591 assert_response :success
592 assert_template "user/login"
593 get auth_path(:provider => "facebook", :origin => "/login?referer=%2Fhistory", :referer => "/history")
594 assert_response :redirect
595 assert_redirected_to auth_success_path(:provider => "facebook")
597 assert_response :redirect
598 assert_redirected_to auth_failure_path(:strategy => "facebook", :message => "connection_failed", :origin => "/login?referer=%2Fhistory")
600 assert_response :redirect
602 assert_response :success
603 assert_template "login"
604 assert_select "div.flash.error", "Connection to authentication provider failed"
605 assert_select "span.username", false
608 def test_login_facebook_invalid_credentials
609 OmniAuth.config.mock_auth[:facebook] = :invalid_credentials
611 get "/login", :referer => "/history"
612 assert_response :redirect
613 assert_redirected_to "controller" => "user", "action" => "login", "cookie_test" => "true", "referer" => "/history"
615 assert_response :success
616 assert_template "user/login"
617 get auth_path(:provider => "facebook", :origin => "/login?referer=%2Fhistory", :referer => "/history")
618 assert_response :redirect
619 assert_redirected_to auth_success_path(:provider => "facebook")
621 assert_response :redirect
622 assert_redirected_to auth_failure_path(:strategy => "facebook", :message => "invalid_credentials", :origin => "/login?referer=%2Fhistory")
624 assert_response :redirect
626 assert_response :success
627 assert_template "login"
628 assert_select "div.flash.error", "Invalid authentication credentials"
629 assert_select "span.username", false
632 def test_login_facebook_unknown
633 OmniAuth.config.add_mock(:facebook, :uid => "987654321")
635 get "/login", :referer => "/history"
636 assert_response :redirect
637 assert_redirected_to "controller" => "user", "action" => "login", "cookie_test" => "true", "referer" => "/history"
639 assert_response :success
640 assert_template "user/login"
641 get auth_path(:provider => "facebook", :origin => "/login?referer=%2Fhistory", :referer => "/history")
642 assert_response :redirect
643 assert_redirected_to auth_success_path(:provider => "facebook")
645 assert_response :redirect
647 assert_response :success
648 assert_template "user/new"
649 assert_select "span.username", false
652 def test_login_windowslive_success
653 OmniAuth.config.add_mock(:windowslive, :uid => "123456789")
655 get "/login", :referer => "/history"
656 assert_response :redirect
657 assert_redirected_to "controller" => "user", "action" => "login", "cookie_test" => "true", "referer" => "/history"
659 assert_response :success
660 assert_template "user/login"
661 get auth_path(:provider => "windowslive", :origin => "/login?referer=%2Fhistory", :referer => "/history")
662 assert_response :redirect
663 assert_redirected_to auth_success_path(:provider => "windowslive", :origin => "/login?referer=%2Fhistory", :referer => "/history")
665 assert_response :redirect
667 assert_response :success
668 assert_template "changeset/history"
669 assert_select "span.username", "windowsliveuser"
672 def test_login_windowslive_connection_failed
673 OmniAuth.config.mock_auth[:windowslive] = :connection_failed
675 get "/login", :referer => "/history"
676 assert_response :redirect
677 assert_redirected_to "controller" => "user", "action" => "login", "cookie_test" => "true", "referer" => "/history"
679 assert_response :success
680 assert_template "user/login"
681 get auth_path(:provider => "windowslive", :origin => "/login?referer=%2Fhistory", :referer => "/history")
682 assert_response :redirect
683 assert_redirected_to auth_success_path(:provider => "windowslive", :origin => "/login?referer=%2Fhistory", :referer => "/history")
685 assert_response :redirect
686 assert_redirected_to auth_failure_path(:strategy => "windowslive", :message => "connection_failed", :origin => "/login?referer=%2Fhistory")
688 assert_response :redirect
690 assert_response :success
691 assert_template "login"
692 assert_select "div.flash.error", "Connection to authentication provider failed"
693 assert_select "span.username", false
696 def test_login_windowslive_invalid_credentials
697 OmniAuth.config.mock_auth[:windowslive] = :invalid_credentials
699 get "/login", :referer => "/history"
700 assert_response :redirect
701 assert_redirected_to "controller" => "user", "action" => "login", "cookie_test" => "true", "referer" => "/history"
703 assert_response :success
704 assert_template "user/login"
705 get auth_path(:provider => "windowslive", :origin => "/login?referer=%2Fhistory", :referer => "/history")
706 assert_response :redirect
707 assert_redirected_to auth_success_path(:provider => "windowslive", :origin => "/login?referer=%2Fhistory", :referer => "/history")
709 assert_response :redirect
710 assert_redirected_to auth_failure_path(:strategy => "windowslive", :message => "invalid_credentials", :origin => "/login?referer=%2Fhistory")
712 assert_response :redirect
714 assert_response :success
715 assert_template "login"
716 assert_select "div.flash.error", "Invalid authentication credentials"
717 assert_select "span.username", false
720 def test_login_windowslive_unknown
721 OmniAuth.config.add_mock(:windowslive, :uid => "987654321")
723 get "/login", :referer => "/history"
724 assert_response :redirect
725 assert_redirected_to "controller" => "user", "action" => "login", "cookie_test" => "true", "referer" => "/history"
727 assert_response :success
728 assert_template "user/login"
729 get auth_path(:provider => "windowslive", :origin => "/login?referer=%2Fhistory", :referer => "/history")
730 assert_response :redirect
731 assert_redirected_to auth_success_path(:provider => "windowslive", :origin => "/login?referer=%2Fhistory", :referer => "/history")
733 assert_response :redirect
735 assert_response :success
736 assert_template "user/new"
737 assert_select "span.username", false
740 def test_login_github_success
741 OmniAuth.config.add_mock(:github, :uid => "123456789")
743 get "/login", :referer => "/history"
744 assert_response :redirect
745 assert_redirected_to "controller" => "user", "action" => "login", "cookie_test" => "true", "referer" => "/history"
747 assert_response :success
748 assert_template "user/login"
749 get auth_path(:provider => "github", :origin => "/login?referer=%2Fhistory", :referer => "/history")
750 assert_response :redirect
751 assert_redirected_to auth_success_path(:provider => "github", :origin => "/login?referer=%2Fhistory", :referer => "/history")
753 assert_response :redirect
755 assert_response :success
756 assert_template "changeset/history"
757 assert_select "span.username", "githubuser"
760 def test_login_github_connection_failed
761 OmniAuth.config.mock_auth[:github] = :connection_failed
763 get "/login", :referer => "/history"
764 assert_response :redirect
765 assert_redirected_to "controller" => "user", "action" => "login", "cookie_test" => "true", "referer" => "/history"
767 assert_response :success
768 assert_template "user/login"
769 get auth_path(:provider => "github", :origin => "/login?referer=%2Fhistory", :referer => "/history")
770 assert_response :redirect
771 assert_redirected_to auth_success_path(:provider => "github", :origin => "/login?referer=%2Fhistory", :referer => "/history")
773 assert_response :redirect
774 assert_redirected_to auth_failure_path(:strategy => "github", :message => "connection_failed", :origin => "/login?referer=%2Fhistory")
776 assert_response :redirect
778 assert_response :success
779 assert_template "login"
780 assert_select "div.flash.error", "Connection to authentication provider failed"
781 assert_select "span.username", false
784 def test_login_github_invalid_credentials
785 OmniAuth.config.mock_auth[:github] = :invalid_credentials
787 get "/login", :referer => "/history"
788 assert_response :redirect
789 assert_redirected_to "controller" => "user", "action" => "login", "cookie_test" => "true", "referer" => "/history"
791 assert_response :success
792 assert_template "user/login"
793 get auth_path(:provider => "github", :origin => "/login?referer=%2Fhistory", :referer => "/history")
794 assert_response :redirect
795 assert_redirected_to auth_success_path(:provider => "github", :origin => "/login?referer=%2Fhistory", :referer => "/history")
797 assert_response :redirect
798 assert_redirected_to auth_failure_path(:strategy => "github", :message => "invalid_credentials", :origin => "/login?referer=%2Fhistory")
800 assert_response :redirect
802 assert_response :success
803 assert_template "login"
804 assert_select "div.flash.error", "Invalid authentication credentials"
805 assert_select "span.username", false
808 def test_login_github_unknown
809 OmniAuth.config.add_mock(:github, :uid => "987654321")
811 get "/login", :referer => "/history"
812 assert_response :redirect
813 assert_redirected_to "controller" => "user", "action" => "login", "cookie_test" => "true", "referer" => "/history"
815 assert_response :success
816 assert_template "user/login"
817 get auth_path(:provider => "github", :origin => "/login?referer=%2Fhistory", :referer => "/history")
818 assert_response :redirect
819 assert_redirected_to auth_success_path(:provider => "github", :origin => "/login?referer=%2Fhistory", :referer => "/history")
821 assert_response :redirect
823 assert_response :success
824 assert_template "user/new"
825 assert_select "span.username", false
828 def test_login_wikipedia_success
829 OmniAuth.config.add_mock(:wikipedia, :uid => "123456789")
831 get "/login", :referer => "/history"
832 assert_response :redirect
833 assert_redirected_to "controller" => "user", "action" => "login", "cookie_test" => "true", "referer" => "/history"
835 assert_response :success
836 assert_template "user/login"
837 get auth_path(:provider => "wikipedia", :origin => "/login?referer=%2Fhistory", :referer => "/history")
838 assert_response :redirect
839 assert_redirected_to auth_success_path(:provider => "wikipedia", :origin => "/login?referer=%2Fhistory", :referer => "/history")
841 assert_response :redirect
843 assert_response :success
844 assert_template "changeset/history"
845 assert_select "span.username", "wikipediauser"
848 def test_login_wikipedia_connection_failed
849 OmniAuth.config.mock_auth[:wikipedia] = :connection_failed
851 get "/login", :referer => "/history"
852 assert_response :redirect
853 assert_redirected_to "controller" => "user", "action" => "login", "cookie_test" => "true", "referer" => "/history"
855 assert_response :success
856 assert_template "user/login"
857 get auth_path(:provider => "wikipedia", :origin => "/login?referer=%2Fhistory", :referer => "/history")
858 assert_response :redirect
859 assert_redirected_to auth_success_path(:provider => "wikipedia", :origin => "/login?referer=%2Fhistory", :referer => "/history")
861 assert_response :redirect
862 assert_redirected_to auth_failure_path(:strategy => "wikipedia", :message => "connection_failed", :origin => "/login?referer=%2Fhistory")
864 assert_response :redirect
866 assert_response :success
867 assert_template "login"
868 assert_select "div.flash.error", "Connection to authentication provider failed"
869 assert_select "span.username", false
872 def test_login_wikipedia_invalid_credentials
873 OmniAuth.config.mock_auth[:wikipedia] = :invalid_credentials
875 get "/login", :referer => "/history"
876 assert_response :redirect
877 assert_redirected_to "controller" => "user", "action" => "login", "cookie_test" => "true", "referer" => "/history"
879 assert_response :success
880 assert_template "user/login"
881 get auth_path(:provider => "wikipedia", :origin => "/login?referer=%2Fhistory", :referer => "/history")
882 assert_response :redirect
883 assert_redirected_to auth_success_path(:provider => "wikipedia", :origin => "/login?referer=%2Fhistory", :referer => "/history")
885 assert_response :redirect
886 assert_redirected_to auth_failure_path(:strategy => "wikipedia", :message => "invalid_credentials", :origin => "/login?referer=%2Fhistory")
888 assert_response :redirect
890 assert_response :success
891 assert_template "login"
892 assert_select "div.flash.error", "Invalid authentication credentials"
893 assert_select "span.username", false
896 def test_login_wikipedia_unknown
897 OmniAuth.config.add_mock(:wikipedia, :uid => "987654321")
899 get "/login", :referer => "/history"
900 assert_response :redirect
901 assert_redirected_to "controller" => "user", "action" => "login", "cookie_test" => "true", "referer" => "/history"
903 assert_response :success
904 assert_template "user/login"
905 get auth_path(:provider => "wikipedia", :origin => "/login?referer=%2Fhistory", :referer => "/history")
906 assert_response :redirect
907 assert_redirected_to auth_success_path(:provider => "wikipedia", :origin => "/login?referer=%2Fhistory", :referer => "/history")
909 assert_response :redirect
911 assert_response :success
912 assert_template "user/new"
913 assert_select "span.username", false
918 def try_password_login(username, password, remember_me = nil)
920 assert_response :redirect
921 assert_redirected_to :controller => :user, :action => :login, :cookie_test => true
923 assert_response :success
924 assert_template "login"
925 assert_select "input#username", 1 do
926 assert_select "[value]", false
928 assert_select "input#password", 1 do
929 assert_select "[value=?]", ""
931 assert_select "input#remember_me", 1 do
932 assert_select "[checked]", false
935 post "/login", :username => username, :password => "wrong", :remember_me => remember_me, :referer => "/history"
936 assert_response :redirect
938 assert_response :success
939 assert_template "login"
940 assert_select "input#username", 1 do
941 assert_select "[value=?]", username
943 assert_select "input#password", 1 do
944 assert_select "[value=?]", ""
946 assert_select "input#remember_me", 1 do
947 assert_select "[checked]", remember_me == "yes"
950 post "/login", :username => username, :password => password, :remember_me => remember_me, :referer => "/history"
951 assert_response :redirect
953 assert_response :success