3 class UserCreationTest < ActionDispatch::IntegrationTest
9 OmniAuth.config.test_mode = true
15 OmniAuth.config.mock_auth[:openid] = nil
16 OmniAuth.config.mock_auth[:google] = nil
17 OmniAuth.config.mock_auth[:facebook] = nil
18 OmniAuth.config.mock_auth[:windowslive] = nil
19 OmniAuth.config.test_mode = false
22 def test_create_user_form
23 I18n.available_locales.each do |locale|
24 get_via_redirect "/user/new", {}, { "HTTP_ACCEPT_LANGUAGE" => locale.to_s }
25 assert_response :success
26 assert_template "user/new"
30 def test_user_create_submit_duplicate_email
31 I18n.available_locales.each do |locale|
32 dup_email = users(:public_user).email
33 display_name = "#{locale}_new_tester"
34 assert_difference("User.count", 0) do
35 assert_difference("ActionMailer::Base.deliveries.size", 0) do
37 { :user => { :email => dup_email, :email_confirmation => dup_email, :display_name => display_name, :pass_crypt => "testtest", :pass_crypt_confirmation => "testtest" } },
38 { "HTTP_ACCEPT_LANGUAGE" => locale.to_s }
41 assert_response :success
42 assert_template "user/new"
43 assert_equal locale.to_s, response.headers["Content-Language"] unless locale == :root
44 assert_select "form > fieldset > div.form-row > input.field_with_errors#user_email"
45 assert_no_missing_translations
49 def test_user_create_submit_duplicate_username
50 I18n.available_locales.each do |locale|
51 dup_display_name = users(:public_user).display_name
52 email = "#{locale}_new_tester"
53 assert_difference("User.count", 0) do
54 assert_difference("ActionMailer::Base.deliveries.size", 0) do
56 { :user => { :email => email, :email_confirmation => email, :display_name => dup_display_name, :pass_crypt => "testtest", :pass_crypt_confirmation => "testtest" } },
57 { "HTTP_ACCEPT_LANGUAGE" => locale.to_s }
60 assert_response :success
61 assert_template "user/new"
62 assert_select "form > fieldset > div.form-row > input.field_with_errors#user_display_name"
63 assert_no_missing_translations
67 def test_user_create_success
68 I18n.available_locales.each do |locale|
69 new_email = "#{locale}newtester@osm.org"
70 display_name = "#{locale}_new_tester"
72 assert_difference("User.count", 0) do
73 assert_difference("ActionMailer::Base.deliveries.size", 0) do
75 :user => { :email => new_email, :email_confirmation => new_email, :display_name => display_name, :pass_crypt => "testtest", :pass_crypt_confirmation => "testtest" }
79 assert_redirected_to "/user/terms"
81 assert_difference("User.count") do
82 assert_difference("ActionMailer::Base.deliveries.size", 1) do
83 post_via_redirect "/user/save", {},
84 { "HTTP_ACCEPT_LANGUAGE" => "#{locale}" }
89 register_email = ActionMailer::Base.deliveries.first
91 assert_equal register_email.to[0], new_email
92 # Check that the confirm account url is correct
93 assert_match /#{@url}/, register_email.body.to_s
96 assert_response :success
97 assert_template "user/confirm"
99 ActionMailer::Base.deliveries.clear
103 # Check that the user can successfully recover their password
104 def lost_password_recovery_success
105 # Open the lost password form
106 # Submit the lost password form
108 # Submit the reset password token
109 # Check that the password has changed, and the user can login
112 def test_user_create_redirect
113 new_email = "redirect_tester@osm.org"
114 display_name = "redirect_tester"
115 password = "testtest"
116 # nothing special about this page, just need a protected page to redirect back to.
117 referer = "/traces/mine"
118 assert_difference("User.count") do
119 assert_difference("ActionMailer::Base.deliveries.size", 1) do
121 :user => { :email => new_email, :email_confirmation => new_email, :display_name => display_name, :pass_crypt => password, :pass_crypt_confirmation => password }, :referer => referer
122 assert_redirected_to "/user/terms"
123 post_via_redirect "/user/save",
124 :user => { :email => new_email, :email_confirmation => new_email, :display_name => display_name, :pass_crypt => password, :pass_crypt_confirmation => password }
129 register_email = ActionMailer::Base.deliveries.first
131 assert_equal register_email.to[0], new_email
132 # Check that the confirm account url is correct
133 confirm_regex = Regexp.new("/user/redirect_tester/confirm\\?confirm_string=([a-zA-Z0-9]*)")
134 register_email.parts.each do |part|
135 assert_match confirm_regex, part.body.to_s
137 confirm_string = register_email.parts[0].body.match(confirm_regex)[1]
140 assert_response :success
141 assert_template "user/confirm"
143 ActionMailer::Base.deliveries.clear
145 # Go to the confirmation page
146 get "/user/#{display_name}/confirm", :confirm_string => confirm_string
147 assert_response :success
148 assert_template "user/confirm"
150 post "/user/#{display_name}/confirm", :confirm_string => confirm_string
151 assert_response :redirect
153 assert_response :success
154 assert_template "site/welcome"
157 def test_user_create_openid_success
158 OmniAuth.config.add_mock(:openid, :uid => "http://localhost:1123/new.tester")
160 new_email = "newtester-openid@osm.org"
161 display_name = "new_tester-openid"
162 password = "testtest"
163 assert_difference("User.count") do
164 assert_difference("ActionMailer::Base.deliveries.size", 1) do
166 :user => { :email => new_email, :email_confirmation => new_email, :display_name => display_name, :auth_provider => "openid", :auth_uid => "http://localhost:1123/new.tester", :pass_crypt => "", :pass_crypt_confirmation => "" }
167 assert_response :redirect
168 assert_redirected_to auth_path(:provider => "openid", :openid_url => "http://localhost:1123/new.tester", :origin => "/user/new")
170 assert_response :redirect
171 assert_redirected_to auth_success_path(:provider => "openid", :openid_url => "http://localhost:1123/new.tester", :origin => "/user/new")
173 assert_response :redirect
174 assert_redirected_to "/user/terms"
176 :user => { :email => new_email, :email_confirmation => new_email, :display_name => display_name, :auth_provider => "openid", :auth_uid => "http://localhost:1123/new.tester", :pass_crypt => password, :pass_crypt_confirmation => password }
177 assert_response :redirect
183 assert_response :success
184 assert_template "user/confirm"
186 ActionMailer::Base.deliveries.clear
189 def test_user_create_openid_failure
190 OmniAuth.config.mock_auth[:openid] = :connection_failed
192 new_email = "newtester-openid2@osm.org"
193 display_name = "new_tester-openid2"
194 assert_difference("User.count", 0) do
195 assert_difference("ActionMailer::Base.deliveries.size", 0) do
197 :user => { :email => new_email, :email_confirmation => new_email, :display_name => display_name, :auth_provider => "openid", :auth_uid => "http://localhost:1123/new.tester", :pass_crypt => "", :pass_crypt_confirmation => "" }
198 assert_response :redirect
199 assert_redirected_to auth_path(:provider => "openid", :openid_url => "http://localhost:1123/new.tester", :origin => "/user/new")
201 assert_response :redirect
202 assert_redirected_to auth_success_path(:provider => "openid", :openid_url => "http://localhost:1123/new.tester", :origin => "/user/new")
204 assert_response :redirect
205 assert_redirected_to auth_failure_path(:strategy => "openid", :message => "connection_failed", :origin => "/user/new")
207 assert_response :redirect
209 assert_response :success
210 assert_template "user/new"
214 ActionMailer::Base.deliveries.clear
217 def test_user_create_openid_redirect
218 OmniAuth.config.add_mock(:openid, :uid => "http://localhost:1123/new.tester")
220 new_email = "redirect_tester_openid@osm.org"
221 display_name = "redirect_tester_openid"
222 # nothing special about this page, just need a protected page to redirect back to.
223 referer = "/traces/mine"
224 assert_difference("User.count") do
225 assert_difference("ActionMailer::Base.deliveries.size", 1) do
227 :user => { :email => new_email, :email_confirmation => new_email, :display_name => display_name, :auth_provider => "openid", :auth_uid => "http://localhost:1123/new.tester", :pass_crypt => "", :pass_crypt_confirmation => "" }, :referer => referer
228 assert_response :redirect
229 assert_redirected_to auth_path(:provider => "openid", :openid_url => "http://localhost:1123/new.tester", :origin => "/user/new")
231 assert_response :redirect
232 assert_redirected_to auth_success_path(:provider => "openid", :openid_url => "http://localhost:1123/new.tester", :origin => "/user/new")
234 assert_response :redirect
235 assert_redirected_to "/user/terms"
236 post_via_redirect "/user/save",
237 :user => { :email => new_email, :email_confirmation => new_email, :display_name => display_name, :auth_provider => "openid", :auth_uid => "http://localhost:1123/new.tester", :pass_crypt => "testtest", :pass_crypt_confirmation => "testtest" }
242 register_email = ActionMailer::Base.deliveries.first
244 assert_equal register_email.to[0], new_email
245 # Check that the confirm account url is correct
246 confirm_regex = Regexp.new("/user/redirect_tester_openid/confirm\\?confirm_string=([a-zA-Z0-9]*)")
247 register_email.parts.each do |part|
248 assert_match confirm_regex, part.body.to_s
250 confirm_string = register_email.parts[0].body.match(confirm_regex)[1]
253 assert_response :success
254 assert_template "user/confirm"
256 ActionMailer::Base.deliveries.clear
258 # Go to the confirmation page
259 get "/user/#{display_name}/confirm", :confirm_string => confirm_string
260 assert_response :success
261 assert_template "user/confirm"
263 post "/user/#{display_name}/confirm", :confirm_string => confirm_string
264 assert_response :redirect
266 assert_response :success
267 assert_template "site/welcome"
270 def test_user_create_google_success
271 OmniAuth.config.add_mock(:google, :uid => "123454321", :extra => {
272 :id_info => { "openid_id" => "http://localhost:1123/new.tester" }
275 new_email = "newtester-google@osm.org"
276 display_name = "new_tester-google"
277 password = "testtest"
278 assert_difference("User.count") do
279 assert_difference("ActionMailer::Base.deliveries.size", 1) do
281 :user => { :email => new_email, :email_confirmation => new_email, :display_name => display_name, :auth_provider => "google", :pass_crypt => "", :pass_crypt_confirmation => "" }
282 assert_response :redirect
283 assert_redirected_to auth_path(:provider => "google", :origin => "/user/new")
285 assert_response :redirect
286 assert_redirected_to auth_success_path(:provider => "google")
288 assert_response :redirect
289 assert_redirected_to "/user/terms"
291 :user => { :email => new_email, :email_confirmation => new_email, :display_name => display_name, :auth_provider => "google", :auth_uid => "123454321", :pass_crypt => password, :pass_crypt_confirmation => password }
292 assert_response :redirect
298 assert_response :success
299 assert_template "user/confirm"
301 ActionMailer::Base.deliveries.clear
304 def test_user_create_google_failure
305 OmniAuth.config.mock_auth[:google] = :connection_failed
307 new_email = "newtester-google2@osm.org"
308 display_name = "new_tester-google2"
309 assert_difference("User.count", 0) do
310 assert_difference("ActionMailer::Base.deliveries.size", 0) do
312 :user => { :email => new_email, :email_confirmation => new_email, :display_name => display_name, :auth_provider => "google", :pass_crypt => "", :pass_crypt_confirmation => "" }
313 assert_response :redirect
314 assert_redirected_to auth_path(:provider => "google", :origin => "/user/new")
316 assert_response :redirect
317 assert_redirected_to auth_success_path(:provider => "google")
319 assert_response :redirect
320 assert_redirected_to auth_failure_path(:strategy => "google", :message => "connection_failed", :origin => "/user/new")
322 assert_response :redirect
324 assert_response :success
325 assert_template "user/new"
329 ActionMailer::Base.deliveries.clear
332 def test_user_create_google_redirect
333 OmniAuth.config.add_mock(:google, :uid => "123454321", :extra => {
334 :id_info => { "openid_id" => "http://localhost:1123/new.tester" }
337 new_email = "redirect_tester_google@osm.org"
338 display_name = "redirect_tester_google"
339 # nothing special about this page, just need a protected page to redirect back to.
340 referer = "/traces/mine"
341 assert_difference("User.count") do
342 assert_difference("ActionMailer::Base.deliveries.size", 1) do
344 :user => { :email => new_email, :email_confirmation => new_email, :display_name => display_name, :auth_provider => "google", :pass_crypt => "", :pass_crypt_confirmation => "" }, :referer => referer
345 assert_response :redirect
346 assert_redirected_to auth_path(:provider => "google", :origin => "/user/new")
348 assert_response :redirect
349 assert_redirected_to auth_success_path(:provider => "google")
351 assert_response :redirect
352 assert_redirected_to "/user/terms"
353 post_via_redirect "/user/save",
354 :user => { :email => new_email, :email_confirmation => new_email, :display_name => display_name, :auth_provider => "google", :auth_uid => "http://localhost:1123/new.tester", :pass_crypt => "testtest", :pass_crypt_confirmation => "testtest" }
359 register_email = ActionMailer::Base.deliveries.first
361 assert_equal register_email.to[0], new_email
362 # Check that the confirm account url is correct
363 confirm_regex = Regexp.new("/user/redirect_tester_google/confirm\\?confirm_string=([a-zA-Z0-9]*)")
364 register_email.parts.each do |part|
365 assert_match confirm_regex, part.body.to_s
367 confirm_string = register_email.parts[0].body.match(confirm_regex)[1]
370 assert_response :success
371 assert_template "user/confirm"
373 ActionMailer::Base.deliveries.clear
375 # Go to the confirmation page
376 get "/user/#{display_name}/confirm", :confirm_string => confirm_string
377 assert_response :success
378 assert_template "user/confirm"
380 post "/user/#{display_name}/confirm", :confirm_string => confirm_string
381 assert_response :redirect
383 assert_response :success
384 assert_template "site/welcome"
387 def test_user_create_facebook_success
388 OmniAuth.config.add_mock(:facebook, :uid => "123454321")
390 new_email = "newtester-facebook@osm.org"
391 display_name = "new_tester-facebook"
392 password = "testtest"
393 assert_difference("User.count") do
394 assert_difference("ActionMailer::Base.deliveries.size", 1) do
396 :user => { :email => new_email, :email_confirmation => new_email, :display_name => display_name, :auth_provider => "facebook", :pass_crypt => "", :pass_crypt_confirmation => "" }
397 assert_response :redirect
398 assert_redirected_to auth_path(:provider => "facebook", :origin => "/user/new")
400 assert_response :redirect
401 assert_redirected_to auth_success_path(:provider => "facebook")
403 assert_response :redirect
404 assert_redirected_to "/user/terms"
406 :user => { :email => new_email, :email_confirmation => new_email, :display_name => display_name, :auth_provider => "facebook", :auth_uid => "123454321", :pass_crypt => password, :pass_crypt_confirmation => password }
407 assert_response :redirect
413 assert_response :success
414 assert_template "user/confirm"
416 ActionMailer::Base.deliveries.clear
419 def test_user_create_facebook_failure
420 OmniAuth.config.mock_auth[:facebook] = :connection_failed
422 new_email = "newtester-facebook2@osm.org"
423 display_name = "new_tester-facebook2"
424 assert_difference("User.count", 0) do
425 assert_difference("ActionMailer::Base.deliveries.size", 0) do
427 :user => { :email => new_email, :email_confirmation => new_email, :display_name => display_name, :auth_provider => "facebook", :pass_crypt => "", :pass_crypt_confirmation => "" }
428 assert_response :redirect
429 assert_redirected_to auth_path(:provider => "facebook", :origin => "/user/new")
431 assert_response :redirect
432 assert_redirected_to auth_success_path(:provider => "facebook")
434 assert_response :redirect
435 assert_redirected_to auth_failure_path(:strategy => "facebook", :message => "connection_failed", :origin => "/user/new")
437 assert_response :redirect
439 assert_response :success
440 assert_template "user/new"
444 ActionMailer::Base.deliveries.clear
447 def test_user_create_facebook_redirect
448 OmniAuth.config.add_mock(:facebook, :uid => "123454321")
450 new_email = "redirect_tester_facebook@osm.org"
451 display_name = "redirect_tester_facebook"
452 # nothing special about this page, just need a protected page to redirect back to.
453 referer = "/traces/mine"
454 assert_difference("User.count") do
455 assert_difference("ActionMailer::Base.deliveries.size", 1) do
457 :user => { :email => new_email, :email_confirmation => new_email, :display_name => display_name, :auth_provider => "facebook", :pass_crypt => "", :pass_crypt_confirmation => "" }, :referer => referer
458 assert_response :redirect
459 assert_redirected_to auth_path(:provider => "facebook", :origin => "/user/new")
461 assert_response :redirect
462 assert_redirected_to auth_success_path(:provider => "facebook")
464 assert_response :redirect
465 assert_redirected_to "/user/terms"
466 post_via_redirect "/user/save",
467 :user => { :email => new_email, :email_confirmation => new_email, :display_name => display_name, :auth_provider => "facebook", :auth_uid => "http://localhost:1123/new.tester", :pass_crypt => "testtest", :pass_crypt_confirmation => "testtest" }
472 register_email = ActionMailer::Base.deliveries.first
474 assert_equal register_email.to[0], new_email
475 # Check that the confirm account url is correct
476 confirm_regex = Regexp.new("/user/redirect_tester_facebook/confirm\\?confirm_string=([a-zA-Z0-9]*)")
477 register_email.parts.each do |part|
478 assert_match confirm_regex, part.body.to_s
480 confirm_string = register_email.parts[0].body.match(confirm_regex)[1]
483 assert_response :success
484 assert_template "user/confirm"
486 ActionMailer::Base.deliveries.clear
488 # Go to the confirmation page
489 get "/user/#{display_name}/confirm", :confirm_string => confirm_string
490 assert_response :success
491 assert_template "user/confirm"
493 post "/user/#{display_name}/confirm", :confirm_string => confirm_string
494 assert_response :redirect
496 assert_response :success
497 assert_template "site/welcome"
500 def test_user_create_windowslive_success
501 OmniAuth.config.add_mock(:windowslive, :uid => "123454321")
503 new_email = "newtester-windowslive@osm.org"
504 display_name = "new_tester-windowslive"
505 password = "testtest"
506 assert_difference("User.count") do
507 assert_difference("ActionMailer::Base.deliveries.size", 1) do
509 :user => { :email => new_email, :email_confirmation => new_email, :display_name => display_name, :auth_provider => "windowslive", :pass_crypt => "", :pass_crypt_confirmation => "" }
510 assert_response :redirect
511 assert_redirected_to auth_path(:provider => "windowslive", :origin => "/user/new")
513 assert_response :redirect
514 assert_redirected_to auth_success_path(:provider => "windowslive", :origin => "/user/new")
516 assert_response :redirect
517 assert_redirected_to "/user/terms"
519 :user => { :email => new_email, :email_confirmation => new_email, :display_name => display_name, :auth_provider => "windowslive", :auth_uid => "123454321", :pass_crypt => password, :pass_crypt_confirmation => password }
520 assert_response :redirect
526 assert_response :success
527 assert_template "user/confirm"
529 ActionMailer::Base.deliveries.clear
532 def test_user_create_windowslive_failure
533 OmniAuth.config.mock_auth[:windowslive] = :connection_failed
535 new_email = "newtester-windowslive2@osm.org"
536 display_name = "new_tester-windowslive2"
537 assert_difference("User.count", 0) do
538 assert_difference("ActionMailer::Base.deliveries.size", 0) do
540 :user => { :email => new_email, :email_confirmation => new_email, :display_name => display_name, :auth_provider => "windowslive", :pass_crypt => "", :pass_crypt_confirmation => "" }
541 assert_response :redirect
542 assert_redirected_to auth_path(:provider => "windowslive", :origin => "/user/new")
544 assert_response :redirect
545 assert_redirected_to auth_success_path(:provider => "windowslive", :origin => "/user/new")
547 assert_response :redirect
548 assert_redirected_to auth_failure_path(:strategy => "windowslive", :message => "connection_failed", :origin => "/user/new")
550 assert_response :redirect
552 assert_response :success
553 assert_template "user/new"
557 ActionMailer::Base.deliveries.clear
560 def test_user_create_windowslive_redirect
561 OmniAuth.config.add_mock(:windowslive, :uid => "123454321")
563 new_email = "redirect_tester_windowslive@osm.org"
564 display_name = "redirect_tester_windowslive"
565 # nothing special about this page, just need a protected page to redirect back to.
566 referer = "/traces/mine"
567 assert_difference("User.count") do
568 assert_difference("ActionMailer::Base.deliveries.size", 1) do
570 :user => { :email => new_email, :email_confirmation => new_email, :display_name => display_name, :auth_provider => "windowslive", :pass_crypt => "", :pass_crypt_confirmation => "" }, :referer => referer
571 assert_response :redirect
572 assert_redirected_to auth_path(:provider => "windowslive", :origin => "/user/new")
574 assert_response :redirect
575 assert_redirected_to auth_success_path(:provider => "windowslive", :origin => "/user/new")
577 assert_response :redirect
578 assert_redirected_to "/user/terms"
579 post_via_redirect "/user/save",
580 :user => { :email => new_email, :email_confirmation => new_email, :display_name => display_name, :auth_provider => "windowslive", :auth_uid => "http://localhost:1123/new.tester", :pass_crypt => "testtest", :pass_crypt_confirmation => "testtest" }
585 register_email = ActionMailer::Base.deliveries.first
587 assert_equal register_email.to[0], new_email
588 # Check that the confirm account url is correct
589 confirm_regex = Regexp.new("/user/redirect_tester_windowslive/confirm\\?confirm_string=([a-zA-Z0-9]*)")
590 register_email.parts.each do |part|
591 assert_match confirm_regex, part.body.to_s
593 confirm_string = register_email.parts[0].body.match(confirm_regex)[1]
596 assert_response :success
597 assert_template "user/confirm"
599 ActionMailer::Base.deliveries.clear
601 # Go to the confirmation page
602 get "/user/#{display_name}/confirm", :confirm_string => confirm_string
603 assert_response :success
604 assert_template "user/confirm"
606 post "/user/#{display_name}/confirm", :confirm_string => confirm_string
607 assert_response :redirect
609 assert_response :success
610 assert_template "site/welcome"