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.test_mode = false
20 def test_create_user_form
21 I18n.available_locales.each do |locale|
22 get_via_redirect "/user/new", {}, { "HTTP_ACCEPT_LANGUAGE" => locale.to_s }
23 assert_response :success
24 assert_template "user/new"
28 def test_user_create_submit_duplicate_email
29 I18n.available_locales.each do |locale|
30 dup_email = users(:public_user).email
31 display_name = "#{locale}_new_tester"
32 assert_difference("User.count", 0) do
33 assert_difference("ActionMailer::Base.deliveries.size", 0) do
35 { :user => { :email => dup_email, :email_confirmation => dup_email, :display_name => display_name, :pass_crypt => "testtest", :pass_crypt_confirmation => "testtest" } },
36 { "HTTP_ACCEPT_LANGUAGE" => locale.to_s }
39 assert_response :success
40 assert_template "user/new"
41 assert_equal response.headers["Content-Language"][0..1], locale.to_s[0..1] unless locale == :root
42 assert_select "form > fieldset > div.form-row > input.field_with_errors#user_email"
43 assert_no_missing_translations
47 def test_user_create_submit_duplicate_username
48 I18n.available_locales.each do |locale|
49 dup_display_name = users(:public_user).display_name
50 email = "#{locale}_new_tester"
51 assert_difference("User.count", 0) do
52 assert_difference("ActionMailer::Base.deliveries.size", 0) do
54 { :user => { :email => email, :email_confirmation => email, :display_name => dup_display_name, :pass_crypt => "testtest", :pass_crypt_confirmation => "testtest" } },
55 { "HTTP_ACCEPT_LANGUAGE" => locale.to_s }
58 assert_response :success
59 assert_template "user/new"
60 assert_select "form > fieldset > div.form-row > input.field_with_errors#user_display_name"
61 assert_no_missing_translations
65 def test_user_create_success
66 I18n.available_locales.each do |locale|
67 new_email = "#{locale}newtester@osm.org"
68 display_name = "#{locale}_new_tester"
70 assert_difference("User.count", 0) do
71 assert_difference("ActionMailer::Base.deliveries.size", 0) do
73 :user => { :email => new_email, :email_confirmation => new_email, :display_name => display_name, :pass_crypt => "testtest", :pass_crypt_confirmation => "testtest" }
77 assert_redirected_to "/user/terms"
79 assert_difference("User.count") do
80 assert_difference("ActionMailer::Base.deliveries.size", 1) do
81 post_via_redirect "/user/save", {},
82 { "HTTP_ACCEPT_LANGUAGE" => "#{locale}" }
87 register_email = ActionMailer::Base.deliveries.first
89 assert_equal register_email.to[0], new_email
90 # Check that the confirm account url is correct
91 assert_match /#{@url}/, register_email.body.to_s
94 assert_response :success
95 assert_template "user/confirm"
97 ActionMailer::Base.deliveries.clear
101 # Check that the user can successfully recover their password
102 def lost_password_recovery_success
103 # Open the lost password form
104 # Submit the lost password form
106 # Submit the reset password token
107 # Check that the password has changed, and the user can login
110 def test_user_create_redirect
111 new_email = "redirect_tester@osm.org"
112 display_name = "redirect_tester"
113 password = "testtest"
114 # nothing special about this page, just need a protected page to redirect back to.
115 referer = "/traces/mine"
116 assert_difference("User.count") do
117 assert_difference("ActionMailer::Base.deliveries.size", 1) do
119 :user => { :email => new_email, :email_confirmation => new_email, :display_name => display_name, :pass_crypt => password, :pass_crypt_confirmation => password }, :referer => referer
120 assert_redirected_to "/user/terms"
121 post_via_redirect "/user/save",
122 :user => { :email => new_email, :email_confirmation => new_email, :display_name => display_name, :pass_crypt => password, :pass_crypt_confirmation => password }
127 register_email = ActionMailer::Base.deliveries.first
129 assert_equal register_email.to[0], new_email
130 # Check that the confirm account url is correct
131 confirm_regex = Regexp.new("/user/redirect_tester/confirm\\?confirm_string=([a-zA-Z0-9]*)")
132 register_email.parts.each do |part|
133 assert_match confirm_regex, part.body.to_s
135 confirm_string = register_email.parts[0].body.match(confirm_regex)[1]
138 assert_response :success
139 assert_template "user/confirm"
141 ActionMailer::Base.deliveries.clear
143 # Go to the confirmation page
144 get "/user/#{display_name}/confirm", :confirm_string => confirm_string
145 assert_response :success
146 assert_template "user/confirm"
148 post "/user/#{display_name}/confirm", :confirm_string => confirm_string
149 assert_response :redirect
151 assert_response :success
152 assert_template "site/welcome"
155 def test_user_create_openid_success
156 OmniAuth.config.add_mock(:openid, :uid => "http://localhost:1123/new.tester")
158 new_email = "newtester-openid@osm.org"
159 display_name = "new_tester-openid"
160 password = "testtest"
161 assert_difference("User.count") do
162 assert_difference("ActionMailer::Base.deliveries.size", 1) do
164 :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 => "" }
165 assert_response :redirect
166 assert_redirected_to auth_path(:provider => "openid", :openid_url => "http://localhost:1123/new.tester", :origin => "/user/new")
168 assert_response :redirect
169 assert_redirected_to auth_success_path(:provider => "openid", :openid_url => "http://localhost:1123/new.tester", :origin => "/user/new")
171 assert_response :redirect
172 assert_redirected_to "/user/terms"
174 :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 }
175 assert_response :redirect
181 assert_response :success
182 assert_template "user/confirm"
184 ActionMailer::Base.deliveries.clear
187 def test_user_create_openid_failure
188 OmniAuth.config.mock_auth[:openid] = :connection_failed
190 new_email = "newtester-openid2@osm.org"
191 display_name = "new_tester-openid2"
192 assert_difference("User.count", 0) do
193 assert_difference("ActionMailer::Base.deliveries.size", 0) do
195 :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 => "" }
196 assert_response :redirect
197 assert_redirected_to auth_path(:provider => "openid", :openid_url => "http://localhost:1123/new.tester", :origin => "/user/new")
199 assert_response :redirect
200 assert_redirected_to auth_success_path(:provider => "openid", :openid_url => "http://localhost:1123/new.tester", :origin => "/user/new")
202 assert_response :redirect
203 assert_redirected_to auth_failure_path(:strategy => "openid", :message => "connection_failed", :origin => "/user/new")
205 assert_response :redirect
207 assert_response :success
208 assert_template "user/new"
212 ActionMailer::Base.deliveries.clear
215 def test_user_create_openid_redirect
216 OmniAuth.config.add_mock(:openid, :uid => "http://localhost:1123/new.tester")
218 new_email = "redirect_tester_openid@osm.org"
219 display_name = "redirect_tester_openid"
220 # nothing special about this page, just need a protected page to redirect back to.
221 referer = "/traces/mine"
222 assert_difference("User.count") do
223 assert_difference("ActionMailer::Base.deliveries.size", 1) do
225 :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
226 assert_response :redirect
227 assert_redirected_to auth_path(:provider => "openid", :openid_url => "http://localhost:1123/new.tester", :origin => "/user/new")
229 assert_response :redirect
230 assert_redirected_to auth_success_path(:provider => "openid", :openid_url => "http://localhost:1123/new.tester", :origin => "/user/new")
232 assert_response :redirect
233 assert_redirected_to "/user/terms"
234 post_via_redirect "/user/save",
235 :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" }
240 register_email = ActionMailer::Base.deliveries.first
242 assert_equal register_email.to[0], new_email
243 # Check that the confirm account url is correct
244 confirm_regex = Regexp.new("/user/redirect_tester_openid/confirm\\?confirm_string=([a-zA-Z0-9]*)")
245 register_email.parts.each do |part|
246 assert_match confirm_regex, part.body.to_s
248 confirm_string = register_email.parts[0].body.match(confirm_regex)[1]
251 assert_response :success
252 assert_template "user/confirm"
254 ActionMailer::Base.deliveries.clear
256 # Go to the confirmation page
257 get "/user/#{display_name}/confirm", :confirm_string => confirm_string
258 assert_response :success
259 assert_template "user/confirm"
261 post "/user/#{display_name}/confirm", :confirm_string => confirm_string
262 assert_response :redirect
264 assert_response :success
265 assert_template "site/welcome"
268 def test_user_create_google_success
269 OmniAuth.config.add_mock(:google, :uid => "123454321", :extra => {
270 :id_info => { "openid_id" => "http://localhost:1123/new.tester" }
273 new_email = "newtester-google@osm.org"
274 display_name = "new_tester-google"
275 password = "testtest"
276 assert_difference("User.count") do
277 assert_difference("ActionMailer::Base.deliveries.size", 1) do
279 :user => { :email => new_email, :email_confirmation => new_email, :display_name => display_name, :auth_provider => "google", :pass_crypt => "", :pass_crypt_confirmation => "" }
280 assert_response :redirect
281 assert_redirected_to auth_path(:provider => "google", :origin => "/user/new")
283 assert_response :redirect
284 assert_redirected_to auth_success_path(:provider => "google")
286 assert_response :redirect
287 assert_redirected_to "/user/terms"
289 :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 }
290 assert_response :redirect
296 assert_response :success
297 assert_template "user/confirm"
299 ActionMailer::Base.deliveries.clear
302 def test_user_create_google_failure
303 OmniAuth.config.mock_auth[:google] = :connection_failed
305 new_email = "newtester-google2@osm.org"
306 display_name = "new_tester-google2"
307 assert_difference("User.count", 0) do
308 assert_difference("ActionMailer::Base.deliveries.size", 0) do
310 :user => { :email => new_email, :email_confirmation => new_email, :display_name => display_name, :auth_provider => "google", :pass_crypt => "", :pass_crypt_confirmation => "" }
311 assert_response :redirect
312 assert_redirected_to auth_path(:provider => "google", :origin => "/user/new")
314 assert_response :redirect
315 assert_redirected_to auth_success_path(:provider => "google")
317 assert_response :redirect
318 assert_redirected_to auth_failure_path(:strategy => "google", :message => "connection_failed", :origin => "/user/new")
320 assert_response :redirect
322 assert_response :success
323 assert_template "user/new"
327 ActionMailer::Base.deliveries.clear
330 def test_user_create_google_redirect
331 OmniAuth.config.add_mock(:google, :uid => "123454321", :extra => {
332 :id_info => { "openid_id" => "http://localhost:1123/new.tester" }
335 new_email = "redirect_tester_google@osm.org"
336 display_name = "redirect_tester_google"
337 # nothing special about this page, just need a protected page to redirect back to.
338 referer = "/traces/mine"
339 assert_difference("User.count") do
340 assert_difference("ActionMailer::Base.deliveries.size", 1) do
342 :user => { :email => new_email, :email_confirmation => new_email, :display_name => display_name, :auth_provider => "google", :pass_crypt => "", :pass_crypt_confirmation => "" }, :referer => referer
343 assert_response :redirect
344 assert_redirected_to auth_path(:provider => "google", :origin => "/user/new")
346 assert_response :redirect
347 assert_redirected_to auth_success_path(:provider => "google")
349 assert_response :redirect
350 assert_redirected_to "/user/terms"
351 post_via_redirect "/user/save",
352 :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" }
357 register_email = ActionMailer::Base.deliveries.first
359 assert_equal register_email.to[0], new_email
360 # Check that the confirm account url is correct
361 confirm_regex = Regexp.new("/user/redirect_tester_google/confirm\\?confirm_string=([a-zA-Z0-9]*)")
362 register_email.parts.each do |part|
363 assert_match confirm_regex, part.body.to_s
365 confirm_string = register_email.parts[0].body.match(confirm_regex)[1]
368 assert_response :success
369 assert_template "user/confirm"
371 ActionMailer::Base.deliveries.clear
373 # Go to the confirmation page
374 get "/user/#{display_name}/confirm", :confirm_string => confirm_string
375 assert_response :success
376 assert_template "user/confirm"
378 post "/user/#{display_name}/confirm", :confirm_string => confirm_string
379 assert_response :redirect
381 assert_response :success
382 assert_template "site/welcome"