3 class UserCreationTest < ActionDispatch::IntegrationTest
5 OmniAuth.config.test_mode = true
7 stub_request(:get, /.*gravatar.com.*d=404/).to_return(:status => 404)
11 OmniAuth.config.mock_auth[:openid] = nil
12 OmniAuth.config.mock_auth[:google] = nil
13 OmniAuth.config.mock_auth[:facebook] = nil
14 OmniAuth.config.mock_auth[:microsoft] = nil
15 OmniAuth.config.mock_auth[:github] = nil
16 OmniAuth.config.mock_auth[:wikipedia] = nil
17 OmniAuth.config.test_mode = false
20 def test_create_user_form
23 assert_response :success
24 assert_template "users/new"
27 def test_user_create_submit_duplicate_email
28 dup_email = create(:user).email
29 display_name = "new_tester"
30 assert_difference("User.count", 0) do
31 assert_difference("ActionMailer::Base.deliveries.size", 0) do
32 perform_enqueued_jobs do
34 :params => { :user => { :email => dup_email,
35 :display_name => display_name,
36 :pass_crypt => "testtest",
37 :pass_crypt_confirmation => "testtest",
38 :consider_pd => "1" } }
42 assert_response :success
43 assert_template "users/new"
45 assert_select "form > div > input.is-invalid#user_email"
48 def test_user_create_association_submit_duplicate_email
49 dup_email = create(:user).email
50 display_name = "new_tester"
51 assert_difference("User.count", 0) do
52 assert_no_difference("ActionMailer::Base.deliveries.size") do
53 perform_enqueued_jobs do
55 :params => { :user => { :email => dup_email,
56 :display_name => display_name,
57 :pass_crypt => "testtest",
58 :pass_crypt_confirmation => "testtest",
59 :auth_provider => "google",
60 :auth_uid => "123454321",
61 :consider_pd => "1" } }
65 assert_response :success
66 assert_template "users/new"
68 assert_select "form > div > input.is-invalid#user_email"
71 def test_user_create_submit_duplicate_username
72 dup_display_name = create(:user).display_name
74 assert_difference("User.count", 0) do
75 assert_difference("ActionMailer::Base.deliveries.size", 0) do
76 perform_enqueued_jobs do
78 :params => { :user => { :email => email,
79 :display_name => dup_display_name,
80 :pass_crypt => "testtest",
81 :pass_crypt_confirmation => "testtest" } }
85 assert_response :success
86 assert_template "users/new"
87 assert_select "form > div > input.is-invalid#user_display_name"
90 def test_user_create_submit_mismatched_passwords
91 email = "newtester@osm.org"
92 display_name = "new_tester"
93 assert_difference("User.count", 0) do
94 assert_difference("ActionMailer::Base.deliveries.size", 0) do
95 perform_enqueued_jobs do
97 :params => { :user => { :email => email,
98 :display_name => display_name,
99 :pass_crypt => "testtest",
100 :pass_crypt_confirmation => "blahblah",
101 :consider_pd => "1" } }
105 assert_response :success
106 assert_template "users/new"
107 assert_select "form > div > div > div > input.is-invalid#user_pass_crypt_confirmation"
110 def test_user_create_association_submit_duplicate_username
111 dup_display_name = create(:user).display_name
113 assert_difference("User.count", 0) do
114 assert_no_difference("ActionMailer::Base.deliveries.size") do
115 perform_enqueued_jobs do
117 :params => { :user => { :email => email,
118 :display_name => dup_display_name,
119 :auth_provider => "google",
120 :auth_uid => "123454321",
121 :consider_pd => "1" } }
125 assert_response :success
126 assert_template "users/new"
127 assert_select "form > div > input.is-invalid#user_display_name"
130 def test_user_create_success
131 new_email = "newtester@osm.org"
132 display_name = "new_tester"
134 assert_difference("User.count", 1) do
135 assert_difference("ActionMailer::Base.deliveries.size", 1) do
136 perform_enqueued_jobs do
138 :params => { :user => { :email => new_email,
139 :display_name => display_name,
140 :pass_crypt => "testtest",
141 :pass_crypt_confirmation => "testtest",
142 :consider_pd => "1" } }
143 assert_redirected_to :controller => :confirmations, :action => :confirm, :display_name => display_name
149 assert_response :success
150 assert_template "confirmations/confirm"
152 user = User.find_by(:email => "newtester@osm.org")
154 assert_not_predicate user, :active?
156 register_email = ActionMailer::Base.deliveries.first
157 assert_equal register_email.to.first, new_email
158 found_confirmation_url = register_email.parts.first.parts.first.to_s =~ %r{\shttp://test.host(/\S+)\s}
159 assert found_confirmation_url
160 confirmation_url = Regexp.last_match(1)
161 ActionMailer::Base.deliveries.clear
163 post confirmation_url
165 assert_redirected_to welcome_path
168 assert_predicate user, :active?
170 assert_equal user, User.authenticate(:username => new_email, :password => "testtest")
173 # Check that the user can successfully recover their password
174 def test_lost_password_recovery_success
175 # Open the lost password form
176 # Submit the lost password form
178 # Submit the reset password token
179 # Check that the password has changed, and the user can login
182 def test_user_create_redirect
183 new_email = "redirect_tester@osm.org"
184 display_name = "redirect_tester"
185 password = "testtest"
186 # nothing special about this page, just need a protected page to redirect back to.
187 referer = "/traces/mine"
188 assert_difference("User.count") do
189 assert_difference("ActionMailer::Base.deliveries.size", 1) do
190 perform_enqueued_jobs do
192 :params => { :user => { :email => new_email,
193 :display_name => display_name,
194 :pass_crypt => password,
195 :pass_crypt_confirmation => password,
196 :consider_pd => "1" },
197 :referer => referer }
198 assert_response(:redirect)
199 assert_redirected_to :controller => :confirmations, :action => :confirm, :display_name => display_name
206 register_email = ActionMailer::Base.deliveries.first
208 assert_equal register_email.to.first, new_email
209 # Check that the confirm account url is correct
210 confirm_regex = Regexp.new("confirm_string=([a-zA-Z0-9%_-]*)")
211 email_text_parts(register_email).each do |part|
212 assert_match confirm_regex, part.body.to_s
214 confirm_string = CGI.unescape(email_text_parts(register_email).first.body.match(confirm_regex)[1])
217 assert_response :success
218 assert_template "confirmations/confirm"
220 ActionMailer::Base.deliveries.clear
222 # Go to the confirmation page
223 get "/user/#{display_name}/confirm", :params => { :referer => "/welcome", :confirm_string => confirm_string }
224 assert_response :success
225 assert_template "confirmations/confirm"
227 post "/user/#{display_name}/confirm", :params => { :referer => "/welcome", :confirm_string => confirm_string }
228 assert_response :redirect
230 assert_response :success
231 assert_template "site/welcome"
234 def test_user_create_openid_success
235 new_email = "newtester-openid@osm.org"
236 display_name = "new_tester-openid"
237 openid_url = "http://localhost:1000/new.tester"
238 auth_uid = "http://localhost:1123/new.tester"
240 OmniAuth.config.add_mock(:openid,
242 :info => { :email => new_email, :name => display_name })
244 assert_difference("User.count") do
245 assert_difference("ActionMailer::Base.deliveries.size", 1) do
246 perform_enqueued_jobs do
247 post auth_path(:provider => "openid", :openid_url => openid_url, :origin => "/user/new")
248 assert_redirected_to auth_success_path(:provider => "openid", :openid_url => openid_url, :origin => "/user/new")
250 assert_redirected_to :controller => :users, :action => "new", :nickname => display_name, :email => new_email,
251 :auth_provider => "openid", :auth_uid => auth_uid
254 :params => { :user => { :email => new_email,
255 :display_name => display_name,
256 :auth_provider => "openid",
257 :auth_uid => auth_uid,
258 :consider_pd => "1" } }
264 assert_redirected_to :controller => :confirmations, :action => :confirm, :display_name => display_name
266 ActionMailer::Base.deliveries.clear
269 def test_user_create_openid_duplicate_email
270 dup_user = create(:user)
271 display_name = "new_tester-openid"
272 auth_uid = "123454321"
274 OmniAuth.config.add_mock(:openid,
276 :info => { :email => dup_user.email, :name => display_name })
278 post auth_path(:provider => "openid", :origin => "/user/new")
279 assert_redirected_to auth_success_path(:provider => "openid", :origin => "/user/new")
281 assert_redirected_to :controller => :users, :action => "new", :nickname => display_name, :email => dup_user.email,
282 :auth_provider => "openid", :auth_uid => auth_uid
285 assert_response :success
286 assert_template "users/new"
287 assert_select "form > div > input.is-invalid#user_email"
289 ActionMailer::Base.deliveries.clear
292 def test_user_create_openid_failure
293 OmniAuth.config.mock_auth[:openid] = :connection_failed
295 assert_difference("User.count", 0) do
296 assert_difference("ActionMailer::Base.deliveries.size", 0) do
297 perform_enqueued_jobs do
298 post auth_path(:provider => "openid", :openid_url => "http://localhost:1123/new.tester", :origin => "/user/new")
300 assert_redirected_to auth_failure_path(:strategy => "openid", :message => "connection_failed", :origin => "/user/new")
302 assert_redirected_to "/user/new"
307 ActionMailer::Base.deliveries.clear
310 def test_user_create_openid_redirect
311 openid_url = "http://localhost:1000/new.tester"
312 auth_uid = "http://localhost:1123/new.tester"
313 new_email = "redirect_tester_openid@osm.org"
314 display_name = "redirect_tester_openid"
316 OmniAuth.config.add_mock(:openid,
318 :info => { :email => new_email, :name => display_name })
320 assert_difference("User.count") do
321 assert_difference("ActionMailer::Base.deliveries.size", 1) do
322 perform_enqueued_jobs do
323 post auth_path(:provider => "openid", :openid_url => openid_url, :origin => "/user/new")
324 assert_redirected_to auth_success_path(:provider => "openid", :openid_url => openid_url, :origin => "/user/new")
326 assert_redirected_to :controller => :users, :action => "new", :nickname => display_name, :email => new_email,
327 :auth_provider => "openid", :auth_uid => auth_uid
330 :params => { :user => { :email => new_email,
331 :display_name => display_name,
332 :auth_provider => "openid",
333 :auth_uid => auth_uid,
334 :consider_pd => "1" } }
341 register_email = ActionMailer::Base.deliveries.first
343 assert_equal register_email.to.first, new_email
344 # Check that the confirm account url is correct
345 confirm_regex = Regexp.new("confirm_string=([a-zA-Z0-9%_-]*)")
346 email_text_parts(register_email).each do |part|
347 assert_match confirm_regex, part.body.to_s
349 confirm_string = CGI.unescape(email_text_parts(register_email).first.body.match(confirm_regex)[1])
352 assert_response :success
353 assert_template "confirmations/confirm"
355 ActionMailer::Base.deliveries.clear
357 # Go to the confirmation page
358 get "/user/#{display_name}/confirm", :params => { :referer => "/welcome", :confirm_string => confirm_string }
359 assert_response :success
360 assert_template "confirmations/confirm"
362 post "/user/#{display_name}/confirm", :params => { :referer => "/welcome", :confirm_string => confirm_string }
363 assert_response :redirect
365 assert_response :success
366 assert_template "site/welcome"
369 def test_user_create_google_success
370 new_email = "newtester-google@osm.org"
371 email_hmac = UsersController.message_hmac(new_email)
372 display_name = "new_tester-google"
373 auth_uid = "123454321"
375 OmniAuth.config.add_mock(:google,
377 :extra => { :id_info => { :openid_id => "http://localhost:1123/new.tester" } },
378 :info => { :email => new_email, :name => display_name })
380 assert_difference("User.count") do
381 assert_no_difference("ActionMailer::Base.deliveries.size") do
382 perform_enqueued_jobs do
383 post auth_path(:provider => "google", :origin => "/user/new")
384 assert_redirected_to auth_success_path(:provider => "google")
386 assert_redirected_to :controller => :users, :action => "new", :nickname => display_name,
387 :email => new_email, :email_hmac => email_hmac,
388 :auth_provider => "google", :auth_uid => auth_uid
392 :params => { :user => { :email => new_email,
393 :display_name => display_name,
394 :auth_provider => "google",
395 :auth_uid => auth_uid,
396 :consider_pd => "1" },
397 :email_hmac => email_hmac }
398 assert_redirected_to welcome_path
405 assert_response :success
406 assert_template "site/welcome"
408 ActionMailer::Base.deliveries.clear
411 def test_user_create_google_duplicate_email
412 dup_user = create(:user)
413 display_name = "new_tester-google"
414 auth_uid = "123454321"
416 OmniAuth.config.add_mock(:google,
418 :extra => { :id_info => { :openid_id => "http://localhost:1123/new.tester" } },
419 :info => { :email => dup_user.email, :name => display_name })
421 post auth_path(:provider => "google", :origin => "/user/new")
422 assert_redirected_to auth_success_path(:provider => "google")
424 assert_redirected_to :controller => :users, :action => "new", :nickname => display_name, :email => dup_user.email,
425 :email_hmac => UsersController.message_hmac(dup_user.email),
426 :auth_provider => "google", :auth_uid => auth_uid
429 assert_response :success
430 assert_template "users/new"
431 assert_select "form > div > input.is-invalid#user_email"
433 ActionMailer::Base.deliveries.clear
436 def test_user_create_google_failure
437 OmniAuth.config.mock_auth[:google] = :connection_failed
439 assert_difference("User.count", 0) do
440 assert_difference("ActionMailer::Base.deliveries.size", 0) do
441 perform_enqueued_jobs do
442 post auth_path(:provider => "google", :origin => "/user/new")
443 assert_response :redirect
445 assert_redirected_to auth_failure_path(:strategy => "google", :message => "connection_failed", :origin => "/user/new")
447 assert_redirected_to "/user/new"
452 ActionMailer::Base.deliveries.clear
455 def test_user_create_google_redirect
456 orig_email = "redirect_tester_google_orig@google.com"
457 email_hmac = UsersController.message_hmac(orig_email)
458 new_email = "redirect_tester_google@osm.org"
459 display_name = "redirect_tester_google"
460 auth_uid = "123454321"
462 OmniAuth.config.add_mock(:google,
464 :extra => { :id_info => { :openid_id => "http://localhost:1123/new.tester" } },
465 :info => { :email => orig_email, :name => display_name })
467 assert_difference("User.count") do
468 assert_difference("ActionMailer::Base.deliveries.size", 1) do
469 perform_enqueued_jobs do
470 post auth_path(:provider => "google", :origin => "/user/new")
471 assert_redirected_to auth_success_path(:provider => "google")
473 assert_redirected_to :controller => :users, :action => "new", :nickname => display_name,
474 :email => orig_email, :email_hmac => email_hmac,
475 :auth_provider => "google", :auth_uid => auth_uid
478 :params => { :user => { :email => new_email,
479 :email_hmac => email_hmac,
480 :display_name => display_name,
481 :auth_provider => "google",
482 :auth_uid => auth_uid,
483 :consider_pd => "1" } }
484 assert_response :redirect
491 register_email = ActionMailer::Base.deliveries.first
493 assert_equal register_email.to.first, new_email
494 # Check that the confirm account url is correct
495 confirm_regex = Regexp.new("confirm_string=([a-zA-Z0-9%_-]*)")
496 email_text_parts(register_email).each do |part|
497 assert_match confirm_regex, part.body.to_s
499 confirm_string = CGI.unescape(email_text_parts(register_email).first.body.match(confirm_regex)[1])
502 assert_response :success
503 assert_template "confirmations/confirm"
505 ActionMailer::Base.deliveries.clear
507 # Go to the confirmation page
508 get "/user/#{display_name}/confirm", :params => { :referer => "/welcome", :confirm_string => confirm_string }
509 assert_response :success
510 assert_template "confirmations/confirm"
512 post "/user/#{display_name}/confirm", :params => { :referer => "/welcome", :confirm_string => confirm_string }
513 assert_response :redirect
515 assert_response :success
516 assert_template "site/welcome"
519 def test_user_create_facebook_success
520 new_email = "newtester-facebook@osm.org"
521 email_hmac = UsersController.message_hmac(new_email)
522 display_name = "new_tester-facebook"
523 auth_uid = "123454321"
525 OmniAuth.config.add_mock(:facebook,
527 :info => { "email" => new_email, :name => display_name })
529 assert_difference("User.count") do
530 assert_no_difference("ActionMailer::Base.deliveries.size") do
531 perform_enqueued_jobs do
532 post auth_path(:provider => "facebook", :origin => "/user/new")
533 assert_redirected_to auth_success_path(:provider => "facebook")
535 assert_redirected_to :controller => :users, :action => "new", :nickname => display_name,
536 :email => new_email, :email_hmac => email_hmac,
537 :auth_provider => "facebook", :auth_uid => auth_uid
541 :params => { :user => { :email => new_email,
542 :display_name => display_name,
543 :auth_provider => "facebook",
544 :auth_uid => auth_uid,
545 :consider_pd => "1" },
546 :email_hmac => email_hmac }
547 assert_redirected_to welcome_path
554 assert_response :success
555 assert_template "site/welcome"
557 ActionMailer::Base.deliveries.clear
560 def test_user_create_facebook_duplicate_email
561 dup_user = create(:user)
562 display_name = "new_tester-facebook"
563 auth_uid = "123454321"
565 OmniAuth.config.add_mock(:facebook,
567 :info => { :email => dup_user.email, :name => display_name })
569 post auth_path(:provider => "facebook", :origin => "/user/new")
570 assert_redirected_to auth_success_path(:provider => "facebook")
572 assert_redirected_to :controller => :users, :action => "new", :nickname => display_name, :email => dup_user.email,
573 :email_hmac => UsersController.message_hmac(dup_user.email),
574 :auth_provider => "facebook", :auth_uid => auth_uid
577 assert_response :success
578 assert_template "users/new"
579 assert_select "form > div > input.is-invalid#user_email"
581 ActionMailer::Base.deliveries.clear
584 def test_user_create_facebook_failure
585 OmniAuth.config.mock_auth[:facebook] = :connection_failed
587 assert_difference("User.count", 0) do
588 assert_difference("ActionMailer::Base.deliveries.size", 0) do
589 perform_enqueued_jobs do
590 post auth_path(:provider => "facebook", :origin => "/user/new")
591 assert_response :redirect
593 assert_redirected_to auth_failure_path(:strategy => "facebook", :message => "connection_failed", :origin => "/user/new")
595 assert_redirected_to "/user/new"
600 ActionMailer::Base.deliveries.clear
603 def test_user_create_facebook_redirect
604 orig_email = "redirect_tester_facebook_orig@osm.org"
605 email_hmac = UsersController.message_hmac(orig_email)
606 new_email = "redirect_tester_facebook@osm.org"
607 display_name = "redirect_tester_facebook"
608 auth_uid = "123454321"
610 OmniAuth.config.add_mock(:facebook,
612 :info => { :email => orig_email, :name => display_name })
614 # nothing special about this page, just need a protected page to redirect back to.
615 assert_difference("User.count") do
616 assert_difference("ActionMailer::Base.deliveries.size", 1) do
617 perform_enqueued_jobs do
618 post auth_path(:provider => "facebook", :origin => "/user/new")
619 assert_redirected_to auth_success_path(:provider => "facebook")
621 assert_redirected_to :controller => :users, :action => "new", :nickname => display_name,
622 :email => orig_email, :email_hmac => email_hmac,
623 :auth_provider => "facebook", :auth_uid => auth_uid
627 :params => { :user => { :email => new_email,
628 :email_hmac => email_hmac,
629 :display_name => display_name,
630 :auth_provider => "facebook",
631 :auth_uid => auth_uid,
632 :consider_pd => "1" } }
633 assert_response :redirect
640 register_email = ActionMailer::Base.deliveries.first
642 assert_equal register_email.to.first, new_email
643 # Check that the confirm account url is correct
644 confirm_regex = Regexp.new("confirm_string=([a-zA-Z0-9%_-]*)")
645 email_text_parts(register_email).each do |part|
646 assert_match confirm_regex, part.body.to_s
648 confirm_string = CGI.unescape(email_text_parts(register_email).first.body.match(confirm_regex)[1])
651 assert_response :success
652 assert_template "confirmations/confirm"
654 ActionMailer::Base.deliveries.clear
656 # Go to the confirmation page
657 get "/user/#{display_name}/confirm", :params => { :referer => "/welcome", :confirm_string => confirm_string }
658 assert_response :success
659 assert_template "confirmations/confirm"
661 post "/user/#{display_name}/confirm", :params => { :referer => "/welcome", :confirm_string => confirm_string }
662 assert_response :redirect
664 assert_response :success
665 assert_template "site/welcome"
668 def test_user_create_microsoft_success
669 new_email = "newtester-microsoft@osm.org"
670 email_hmac = UsersController.message_hmac(new_email)
671 display_name = "new_tester-microsoft"
672 auth_uid = "123454321"
674 OmniAuth.config.add_mock(:microsoft,
676 :info => { "email" => new_email, :name => display_name })
678 assert_difference("User.count") do
679 assert_difference("ActionMailer::Base.deliveries.size", 0) do
680 perform_enqueued_jobs do
681 post auth_path(:provider => "microsoft", :origin => "/user/new")
682 assert_redirected_to auth_success_path(:provider => "microsoft")
684 assert_redirected_to :controller => :users, :action => "new", :nickname => display_name,
685 :email => new_email, :email_hmac => email_hmac,
686 :auth_provider => "microsoft", :auth_uid => auth_uid
689 :params => { :user => { :email => new_email,
690 :display_name => display_name,
691 :auth_provider => "microsoft",
692 :auth_uid => auth_uid,
693 :consider_pd => "1" },
694 :email_hmac => email_hmac }
695 assert_redirected_to welcome_path
702 assert_response :success
703 assert_template "site/welcome"
705 ActionMailer::Base.deliveries.clear
708 def test_user_create_microsoft_duplicate_email
709 dup_user = create(:user)
710 display_name = "new_tester-microsoft"
711 auth_uid = "123454321"
713 OmniAuth.config.add_mock(:microsoft,
715 :info => { :email => dup_user.email, :name => display_name })
717 post auth_path(:provider => "microsoft", :origin => "/user/new")
718 assert_redirected_to auth_success_path(:provider => "microsoft")
720 assert_redirected_to :controller => :users, :action => "new", :nickname => display_name, :email => dup_user.email,
721 :email_hmac => UsersController.message_hmac(dup_user.email),
722 :auth_provider => "microsoft", :auth_uid => auth_uid
725 assert_response :success
726 assert_template "users/new"
727 assert_select "form > div > input.is-invalid#user_email"
729 ActionMailer::Base.deliveries.clear
732 def test_user_create_microsoft_failure
733 OmniAuth.config.mock_auth[:microsoft] = :connection_failed
735 assert_difference("User.count", 0) do
736 assert_difference("ActionMailer::Base.deliveries.size", 0) do
737 perform_enqueued_jobs do
738 post auth_path(:provider => "microsoft", :origin => "/user/new")
739 assert_response :redirect
741 assert_redirected_to auth_failure_path(:strategy => "microsoft", :message => "connection_failed", :origin => "/user/new")
743 assert_redirected_to "/user/new"
748 ActionMailer::Base.deliveries.clear
751 def test_user_create_microsoft_redirect
752 orig_email = "redirect_tester_microsoft_orig@osm.org"
753 email_hmac = UsersController.message_hmac(orig_email)
754 new_email = "redirect_tester_microsoft@osm.org"
755 display_name = "redirect_tester_microsoft"
756 auth_uid = "123454321"
758 OmniAuth.config.add_mock(:microsoft,
760 :info => { :email => orig_email, :name => display_name })
762 assert_difference("User.count") do
763 assert_difference("ActionMailer::Base.deliveries.size", 1) do
764 perform_enqueued_jobs do
765 post auth_path(:provider => "microsoft", :origin => "/user/new")
766 assert_redirected_to auth_success_path(:provider => "microsoft")
768 assert_redirected_to :controller => :users, :action => "new", :nickname => display_name,
769 :email => orig_email, :email_hmac => email_hmac,
770 :auth_provider => "microsoft", :auth_uid => auth_uid
774 :params => { :user => { :email => new_email,
775 :email_hmac => email_hmac,
776 :display_name => display_name,
777 :auth_provider => "microsoft",
778 :auth_uid => auth_uid,
779 :consider_pd => "1" } }
780 assert_response :redirect
787 register_email = ActionMailer::Base.deliveries.first
789 assert_equal register_email.to.first, new_email
790 # Check that the confirm account url is correct
791 confirm_regex = Regexp.new("confirm_string=([a-zA-Z0-9%_-]*)")
792 email_text_parts(register_email).each do |part|
793 assert_match confirm_regex, part.body.to_s
795 confirm_string = CGI.unescape(email_text_parts(register_email).first.body.match(confirm_regex)[1])
798 assert_response :success
799 assert_template "confirmations/confirm"
801 ActionMailer::Base.deliveries.clear
803 # Go to the confirmation page
804 get "/user/#{display_name}/confirm", :params => { :referer => "/welcome", :confirm_string => confirm_string }
805 assert_response :success
806 assert_template "confirmations/confirm"
808 post "/user/#{display_name}/confirm", :params => { :referer => "/welcome", :confirm_string => confirm_string }
809 assert_response :redirect
811 assert_response :success
812 assert_template "site/welcome"
815 def test_user_create_github_success
816 new_email = "newtester-github@osm.org"
817 email_hmac = UsersController.message_hmac(new_email)
818 display_name = "new_tester-github"
819 password = "testtest"
820 auth_uid = "123454321"
822 OmniAuth.config.add_mock(:github,
824 :info => { "email" => new_email, :name => display_name })
826 assert_difference("User.count") do
827 assert_no_difference("ActionMailer::Base.deliveries.size") do
828 perform_enqueued_jobs do
829 post auth_path(:provider => "github", :origin => "/user/new")
830 assert_redirected_to auth_success_path(:provider => "github")
832 assert_redirected_to :controller => :users, :action => "new", :nickname => display_name,
833 :email => new_email, :email_hmac => email_hmac,
834 :auth_provider => "github", :auth_uid => auth_uid
838 :params => { :user => { :email => new_email,
839 :display_name => display_name,
840 :auth_provider => "github",
841 :auth_uid => "123454321",
842 :pass_crypt => password,
843 :pass_crypt_confirmation => password },
846 :email_hmac => email_hmac }
847 assert_redirected_to welcome_path
854 assert_response :success
855 assert_template "site/welcome"
857 ActionMailer::Base.deliveries.clear
860 def test_user_create_github_duplicate_email
861 dup_user = create(:user)
862 display_name = "new_tester-github"
863 auth_uid = "123454321"
865 OmniAuth.config.add_mock(:github,
867 :extra => { :id_info => { :openid_id => "http://localhost:1123/new.tester" } },
868 :info => { :email => dup_user.email, :name => display_name })
870 post auth_path(:provider => "github", :origin => "/user/new")
871 assert_redirected_to auth_success_path(:provider => "github")
873 assert_redirected_to :controller => :users, :action => "new", :nickname => display_name,
874 :email => dup_user.email, :email_hmac => UsersController.message_hmac(dup_user.email),
875 :auth_provider => "github", :auth_uid => auth_uid
878 assert_response :success
879 assert_template "users/new"
880 assert_select "form > div > input.is-invalid#user_email"
882 ActionMailer::Base.deliveries.clear
885 def test_user_create_github_failure
886 OmniAuth.config.mock_auth[:github] = :connection_failed
888 assert_difference("User.count", 0) do
889 assert_difference("ActionMailer::Base.deliveries.size", 0) do
890 perform_enqueued_jobs do
891 post auth_path(:provider => "github", :origin => "/user/new")
893 assert_redirected_to auth_failure_path(:strategy => "github", :message => "connection_failed", :origin => "/user/new")
895 assert_redirected_to "/user/new"
900 ActionMailer::Base.deliveries.clear
903 def test_user_create_github_redirect
904 orig_email = "redirect_tester_github_orig@osm.org"
905 email_hmac = UsersController.message_hmac(orig_email)
906 new_email = "redirect_tester_github@osm.org"
907 display_name = "redirect_tester_github"
908 auth_uid = "123454321"
910 OmniAuth.config.add_mock(:github,
912 :info => { :email => orig_email, :name => display_name })
914 assert_difference("User.count") do
915 assert_difference("ActionMailer::Base.deliveries.size", 1) do
916 perform_enqueued_jobs do
917 post auth_path(:provider => "github", :origin => "/user/new")
918 assert_redirected_to auth_success_path(:provider => "github")
920 assert_redirected_to :controller => :users, :action => "new", :nickname => display_name,
921 :email => orig_email, :email_hmac => email_hmac,
922 :auth_provider => "github", :auth_uid => auth_uid
925 :params => { :user => { :email => new_email,
926 :email_hmac => email_hmac,
927 :display_name => display_name,
928 :auth_provider => "github",
929 :auth_uid => auth_uid,
930 :consider_pd => "1" } }
931 assert_response :redirect
938 register_email = ActionMailer::Base.deliveries.first
940 assert_equal register_email.to.first, new_email
941 # Check that the confirm account url is correct
942 confirm_regex = Regexp.new("confirm_string=([a-zA-Z0-9%_-]*)")
943 email_text_parts(register_email).each do |part|
944 assert_match confirm_regex, part.body.to_s
946 confirm_string = CGI.unescape(email_text_parts(register_email).first.body.match(confirm_regex)[1])
949 assert_response :success
950 assert_template "confirmations/confirm"
952 ActionMailer::Base.deliveries.clear
954 # Go to the confirmation page
955 get "/user/#{display_name}/confirm", :params => { :referer => "/welcome", :confirm_string => confirm_string }
956 assert_response :success
957 assert_template "confirmations/confirm"
959 post "/user/#{display_name}/confirm", :params => { :referer => "/welcome", :confirm_string => confirm_string }
960 assert_response :redirect
962 assert_response :success
963 assert_template "site/welcome"
966 def test_user_create_wikipedia_success
967 new_email = "newtester-wikipedia@osm.org"
968 email_hmac = UsersController.message_hmac(new_email)
969 display_name = "new_tester-wikipedia"
970 password = "testtest"
971 auth_uid = "123454321"
973 OmniAuth.config.add_mock(:wikipedia,
975 :info => { :email => new_email, :name => display_name })
977 assert_difference("User.count") do
978 assert_no_difference("ActionMailer::Base.deliveries.size") do
979 perform_enqueued_jobs do
980 post auth_path(:provider => "wikipedia", :origin => "/user/new")
981 assert_redirected_to auth_success_path(:provider => "wikipedia", :origin => "/user/new")
983 assert_redirected_to :controller => :users, :action => "new", :nickname => display_name,
984 :email => new_email, :email_hmac => email_hmac,
985 :auth_provider => "wikipedia", :auth_uid => auth_uid
988 :params => { :user => { :email => new_email,
989 :display_name => display_name,
990 :auth_provider => "wikipedia",
991 :auth_uid => "123454321",
992 :pass_crypt => password,
993 :pass_crypt_confirmation => password },
996 :email_hmac => email_hmac }
997 assert_redirected_to welcome_path
1004 assert_response :success
1005 assert_template "site/welcome"
1008 def test_user_create_wikipedia_duplicate_email
1009 dup_user = create(:user)
1010 display_name = "new_tester-wikipedia"
1011 auth_uid = "123454321"
1013 OmniAuth.config.add_mock(:wikipedia,
1015 :info => { "email" => dup_user.email, :name => display_name })
1017 post auth_path(:provider => "wikipedia", :origin => "/user/new")
1018 assert_redirected_to auth_success_path(:provider => "wikipedia", :origin => "/user/new")
1020 assert_redirected_to :controller => :users, :action => "new", :nickname => display_name,
1021 :email => dup_user.email, :email_hmac => UsersController.message_hmac(dup_user.email),
1022 :auth_provider => "wikipedia", :auth_uid => auth_uid
1025 assert_response :success
1026 assert_template "users/new"
1027 assert_select "form > div > input.is-invalid#user_email"
1029 ActionMailer::Base.deliveries.clear
1032 def test_user_create_wikipedia_failure
1033 OmniAuth.config.mock_auth[:wikipedia] = :connection_failed
1035 assert_difference("User.count", 0) do
1036 assert_difference("ActionMailer::Base.deliveries.size", 0) do
1037 perform_enqueued_jobs do
1038 post auth_path(:provider => "wikipedia", :origin => "/user/new")
1039 assert_response :redirect
1041 assert_redirected_to auth_failure_path(:strategy => "wikipedia", :message => "connection_failed", :origin => "/user/new")
1043 assert_redirected_to "/user/new"
1048 ActionMailer::Base.deliveries.clear
1051 def test_user_create_wikipedia_redirect
1052 orig_email = "redirect_tester_wikipedia_orig@osm.org"
1053 email_hmac = UsersController.message_hmac(orig_email)
1054 new_email = "redirect_tester_wikipedia@osm.org"
1055 display_name = "redirect_tester_wikipedia"
1056 auth_uid = "123454321"
1058 OmniAuth.config.add_mock(:wikipedia,
1060 :info => { :email => orig_email, :name => display_name })
1062 # nothing special about this page, just need a protected page to redirect back to.
1063 assert_difference("User.count") do
1064 assert_difference("ActionMailer::Base.deliveries.size", 1) do
1065 perform_enqueued_jobs do
1066 post auth_path(:provider => "wikipedia", :origin => "/user/new")
1067 assert_redirected_to auth_success_path(:provider => "wikipedia", :origin => "/user/new")
1069 assert_redirected_to :controller => :users, :action => "new", :nickname => display_name,
1070 :email => orig_email, :email_hmac => email_hmac,
1071 :auth_provider => "wikipedia", :auth_uid => auth_uid
1075 :params => { :user => { :email => new_email,
1076 :email_hmac => email_hmac,
1077 :display_name => display_name,
1078 :auth_provider => "wikipedia",
1079 :auth_uid => auth_uid,
1080 :consider_pd => "1" } }
1081 assert_response :redirect
1088 register_email = ActionMailer::Base.deliveries.first
1090 assert_equal register_email.to.first, new_email
1091 # Check that the confirm account url is correct
1092 confirm_regex = Regexp.new("confirm_string=([a-zA-Z0-9%_-]*)")
1093 email_text_parts(register_email).each do |part|
1094 assert_match confirm_regex, part.body.to_s
1096 confirm_string = CGI.unescape(email_text_parts(register_email).first.body.match(confirm_regex)[1])
1099 assert_response :success
1100 assert_template "confirmations/confirm"
1102 ActionMailer::Base.deliveries.clear
1104 # Go to the confirmation page
1105 get "/user/#{display_name}/confirm", :params => { :referer => "/welcome", :confirm_string => confirm_string }
1106 assert_response :success
1107 assert_template "confirmations/confirm"
1109 post "/user/#{display_name}/confirm", :params => { :referer => "/welcome", :confirm_string => confirm_string }
1110 assert_response :redirect
1112 assert_response :success
1113 assert_template "site/welcome"