1 require File.dirname(__FILE__) + '/../test_helper'
3 class UserLoginTest < ActionController::IntegrationTest
10 def test_login_password_success
11 user = users(:normal_user)
14 assert_response :redirect
15 assert_redirected_to "controller" => "user", "action" => "login", "cookie_test" => "true"
17 assert_response :success
18 post '/login', {'username' => user.email, 'password' => "test", :referer => "/browse"}
19 assert_response :redirect
21 assert_response :success
22 assert_template 'changeset/list'
25 def test_login_password_fail
26 user = users(:normal_user)
29 assert_response :redirect
30 assert_redirected_to "controller" => "user", "action" => "login", "cookie_test" => "true"
32 assert_response :success
33 post '/login', {'username' => user.email, 'password' => "wrong", :referer => "/browse"}
34 assert_response :redirect
36 assert_response :success
37 assert_template 'login'
40 def test_login_openid_success
42 assert_response :redirect
43 assert_redirected_to "controller" => "user", "action" => "login", "cookie_test" => "true"
45 assert_response :success
46 post '/login', {'openid_url' => "http://localhost:1123/john.doe?openid.success=true", :referer => "/browse"}
47 assert_response :redirect
49 res = openid_request(@response.redirect_url)
50 res2 = post '/login', res
52 assert_response :redirect
54 assert_response :success
55 assert_template 'changeset/list'
58 def test_login_openid_cancel
60 assert_response :redirect
61 assert_redirected_to "controller" => "user", "action" => "login", "cookie_test" => "true"
63 assert_response :success
64 post '/login', {'openid_url' => "http://localhost:1123/john.doe", :referer => "/diary"}
65 assert_response :redirect
67 res = openid_request(@response.redirect_url)
70 assert_response :redirect
72 assert_response :success
73 assert_template 'login'
76 def test_login_openid_invalid_provider
78 assert_response :redirect
79 assert_redirected_to "controller" => "user", "action" => "login", "cookie_test" => "true"
81 assert_response :success
82 #Use a different port that doesn't have the OpenID provider running on to test an invalid openID
83 post '/login', {'openid_url' => "http://localhost:1124/john.doe", :referer => "/diary"}
84 assert_response :redirect
86 assert_response :success
87 assert_template 'login'
90 def test_login_openid_invalid_url
92 assert_response :redirect
93 assert_redirected_to "controller" => "user", "action" => "login", "cookie_test" => "true"
95 assert_response :success
96 #Use a url with an invalid protocol to make sure it handles that correctly too
97 post '/login', {'openid_url' => "htt://localhost:1123/john.doe", :referer => "/diary"}
98 assert_response :redirect
100 assert_response :success
101 assert_template 'login'
104 def test_login_openid_unknown
106 assert_response :redirect
107 assert_redirected_to "controller" => "user", "action" => "login", "cookie_test" => "true"
109 assert_response :success
110 post '/login', {'openid_url' => "http://localhost:1123/john.doe?openid.success=true_somethingelse", :referer => "/diary"}
111 assert_response :redirect
113 res = openid_request(@response.redirect_url)
114 res2 = post '/login', res
116 assert_response :redirect
118 assert_response :success
119 assert_template 'user/new'