3 class UserLoginTest < ActionDispatch::IntegrationTest
7 OmniAuth.config.test_mode = true
11 OmniAuth.config.mock_auth[:openid] = nil
12 OmniAuth.config.test_mode = false
15 def test_login_email_password_normal
16 user = users(:normal_user)
19 assert_response :redirect
20 assert_redirected_to "controller" => "user", "action" => "login", "cookie_test" => "true"
22 assert_response :success
24 post "/login", "username" => user.email, "password" => "wrong", :referer => "/history"
25 assert_response :redirect
27 assert_response :success
28 assert_template "login"
30 post "/login", "username" => user.email, "password" => "test", :referer => "/history"
31 assert_response :redirect
33 assert_response :success
34 assert_template "changeset/history"
35 assert_select "span.username", "test"
38 def test_login_email_password_normal_upcase
39 user = users(:normal_user)
42 assert_response :redirect
43 assert_redirected_to "controller" => "user", "action" => "login", "cookie_test" => "true"
45 assert_response :success
47 post "/login", "username" => user.email.upcase, "password" => "wrong", :referer => "/history"
48 assert_response :redirect
50 assert_response :success
51 assert_template "login"
53 post "/login", "username" => user.email.upcase, "password" => "test", :referer => "/history"
54 assert_response :redirect
56 assert_response :success
57 assert_template "changeset/history"
58 assert_select "span.username", "TEST"
61 def test_login_email_password_normal_titlecase
62 user = users(:normal_user)
65 assert_response :redirect
66 assert_redirected_to "controller" => "user", "action" => "login", "cookie_test" => "true"
68 assert_response :success
70 post "/login", "username" => user.email.titlecase, "password" => "wrong", :referer => "/history"
71 assert_response :redirect
73 assert_response :success
74 assert_template "login"
76 post "/login", "username" => user.email.titlecase, "password" => "test", :referer => "/history"
77 assert_response :redirect
79 assert_response :success
80 assert_template "login"
81 assert_select "span.username", false
84 def test_login_email_password_public
85 user = users(:public_user)
88 assert_response :redirect
89 assert_redirected_to "controller" => "user", "action" => "login", "cookie_test" => "true"
91 assert_response :success
93 post "/login", "username" => user.email, "password" => "wrong", :referer => "/history"
94 assert_response :redirect
96 assert_response :success
97 assert_template "login"
99 post "/login", "username" => user.email, "password" => "test", :referer => "/history"
100 assert_response :redirect
102 assert_response :success
103 assert_template "changeset/history"
104 assert_select "span.username", "test2"
107 def test_login_email_password_public_upcase
108 user = users(:public_user)
111 assert_response :redirect
112 assert_redirected_to "controller" => "user", "action" => "login", "cookie_test" => "true"
114 assert_response :success
116 post "/login", "username" => user.email.upcase, "password" => "wrong", :referer => "/history"
117 assert_response :redirect
119 assert_response :success
120 assert_template "login"
122 post "/login", "username" => user.email.upcase, "password" => "test", :referer => "/history"
123 assert_response :redirect
125 assert_response :success
126 assert_template "changeset/history"
127 assert_select "span.username", "test2"
130 def test_login_email_password_public_titlecase
131 user = users(:public_user)
134 assert_response :redirect
135 assert_redirected_to "controller" => "user", "action" => "login", "cookie_test" => "true"
137 assert_response :success
139 post "/login", "username" => user.email.titlecase, "password" => "wrong", :referer => "/history"
140 assert_response :redirect
142 assert_response :success
143 assert_template "login"
145 post "/login", "username" => user.email.titlecase, "password" => "test", :referer => "/history"
146 assert_response :redirect
148 assert_response :success
149 assert_template "changeset/history"
150 assert_select "span.username", "test2"
153 def test_login_username_password_normal
154 user = users(:normal_user)
157 assert_response :redirect
158 assert_redirected_to "controller" => "user", "action" => "login", "cookie_test" => "true"
160 assert_response :success
162 post "/login", "username" => user.display_name, "password" => "wrong", :referer => "/history"
163 assert_response :redirect
165 assert_response :success
166 assert_template "login"
168 post "/login", "username" => user.display_name, "password" => "test", :referer => "/history"
169 assert_response :redirect
171 assert_response :success
172 assert_template "changeset/history"
173 assert_select "span.username", "test"
176 def test_login_username_password_normal_upcase
177 user = users(:normal_user)
180 assert_response :redirect
181 assert_redirected_to "controller" => "user", "action" => "login", "cookie_test" => "true"
183 assert_response :success
185 post "/login", "username" => user.display_name.upcase, "password" => "wrong", :referer => "/history"
186 assert_response :redirect
188 assert_response :success
189 assert_template "login"
191 post "/login", "username" => user.display_name.upcase, "password" => "test", :referer => "/history"
192 assert_response :redirect
194 assert_response :success
195 assert_template "changeset/history"
196 assert_select "span.username", "TEST"
199 def test_login_username_password_normal_titlecase
200 user = users(:normal_user)
203 assert_response :redirect
204 assert_redirected_to "controller" => "user", "action" => "login", "cookie_test" => "true"
206 assert_response :success
208 post "/login", "username" => user.display_name.titlecase, "password" => "wrong", :referer => "/history"
209 assert_response :redirect
211 assert_response :success
212 assert_template "login"
214 post "/login", "username" => user.display_name.titlecase, "password" => "test", :referer => "/history"
215 assert_response :redirect
217 assert_response :success
218 assert_template "login"
219 assert_select "span.username", false
222 def test_login_username_password_public
223 user = users(:public_user)
226 assert_response :redirect
227 assert_redirected_to "controller" => "user", "action" => "login", "cookie_test" => "true"
229 assert_response :success
231 post "/login", "username" => user.display_name, "password" => "wrong", :referer => "/history"
232 assert_response :redirect
234 assert_response :success
235 assert_template "login"
237 post "/login", "username" => user.display_name, "password" => "test", :referer => "/history"
238 assert_response :redirect
240 assert_response :success
241 assert_template "changeset/history"
242 assert_select "span.username", "test2"
245 def test_login_username_password_public_upcase
246 user = users(:public_user)
249 assert_response :redirect
250 assert_redirected_to "controller" => "user", "action" => "login", "cookie_test" => "true"
252 assert_response :success
254 post "/login", "username" => user.display_name.upcase, "password" => "wrong", :referer => "/history"
255 assert_response :redirect
257 assert_response :success
258 assert_template "login"
260 post "/login", "username" => user.display_name.upcase, "password" => "test", :referer => "/history"
261 assert_response :redirect
263 assert_response :success
264 assert_template "changeset/history"
265 assert_select "span.username", "test2"
268 def test_login_username_password_public_titlecase
269 user = users(:public_user)
272 assert_response :redirect
273 assert_redirected_to "controller" => "user", "action" => "login", "cookie_test" => "true"
275 assert_response :success
277 post "/login", "username" => user.display_name.titlecase, "password" => "wrong", :referer => "/history"
278 assert_response :redirect
280 assert_response :success
281 assert_template "login"
283 post "/login", "username" => user.display_name.titlecase, "password" => "test", :referer => "/history"
284 assert_response :redirect
286 assert_response :success
287 assert_template "changeset/history"
288 assert_select "span.username", "test2"
291 def test_login_openid_success
292 OmniAuth.config.add_mock(:openid, :uid => "http://localhost:1123/john.doe")
295 assert_response :redirect
296 assert_redirected_to "controller" => "user", "action" => "login", "cookie_test" => "true"
298 assert_response :success
299 post "/login", "openid_url" => "http://localhost:1123/john.doe", :referer => "/history"
300 assert_response :redirect
301 assert_redirected_to auth_path(:provider => "openid", :openid_url => "http://localhost:1123/john.doe", :origin => "/login")
303 assert_response :redirect
304 assert_redirected_to auth_success_path(:provider => "openid", :openid_url => "http://localhost:1123/john.doe", :origin => "/login")
306 assert_response :redirect
308 assert_response :success
309 assert_template "changeset/history"
310 assert_select "span.username", "openIDuser"
313 def test_login_openid_connection_failed
314 OmniAuth.config.mock_auth[:openid] = :connection_failed
317 assert_response :redirect
318 assert_redirected_to "controller" => "user", "action" => "login", "cookie_test" => "true"
320 assert_response :success
321 post "/login", "openid_url" => "http://localhost:1123/john.doe", :referer => "/history"
322 assert_response :redirect
323 assert_redirected_to auth_path(:provider => "openid", :openid_url => "http://localhost:1123/john.doe", :origin => "/login")
325 assert_response :redirect
326 assert_redirected_to auth_success_path(:provider => "openid", :openid_url => "http://localhost:1123/john.doe", :origin => "/login")
328 assert_response :redirect
329 assert_redirected_to auth_failure_path(:strategy => "openid", :message => "connection_failed", :origin => "/login")
331 assert_response :redirect
333 assert_response :success
334 assert_template "login"
335 assert_select "div.flash.error", "Connection to authentication provider failed"
336 assert_select "span.username", false
339 def test_login_openid_invalid_credentials
340 OmniAuth.config.mock_auth[:openid] = :invalid_credentials
343 assert_response :redirect
344 assert_redirected_to "controller" => "user", "action" => "login", "cookie_test" => "true"
346 assert_response :success
347 post "/login", "openid_url" => "http://localhost:1123/john.doe", :referer => "/history"
348 assert_response :redirect
349 assert_redirected_to auth_path(:provider => "openid", :openid_url => "http://localhost:1123/john.doe", :origin => "/login")
351 assert_response :redirect
352 assert_redirected_to auth_success_path(:provider => "openid", :openid_url => "http://localhost:1123/john.doe", :origin => "/login")
354 assert_response :redirect
355 assert_redirected_to auth_failure_path(:strategy => "openid", :message => "invalid_credentials", :origin => "/login")
357 assert_response :redirect
359 assert_response :success
360 assert_template "login"
361 assert_select "div.flash.error", "Invalid authentication credentials"
362 assert_select "span.username", false
365 def test_login_openid_unknown
366 OmniAuth.config.add_mock(:openid, :uid => "http://localhost:1123/fred.bloggs")
369 assert_response :redirect
370 assert_redirected_to "controller" => "user", "action" => "login", "cookie_test" => "true"
372 assert_response :success
373 post "/login", "openid_url" => "http://localhost:1123/fred.bloggs", :referer => "/diary"
374 assert_response :redirect
375 assert_redirected_to auth_path(:provider => "openid", :openid_url => "http://localhost:1123/fred.bloggs", :origin => "/login")
377 assert_response :redirect
378 assert_redirected_to auth_success_path(:provider => "openid", :openid_url => "http://localhost:1123/fred.bloggs", :origin => "/login")
380 assert_response :redirect
382 assert_response :success
383 assert_template "user/new"
384 assert_select "span.username", false