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.test_mode = false
19 def test_login_email_password_normal
20 user = users(:normal_user)
22 try_password_login user.email, "test"
24 assert_template "changeset/history"
25 assert_select "span.username", "test"
28 def test_login_email_password_normal_upcase
29 user = users(:normal_user)
31 try_password_login user.email.upcase, "test"
33 assert_template "changeset/history"
34 assert_select "span.username", "TEST"
37 def test_login_email_password_normal_titlecase
38 user = users(:normal_user)
40 try_password_login user.email.titlecase, "test"
42 assert_template "login"
43 assert_select "span.username", false
46 def test_login_email_password_public
47 user = users(:public_user)
49 try_password_login user.email, "test"
51 assert_template "changeset/history"
52 assert_select "span.username", "test2"
55 def test_login_email_password_public_upcase
56 user = users(:public_user)
58 try_password_login user.email.upcase, "test"
60 assert_template "changeset/history"
61 assert_select "span.username", "test2"
64 def test_login_email_password_public_titlecase
65 user = users(:public_user)
67 try_password_login user.email.titlecase, "test"
69 assert_template "changeset/history"
70 assert_select "span.username", "test2"
73 def test_login_email_password_inactive
74 user = users(:inactive_user)
76 try_password_login user.email, "test2"
78 assert_template "confirm"
79 assert_select "span.username", false
82 def test_login_email_password_inactive_upcase
83 user = users(:inactive_user)
85 try_password_login user.email.upcase, "test2"
87 assert_template "confirm"
88 assert_select "span.username", false
91 def test_login_email_password_inactive_titlecase
92 user = users(:inactive_user)
94 try_password_login user.email.titlecase, "test2"
96 assert_template "confirm"
97 assert_select "span.username", false
100 def test_login_email_password_suspended
101 user = users(:suspended_user)
103 try_password_login user.email, "test"
105 assert_template "login"
106 assert_select "span.username", false
107 assert_select "div.flash.error", /your account has been suspended/
110 def test_login_email_password_suspended_upcase
111 user = users(:suspended_user)
113 try_password_login user.email.upcase, "test"
115 assert_template "login"
116 assert_select "span.username", false
117 assert_select "div.flash.error", /your account has been suspended/
120 def test_login_email_password_suspended_titlecase
121 user = users(:suspended_user)
123 try_password_login user.email.titlecase, "test"
125 assert_template "login"
126 assert_select "span.username", false
127 assert_select "div.flash.error", /your account has been suspended/
130 def test_login_email_password_blocked
131 user = users(:blocked_user)
132 create(:user_block, :needs_view, :user => user)
134 try_password_login user.email, "test"
136 assert_template "user_blocks/show"
137 assert_select "span.username", "blocked"
140 def test_login_email_password_blocked_upcase
141 user = users(:blocked_user)
142 create(:user_block, :needs_view, :user => user)
144 try_password_login user.email.upcase, "test"
146 assert_template "user_blocks/show"
147 assert_select "span.username", "blocked"
150 def test_login_email_password_blocked_titlecase
151 user = users(:blocked_user)
152 create(:user_block, :needs_view, :user => user)
154 try_password_login user.email.titlecase, "test"
156 assert_template "user_blocks/show"
157 assert_select "span.username", "blocked"
160 def test_login_username_password_normal
161 user = users(:normal_user)
163 try_password_login user.display_name, "test"
165 assert_template "changeset/history"
166 assert_select "span.username", "test"
169 def test_login_username_password_normal_upcase
170 user = users(:normal_user)
172 try_password_login user.display_name.upcase, "test"
174 assert_template "changeset/history"
175 assert_select "span.username", "TEST"
178 def test_login_username_password_normal_titlecase
179 user = users(:normal_user)
181 try_password_login user.display_name.titlecase, "test"
183 assert_template "login"
184 assert_select "span.username", false
187 def test_login_username_password_public
188 user = users(:public_user)
190 try_password_login user.display_name, "test"
192 assert_template "changeset/history"
193 assert_select "span.username", "test2"
196 def test_login_username_password_public_upcase
197 user = users(:public_user)
199 try_password_login user.display_name.upcase, "test"
201 assert_template "changeset/history"
202 assert_select "span.username", "test2"
205 def test_login_username_password_public_titlecase
206 user = users(:public_user)
208 try_password_login user.display_name.titlecase, "test"
210 assert_template "changeset/history"
211 assert_select "span.username", "test2"
214 def test_login_username_password_inactive
215 user = users(:inactive_user)
217 try_password_login user.display_name, "test2"
219 assert_template "confirm"
220 assert_select "span.username", false
223 def test_login_username_password_inactive_upcase
224 user = users(:inactive_user)
226 try_password_login user.display_name.upcase, "test2"
228 assert_template "confirm"
229 assert_select "span.username", false
232 def test_login_username_password_inactive_titlecase
233 user = users(:inactive_user)
235 try_password_login user.display_name.titlecase, "test2"
237 assert_template "confirm"
238 assert_select "span.username", false
241 def test_login_username_password_suspended
242 user = users(:suspended_user)
244 try_password_login user.display_name, "test"
246 assert_template "login"
247 assert_select "span.username", false
248 assert_select "div.flash.error", /your account has been suspended/
251 def test_login_username_password_suspended_upcase
252 user = users(:suspended_user)
254 try_password_login user.display_name.upcase, "test"
256 assert_template "login"
257 assert_select "span.username", false
258 assert_select "div.flash.error", /your account has been suspended/
261 def test_login_username_password_suspended_titlecase
262 user = users(:suspended_user)
264 try_password_login user.display_name.titlecase, "test"
266 assert_template "login"
267 assert_select "span.username", false
268 assert_select "div.flash.error", /your account has been suspended/
271 def test_login_username_password_blocked
272 user = users(:blocked_user)
273 create(:user_block, :needs_view, :user => user)
275 try_password_login user.display_name.upcase, "test"
277 assert_template "user_blocks/show"
278 assert_select "span.username", "blocked"
281 def test_login_username_password_blocked_upcase
282 user = users(:blocked_user)
283 create(:user_block, :needs_view, :user => user)
285 try_password_login user.display_name, "test"
287 assert_template "user_blocks/show"
288 assert_select "span.username", "blocked"
291 def test_login_username_password_blocked_titlecase
292 user = users(:blocked_user)
293 create(:user_block, :needs_view, :user => user)
295 try_password_login user.display_name.titlecase, "test"
297 assert_template "user_blocks/show"
298 assert_select "span.username", "blocked"
301 def test_login_email_password_remember_me
302 user = users(:normal_user)
304 try_password_login user.email, "test", "yes"
306 assert_template "changeset/history"
307 assert_select "span.username", "test"
308 assert session.key?(:_remember_for)
311 def test_login_username_password_remember_me
312 user = users(:normal_user)
314 try_password_login user.display_name, "test", "yes"
316 assert_template "changeset/history"
317 assert_select "span.username", "test"
318 assert session.key?(:_remember_for)
321 def test_login_openid_success
322 OmniAuth.config.add_mock(:openid, :uid => "http://localhost:1123/john.doe")
324 get "/login", :referer => "/history"
325 assert_response :redirect
326 assert_redirected_to :controller => :user, :action => :login, :cookie_test => true, :referer => "/history"
328 assert_response :success
329 assert_template "user/login"
330 post "/login", :openid_url => "http://localhost:1123/john.doe", :referer => "/history"
331 assert_response :redirect
332 assert_redirected_to auth_path(:provider => "openid", :openid_url => "http://localhost:1123/john.doe", :origin => "/login?referer=%2Fhistory", :referer => "/history")
334 assert_response :redirect
335 assert_redirected_to auth_success_path(:provider => "openid", :openid_url => "http://localhost:1123/john.doe", :origin => "/login?referer=%2Fhistory", :referer => "/history")
337 assert_response :redirect
339 assert_response :success
340 assert_template "changeset/history"
341 assert_select "span.username", "openIDuser"
344 def test_login_openid_remember_me
345 OmniAuth.config.add_mock(:openid, :uid => "http://localhost:1123/john.doe")
347 get "/login", :referer => "/history"
348 assert_response :redirect
349 assert_redirected_to :controller => :user, :action => :login, :cookie_test => true, :referer => "/history"
351 assert_response :success
352 assert_template "user/login"
353 post "/login", :openid_url => "http://localhost:1123/john.doe", :remember_me_openid => true, :referer => "/history"
354 assert_response :redirect
355 assert_redirected_to auth_path(:provider => "openid", :openid_url => "http://localhost:1123/john.doe", :origin => "/login?referer=%2Fhistory", :referer => "/history")
357 assert_response :redirect
358 assert_redirected_to auth_success_path(:provider => "openid", :openid_url => "http://localhost:1123/john.doe", :origin => "/login?referer=%2Fhistory", :referer => "/history")
360 assert_response :redirect
362 assert_response :success
363 assert_template "changeset/history"
364 assert_select "span.username", "openIDuser"
365 assert session.key?(:_remember_for)
368 def test_login_openid_connection_failed
369 OmniAuth.config.mock_auth[:openid] = :connection_failed
371 get "/login", :referer => "/history"
372 assert_response :redirect
373 assert_redirected_to :controller => :user, :action => :login, :cookie_test => true, :referer => "/history"
375 assert_response :success
376 assert_template "user/login"
377 post "/login", :openid_url => "http://localhost:1123/john.doe", :referer => "/history"
378 assert_response :redirect
379 assert_redirected_to auth_path(:provider => "openid", :openid_url => "http://localhost:1123/john.doe", :origin => "/login?referer=%2Fhistory", :referer => "/history")
381 assert_response :redirect
382 assert_redirected_to auth_success_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_failure_path(:strategy => "openid", :message => "connection_failed", :origin => "/login?referer=%2Fhistory")
387 assert_response :redirect
389 assert_response :success
390 assert_template "login"
391 assert_select "div.flash.error", "Connection to authentication provider failed"
392 assert_select "span.username", false
395 def test_login_openid_invalid_credentials
396 OmniAuth.config.mock_auth[:openid] = :invalid_credentials
398 get "/login", :referer => "/history"
399 assert_response :redirect
400 assert_redirected_to :controller => :user, :action => :login, :cookie_test => true, :referer => "/history"
402 assert_response :success
403 assert_template "user/login"
404 post "/login", :openid_url => "http://localhost:1123/john.doe", :referer => "/history"
405 assert_response :redirect
406 assert_redirected_to auth_path(:provider => "openid", :openid_url => "http://localhost:1123/john.doe", :origin => "/login?referer=%2Fhistory", :referer => "/history")
408 assert_response :redirect
409 assert_redirected_to auth_success_path(:provider => "openid", :openid_url => "http://localhost:1123/john.doe", :origin => "/login?referer=%2Fhistory", :referer => "/history")
411 assert_response :redirect
412 assert_redirected_to auth_failure_path(:strategy => "openid", :message => "invalid_credentials", :origin => "/login?referer=%2Fhistory")
414 assert_response :redirect
416 assert_response :success
417 assert_template "login"
418 assert_select "div.flash.error", "Invalid authentication credentials"
419 assert_select "span.username", false
422 def test_login_openid_unknown
423 OmniAuth.config.add_mock(:openid, :uid => "http://localhost:1123/fred.bloggs")
425 get "/login", :referer => "/history"
426 assert_response :redirect
427 assert_redirected_to :controller => :user, :action => :login, :cookie_test => true, :referer => "/history"
429 assert_response :success
430 assert_template "user/login"
431 post "/login", :openid_url => "http://localhost:1123/fred.bloggs", :referer => "/history"
432 assert_response :redirect
433 assert_redirected_to auth_path(:provider => "openid", :openid_url => "http://localhost:1123/fred.bloggs", :origin => "/login?referer=%2Fhistory", :referer => "/history")
435 assert_response :redirect
436 assert_redirected_to auth_success_path(:provider => "openid", :openid_url => "http://localhost:1123/fred.bloggs", :origin => "/login?referer=%2Fhistory", :referer => "/history")
438 assert_response :redirect
440 assert_response :success
441 assert_template "user/new"
442 assert_select "span.username", false
445 def test_login_google_success
446 OmniAuth.config.add_mock(:google, :uid => "123456789", :extra => {
447 :id_info => { "openid_id" => "http://localhost:1123/fred.bloggs" }
450 get "/login", :referer => "/history"
451 assert_response :redirect
452 assert_redirected_to "controller" => "user", "action" => "login", "cookie_test" => "true", "referer" => "/history"
454 assert_response :success
455 assert_template "user/login"
456 get auth_path(:provider => "google", :origin => "/login?referer=%2Fhistory", :referer => "/history")
457 assert_response :redirect
458 assert_redirected_to auth_success_path(:provider => "google")
460 assert_response :redirect
462 assert_response :success
463 assert_template "changeset/history"
464 assert_select "span.username", "googleuser"
467 def test_login_google_connection_failed
468 OmniAuth.config.mock_auth[:google] = :connection_failed
470 get "/login", :referer => "/history"
471 assert_response :redirect
472 assert_redirected_to "controller" => "user", "action" => "login", "cookie_test" => "true", "referer" => "/history"
474 assert_response :success
475 assert_template "user/login"
476 get auth_path(:provider => "google", :origin => "/login?referer=%2Fhistory", :referer => "/history")
477 assert_response :redirect
478 assert_redirected_to auth_success_path(:provider => "google")
480 assert_response :redirect
481 assert_redirected_to auth_failure_path(:strategy => "google", :message => "connection_failed", :origin => "/login?referer=%2Fhistory")
483 assert_response :redirect
485 assert_response :success
486 assert_template "login"
487 assert_select "div.flash.error", "Connection to authentication provider failed"
488 assert_select "span.username", false
491 def test_login_google_invalid_credentials
492 OmniAuth.config.mock_auth[:google] = :invalid_credentials
494 get "/login", :referer => "/history"
495 assert_response :redirect
496 assert_redirected_to "controller" => "user", "action" => "login", "cookie_test" => "true", "referer" => "/history"
498 assert_response :success
499 assert_template "user/login"
500 get auth_path(:provider => "google", :origin => "/login?referer=%2Fhistory", :referer => "/history")
501 assert_response :redirect
502 assert_redirected_to auth_success_path(:provider => "google")
504 assert_response :redirect
505 assert_redirected_to auth_failure_path(:strategy => "google", :message => "invalid_credentials", :origin => "/login?referer=%2Fhistory")
507 assert_response :redirect
509 assert_response :success
510 assert_template "login"
511 assert_select "div.flash.error", "Invalid authentication credentials"
512 assert_select "span.username", false
515 def test_login_google_unknown
516 OmniAuth.config.add_mock(:google, :uid => "987654321", :extra => {
517 :id_info => { "openid_id" => "http://localhost:1123/fred.bloggs" }
520 get "/login", :referer => "/history"
521 assert_response :redirect
522 assert_redirected_to "controller" => "user", "action" => "login", "cookie_test" => "true", "referer" => "/history"
524 assert_response :success
525 assert_template "user/login"
526 get auth_path(:provider => "google", :origin => "/login?referer=%2Fhistory", :referer => "/history")
527 assert_response :redirect
528 assert_redirected_to auth_success_path(:provider => "google")
530 assert_response :redirect
532 assert_response :success
533 assert_template "user/new"
534 assert_select "span.username", false
537 def test_login_google_upgrade
538 OmniAuth.config.add_mock(:google, :uid => "987654321", :extra => {
539 :id_info => { "openid_id" => "http://localhost:1123/john.doe" }
542 get "/login", :referer => "/history"
543 assert_response :redirect
544 assert_redirected_to "controller" => "user", "action" => "login", "cookie_test" => "true", "referer" => "/history"
546 assert_response :success
547 assert_template "user/login"
548 get auth_path(:provider => "google", :origin => "/login?referer=%2Fhistory", :referer => "/history")
549 assert_response :redirect
550 assert_redirected_to auth_success_path(:provider => "google")
552 assert_response :redirect
554 assert_response :success
555 assert_template "changeset/history"
556 assert_select "span.username", "openIDuser"
558 user = User.find_by(:display_name => "openIDuser")
559 assert_equal "google", user.auth_provider
560 assert_equal "987654321", user.auth_uid
563 def test_login_facebook_success
564 OmniAuth.config.add_mock(:facebook, :uid => "123456789")
566 get "/login", :referer => "/history"
567 assert_response :redirect
568 assert_redirected_to "controller" => "user", "action" => "login", "cookie_test" => "true", "referer" => "/history"
570 assert_response :success
571 assert_template "user/login"
572 get auth_path(:provider => "facebook", :origin => "/login?referer=%2Fhistory", :referer => "/history")
573 assert_response :redirect
574 assert_redirected_to auth_success_path(:provider => "facebook")
576 assert_response :redirect
578 assert_response :success
579 assert_template "changeset/history"
580 assert_select "span.username", "facebookuser"
583 def test_login_facebook_connection_failed
584 OmniAuth.config.mock_auth[:facebook] = :connection_failed
586 get "/login", :referer => "/history"
587 assert_response :redirect
588 assert_redirected_to "controller" => "user", "action" => "login", "cookie_test" => "true", "referer" => "/history"
590 assert_response :success
591 assert_template "user/login"
592 get auth_path(:provider => "facebook", :origin => "/login?referer=%2Fhistory", :referer => "/history")
593 assert_response :redirect
594 assert_redirected_to auth_success_path(:provider => "facebook")
596 assert_response :redirect
597 assert_redirected_to auth_failure_path(:strategy => "facebook", :message => "connection_failed", :origin => "/login?referer=%2Fhistory")
599 assert_response :redirect
601 assert_response :success
602 assert_template "login"
603 assert_select "div.flash.error", "Connection to authentication provider failed"
604 assert_select "span.username", false
607 def test_login_facebook_invalid_credentials
608 OmniAuth.config.mock_auth[:facebook] = :invalid_credentials
610 get "/login", :referer => "/history"
611 assert_response :redirect
612 assert_redirected_to "controller" => "user", "action" => "login", "cookie_test" => "true", "referer" => "/history"
614 assert_response :success
615 assert_template "user/login"
616 get auth_path(:provider => "facebook", :origin => "/login?referer=%2Fhistory", :referer => "/history")
617 assert_response :redirect
618 assert_redirected_to auth_success_path(:provider => "facebook")
620 assert_response :redirect
621 assert_redirected_to auth_failure_path(:strategy => "facebook", :message => "invalid_credentials", :origin => "/login?referer=%2Fhistory")
623 assert_response :redirect
625 assert_response :success
626 assert_template "login"
627 assert_select "div.flash.error", "Invalid authentication credentials"
628 assert_select "span.username", false
631 def test_login_facebook_unknown
632 OmniAuth.config.add_mock(:facebook, :uid => "987654321")
634 get "/login", :referer => "/history"
635 assert_response :redirect
636 assert_redirected_to "controller" => "user", "action" => "login", "cookie_test" => "true", "referer" => "/history"
638 assert_response :success
639 assert_template "user/login"
640 get auth_path(:provider => "facebook", :origin => "/login?referer=%2Fhistory", :referer => "/history")
641 assert_response :redirect
642 assert_redirected_to auth_success_path(:provider => "facebook")
644 assert_response :redirect
646 assert_response :success
647 assert_template "user/new"
648 assert_select "span.username", false
651 def test_login_windowslive_success
652 OmniAuth.config.add_mock(:windowslive, :uid => "123456789")
654 get "/login", :referer => "/history"
655 assert_response :redirect
656 assert_redirected_to "controller" => "user", "action" => "login", "cookie_test" => "true", "referer" => "/history"
658 assert_response :success
659 assert_template "user/login"
660 get auth_path(:provider => "windowslive", :origin => "/login?referer=%2Fhistory", :referer => "/history")
661 assert_response :redirect
662 assert_redirected_to auth_success_path(:provider => "windowslive", :origin => "/login?referer=%2Fhistory", :referer => "/history")
664 assert_response :redirect
666 assert_response :success
667 assert_template "changeset/history"
668 assert_select "span.username", "windowsliveuser"
671 def test_login_windowslive_connection_failed
672 OmniAuth.config.mock_auth[:windowslive] = :connection_failed
674 get "/login", :referer => "/history"
675 assert_response :redirect
676 assert_redirected_to "controller" => "user", "action" => "login", "cookie_test" => "true", "referer" => "/history"
678 assert_response :success
679 assert_template "user/login"
680 get auth_path(:provider => "windowslive", :origin => "/login?referer=%2Fhistory", :referer => "/history")
681 assert_response :redirect
682 assert_redirected_to auth_success_path(:provider => "windowslive", :origin => "/login?referer=%2Fhistory", :referer => "/history")
684 assert_response :redirect
685 assert_redirected_to auth_failure_path(:strategy => "windowslive", :message => "connection_failed", :origin => "/login?referer=%2Fhistory")
687 assert_response :redirect
689 assert_response :success
690 assert_template "login"
691 assert_select "div.flash.error", "Connection to authentication provider failed"
692 assert_select "span.username", false
695 def test_login_windowslive_invalid_credentials
696 OmniAuth.config.mock_auth[:windowslive] = :invalid_credentials
698 get "/login", :referer => "/history"
699 assert_response :redirect
700 assert_redirected_to "controller" => "user", "action" => "login", "cookie_test" => "true", "referer" => "/history"
702 assert_response :success
703 assert_template "user/login"
704 get auth_path(:provider => "windowslive", :origin => "/login?referer=%2Fhistory", :referer => "/history")
705 assert_response :redirect
706 assert_redirected_to auth_success_path(:provider => "windowslive", :origin => "/login?referer=%2Fhistory", :referer => "/history")
708 assert_response :redirect
709 assert_redirected_to auth_failure_path(:strategy => "windowslive", :message => "invalid_credentials", :origin => "/login?referer=%2Fhistory")
711 assert_response :redirect
713 assert_response :success
714 assert_template "login"
715 assert_select "div.flash.error", "Invalid authentication credentials"
716 assert_select "span.username", false
719 def test_login_windowslive_unknown
720 OmniAuth.config.add_mock(:windowslive, :uid => "987654321")
722 get "/login", :referer => "/history"
723 assert_response :redirect
724 assert_redirected_to "controller" => "user", "action" => "login", "cookie_test" => "true", "referer" => "/history"
726 assert_response :success
727 assert_template "user/login"
728 get auth_path(:provider => "windowslive", :origin => "/login?referer=%2Fhistory", :referer => "/history")
729 assert_response :redirect
730 assert_redirected_to auth_success_path(:provider => "windowslive", :origin => "/login?referer=%2Fhistory", :referer => "/history")
732 assert_response :redirect
734 assert_response :success
735 assert_template "user/new"
736 assert_select "span.username", false
739 def test_login_github_success
740 OmniAuth.config.add_mock(:github, :uid => "123456789")
742 get "/login", :referer => "/history"
743 assert_response :redirect
744 assert_redirected_to "controller" => "user", "action" => "login", "cookie_test" => "true", "referer" => "/history"
746 assert_response :success
747 assert_template "user/login"
748 get auth_path(:provider => "github", :origin => "/login?referer=%2Fhistory", :referer => "/history")
749 assert_response :redirect
750 assert_redirected_to auth_success_path(:provider => "github", :origin => "/login?referer=%2Fhistory", :referer => "/history")
752 assert_response :redirect
754 assert_response :success
755 assert_template "changeset/history"
756 assert_select "span.username", "githubuser"
759 def test_login_github_connection_failed
760 OmniAuth.config.mock_auth[:github] = :connection_failed
762 get "/login", :referer => "/history"
763 assert_response :redirect
764 assert_redirected_to "controller" => "user", "action" => "login", "cookie_test" => "true", "referer" => "/history"
766 assert_response :success
767 assert_template "user/login"
768 get auth_path(:provider => "github", :origin => "/login?referer=%2Fhistory", :referer => "/history")
769 assert_response :redirect
770 assert_redirected_to auth_success_path(:provider => "github", :origin => "/login?referer=%2Fhistory", :referer => "/history")
772 assert_response :redirect
773 assert_redirected_to auth_failure_path(:strategy => "github", :message => "connection_failed", :origin => "/login?referer=%2Fhistory")
775 assert_response :redirect
777 assert_response :success
778 assert_template "login"
779 assert_select "div.flash.error", "Connection to authentication provider failed"
780 assert_select "span.username", false
783 def test_login_github_invalid_credentials
784 OmniAuth.config.mock_auth[:github] = :invalid_credentials
786 get "/login", :referer => "/history"
787 assert_response :redirect
788 assert_redirected_to "controller" => "user", "action" => "login", "cookie_test" => "true", "referer" => "/history"
790 assert_response :success
791 assert_template "user/login"
792 get auth_path(:provider => "github", :origin => "/login?referer=%2Fhistory", :referer => "/history")
793 assert_response :redirect
794 assert_redirected_to auth_success_path(:provider => "github", :origin => "/login?referer=%2Fhistory", :referer => "/history")
796 assert_response :redirect
797 assert_redirected_to auth_failure_path(:strategy => "github", :message => "invalid_credentials", :origin => "/login?referer=%2Fhistory")
799 assert_response :redirect
801 assert_response :success
802 assert_template "login"
803 assert_select "div.flash.error", "Invalid authentication credentials"
804 assert_select "span.username", false
807 def test_login_github_unknown
808 OmniAuth.config.add_mock(:github, :uid => "987654321")
810 get "/login", :referer => "/history"
811 assert_response :redirect
812 assert_redirected_to "controller" => "user", "action" => "login", "cookie_test" => "true", "referer" => "/history"
814 assert_response :success
815 assert_template "user/login"
816 get auth_path(:provider => "github", :origin => "/login?referer=%2Fhistory", :referer => "/history")
817 assert_response :redirect
818 assert_redirected_to auth_success_path(:provider => "github", :origin => "/login?referer=%2Fhistory", :referer => "/history")
820 assert_response :redirect
822 assert_response :success
823 assert_template "user/new"
824 assert_select "span.username", false
829 def try_password_login(username, password, remember_me = nil)
831 assert_response :redirect
832 assert_redirected_to :controller => :user, :action => :login, :cookie_test => true
834 assert_response :success
835 assert_template "login"
836 assert_select "input#username", 1 do
837 assert_select "[value]", false
839 assert_select "input#password", 1 do
840 assert_select "[value=?]", ""
842 assert_select "input#remember_me", 1 do
843 assert_select "[checked]", false
846 post "/login", :username => username, :password => "wrong", :remember_me => remember_me, :referer => "/history"
847 assert_response :redirect
849 assert_response :success
850 assert_template "login"
851 assert_select "input#username", 1 do
852 assert_select "[value=?]", username
854 assert_select "input#password", 1 do
855 assert_select "[value=?]", ""
857 assert_select "input#remember_me", 1 do
858 assert_select "[checked]", remember_me == "yes"
861 post "/login", :username => username, :password => password, :remember_me => remember_me, :referer => "/history"
862 assert_response :redirect
864 assert_response :success