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_bad_auth_provider
49 assert_difference("User.count", 0) do
50 assert_no_difference("ActionMailer::Base.deliveries.size") do
51 perform_enqueued_jobs do
53 :params => { :user => { :email => "test@example.com",
54 :display_name => "new_tester",
55 :pass_crypt => "testtest",
56 :pass_crypt_confirmation => "testtest",
57 :auth_provider => "noprovider",
58 :auth_uid => "123454321",
59 :consider_pd => "1" } }
60 assert_redirected_to auth_path(:provider => "noprovider", :origin => "/user/new")
61 post response.location
65 assert_response :not_found
68 def test_user_create_association_no_auth_uid
69 OmniAuth.config.mock_auth[:google] = :invalid_credentials
70 assert_difference("User.count", 0) do
71 assert_no_difference("ActionMailer::Base.deliveries.size") do
72 perform_enqueued_jobs do
74 :params => { :user => { :email => "test@example.com",
75 :display_name => "new_tester",
76 :pass_crypt => "testtest",
77 :pass_crypt_confirmation => "testtest",
78 :auth_provider => "google",
79 :consider_pd => "1" } }
80 assert_redirected_to auth_path(:provider => "google", :origin => "/user/new")
81 post response.location
86 assert_redirected_to auth_failure_path(:strategy => "google", :message => "invalid_credentials", :origin => "/user/new")
89 def test_user_create_association_submit_duplicate_email
90 dup_email = create(:user).email
91 display_name = "new_tester"
92 assert_difference("User.count", 0) do
93 assert_no_difference("ActionMailer::Base.deliveries.size") do
94 perform_enqueued_jobs do
96 :params => { :user => { :email => dup_email,
97 :display_name => display_name,
98 :pass_crypt => "testtest",
99 :pass_crypt_confirmation => "testtest",
100 :auth_provider => "google",
101 :auth_uid => "123454321",
102 :consider_pd => "1" } }
106 assert_response :success
107 assert_template "users/new"
109 assert_select "form > div > input.is-invalid#user_email"
112 def test_user_create_submit_duplicate_username
113 dup_display_name = create(:user).display_name
115 assert_difference("User.count", 0) do
116 assert_difference("ActionMailer::Base.deliveries.size", 0) do
117 perform_enqueued_jobs do
119 :params => { :user => { :email => email,
120 :display_name => dup_display_name,
121 :pass_crypt => "testtest",
122 :pass_crypt_confirmation => "testtest" } }
126 assert_response :success
127 assert_template "users/new"
128 assert_select "form > div > input.is-invalid#user_display_name"
131 def test_user_create_submit_mismatched_passwords
132 email = "newtester@osm.org"
133 display_name = "new_tester"
134 assert_difference("User.count", 0) do
135 assert_difference("ActionMailer::Base.deliveries.size", 0) do
136 perform_enqueued_jobs do
138 :params => { :user => { :email => email,
139 :display_name => display_name,
140 :pass_crypt => "testtest",
141 :pass_crypt_confirmation => "blahblah",
142 :consider_pd => "1" } }
146 assert_response :success
147 assert_template "users/new"
148 assert_select "form > div > div > div > input.is-invalid#user_pass_crypt_confirmation"
151 def test_user_create_association_submit_duplicate_username
152 dup_display_name = create(:user).display_name
154 assert_difference("User.count", 0) do
155 assert_no_difference("ActionMailer::Base.deliveries.size") do
156 perform_enqueued_jobs do
158 :params => { :user => { :email => email,
159 :display_name => dup_display_name,
160 :auth_provider => "google",
161 :auth_uid => "123454321",
162 :consider_pd => "1" } }
166 assert_response :success
167 assert_template "users/new"
168 assert_select "form > div > input.is-invalid#user_display_name"
171 def test_user_create_success
172 new_email = "newtester@osm.org"
173 display_name = "new_tester"
175 assert_difference("User.count", 1) do
176 assert_difference("ActionMailer::Base.deliveries.size", 1) do
177 perform_enqueued_jobs do
179 :params => { :user => { :email => new_email,
180 :display_name => display_name,
181 :pass_crypt => "testtest",
182 :pass_crypt_confirmation => "testtest",
183 :consider_pd => "1" } }
184 assert_redirected_to :controller => :confirmations, :action => :confirm, :display_name => display_name
190 assert_response :success
191 assert_template "confirmations/confirm"
193 user = User.find_by(:email => "newtester@osm.org")
195 assert_not_predicate user, :active?
197 register_email = ActionMailer::Base.deliveries.first
198 assert_equal register_email.to.first, new_email
199 found_confirmation_url = register_email.parts.first.parts.first.to_s =~ %r{\shttp://test.host(/\S+)\s}
200 assert found_confirmation_url
201 confirmation_url = Regexp.last_match(1)
202 ActionMailer::Base.deliveries.clear
204 post confirmation_url
206 assert_redirected_to welcome_path
209 assert_predicate user, :active?
211 assert_equal user, User.authenticate(:username => new_email, :password => "testtest")
214 # Check that the user can successfully recover their password
215 def test_lost_password_recovery_success
216 # Open the lost password form
217 # Submit the lost password form
219 # Submit the reset password token
220 # Check that the password has changed, and the user can login
223 def test_user_create_redirect
224 new_email = "redirect_tester@osm.org"
225 display_name = "redirect_tester"
226 password = "testtest"
227 # nothing special about this page, just need a protected page to redirect back to.
228 referer = "/traces/mine"
229 assert_difference("User.count") do
230 assert_difference("ActionMailer::Base.deliveries.size", 1) do
231 perform_enqueued_jobs do
233 :params => { :user => { :email => new_email,
234 :display_name => display_name,
235 :pass_crypt => password,
236 :pass_crypt_confirmation => password,
237 :consider_pd => "1" },
238 :referer => referer }
239 assert_response(:redirect)
240 assert_redirected_to :controller => :confirmations, :action => :confirm, :display_name => display_name
247 register_email = ActionMailer::Base.deliveries.first
249 assert_equal register_email.to.first, new_email
250 # Check that the confirm account url is correct
251 confirm_regex = Regexp.new("confirm_string=([a-zA-Z0-9%_-]*)")
252 email_text_parts(register_email).each do |part|
253 assert_match confirm_regex, part.body.to_s
255 confirm_string = CGI.unescape(email_text_parts(register_email).first.body.match(confirm_regex)[1])
258 assert_response :success
259 assert_template "confirmations/confirm"
261 ActionMailer::Base.deliveries.clear
263 # Go to the confirmation page
264 get "/user/#{display_name}/confirm", :params => { :referer => "/welcome", :confirm_string => confirm_string }
265 assert_response :success
266 assert_template "confirmations/confirm"
268 post "/user/#{display_name}/confirm", :params => { :referer => "/welcome", :confirm_string => confirm_string }
269 assert_response :redirect
271 assert_response :success
272 assert_template "site/welcome"
275 def test_user_create_openid_success
276 new_email = "newtester-openid@osm.org"
277 display_name = "new_tester-openid"
278 auth_uid = "http://localhost:1123/new.tester"
280 OmniAuth.config.add_mock(:openid,
282 :info => { :email => new_email, :name => display_name })
284 assert_difference("User.count") do
285 assert_difference("ActionMailer::Base.deliveries.size", 1) do
286 perform_enqueued_jobs do
287 post auth_path(:provider => "openid", :openid_url => "http://localhost:1123/new.tester", :origin => "/user/new")
288 assert_redirected_to auth_success_path(:provider => "openid", :openid_url => "http://localhost:1123/new.tester", :origin => "/user/new")
290 assert_redirected_to :controller => :users, :action => "new", :nickname => display_name, :email => new_email,
291 :auth_provider => "openid", :auth_uid => auth_uid
294 :params => { :user => { :email => new_email,
295 :display_name => display_name,
296 :auth_provider => "openid",
297 :auth_uid => "http://localhost:1123/new.tester",
298 :consider_pd => "1" } }
299 assert_redirected_to auth_path(:provider => "openid", :openid_url => "http://localhost:1123/new.tester", :origin => "/user/new")
300 post response.location
307 assert_redirected_to :controller => :confirmations, :action => :confirm, :display_name => display_name
309 ActionMailer::Base.deliveries.clear
312 def test_user_create_openid_duplicate_email
313 dup_user = create(:user)
314 display_name = "new_tester-openid"
315 auth_uid = "123454321"
317 OmniAuth.config.add_mock(:openid,
319 :info => { :email => dup_user.email, :name => display_name })
321 post auth_path(:provider => "openid", :origin => "/user/new")
322 assert_redirected_to auth_success_path(:provider => "openid", :origin => "/user/new")
324 assert_redirected_to :controller => :users, :action => "new", :nickname => display_name, :email => dup_user.email,
325 :auth_provider => "openid", :auth_uid => auth_uid
328 assert_response :success
329 assert_template "users/new"
330 assert_select "form > div > input.is-invalid#user_email"
332 ActionMailer::Base.deliveries.clear
335 def test_user_create_openid_failure
336 OmniAuth.config.mock_auth[:openid] = :connection_failed
338 new_email = "newtester-openid2@osm.org"
339 display_name = "new_tester-openid2"
340 assert_difference("User.count", 0) do
341 assert_difference("ActionMailer::Base.deliveries.size", 0) do
342 perform_enqueued_jobs do
344 :params => { :user => { :email => new_email,
345 :email_confirmation => new_email,
346 :display_name => display_name,
347 :auth_provider => "openid",
348 :auth_uid => "http://localhost:1123/new.tester",
350 :pass_crypt_confirmation => "" } }
351 assert_redirected_to auth_path(:provider => "openid", :openid_url => "http://localhost:1123/new.tester", :origin => "/user/new")
352 post response.location
353 assert_redirected_to auth_success_path(:provider => "openid", :openid_url => "http://localhost:1123/new.tester", :origin => "/user/new")
355 assert_redirected_to auth_failure_path(:strategy => "openid", :message => "connection_failed", :origin => "/user/new")
357 assert_redirected_to "/user/new"
362 ActionMailer::Base.deliveries.clear
365 def test_user_create_openid_redirect
366 auth_uid = "http://localhost:1123/new.tester"
367 new_email = "redirect_tester_openid@osm.org"
368 display_name = "redirect_tester_openid"
370 OmniAuth.config.add_mock(:openid,
372 :info => { :email => new_email, :name => display_name })
374 assert_difference("User.count") do
375 assert_difference("ActionMailer::Base.deliveries.size", 1) do
376 perform_enqueued_jobs do
377 post auth_path(:provider => "openid", :openid_url => "http://localhost:1123/new.tester", :origin => "/user/new")
378 assert_redirected_to auth_success_path(:provider => "openid", :openid_url => "http://localhost:1123/new.tester", :origin => "/user/new")
380 assert_redirected_to :controller => :users, :action => "new", :nickname => display_name, :email => new_email,
381 :auth_provider => "openid", :auth_uid => auth_uid
384 :params => { :user => { :email => new_email,
385 :display_name => display_name,
386 :auth_provider => "openid",
387 :auth_uid => auth_uid,
388 :consider_pd => "1" } }
389 assert_redirected_to auth_path(:provider => "openid", :openid_url => "http://localhost:1123/new.tester", :origin => "/user/new")
390 post response.location
391 assert_redirected_to auth_success_path(:provider => "openid", :openid_url => "http://localhost:1123/new.tester", :origin => "/user/new")
393 assert_redirected_to :controller => :confirmations, :action => :confirm, :display_name => display_name
400 register_email = ActionMailer::Base.deliveries.first
402 assert_equal register_email.to.first, new_email
403 # Check that the confirm account url is correct
404 confirm_regex = Regexp.new("confirm_string=([a-zA-Z0-9%_-]*)")
405 email_text_parts(register_email).each do |part|
406 assert_match confirm_regex, part.body.to_s
408 confirm_string = CGI.unescape(email_text_parts(register_email).first.body.match(confirm_regex)[1])
411 assert_response :success
412 assert_template "confirmations/confirm"
414 ActionMailer::Base.deliveries.clear
416 # Go to the confirmation page
417 get "/user/#{display_name}/confirm", :params => { :referer => "/welcome", :confirm_string => confirm_string }
418 assert_response :success
419 assert_template "confirmations/confirm"
421 post "/user/#{display_name}/confirm", :params => { :referer => "/welcome", :confirm_string => confirm_string }
422 assert_response :redirect
424 assert_response :success
425 assert_template "site/welcome"
428 def test_user_create_google_success
429 new_email = "newtester-google@osm.org"
430 email_hmac = UsersController.message_hmac(new_email)
431 display_name = "new_tester-google"
432 auth_uid = "123454321"
434 OmniAuth.config.add_mock(:google,
436 :extra => { :id_info => { :openid_id => "http://localhost:1123/new.tester" } },
437 :info => { :email => new_email, :name => display_name })
439 assert_difference("User.count") do
440 assert_no_difference("ActionMailer::Base.deliveries.size") do
441 perform_enqueued_jobs do
442 post auth_path(:provider => "google", :origin => "/user/new")
443 assert_redirected_to auth_success_path(:provider => "google")
445 assert_redirected_to :controller => :users, :action => "new", :nickname => display_name,
446 :email => new_email, :email_hmac => email_hmac,
447 :auth_provider => "google", :auth_uid => auth_uid
451 :params => { :user => { :email => new_email,
452 :display_name => display_name,
453 :auth_provider => "google",
454 :auth_uid => auth_uid,
455 :consider_pd => "1" },
456 :email_hmac => email_hmac }
457 assert_redirected_to auth_path(:provider => "google", :origin => "/user/new")
458 post response.location
459 assert_redirected_to auth_success_path(:provider => "google")
461 assert_redirected_to welcome_path
468 assert_response :success
469 assert_template "site/welcome"
471 ActionMailer::Base.deliveries.clear
474 def test_user_create_google_duplicate_email
475 dup_user = create(:user)
476 display_name = "new_tester-google"
477 auth_uid = "123454321"
479 OmniAuth.config.add_mock(:google,
481 :extra => { :id_info => { :openid_id => "http://localhost:1123/new.tester" } },
482 :info => { :email => dup_user.email, :name => display_name })
484 post auth_path(:provider => "google", :origin => "/user/new")
485 assert_redirected_to auth_success_path(:provider => "google")
487 assert_redirected_to :controller => :users, :action => "new", :nickname => display_name, :email => dup_user.email,
488 :email_hmac => UsersController.message_hmac(dup_user.email),
489 :auth_provider => "google", :auth_uid => auth_uid
492 assert_response :success
493 assert_template "users/new"
494 assert_select "form > div > input.is-invalid#user_email"
496 ActionMailer::Base.deliveries.clear
499 def test_user_create_google_failure
500 OmniAuth.config.mock_auth[:google] = :connection_failed
502 new_email = "newtester-google2@osm.org"
503 display_name = "new_tester-google2"
504 assert_difference("User.count", 0) do
505 assert_difference("ActionMailer::Base.deliveries.size", 0) do
506 perform_enqueued_jobs do
508 :params => { :user => { :email => new_email,
509 :email_confirmation => new_email,
510 :display_name => display_name,
511 :auth_provider => "google",
512 :auth_uid => "123454321",
514 :pass_crypt_confirmation => "" } }
515 assert_redirected_to auth_path(:provider => "google", :origin => "/user/new")
516 post response.location
517 assert_redirected_to auth_success_path(:provider => "google")
519 assert_redirected_to auth_failure_path(:strategy => "google", :message => "connection_failed", :origin => "/user/new")
521 assert_redirected_to "/user/new"
526 ActionMailer::Base.deliveries.clear
529 def test_user_create_google_redirect
530 orig_email = "redirect_tester_google_orig@google.com"
531 email_hmac = UsersController.message_hmac(orig_email)
532 new_email = "redirect_tester_google@osm.org"
533 display_name = "redirect_tester_google"
534 auth_uid = "123454321"
536 OmniAuth.config.add_mock(:google,
538 :extra => { :id_info => { :openid_id => "http://localhost:1123/new.tester" } },
539 :info => { :email => orig_email, :name => display_name })
541 assert_difference("User.count") do
542 assert_difference("ActionMailer::Base.deliveries.size", 1) do
543 perform_enqueued_jobs do
544 post auth_path(:provider => "google", :origin => "/user/new")
545 assert_redirected_to auth_success_path(:provider => "google")
547 assert_redirected_to :controller => :users, :action => "new", :nickname => display_name,
548 :email => orig_email, :email_hmac => email_hmac,
549 :auth_provider => "google", :auth_uid => auth_uid
552 :params => { :user => { :email => new_email,
553 :email_hmac => email_hmac,
554 :display_name => display_name,
555 :auth_provider => "google",
556 :auth_uid => auth_uid,
557 :consider_pd => "1" } }
558 assert_redirected_to auth_path(:provider => "google", :origin => "/user/new")
559 post response.location
560 assert_redirected_to auth_success_path(:provider => "google")
562 assert_redirected_to :controller => :confirmations, :action => :confirm, :display_name => display_name
569 register_email = ActionMailer::Base.deliveries.first
571 assert_equal register_email.to.first, new_email
572 # Check that the confirm account url is correct
573 confirm_regex = Regexp.new("confirm_string=([a-zA-Z0-9%_-]*)")
574 email_text_parts(register_email).each do |part|
575 assert_match confirm_regex, part.body.to_s
577 confirm_string = CGI.unescape(email_text_parts(register_email).first.body.match(confirm_regex)[1])
580 assert_response :success
581 assert_template "confirmations/confirm"
583 ActionMailer::Base.deliveries.clear
585 # Go to the confirmation page
586 get "/user/#{display_name}/confirm", :params => { :referer => "/welcome", :confirm_string => confirm_string }
587 assert_response :success
588 assert_template "confirmations/confirm"
590 post "/user/#{display_name}/confirm", :params => { :referer => "/welcome", :confirm_string => confirm_string }
591 assert_response :redirect
593 assert_response :success
594 assert_template "site/welcome"
597 def test_user_create_facebook_success
598 new_email = "newtester-facebook@osm.org"
599 email_hmac = UsersController.message_hmac(new_email)
600 display_name = "new_tester-facebook"
601 auth_uid = "123454321"
603 OmniAuth.config.add_mock(:facebook,
605 :info => { "email" => new_email, :name => display_name })
607 assert_difference("User.count") do
608 assert_no_difference("ActionMailer::Base.deliveries.size") do
609 perform_enqueued_jobs do
610 post auth_path(:provider => "facebook", :origin => "/user/new")
611 assert_redirected_to auth_success_path(:provider => "facebook")
613 assert_redirected_to :controller => :users, :action => "new", :nickname => display_name,
614 :email => new_email, :email_hmac => email_hmac,
615 :auth_provider => "facebook", :auth_uid => auth_uid
619 :params => { :user => { :email => new_email,
620 :display_name => display_name,
621 :auth_provider => "facebook",
622 :auth_uid => auth_uid,
623 :consider_pd => "1" },
624 :email_hmac => email_hmac }
625 assert_redirected_to auth_path(:provider => "facebook", :origin => "/user/new")
626 post response.location
627 assert_redirected_to auth_success_path(:provider => "facebook")
629 assert_redirected_to welcome_path
636 assert_response :success
637 assert_template "site/welcome"
639 ActionMailer::Base.deliveries.clear
642 def test_user_create_facebook_duplicate_email
643 dup_user = create(:user)
644 display_name = "new_tester-facebook"
645 auth_uid = "123454321"
647 OmniAuth.config.add_mock(:facebook,
649 :info => { :email => dup_user.email, :name => display_name })
651 post auth_path(:provider => "facebook", :origin => "/user/new")
652 assert_redirected_to auth_success_path(:provider => "facebook")
654 assert_redirected_to :controller => :users, :action => "new", :nickname => display_name, :email => dup_user.email,
655 :email_hmac => UsersController.message_hmac(dup_user.email),
656 :auth_provider => "facebook", :auth_uid => auth_uid
659 assert_response :success
660 assert_template "users/new"
661 assert_select "form > div > input.is-invalid#user_email"
663 ActionMailer::Base.deliveries.clear
666 def test_user_create_facebook_failure
667 OmniAuth.config.mock_auth[:facebook] = :connection_failed
669 new_email = "newtester-facebook2@osm.org"
670 display_name = "new_tester-facebook2"
671 assert_difference("User.count", 0) do
672 assert_difference("ActionMailer::Base.deliveries.size", 0) do
673 perform_enqueued_jobs do
675 :params => { :user => { :email => new_email,
676 :email_confirmation => new_email,
677 :display_name => display_name,
678 :auth_provider => "facebook",
679 :auth_uid => "123454321",
681 :pass_crypt_confirmation => "" } }
682 assert_redirected_to auth_path(:provider => "facebook", :origin => "/user/new")
683 post response.location
684 assert_redirected_to auth_success_path(:provider => "facebook")
686 assert_redirected_to auth_failure_path(:strategy => "facebook", :message => "connection_failed", :origin => "/user/new")
688 assert_redirected_to "/user/new"
693 ActionMailer::Base.deliveries.clear
696 def test_user_create_facebook_redirect
697 orig_email = "redirect_tester_facebook_orig@osm.org"
698 email_hmac = UsersController.message_hmac(orig_email)
699 new_email = "redirect_tester_facebook@osm.org"
700 display_name = "redirect_tester_facebook"
701 auth_uid = "123454321"
703 OmniAuth.config.add_mock(:facebook,
705 :info => { :email => orig_email, :name => display_name })
707 # nothing special about this page, just need a protected page to redirect back to.
708 assert_difference("User.count") do
709 assert_difference("ActionMailer::Base.deliveries.size", 1) do
710 perform_enqueued_jobs do
711 post auth_path(:provider => "facebook", :origin => "/user/new")
712 assert_redirected_to auth_success_path(:provider => "facebook")
714 assert_redirected_to :controller => :users, :action => "new", :nickname => display_name,
715 :email => orig_email, :email_hmac => email_hmac,
716 :auth_provider => "facebook", :auth_uid => auth_uid
720 :params => { :user => { :email => new_email,
721 :email_hmac => email_hmac,
722 :display_name => display_name,
723 :auth_provider => "facebook",
724 :auth_uid => auth_uid,
725 :consider_pd => "1" } }
726 assert_redirected_to auth_path(:provider => "facebook", :origin => "/user/new")
727 post response.location
728 assert_redirected_to auth_success_path(:provider => "facebook")
730 assert_redirected_to :controller => :confirmations, :action => :confirm, :display_name => display_name
731 assert_response :redirect
738 register_email = ActionMailer::Base.deliveries.first
740 assert_equal register_email.to.first, new_email
741 # Check that the confirm account url is correct
742 confirm_regex = Regexp.new("confirm_string=([a-zA-Z0-9%_-]*)")
743 email_text_parts(register_email).each do |part|
744 assert_match confirm_regex, part.body.to_s
746 confirm_string = CGI.unescape(email_text_parts(register_email).first.body.match(confirm_regex)[1])
749 assert_response :success
750 assert_template "confirmations/confirm"
752 ActionMailer::Base.deliveries.clear
754 # Go to the confirmation page
755 get "/user/#{display_name}/confirm", :params => { :referer => "/welcome", :confirm_string => confirm_string }
756 assert_response :success
757 assert_template "confirmations/confirm"
759 post "/user/#{display_name}/confirm", :params => { :referer => "/welcome", :confirm_string => confirm_string }
760 assert_response :redirect
762 assert_response :success
763 assert_template "site/welcome"
766 def test_user_create_microsoft_success
767 new_email = "newtester-microsoft@osm.org"
768 email_hmac = UsersController.message_hmac(new_email)
769 display_name = "new_tester-microsoft"
770 auth_uid = "123454321"
772 OmniAuth.config.add_mock(:microsoft,
774 :info => { "email" => new_email, :name => display_name })
776 assert_difference("User.count") do
777 assert_difference("ActionMailer::Base.deliveries.size", 0) do
778 perform_enqueued_jobs do
779 post auth_path(:provider => "microsoft", :origin => "/user/new")
780 assert_redirected_to auth_success_path(:provider => "microsoft")
782 assert_redirected_to :controller => :users, :action => "new", :nickname => display_name,
783 :email => new_email, :email_hmac => email_hmac,
784 :auth_provider => "microsoft", :auth_uid => auth_uid
787 :params => { :user => { :email => new_email,
788 :display_name => display_name,
789 :auth_provider => "microsoft",
790 :auth_uid => auth_uid,
791 :consider_pd => "1" },
792 :email_hmac => email_hmac }
793 assert_redirected_to auth_path(:provider => "microsoft", :origin => "/user/new")
794 post response.location
795 assert_redirected_to auth_success_path(:provider => "microsoft")
797 assert_redirected_to welcome_path
804 assert_response :success
805 assert_template "site/welcome"
807 ActionMailer::Base.deliveries.clear
810 def test_user_create_microsoft_duplicate_email
811 dup_user = create(:user)
812 display_name = "new_tester-microsoft"
813 auth_uid = "123454321"
815 OmniAuth.config.add_mock(:microsoft,
817 :info => { :email => dup_user.email, :name => display_name })
819 post auth_path(:provider => "microsoft", :origin => "/user/new")
820 assert_redirected_to auth_success_path(:provider => "microsoft")
822 assert_redirected_to :controller => :users, :action => "new", :nickname => display_name, :email => dup_user.email,
823 :email_hmac => UsersController.message_hmac(dup_user.email),
824 :auth_provider => "microsoft", :auth_uid => auth_uid
827 assert_response :success
828 assert_template "users/new"
829 assert_select "form > div > input.is-invalid#user_email"
831 ActionMailer::Base.deliveries.clear
834 def test_user_create_microsoft_failure
835 OmniAuth.config.mock_auth[:microsoft] = :connection_failed
837 new_email = "newtester-microsoft2@osm.org"
838 display_name = "new_tester-microsoft2"
839 assert_difference("User.count", 0) do
840 assert_difference("ActionMailer::Base.deliveries.size", 0) do
841 perform_enqueued_jobs do
843 :params => { :user => { :email => new_email,
844 :email_confirmation => new_email,
845 :display_name => display_name,
846 :auth_provider => "microsoft",
847 :auth_uid => "123454321",
849 :pass_crypt_confirmation => "" } }
850 assert_redirected_to auth_path(:provider => "microsoft", :origin => "/user/new")
851 post response.location
852 assert_redirected_to auth_success_path(:provider => "microsoft")
854 assert_redirected_to auth_failure_path(:strategy => "microsoft", :message => "connection_failed", :origin => "/user/new")
856 assert_redirected_to "/user/new"
861 ActionMailer::Base.deliveries.clear
864 def test_user_create_microsoft_redirect
865 orig_email = "redirect_tester_microsoft_orig@osm.org"
866 email_hmac = UsersController.message_hmac(orig_email)
867 new_email = "redirect_tester_microsoft@osm.org"
868 display_name = "redirect_tester_microsoft"
869 auth_uid = "123454321"
871 OmniAuth.config.add_mock(:microsoft,
873 :info => { :email => orig_email, :name => display_name })
875 assert_difference("User.count") do
876 assert_difference("ActionMailer::Base.deliveries.size", 1) do
877 perform_enqueued_jobs do
878 post auth_path(:provider => "microsoft", :origin => "/user/new")
879 assert_redirected_to auth_success_path(:provider => "microsoft")
881 assert_redirected_to :controller => :users, :action => "new", :nickname => display_name,
882 :email => orig_email, :email_hmac => email_hmac,
883 :auth_provider => "microsoft", :auth_uid => auth_uid
887 :params => { :user => { :email => new_email,
888 :email_hmac => email_hmac,
889 :display_name => display_name,
890 :auth_provider => "microsoft",
891 :auth_uid => auth_uid,
892 :consider_pd => "1" } }
893 assert_redirected_to auth_path(:provider => "microsoft", :origin => "/user/new")
894 post response.location
895 assert_redirected_to auth_success_path(:provider => "microsoft")
897 assert_redirected_to :controller => :confirmations, :action => :confirm, :display_name => display_name
898 assert_response :redirect
905 register_email = ActionMailer::Base.deliveries.first
907 assert_equal register_email.to.first, new_email
908 # Check that the confirm account url is correct
909 confirm_regex = Regexp.new("confirm_string=([a-zA-Z0-9%_-]*)")
910 email_text_parts(register_email).each do |part|
911 assert_match confirm_regex, part.body.to_s
913 confirm_string = CGI.unescape(email_text_parts(register_email).first.body.match(confirm_regex)[1])
916 assert_response :success
917 assert_template "confirmations/confirm"
919 ActionMailer::Base.deliveries.clear
921 # Go to the confirmation page
922 get "/user/#{display_name}/confirm", :params => { :referer => "/welcome", :confirm_string => confirm_string }
923 assert_response :success
924 assert_template "confirmations/confirm"
926 post "/user/#{display_name}/confirm", :params => { :referer => "/welcome", :confirm_string => confirm_string }
927 assert_response :redirect
929 assert_response :success
930 assert_template "site/welcome"
933 def test_user_create_github_success
934 new_email = "newtester-github@osm.org"
935 email_hmac = UsersController.message_hmac(new_email)
936 display_name = "new_tester-github"
937 password = "testtest"
938 auth_uid = "123454321"
940 OmniAuth.config.add_mock(:github,
942 :info => { "email" => new_email, :name => display_name })
944 assert_difference("User.count") do
945 assert_no_difference("ActionMailer::Base.deliveries.size") do
946 perform_enqueued_jobs do
947 post auth_path(:provider => "github", :origin => "/user/new")
948 assert_redirected_to auth_success_path(:provider => "github")
950 assert_redirected_to :controller => :users, :action => "new", :nickname => display_name,
951 :email => new_email, :email_hmac => email_hmac,
952 :auth_provider => "github", :auth_uid => auth_uid
956 :params => { :user => { :email => new_email,
957 :display_name => display_name,
958 :auth_provider => "github",
959 :auth_uid => "123454321",
960 :pass_crypt => password,
961 :pass_crypt_confirmation => password },
964 :email_hmac => email_hmac }
965 assert_redirected_to auth_path(:provider => "github", :origin => "/user/new")
966 post response.location
967 assert_redirected_to auth_success_path(:provider => "github")
969 assert_redirected_to welcome_path
976 assert_response :success
977 assert_template "site/welcome"
979 ActionMailer::Base.deliveries.clear
982 def test_user_create_github_duplicate_email
983 dup_user = create(:user)
984 display_name = "new_tester-github"
985 auth_uid = "123454321"
987 OmniAuth.config.add_mock(:github,
989 :extra => { :id_info => { :openid_id => "http://localhost:1123/new.tester" } },
990 :info => { :email => dup_user.email, :name => display_name })
992 post auth_path(:provider => "github", :origin => "/user/new")
993 assert_redirected_to auth_success_path(:provider => "github")
995 assert_redirected_to :controller => :users, :action => "new", :nickname => display_name,
996 :email => dup_user.email, :email_hmac => UsersController.message_hmac(dup_user.email),
997 :auth_provider => "github", :auth_uid => auth_uid
1000 assert_response :success
1001 assert_template "users/new"
1002 assert_select "form > div > input.is-invalid#user_email"
1004 ActionMailer::Base.deliveries.clear
1007 def test_user_create_github_failure
1008 OmniAuth.config.mock_auth[:github] = :connection_failed
1010 new_email = "newtester-github2@osm.org"
1011 display_name = "new_tester-github2"
1012 assert_difference("User.count", 0) do
1013 assert_difference("ActionMailer::Base.deliveries.size", 0) do
1014 perform_enqueued_jobs do
1016 :params => { :user => { :email => new_email,
1017 :email_confirmation => new_email,
1018 :display_name => display_name,
1019 :auth_provider => "github",
1020 :auth_uid => "123454321",
1022 :pass_crypt_confirmation => "" } }
1023 assert_redirected_to auth_path(:provider => "github", :origin => "/user/new")
1024 post response.location
1025 assert_redirected_to auth_success_path(:provider => "github")
1027 assert_redirected_to auth_failure_path(:strategy => "github", :message => "connection_failed", :origin => "/user/new")
1029 assert_redirected_to "/user/new"
1034 ActionMailer::Base.deliveries.clear
1037 def test_user_create_github_redirect
1038 orig_email = "redirect_tester_github_orig@osm.org"
1039 email_hmac = UsersController.message_hmac(orig_email)
1040 new_email = "redirect_tester_github@osm.org"
1041 display_name = "redirect_tester_github"
1042 auth_uid = "123454321"
1044 OmniAuth.config.add_mock(:github,
1046 :info => { :email => orig_email, :name => display_name })
1048 assert_difference("User.count") do
1049 assert_difference("ActionMailer::Base.deliveries.size", 1) do
1050 perform_enqueued_jobs do
1051 post auth_path(:provider => "github", :origin => "/user/new")
1052 assert_redirected_to auth_success_path(:provider => "github")
1054 assert_redirected_to :controller => :users, :action => "new", :nickname => display_name,
1055 :email => orig_email, :email_hmac => email_hmac,
1056 :auth_provider => "github", :auth_uid => auth_uid
1059 :params => { :user => { :email => new_email,
1060 :email_hmac => email_hmac,
1061 :display_name => display_name,
1062 :auth_provider => "github",
1063 :auth_uid => auth_uid,
1064 :consider_pd => "1" } }
1065 assert_redirected_to auth_path(:provider => "github", :origin => "/user/new")
1066 post response.location
1067 assert_redirected_to auth_success_path(:provider => "github")
1069 assert_redirected_to :controller => :confirmations, :action => :confirm, :display_name => display_name
1070 assert_response :redirect
1077 register_email = ActionMailer::Base.deliveries.first
1079 assert_equal register_email.to.first, new_email
1080 # Check that the confirm account url is correct
1081 confirm_regex = Regexp.new("confirm_string=([a-zA-Z0-9%_-]*)")
1082 email_text_parts(register_email).each do |part|
1083 assert_match confirm_regex, part.body.to_s
1085 confirm_string = CGI.unescape(email_text_parts(register_email).first.body.match(confirm_regex)[1])
1088 assert_response :success
1089 assert_template "confirmations/confirm"
1091 ActionMailer::Base.deliveries.clear
1093 # Go to the confirmation page
1094 get "/user/#{display_name}/confirm", :params => { :referer => "/welcome", :confirm_string => confirm_string }
1095 assert_response :success
1096 assert_template "confirmations/confirm"
1098 post "/user/#{display_name}/confirm", :params => { :referer => "/welcome", :confirm_string => confirm_string }
1099 assert_response :redirect
1101 assert_response :success
1102 assert_template "site/welcome"
1105 def test_user_create_wikipedia_success
1106 new_email = "newtester-wikipedia@osm.org"
1107 email_hmac = UsersController.message_hmac(new_email)
1108 display_name = "new_tester-wikipedia"
1109 password = "testtest"
1110 auth_uid = "123454321"
1112 OmniAuth.config.add_mock(:wikipedia,
1114 :info => { :email => new_email, :name => display_name })
1116 assert_difference("User.count") do
1117 assert_no_difference("ActionMailer::Base.deliveries.size") do
1118 perform_enqueued_jobs do
1119 post auth_path(:provider => "wikipedia", :origin => "/user/new")
1120 assert_redirected_to auth_success_path(:provider => "wikipedia", :origin => "/user/new")
1122 assert_redirected_to :controller => :users, :action => "new", :nickname => display_name,
1123 :email => new_email, :email_hmac => email_hmac,
1124 :auth_provider => "wikipedia", :auth_uid => auth_uid
1127 :params => { :user => { :email => new_email,
1128 :display_name => display_name,
1129 :auth_provider => "wikipedia",
1130 :auth_uid => "123454321",
1131 :pass_crypt => password,
1132 :pass_crypt_confirmation => password },
1135 :email_hmac => email_hmac }
1136 assert_redirected_to auth_path(:provider => "wikipedia", :origin => "/user/new")
1137 post response.location
1138 assert_redirected_to auth_success_path(:provider => "wikipedia", :origin => "/user/new")
1140 assert_redirected_to welcome_path
1147 assert_response :success
1148 assert_template "site/welcome"
1151 def test_user_create_wikipedia_duplicate_email
1152 dup_user = create(:user)
1153 display_name = "new_tester-wikipedia"
1154 auth_uid = "123454321"
1156 OmniAuth.config.add_mock(:wikipedia,
1158 :info => { "email" => dup_user.email, :name => display_name })
1160 post auth_path(:provider => "wikipedia", :origin => "/user/new")
1161 assert_redirected_to auth_success_path(:provider => "wikipedia", :origin => "/user/new")
1163 assert_redirected_to :controller => :users, :action => "new", :nickname => display_name,
1164 :email => dup_user.email, :email_hmac => UsersController.message_hmac(dup_user.email),
1165 :auth_provider => "wikipedia", :auth_uid => auth_uid
1168 assert_response :success
1169 assert_template "users/new"
1170 assert_select "form > div > input.is-invalid#user_email"
1172 ActionMailer::Base.deliveries.clear
1175 def test_user_create_wikipedia_failure
1176 OmniAuth.config.mock_auth[:wikipedia] = :connection_failed
1178 new_email = "newtester-wikipedia2@osm.org"
1179 display_name = "new_tester-wikipedia2"
1180 assert_difference("User.count", 0) do
1181 assert_difference("ActionMailer::Base.deliveries.size", 0) do
1182 perform_enqueued_jobs do
1184 :params => { :user => { :email => new_email,
1185 :email_confirmation => new_email,
1186 :display_name => display_name,
1187 :auth_provider => "wikipedia",
1188 :auth_uid => "123454321",
1190 :pass_crypt_confirmation => "" } }
1191 assert_redirected_to auth_path(:provider => "wikipedia", :origin => "/user/new")
1192 post response.location
1193 assert_redirected_to auth_success_path(:provider => "wikipedia", :origin => "/user/new")
1195 assert_redirected_to auth_failure_path(:strategy => "wikipedia", :message => "connection_failed", :origin => "/user/new")
1197 assert_redirected_to "/user/new"
1202 ActionMailer::Base.deliveries.clear
1205 def test_user_create_wikipedia_redirect
1206 orig_email = "redirect_tester_wikipedia_orig@osm.org"
1207 email_hmac = UsersController.message_hmac(orig_email)
1208 new_email = "redirect_tester_wikipedia@osm.org"
1209 display_name = "redirect_tester_wikipedia"
1210 auth_uid = "123454321"
1212 OmniAuth.config.add_mock(:wikipedia,
1214 :info => { :email => orig_email, :name => display_name })
1216 # nothing special about this page, just need a protected page to redirect back to.
1217 assert_difference("User.count") do
1218 assert_difference("ActionMailer::Base.deliveries.size", 1) do
1219 perform_enqueued_jobs do
1220 post auth_path(:provider => "wikipedia", :origin => "/user/new")
1221 assert_redirected_to auth_success_path(:provider => "wikipedia", :origin => "/user/new")
1223 assert_redirected_to :controller => :users, :action => "new", :nickname => display_name,
1224 :email => orig_email, :email_hmac => email_hmac,
1225 :auth_provider => "wikipedia", :auth_uid => auth_uid
1229 :params => { :user => { :email => new_email,
1230 :email_hmac => email_hmac,
1231 :display_name => display_name,
1232 :auth_provider => "wikipedia",
1233 :auth_uid => auth_uid,
1234 :consider_pd => "1" } }
1235 assert_redirected_to auth_path(:provider => "wikipedia", :origin => "/user/new")
1236 post response.location
1237 assert_redirected_to auth_success_path(:provider => "wikipedia", :origin => "/user/new")
1239 assert_redirected_to :controller => :confirmations, :action => :confirm, :display_name => display_name
1240 assert_response :redirect
1247 register_email = ActionMailer::Base.deliveries.first
1249 assert_equal register_email.to.first, new_email
1250 # Check that the confirm account url is correct
1251 confirm_regex = Regexp.new("confirm_string=([a-zA-Z0-9%_-]*)")
1252 email_text_parts(register_email).each do |part|
1253 assert_match confirm_regex, part.body.to_s
1255 confirm_string = CGI.unescape(email_text_parts(register_email).first.body.match(confirm_regex)[1])
1258 assert_response :success
1259 assert_template "confirmations/confirm"
1261 ActionMailer::Base.deliveries.clear
1263 # Go to the confirmation page
1264 get "/user/#{display_name}/confirm", :params => { :referer => "/welcome", :confirm_string => confirm_string }
1265 assert_response :success
1266 assert_template "confirmations/confirm"
1268 post "/user/#{display_name}/confirm", :params => { :referer => "/welcome", :confirm_string => confirm_string }
1269 assert_response :redirect
1271 assert_response :success
1272 assert_template "site/welcome"