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'
30 assert_select "span.username", "test"
33 def test_login_email_password_normal_upcase
34 user = users(:normal_user)
37 assert_response :redirect
38 assert_redirected_to "controller" => "user", "action" => "login", "cookie_test" => "true"
40 assert_response :success
42 post '/login', 'username' => user.email.upcase, 'password' => "wrong", :referer => "/history"
43 assert_response :redirect
45 assert_response :success
46 assert_template 'login'
48 post '/login', 'username' => user.email.upcase, 'password' => "test", :referer => "/history"
49 assert_response :redirect
51 assert_response :success
52 assert_template 'changeset/history'
53 assert_select "span.username", "TEST"
56 def test_login_email_password_normal_titlecase
57 user = users(:normal_user)
60 assert_response :redirect
61 assert_redirected_to "controller" => "user", "action" => "login", "cookie_test" => "true"
63 assert_response :success
65 post '/login', 'username' => user.email.titlecase, 'password' => "wrong", :referer => "/history"
66 assert_response :redirect
68 assert_response :success
69 assert_template 'login'
71 post '/login', 'username' => user.email.titlecase, 'password' => "test", :referer => "/history"
72 assert_response :redirect
74 assert_response :success
75 assert_template 'login'
76 assert_select "span.username", false
79 def test_login_email_password_public
80 user = users(:public_user)
83 assert_response :redirect
84 assert_redirected_to "controller" => "user", "action" => "login", "cookie_test" => "true"
86 assert_response :success
88 post '/login', 'username' => user.email, 'password' => "wrong", :referer => "/history"
89 assert_response :redirect
91 assert_response :success
92 assert_template 'login'
94 post '/login', 'username' => user.email, 'password' => "test", :referer => "/history"
95 assert_response :redirect
97 assert_response :success
98 assert_template 'changeset/history'
99 assert_select "span.username", "test2"
102 def test_login_email_password_public_upcase
103 user = users(:public_user)
106 assert_response :redirect
107 assert_redirected_to "controller" => "user", "action" => "login", "cookie_test" => "true"
109 assert_response :success
111 post '/login', 'username' => user.email.upcase, 'password' => "wrong", :referer => "/history"
112 assert_response :redirect
114 assert_response :success
115 assert_template 'login'
117 post '/login', 'username' => user.email.upcase, 'password' => "test", :referer => "/history"
118 assert_response :redirect
120 assert_response :success
121 assert_template 'changeset/history'
122 assert_select "span.username", "test2"
125 def test_login_email_password_public_titlecase
126 user = users(:public_user)
129 assert_response :redirect
130 assert_redirected_to "controller" => "user", "action" => "login", "cookie_test" => "true"
132 assert_response :success
134 post '/login', 'username' => user.email.titlecase, 'password' => "wrong", :referer => "/history"
135 assert_response :redirect
137 assert_response :success
138 assert_template 'login'
140 post '/login', 'username' => user.email.titlecase, 'password' => "test", :referer => "/history"
141 assert_response :redirect
143 assert_response :success
144 assert_template 'changeset/history'
145 assert_select "span.username", "test2"
148 def test_login_username_password_normal
149 user = users(:normal_user)
152 assert_response :redirect
153 assert_redirected_to "controller" => "user", "action" => "login", "cookie_test" => "true"
155 assert_response :success
157 post '/login', 'username' => user.display_name, 'password' => "wrong", :referer => "/history"
158 assert_response :redirect
160 assert_response :success
161 assert_template 'login'
163 post '/login', 'username' => user.display_name, 'password' => "test", :referer => "/history"
164 assert_response :redirect
166 assert_response :success
167 assert_template 'changeset/history'
168 assert_select "span.username", "test"
171 def test_login_username_password_normal_upcase
172 user = users(:normal_user)
175 assert_response :redirect
176 assert_redirected_to "controller" => "user", "action" => "login", "cookie_test" => "true"
178 assert_response :success
180 post '/login', 'username' => user.display_name.upcase, 'password' => "wrong", :referer => "/history"
181 assert_response :redirect
183 assert_response :success
184 assert_template 'login'
186 post '/login', 'username' => user.display_name.upcase, 'password' => "test", :referer => "/history"
187 assert_response :redirect
189 assert_response :success
190 assert_template 'changeset/history'
191 assert_select "span.username", "TEST"
194 def test_login_username_password_normal_titlecase
195 user = users(:normal_user)
198 assert_response :redirect
199 assert_redirected_to "controller" => "user", "action" => "login", "cookie_test" => "true"
201 assert_response :success
203 post '/login', 'username' => user.display_name.titlecase, 'password' => "wrong", :referer => "/history"
204 assert_response :redirect
206 assert_response :success
207 assert_template 'login'
209 post '/login', 'username' => user.display_name.titlecase, 'password' => "test", :referer => "/history"
210 assert_response :redirect
212 assert_response :success
213 assert_template 'login'
214 assert_select "span.username", false
217 def test_login_username_password_public
218 user = users(:public_user)
221 assert_response :redirect
222 assert_redirected_to "controller" => "user", "action" => "login", "cookie_test" => "true"
224 assert_response :success
226 post '/login', 'username' => user.display_name, 'password' => "wrong", :referer => "/history"
227 assert_response :redirect
229 assert_response :success
230 assert_template 'login'
232 post '/login', 'username' => user.display_name, 'password' => "test", :referer => "/history"
233 assert_response :redirect
235 assert_response :success
236 assert_template 'changeset/history'
237 assert_select "span.username", "test2"
240 def test_login_username_password_public_upcase
241 user = users(:public_user)
244 assert_response :redirect
245 assert_redirected_to "controller" => "user", "action" => "login", "cookie_test" => "true"
247 assert_response :success
249 post '/login', 'username' => user.display_name.upcase, 'password' => "wrong", :referer => "/history"
250 assert_response :redirect
252 assert_response :success
253 assert_template 'login'
255 post '/login', 'username' => user.display_name.upcase, 'password' => "test", :referer => "/history"
256 assert_response :redirect
258 assert_response :success
259 assert_template 'changeset/history'
260 assert_select "span.username", "test2"
263 def test_login_username_password_public_titlecase
264 user = users(:public_user)
267 assert_response :redirect
268 assert_redirected_to "controller" => "user", "action" => "login", "cookie_test" => "true"
270 assert_response :success
272 post '/login', 'username' => user.display_name.titlecase, 'password' => "wrong", :referer => "/history"
273 assert_response :redirect
275 assert_response :success
276 assert_template 'login'
278 post '/login', 'username' => user.display_name.titlecase, 'password' => "test", :referer => "/history"
279 assert_response :redirect
281 assert_response :success
282 assert_template 'changeset/history'
283 assert_select "span.username", "test2"
286 def test_login_openid_success
288 assert_response :redirect
289 assert_redirected_to "controller" => "user", "action" => "login", "cookie_test" => "true"
291 assert_response :success
292 post '/login', 'openid_url' => "http://localhost:1123/john.doe?openid.success=true", :referer => "/history"
293 assert_response :redirect
295 post '/login', openid_request(@response.redirect_url)
297 assert_response :redirect
299 assert_response :success
300 assert_template 'changeset/history'
301 assert_select "span.username", "openIDuser"
304 def test_login_openid_cancel
306 assert_response :redirect
307 assert_redirected_to "controller" => "user", "action" => "login", "cookie_test" => "true"
309 assert_response :success
310 post '/login', 'openid_url' => "http://localhost:1123/john.doe", :referer => "/diary"
311 assert_response :redirect
313 post '/login', openid_request(@response.redirect_url)
315 assert_response :redirect
317 assert_response :success
318 assert_template 'login'
319 assert_select "span.username", false
322 def test_login_openid_invalid_provider
324 assert_response :redirect
325 assert_redirected_to "controller" => "user", "action" => "login", "cookie_test" => "true"
327 assert_response :success
328 # Use a different port that doesn't have the OpenID provider running on to test an invalid openID
329 post '/login', 'openid_url' => "http://localhost:1124/john.doe", :referer => "/diary"
330 assert_response :redirect
332 assert_response :success
333 assert_template 'login'
334 assert_select "span.username", false
337 def test_login_openid_invalid_url
339 assert_response :redirect
340 assert_redirected_to "controller" => "user", "action" => "login", "cookie_test" => "true"
342 assert_response :success
343 # Use a url with an invalid protocol to make sure it handles that correctly too
344 post '/login', 'openid_url' => "htt://localhost:1123/john.doe", :referer => "/diary"
345 assert_response :redirect
347 assert_response :success
348 assert_template 'login'
349 assert_select "span.username", false
352 def test_login_openid_unknown
354 assert_response :redirect
355 assert_redirected_to "controller" => "user", "action" => "login", "cookie_test" => "true"
357 assert_response :success
358 post '/login', 'openid_url' => "http://localhost:1123/john.doe?openid.success=true_somethingelse", :referer => "/diary"
359 assert_response :redirect
361 res = openid_request(@response.redirect_url)
364 assert_response :redirect
366 assert_response :success
367 assert_template 'user/new'
368 assert_select "span.username", false