3 class UserLoginTest < ActionDispatch::IntegrationTest
4 fixtures :users, :user_blocks
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)
133 try_password_login user.email, "test"
135 assert_template "user_blocks/show"
136 assert_select "span.username", "blocked"
139 def test_login_email_password_blocked_upcase
140 user = users(:blocked_user)
142 try_password_login user.email.upcase, "test"
144 assert_template "user_blocks/show"
145 assert_select "span.username", "blocked"
148 def test_login_email_password_blocked_titlecase
149 user = users(:blocked_user)
151 try_password_login user.email.titlecase, "test"
153 assert_template "user_blocks/show"
154 assert_select "span.username", "blocked"
157 def test_login_username_password_normal
158 user = users(:normal_user)
160 try_password_login user.display_name, "test"
162 assert_template "changeset/history"
163 assert_select "span.username", "test"
166 def test_login_username_password_normal_upcase
167 user = users(:normal_user)
169 try_password_login user.display_name.upcase, "test"
171 assert_template "changeset/history"
172 assert_select "span.username", "TEST"
175 def test_login_username_password_normal_titlecase
176 user = users(:normal_user)
178 try_password_login user.display_name.titlecase, "test"
180 assert_template "login"
181 assert_select "span.username", false
184 def test_login_username_password_public
185 user = users(:public_user)
187 try_password_login user.display_name, "test"
189 assert_template "changeset/history"
190 assert_select "span.username", "test2"
193 def test_login_username_password_public_upcase
194 user = users(:public_user)
196 try_password_login user.display_name.upcase, "test"
198 assert_template "changeset/history"
199 assert_select "span.username", "test2"
202 def test_login_username_password_public_titlecase
203 user = users(:public_user)
205 try_password_login user.display_name.titlecase, "test"
207 assert_template "changeset/history"
208 assert_select "span.username", "test2"
211 def test_login_username_password_inactive
212 user = users(:inactive_user)
214 try_password_login user.display_name, "test2"
216 assert_template "confirm"
217 assert_select "span.username", false
220 def test_login_username_password_inactive_upcase
221 user = users(:inactive_user)
223 try_password_login user.display_name.upcase, "test2"
225 assert_template "confirm"
226 assert_select "span.username", false
229 def test_login_username_password_inactive_titlecase
230 user = users(:inactive_user)
232 try_password_login user.display_name.titlecase, "test2"
234 assert_template "confirm"
235 assert_select "span.username", false
238 def test_login_username_password_suspended
239 user = users(:suspended_user)
241 try_password_login user.display_name, "test"
243 assert_template "login"
244 assert_select "span.username", false
245 assert_select "div.flash.error", /your account has been suspended/
248 def test_login_username_password_suspended_upcase
249 user = users(:suspended_user)
251 try_password_login user.display_name.upcase, "test"
253 assert_template "login"
254 assert_select "span.username", false
255 assert_select "div.flash.error", /your account has been suspended/
258 def test_login_username_password_suspended_titlecase
259 user = users(:suspended_user)
261 try_password_login user.display_name.titlecase, "test"
263 assert_template "login"
264 assert_select "span.username", false
265 assert_select "div.flash.error", /your account has been suspended/
268 def test_login_username_password_blocked
269 user = users(:blocked_user)
271 try_password_login user.display_name.upcase, "test"
273 assert_template "user_blocks/show"
274 assert_select "span.username", "blocked"
277 def test_login_username_password_blocked_upcase
278 user = users(:blocked_user)
280 try_password_login user.display_name, "test"
282 assert_template "user_blocks/show"
283 assert_select "span.username", "blocked"
286 def test_login_username_password_blocked_titlecase
287 user = users(:blocked_user)
289 try_password_login user.display_name.titlecase, "test"
291 assert_template "user_blocks/show"
292 assert_select "span.username", "blocked"
295 def test_login_email_password_remember_me
296 user = users(:normal_user)
298 try_password_login user.email, "test", "yes"
300 assert_template "changeset/history"
301 assert_select "span.username", "test"
302 assert session.key?(:_remember_for)
305 def test_login_username_password_remember_me
306 user = users(:normal_user)
308 try_password_login user.display_name, "test", "yes"
310 assert_template "changeset/history"
311 assert_select "span.username", "test"
312 assert session.key?(:_remember_for)
315 def test_login_openid_success
316 OmniAuth.config.add_mock(:openid, :uid => "http://localhost:1123/john.doe")
318 get "/login", :referer => "/history"
319 assert_response :redirect
320 assert_redirected_to :controller => :user, :action => :login, :cookie_test => true, :referer => "/history"
322 assert_response :success
323 assert_template "user/login"
324 post "/login", :openid_url => "http://localhost:1123/john.doe", :referer => "/history"
325 assert_response :redirect
326 assert_redirected_to auth_path(:provider => "openid", :openid_url => "http://localhost:1123/john.doe", :origin => "/login?referer=%2Fhistory", :referer => "/history")
328 assert_response :redirect
329 assert_redirected_to auth_success_path(:provider => "openid", :openid_url => "http://localhost:1123/john.doe", :origin => "/login?referer=%2Fhistory", :referer => "/history")
331 assert_response :redirect
333 assert_response :success
334 assert_template "changeset/history"
335 assert_select "span.username", "openIDuser"
338 def test_login_openid_remember_me
339 OmniAuth.config.add_mock(:openid, :uid => "http://localhost:1123/john.doe")
341 get "/login", :referer => "/history"
342 assert_response :redirect
343 assert_redirected_to :controller => :user, :action => :login, :cookie_test => true, :referer => "/history"
345 assert_response :success
346 assert_template "user/login"
347 post "/login", :openid_url => "http://localhost:1123/john.doe", :remember_me_openid => true, :referer => "/history"
348 assert_response :redirect
349 assert_redirected_to auth_path(:provider => "openid", :openid_url => "http://localhost:1123/john.doe", :origin => "/login?referer=%2Fhistory", :referer => "/history")
351 assert_response :redirect
352 assert_redirected_to auth_success_path(:provider => "openid", :openid_url => "http://localhost:1123/john.doe", :origin => "/login?referer=%2Fhistory", :referer => "/history")
354 assert_response :redirect
356 assert_response :success
357 assert_template "changeset/history"
358 assert_select "span.username", "openIDuser"
359 assert session.key?(:_remember_for)
362 def test_login_openid_connection_failed
363 OmniAuth.config.mock_auth[:openid] = :connection_failed
365 get "/login", :referer => "/history"
366 assert_response :redirect
367 assert_redirected_to :controller => :user, :action => :login, :cookie_test => true, :referer => "/history"
369 assert_response :success
370 assert_template "user/login"
371 post "/login", :openid_url => "http://localhost:1123/john.doe", :referer => "/history"
372 assert_response :redirect
373 assert_redirected_to auth_path(:provider => "openid", :openid_url => "http://localhost:1123/john.doe", :origin => "/login?referer=%2Fhistory", :referer => "/history")
375 assert_response :redirect
376 assert_redirected_to auth_success_path(:provider => "openid", :openid_url => "http://localhost:1123/john.doe", :origin => "/login?referer=%2Fhistory", :referer => "/history")
378 assert_response :redirect
379 assert_redirected_to auth_failure_path(:strategy => "openid", :message => "connection_failed", :origin => "/login?referer=%2Fhistory")
381 assert_response :redirect
383 assert_response :success
384 assert_template "login"
385 assert_select "div.flash.error", "Connection to authentication provider failed"
386 assert_select "span.username", false
389 def test_login_openid_invalid_credentials
390 OmniAuth.config.mock_auth[:openid] = :invalid_credentials
392 get "/login", :referer => "/history"
393 assert_response :redirect
394 assert_redirected_to :controller => :user, :action => :login, :cookie_test => true, :referer => "/history"
396 assert_response :success
397 assert_template "user/login"
398 post "/login", :openid_url => "http://localhost:1123/john.doe", :referer => "/history"
399 assert_response :redirect
400 assert_redirected_to auth_path(:provider => "openid", :openid_url => "http://localhost:1123/john.doe", :origin => "/login?referer=%2Fhistory", :referer => "/history")
402 assert_response :redirect
403 assert_redirected_to auth_success_path(:provider => "openid", :openid_url => "http://localhost:1123/john.doe", :origin => "/login?referer=%2Fhistory", :referer => "/history")
405 assert_response :redirect
406 assert_redirected_to auth_failure_path(:strategy => "openid", :message => "invalid_credentials", :origin => "/login?referer=%2Fhistory")
408 assert_response :redirect
410 assert_response :success
411 assert_template "login"
412 assert_select "div.flash.error", "Invalid authentication credentials"
413 assert_select "span.username", false
416 def test_login_openid_unknown
417 OmniAuth.config.add_mock(:openid, :uid => "http://localhost:1123/fred.bloggs")
419 get "/login", :referer => "/history"
420 assert_response :redirect
421 assert_redirected_to :controller => :user, :action => :login, :cookie_test => true, :referer => "/history"
423 assert_response :success
424 assert_template "user/login"
425 post "/login", :openid_url => "http://localhost:1123/fred.bloggs", :referer => "/history"
426 assert_response :redirect
427 assert_redirected_to auth_path(:provider => "openid", :openid_url => "http://localhost:1123/fred.bloggs", :origin => "/login?referer=%2Fhistory", :referer => "/history")
429 assert_response :redirect
430 assert_redirected_to auth_success_path(:provider => "openid", :openid_url => "http://localhost:1123/fred.bloggs", :origin => "/login?referer=%2Fhistory", :referer => "/history")
432 assert_response :redirect
434 assert_response :success
435 assert_template "user/new"
436 assert_select "span.username", false
439 def test_login_google_success
440 OmniAuth.config.add_mock(:google, :uid => "123456789", :extra => {
441 :id_info => { "openid_id" => "http://localhost:1123/fred.bloggs" }
444 get "/login", :referer => "/history"
445 assert_response :redirect
446 assert_redirected_to "controller" => "user", "action" => "login", "cookie_test" => "true", "referer" => "/history"
448 assert_response :success
449 assert_template "user/login"
450 get auth_path(:provider => "google", :origin => "/login?referer=%2Fhistory", :referer => "/history")
451 assert_response :redirect
452 assert_redirected_to auth_success_path(:provider => "google")
454 assert_response :redirect
456 assert_response :success
457 assert_template "changeset/history"
458 assert_select "span.username", "googleuser"
461 def test_login_google_connection_failed
462 OmniAuth.config.mock_auth[:google] = :connection_failed
464 get "/login", :referer => "/history"
465 assert_response :redirect
466 assert_redirected_to "controller" => "user", "action" => "login", "cookie_test" => "true", "referer" => "/history"
468 assert_response :success
469 assert_template "user/login"
470 get auth_path(:provider => "google", :origin => "/login?referer=%2Fhistory", :referer => "/history")
471 assert_response :redirect
472 assert_redirected_to auth_success_path(:provider => "google")
474 assert_response :redirect
475 assert_redirected_to auth_failure_path(:strategy => "google", :message => "connection_failed", :origin => "/login?referer=%2Fhistory")
477 assert_response :redirect
479 assert_response :success
480 assert_template "login"
481 assert_select "div.flash.error", "Connection to authentication provider failed"
482 assert_select "span.username", false
485 def test_login_google_invalid_credentials
486 OmniAuth.config.mock_auth[:google] = :invalid_credentials
488 get "/login", :referer => "/history"
489 assert_response :redirect
490 assert_redirected_to "controller" => "user", "action" => "login", "cookie_test" => "true", "referer" => "/history"
492 assert_response :success
493 assert_template "user/login"
494 get auth_path(:provider => "google", :origin => "/login?referer=%2Fhistory", :referer => "/history")
495 assert_response :redirect
496 assert_redirected_to auth_success_path(:provider => "google")
498 assert_response :redirect
499 assert_redirected_to auth_failure_path(:strategy => "google", :message => "invalid_credentials", :origin => "/login?referer=%2Fhistory")
501 assert_response :redirect
503 assert_response :success
504 assert_template "login"
505 assert_select "div.flash.error", "Invalid authentication credentials"
506 assert_select "span.username", false
509 def test_login_google_unknown
510 OmniAuth.config.add_mock(:google, :uid => "987654321", :extra => {
511 :id_info => { "openid_id" => "http://localhost:1123/fred.bloggs" }
514 get "/login", :referer => "/history"
515 assert_response :redirect
516 assert_redirected_to "controller" => "user", "action" => "login", "cookie_test" => "true", "referer" => "/history"
518 assert_response :success
519 assert_template "user/login"
520 get auth_path(:provider => "google", :origin => "/login?referer=%2Fhistory", :referer => "/history")
521 assert_response :redirect
522 assert_redirected_to auth_success_path(:provider => "google")
524 assert_response :redirect
526 assert_response :success
527 assert_template "user/new"
528 assert_select "span.username", false
531 def test_login_google_upgrade
532 OmniAuth.config.add_mock(:google, :uid => "987654321", :extra => {
533 :id_info => { "openid_id" => "http://localhost:1123/john.doe" }
536 get "/login", :referer => "/history"
537 assert_response :redirect
538 assert_redirected_to "controller" => "user", "action" => "login", "cookie_test" => "true", "referer" => "/history"
540 assert_response :success
541 assert_template "user/login"
542 get auth_path(:provider => "google", :origin => "/login?referer=%2Fhistory", :referer => "/history")
543 assert_response :redirect
544 assert_redirected_to auth_success_path(:provider => "google")
546 assert_response :redirect
548 assert_response :success
549 assert_template "changeset/history"
550 assert_select "span.username", "openIDuser"
552 user = User.find_by_display_name("openIDuser")
553 assert_equal "google", user.auth_provider
554 assert_equal "987654321", user.auth_uid
557 def test_login_facebook_success
558 OmniAuth.config.add_mock(:facebook, :uid => "123456789")
560 get "/login", :referer => "/history"
561 assert_response :redirect
562 assert_redirected_to "controller" => "user", "action" => "login", "cookie_test" => "true", "referer" => "/history"
564 assert_response :success
565 assert_template "user/login"
566 get auth_path(:provider => "facebook", :origin => "/login?referer=%2Fhistory", :referer => "/history")
567 assert_response :redirect
568 assert_redirected_to auth_success_path(:provider => "facebook")
570 assert_response :redirect
572 assert_response :success
573 assert_template "changeset/history"
574 assert_select "span.username", "facebookuser"
577 def test_login_facebook_connection_failed
578 OmniAuth.config.mock_auth[:facebook] = :connection_failed
580 get "/login", :referer => "/history"
581 assert_response :redirect
582 assert_redirected_to "controller" => "user", "action" => "login", "cookie_test" => "true", "referer" => "/history"
584 assert_response :success
585 assert_template "user/login"
586 get auth_path(:provider => "facebook", :origin => "/login?referer=%2Fhistory", :referer => "/history")
587 assert_response :redirect
588 assert_redirected_to auth_success_path(:provider => "facebook")
590 assert_response :redirect
591 assert_redirected_to auth_failure_path(:strategy => "facebook", :message => "connection_failed", :origin => "/login?referer=%2Fhistory")
593 assert_response :redirect
595 assert_response :success
596 assert_template "login"
597 assert_select "div.flash.error", "Connection to authentication provider failed"
598 assert_select "span.username", false
601 def test_login_facebook_invalid_credentials
602 OmniAuth.config.mock_auth[:facebook] = :invalid_credentials
604 get "/login", :referer => "/history"
605 assert_response :redirect
606 assert_redirected_to "controller" => "user", "action" => "login", "cookie_test" => "true", "referer" => "/history"
608 assert_response :success
609 assert_template "user/login"
610 get auth_path(:provider => "facebook", :origin => "/login?referer=%2Fhistory", :referer => "/history")
611 assert_response :redirect
612 assert_redirected_to auth_success_path(:provider => "facebook")
614 assert_response :redirect
615 assert_redirected_to auth_failure_path(:strategy => "facebook", :message => "invalid_credentials", :origin => "/login?referer=%2Fhistory")
617 assert_response :redirect
619 assert_response :success
620 assert_template "login"
621 assert_select "div.flash.error", "Invalid authentication credentials"
622 assert_select "span.username", false
625 def test_login_facebook_unknown
626 OmniAuth.config.add_mock(:facebook, :uid => "987654321")
628 get "/login", :referer => "/history"
629 assert_response :redirect
630 assert_redirected_to "controller" => "user", "action" => "login", "cookie_test" => "true", "referer" => "/history"
632 assert_response :success
633 assert_template "user/login"
634 get auth_path(:provider => "facebook", :origin => "/login?referer=%2Fhistory", :referer => "/history")
635 assert_response :redirect
636 assert_redirected_to auth_success_path(:provider => "facebook")
638 assert_response :redirect
640 assert_response :success
641 assert_template "user/new"
642 assert_select "span.username", false
645 def test_login_windowslive_success
646 OmniAuth.config.add_mock(:windowslive, :uid => "123456789")
648 get "/login", :referer => "/history"
649 assert_response :redirect
650 assert_redirected_to "controller" => "user", "action" => "login", "cookie_test" => "true", "referer" => "/history"
652 assert_response :success
653 assert_template "user/login"
654 get auth_path(:provider => "windowslive", :origin => "/login?referer=%2Fhistory", :referer => "/history")
655 assert_response :redirect
656 assert_redirected_to auth_success_path(:provider => "windowslive", :origin => "/login?referer=%2Fhistory", :referer => "/history")
658 assert_response :redirect
660 assert_response :success
661 assert_template "changeset/history"
662 assert_select "span.username", "windowsliveuser"
665 def test_login_windowslive_connection_failed
666 OmniAuth.config.mock_auth[:windowslive] = :connection_failed
668 get "/login", :referer => "/history"
669 assert_response :redirect
670 assert_redirected_to "controller" => "user", "action" => "login", "cookie_test" => "true", "referer" => "/history"
672 assert_response :success
673 assert_template "user/login"
674 get auth_path(:provider => "windowslive", :origin => "/login?referer=%2Fhistory", :referer => "/history")
675 assert_response :redirect
676 assert_redirected_to auth_success_path(:provider => "windowslive", :origin => "/login?referer=%2Fhistory", :referer => "/history")
678 assert_response :redirect
679 assert_redirected_to auth_failure_path(:strategy => "windowslive", :message => "connection_failed", :origin => "/login?referer=%2Fhistory")
681 assert_response :redirect
683 assert_response :success
684 assert_template "login"
685 assert_select "div.flash.error", "Connection to authentication provider failed"
686 assert_select "span.username", false
689 def test_login_windowslive_invalid_credentials
690 OmniAuth.config.mock_auth[:windowslive] = :invalid_credentials
692 get "/login", :referer => "/history"
693 assert_response :redirect
694 assert_redirected_to "controller" => "user", "action" => "login", "cookie_test" => "true", "referer" => "/history"
696 assert_response :success
697 assert_template "user/login"
698 get auth_path(:provider => "windowslive", :origin => "/login?referer=%2Fhistory", :referer => "/history")
699 assert_response :redirect
700 assert_redirected_to auth_success_path(:provider => "windowslive", :origin => "/login?referer=%2Fhistory", :referer => "/history")
702 assert_response :redirect
703 assert_redirected_to auth_failure_path(:strategy => "windowslive", :message => "invalid_credentials", :origin => "/login?referer=%2Fhistory")
705 assert_response :redirect
707 assert_response :success
708 assert_template "login"
709 assert_select "div.flash.error", "Invalid authentication credentials"
710 assert_select "span.username", false
713 def test_login_windowslive_unknown
714 OmniAuth.config.add_mock(:windowslive, :uid => "987654321")
716 get "/login", :referer => "/history"
717 assert_response :redirect
718 assert_redirected_to "controller" => "user", "action" => "login", "cookie_test" => "true", "referer" => "/history"
720 assert_response :success
721 assert_template "user/login"
722 get auth_path(:provider => "windowslive", :origin => "/login?referer=%2Fhistory", :referer => "/history")
723 assert_response :redirect
724 assert_redirected_to auth_success_path(:provider => "windowslive", :origin => "/login?referer=%2Fhistory", :referer => "/history")
726 assert_response :redirect
728 assert_response :success
729 assert_template "user/new"
730 assert_select "span.username", false
733 def test_login_github_success
734 OmniAuth.config.add_mock(:github, :uid => "123456789")
736 get "/login", :referer => "/history"
737 assert_response :redirect
738 assert_redirected_to "controller" => "user", "action" => "login", "cookie_test" => "true", "referer" => "/history"
740 assert_response :success
741 assert_template "user/login"
742 get auth_path(:provider => "github", :origin => "/login?referer=%2Fhistory", :referer => "/history")
743 assert_response :redirect
744 assert_redirected_to auth_success_path(:provider => "github", :origin => "/login?referer=%2Fhistory", :referer => "/history")
746 assert_response :redirect
748 assert_response :success
749 assert_template "changeset/history"
750 assert_select "span.username", "githubuser"
753 def test_login_github_connection_failed
754 OmniAuth.config.mock_auth[:github] = :connection_failed
756 get "/login", :referer => "/history"
757 assert_response :redirect
758 assert_redirected_to "controller" => "user", "action" => "login", "cookie_test" => "true", "referer" => "/history"
760 assert_response :success
761 assert_template "user/login"
762 get auth_path(:provider => "github", :origin => "/login?referer=%2Fhistory", :referer => "/history")
763 assert_response :redirect
764 assert_redirected_to auth_success_path(:provider => "github", :origin => "/login?referer=%2Fhistory", :referer => "/history")
766 assert_response :redirect
767 assert_redirected_to auth_failure_path(:strategy => "github", :message => "connection_failed", :origin => "/login?referer=%2Fhistory")
769 assert_response :redirect
771 assert_response :success
772 assert_template "login"
773 assert_select "div.flash.error", "Connection to authentication provider failed"
774 assert_select "span.username", false
777 def test_login_github_invalid_credentials
778 OmniAuth.config.mock_auth[:github] = :invalid_credentials
780 get "/login", :referer => "/history"
781 assert_response :redirect
782 assert_redirected_to "controller" => "user", "action" => "login", "cookie_test" => "true", "referer" => "/history"
784 assert_response :success
785 assert_template "user/login"
786 get auth_path(:provider => "github", :origin => "/login?referer=%2Fhistory", :referer => "/history")
787 assert_response :redirect
788 assert_redirected_to auth_success_path(:provider => "github", :origin => "/login?referer=%2Fhistory", :referer => "/history")
790 assert_response :redirect
791 assert_redirected_to auth_failure_path(:strategy => "github", :message => "invalid_credentials", :origin => "/login?referer=%2Fhistory")
793 assert_response :redirect
795 assert_response :success
796 assert_template "login"
797 assert_select "div.flash.error", "Invalid authentication credentials"
798 assert_select "span.username", false
801 def test_login_github_unknown
802 OmniAuth.config.add_mock(:github, :uid => "987654321")
804 get "/login", :referer => "/history"
805 assert_response :redirect
806 assert_redirected_to "controller" => "user", "action" => "login", "cookie_test" => "true", "referer" => "/history"
808 assert_response :success
809 assert_template "user/login"
810 get auth_path(:provider => "github", :origin => "/login?referer=%2Fhistory", :referer => "/history")
811 assert_response :redirect
812 assert_redirected_to auth_success_path(:provider => "github", :origin => "/login?referer=%2Fhistory", :referer => "/history")
814 assert_response :redirect
816 assert_response :success
817 assert_template "user/new"
818 assert_select "span.username", false
823 def try_password_login(username, password, remember_me = nil)
825 assert_response :redirect
826 assert_redirected_to :controller => :user, :action => :login, :cookie_test => true
828 assert_response :success
829 assert_template "login"
830 assert_select "input#username", 1 do
831 assert_select "[value]", false
833 assert_select "input#password", 1 do
834 assert_select "[value=?]", ""
836 assert_select "input#remember_me", 1 do
837 assert_select "[checked]", false
840 post "/login", :username => username, :password => "wrong", :remember_me => remember_me, :referer => "/history"
841 assert_response :redirect
843 assert_response :success
844 assert_template "login"
845 assert_select "input#username", 1 do
846 assert_select "[value=?]", username
848 assert_select "input#password", 1 do
849 assert_select "[value=?]", ""
851 assert_select "input#remember_me", 1 do
852 assert_select "[checked]", remember_me == "yes"
855 post "/login", :username => username, :password => password, :remember_me => remember_me, :referer => "/history"
856 assert_response :redirect
858 assert_response :success