3 class UserCreationTest < ActionDispatch::IntegrationTest
7 OmniAuth.config.test_mode = true
11 OmniAuth.config.mock_auth[:openid] = nil
12 OmniAuth.config.test_mode = false
15 def test_create_user_form
16 I18n.available_locales.each do |locale|
17 get_via_redirect "/user/new", {}, { "HTTP_ACCEPT_LANGUAGE" => locale.to_s }
18 assert_response :success
19 assert_template "user/new"
23 def test_user_create_submit_duplicate_email
24 I18n.available_locales.each do |locale|
25 dup_email = users(:public_user).email
26 display_name = "#{locale}_new_tester"
27 assert_difference("User.count", 0) do
28 assert_difference("ActionMailer::Base.deliveries.size", 0) do
30 { :user => { :email => dup_email, :email_confirmation => dup_email, :display_name => display_name, :pass_crypt => "testtest", :pass_crypt_confirmation => "testtest" } },
31 { "HTTP_ACCEPT_LANGUAGE" => locale.to_s }
34 assert_response :success
35 assert_template "user/new"
36 assert_equal response.headers["Content-Language"][0..1], locale.to_s[0..1] unless locale == :root
37 assert_select "form > fieldset > div.form-row > input.field_with_errors#user_email"
38 assert_no_missing_translations
42 def test_user_create_submit_duplicate_username
43 I18n.available_locales.each do |locale|
44 dup_display_name = users(:public_user).display_name
45 email = "#{locale}_new_tester"
46 assert_difference("User.count", 0) do
47 assert_difference("ActionMailer::Base.deliveries.size", 0) do
49 { :user => { :email => email, :email_confirmation => email, :display_name => dup_display_name, :pass_crypt => "testtest", :pass_crypt_confirmation => "testtest" } },
50 { "HTTP_ACCEPT_LANGUAGE" => locale.to_s }
53 assert_response :success
54 assert_template "user/new"
55 assert_select "form > fieldset > div.form-row > input.field_with_errors#user_display_name"
56 assert_no_missing_translations
60 def test_user_create_success
61 I18n.available_locales.each do |locale|
62 new_email = "#{locale}newtester@osm.org"
63 display_name = "#{locale}_new_tester"
65 assert_difference("User.count", 0) do
66 assert_difference("ActionMailer::Base.deliveries.size", 0) do
68 :user => { :email => new_email, :email_confirmation => new_email, :display_name => display_name, :pass_crypt => "testtest", :pass_crypt_confirmation => "testtest" }
72 assert_redirected_to "/user/terms"
74 assert_difference("User.count") do
75 assert_difference("ActionMailer::Base.deliveries.size", 1) do
76 post_via_redirect "/user/save", {},
77 { "HTTP_ACCEPT_LANGUAGE" => "#{locale}" }
82 register_email = ActionMailer::Base.deliveries.first
84 assert_equal register_email.to[0], new_email
85 # Check that the confirm account url is correct
86 assert_match /#{@url}/, register_email.body.to_s
89 assert_response :success
90 assert_template "user/confirm"
92 ActionMailer::Base.deliveries.clear
96 # Check that the user can successfully recover their password
97 def lost_password_recovery_success
98 # Open the lost password form
99 # Submit the lost password form
101 # Submit the reset password token
102 # Check that the password has changed, and the user can login
105 def test_user_create_redirect
106 new_email = "redirect_tester@osm.org"
107 display_name = "redirect_tester"
108 password = "testtest"
109 # nothing special about this page, just need a protected page to redirect back to.
110 referer = "/traces/mine"
111 assert_difference("User.count") do
112 assert_difference("ActionMailer::Base.deliveries.size", 1) do
114 :user => { :email => new_email, :email_confirmation => new_email, :display_name => display_name, :pass_crypt => password, :pass_crypt_confirmation => password }, :referer => referer
115 assert_redirected_to "/user/terms"
116 post_via_redirect "/user/save",
117 :user => { :email => new_email, :email_confirmation => new_email, :display_name => display_name, :pass_crypt => password, :pass_crypt_confirmation => password }
122 register_email = ActionMailer::Base.deliveries.first
124 assert_equal register_email.to[0], new_email
125 # Check that the confirm account url is correct
126 confirm_regex = Regexp.new("/user/redirect_tester/confirm\\?confirm_string=([a-zA-Z0-9]*)")
127 register_email.parts.each do |part|
128 assert_match confirm_regex, part.body.to_s
130 confirm_string = register_email.parts[0].body.match(confirm_regex)[1]
133 assert_response :success
134 assert_template "user/confirm"
136 ActionMailer::Base.deliveries.clear
138 # Go to the confirmation page
139 get "/user/#{display_name}/confirm", :confirm_string => confirm_string
140 assert_response :success
141 assert_template "user/confirm"
143 post "/user/#{display_name}/confirm", :confirm_string => confirm_string
144 assert_response :redirect
146 assert_response :success
147 assert_template "site/welcome"
150 def test_user_create_openid_success
151 OmniAuth.config.add_mock(:openid, :uid => "http://localhost:1123/new.tester")
153 new_email = "newtester-openid@osm.org"
154 display_name = "new_tester-openid"
155 password = "testtest"
156 assert_difference("User.count") do
157 assert_difference("ActionMailer::Base.deliveries.size", 1) do
159 :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 => "" }
160 assert_response :redirect
161 assert_redirected_to auth_path(:provider => "openid", :openid_url => "http://localhost:1123/new.tester", :origin => "/user/new")
163 assert_response :redirect
164 assert_redirected_to auth_success_path(:provider => "openid", :openid_url => "http://localhost:1123/new.tester", :origin => "/user/new")
166 assert_response :redirect
167 assert_redirected_to "/user/terms"
169 :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 }
170 assert_response :redirect
176 assert_response :success
177 assert_template "user/confirm"
179 ActionMailer::Base.deliveries.clear
182 def test_user_create_openid_failure
183 OmniAuth.config.mock_auth[:openid] = :connection_failed
185 new_email = "newtester-openid2@osm.org"
186 display_name = "new_tester-openid2"
187 assert_difference("User.count", 0) do
188 assert_difference("ActionMailer::Base.deliveries.size", 0) do
190 :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 => "" }
191 assert_response :redirect
192 assert_redirected_to auth_path(:provider => "openid", :openid_url => "http://localhost:1123/new.tester", :origin => "/user/new")
194 assert_response :redirect
195 assert_redirected_to auth_success_path(:provider => "openid", :openid_url => "http://localhost:1123/new.tester", :origin => "/user/new")
197 assert_response :redirect
198 assert_redirected_to auth_failure_path(:strategy => "openid", :message => "connection_failed", :origin => "/user/new")
200 assert_response :redirect
202 assert_response :success
203 assert_template "user/new"
207 ActionMailer::Base.deliveries.clear
210 def test_user_create_openid_redirect
211 OmniAuth.config.add_mock(:openid, :uid => "http://localhost:1123/new.tester")
213 new_email = "redirect_tester_openid@osm.org"
214 display_name = "redirect_tester_openid"
215 # nothing special about this page, just need a protected page to redirect back to.
216 referer = "/traces/mine"
217 assert_difference("User.count") do
218 assert_difference("ActionMailer::Base.deliveries.size", 1) do
220 :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
221 assert_response :redirect
222 assert_redirected_to auth_path(:provider => "openid", :openid_url => "http://localhost:1123/new.tester", :origin => "/user/new")
224 assert_response :redirect
225 assert_redirected_to auth_success_path(:provider => "openid", :openid_url => "http://localhost:1123/new.tester", :origin => "/user/new")
227 assert_response :redirect
228 assert_redirected_to "/user/terms"
229 post_via_redirect "/user/save",
230 :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" }
235 register_email = ActionMailer::Base.deliveries.first
237 assert_equal register_email.to[0], new_email
238 # Check that the confirm account url is correct
239 confirm_regex = Regexp.new("/user/redirect_tester_openid/confirm\\?confirm_string=([a-zA-Z0-9]*)")
240 register_email.parts.each do |part|
241 assert_match confirm_regex, part.body.to_s
243 confirm_string = register_email.parts[0].body.match(confirm_regex)[1]
246 assert_response :success
247 assert_template "user/confirm"
249 ActionMailer::Base.deliveries.clear
251 # Go to the confirmation page
252 get "/user/#{display_name}/confirm", :confirm_string => confirm_string
253 assert_response :success
254 assert_template "user/confirm"
256 post "/user/#{display_name}/confirm", :confirm_string => confirm_string
257 assert_response :redirect
259 assert_response :success
260 assert_template "site/welcome"