1 require File.dirname(__FILE__) + '/../test_helper'
3 class UserLoginTest < ActionDispatch::IntegrationTest
10 def test_login_email_password_normal
11 user = users(:normal_user)
14 assert_response :redirect
15 assert_redirected_to "controller" => "user", "action" => "login", "cookie_test" => "true"
17 assert_response :success
19 post '/login', {'username' => user.email, 'password' => "wrong", :referer => "/history"}
20 assert_response :redirect
22 assert_response :success
23 assert_template 'login'
25 post '/login', {'username' => user.email, 'password' => "test", :referer => "/history"}
26 assert_response :redirect
28 assert_response :success
29 assert_template 'changeset/history'
32 def test_login_email_password_normal_upcase
33 user = users(:normal_user)
36 assert_response :redirect
37 assert_redirected_to "controller" => "user", "action" => "login", "cookie_test" => "true"
39 assert_response :success
41 post '/login', {'username' => user.email.upcase, 'password' => "wrong", :referer => "/history"}
42 assert_response :redirect
44 assert_response :success
45 assert_template 'login'
47 post '/login', {'username' => user.email.upcase, 'password' => "test", :referer => "/history"}
48 assert_response :redirect
50 assert_response :success
51 assert_template 'login'
54 def test_login_email_password_normal_titlecase
55 user = users(:normal_user)
58 assert_response :redirect
59 assert_redirected_to "controller" => "user", "action" => "login", "cookie_test" => "true"
61 assert_response :success
63 post '/login', {'username' => user.email.titlecase, 'password' => "wrong", :referer => "/history"}
64 assert_response :redirect
66 assert_response :success
67 assert_template 'login'
69 post '/login', {'username' => user.email.titlecase, 'password' => "test", :referer => "/history"}
70 assert_response :redirect
72 assert_response :success
73 assert_template 'login'
76 def test_login_email_password_public
77 user = users(:public_user)
80 assert_response :redirect
81 assert_redirected_to "controller" => "user", "action" => "login", "cookie_test" => "true"
83 assert_response :success
85 post '/login', {'username' => user.email, 'password' => "wrong", :referer => "/history"}
86 assert_response :redirect
88 assert_response :success
89 assert_template 'login'
91 post '/login', {'username' => user.email, 'password' => "test", :referer => "/history"}
92 assert_response :redirect
94 assert_response :success
95 assert_template 'changeset/history'
98 def test_login_email_password_public_upcase
99 user = users(:public_user)
102 assert_response :redirect
103 assert_redirected_to "controller" => "user", "action" => "login", "cookie_test" => "true"
105 assert_response :success
107 post '/login', {'username' => user.email.upcase, 'password' => "wrong", :referer => "/history"}
108 assert_response :redirect
110 assert_response :success
111 assert_template 'login'
113 post '/login', {'username' => user.email.upcase, 'password' => "test", :referer => "/history"}
114 assert_response :redirect
116 assert_response :success
117 assert_template 'changeset/history'
120 def test_login_email_password_public_titlecase
121 user = users(:public_user)
124 assert_response :redirect
125 assert_redirected_to "controller" => "user", "action" => "login", "cookie_test" => "true"
127 assert_response :success
129 post '/login', {'username' => user.email.titlecase, 'password' => "wrong", :referer => "/history"}
130 assert_response :redirect
132 assert_response :success
133 assert_template 'login'
135 post '/login', {'username' => user.email.titlecase, 'password' => "test", :referer => "/history"}
136 assert_response :redirect
138 assert_response :success
139 assert_template 'changeset/history'
142 def test_login_username_password_normal
143 user = users(:normal_user)
146 assert_response :redirect
147 assert_redirected_to "controller" => "user", "action" => "login", "cookie_test" => "true"
149 assert_response :success
151 post '/login', {'username' => user.display_name, 'password' => "wrong", :referer => "/history"}
152 assert_response :redirect
154 assert_response :success
155 assert_template 'login'
157 post '/login', {'username' => user.display_name, 'password' => "test", :referer => "/history"}
158 assert_response :redirect
160 assert_response :success
161 assert_template 'changeset/history'
164 def test_login_username_password_normal_upcase
165 user = users(:normal_user)
168 assert_response :redirect
169 assert_redirected_to "controller" => "user", "action" => "login", "cookie_test" => "true"
171 assert_response :success
173 post '/login', {'username' => user.display_name.upcase, 'password' => "wrong", :referer => "/history"}
174 assert_response :redirect
176 assert_response :success
177 assert_template 'login'
179 post '/login', {'username' => user.display_name.upcase, 'password' => "test", :referer => "/history"}
180 assert_response :redirect
182 assert_response :success
183 assert_template 'login'
186 def test_login_username_password_normal_titlecase
187 user = users(:normal_user)
190 assert_response :redirect
191 assert_redirected_to "controller" => "user", "action" => "login", "cookie_test" => "true"
193 assert_response :success
195 post '/login', {'username' => user.display_name.titlecase, 'password' => "wrong", :referer => "/history"}
196 assert_response :redirect
198 assert_response :success
199 assert_template 'login'
201 post '/login', {'username' => user.display_name.titlecase, 'password' => "test", :referer => "/history"}
202 assert_response :redirect
204 assert_response :success
205 assert_template 'login'
208 def test_login_username_password_public
209 user = users(:public_user)
212 assert_response :redirect
213 assert_redirected_to "controller" => "user", "action" => "login", "cookie_test" => "true"
215 assert_response :success
217 post '/login', {'username' => user.display_name, 'password' => "wrong", :referer => "/history"}
218 assert_response :redirect
220 assert_response :success
221 assert_template 'login'
223 post '/login', {'username' => user.display_name, 'password' => "test", :referer => "/history"}
224 assert_response :redirect
226 assert_response :success
227 assert_template 'changeset/history'
230 def test_login_username_password_public_upcase
231 user = users(:public_user)
234 assert_response :redirect
235 assert_redirected_to "controller" => "user", "action" => "login", "cookie_test" => "true"
237 assert_response :success
239 post '/login', {'username' => user.display_name.upcase, 'password' => "wrong", :referer => "/history"}
240 assert_response :redirect
242 assert_response :success
243 assert_template 'login'
245 post '/login', {'username' => user.display_name.upcase, 'password' => "test", :referer => "/history"}
246 assert_response :redirect
248 assert_response :success
249 assert_template 'changeset/history'
252 def test_login_username_password_public_titlecase
253 user = users(:public_user)
256 assert_response :redirect
257 assert_redirected_to "controller" => "user", "action" => "login", "cookie_test" => "true"
259 assert_response :success
261 post '/login', {'username' => user.display_name.titlecase, 'password' => "wrong", :referer => "/history"}
262 assert_response :redirect
264 assert_response :success
265 assert_template 'login'
267 post '/login', {'username' => user.display_name.titlecase, 'password' => "test", :referer => "/history"}
268 assert_response :redirect
270 assert_response :success
271 assert_template 'changeset/history'
274 def test_login_openid_success
276 assert_response :redirect
277 assert_redirected_to "controller" => "user", "action" => "login", "cookie_test" => "true"
279 assert_response :success
280 post '/login', {'openid_url' => "http://localhost:1123/john.doe?openid.success=true", :referer => "/history"}
281 assert_response :redirect
283 res = openid_request(@response.redirect_url)
284 res2 = post '/login', res
286 assert_response :redirect
288 assert_response :success
289 assert_template 'changeset/history'
292 def test_login_openid_cancel
294 assert_response :redirect
295 assert_redirected_to "controller" => "user", "action" => "login", "cookie_test" => "true"
297 assert_response :success
298 post '/login', {'openid_url' => "http://localhost:1123/john.doe", :referer => "/diary"}
299 assert_response :redirect
301 res = openid_request(@response.redirect_url)
304 assert_response :redirect
306 assert_response :success
307 assert_template 'login'
310 def test_login_openid_invalid_provider
312 assert_response :redirect
313 assert_redirected_to "controller" => "user", "action" => "login", "cookie_test" => "true"
315 assert_response :success
316 #Use a different port that doesn't have the OpenID provider running on to test an invalid openID
317 post '/login', {'openid_url' => "http://localhost:1124/john.doe", :referer => "/diary"}
318 assert_response :redirect
320 assert_response :success
321 assert_template 'login'
324 def test_login_openid_invalid_url
326 assert_response :redirect
327 assert_redirected_to "controller" => "user", "action" => "login", "cookie_test" => "true"
329 assert_response :success
330 #Use a url with an invalid protocol to make sure it handles that correctly too
331 post '/login', {'openid_url' => "htt://localhost:1123/john.doe", :referer => "/diary"}
332 assert_response :redirect
334 assert_response :success
335 assert_template 'login'
338 def test_login_openid_unknown
340 assert_response :redirect
341 assert_redirected_to "controller" => "user", "action" => "login", "cookie_test" => "true"
343 assert_response :success
344 post '/login', {'openid_url' => "http://localhost:1123/john.doe?openid.success=true_somethingelse", :referer => "/diary"}
345 assert_response :redirect
347 res = openid_request(@response.redirect_url)
348 res2 = post '/login', res
350 assert_response :redirect
352 assert_response :success
353 assert_template 'user/new'