devise 4.5.0 → 4.6.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of devise might be problematic. Click here for more details.

Files changed (195) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +30 -1
  3. data/MIT-LICENSE +1 -1
  4. data/README.md +18 -0
  5. data/app/controllers/devise/passwords_controller.rb +1 -0
  6. data/app/controllers/devise/registrations_controller.rb +25 -7
  7. data/app/helpers/devise_helper.rb +10 -19
  8. data/app/views/devise/confirmations/new.html.erb +1 -1
  9. data/app/views/devise/passwords/edit.html.erb +1 -1
  10. data/app/views/devise/passwords/new.html.erb +1 -1
  11. data/app/views/devise/registrations/edit.html.erb +1 -1
  12. data/app/views/devise/registrations/new.html.erb +1 -1
  13. data/app/views/devise/sessions/new.html.erb +2 -2
  14. data/app/views/devise/shared/_error_messages.html.erb +15 -0
  15. data/app/views/devise/shared/_links.html.erb +7 -7
  16. data/app/views/devise/unlocks/new.html.erb +1 -1
  17. data/config/locales/en.yml +1 -0
  18. data/lib/devise.rb +4 -0
  19. data/lib/devise/controllers/helpers.rb +1 -1
  20. data/lib/devise/failure_app.rb +28 -3
  21. data/lib/devise/models/authenticatable.rb +7 -15
  22. data/lib/devise/models/confirmable.rb +4 -1
  23. data/lib/devise/models/database_authenticatable.rb +41 -6
  24. data/lib/devise/models/lockable.rb +2 -2
  25. data/lib/devise/models/registerable.rb +2 -0
  26. data/lib/devise/strategies/database_authenticatable.rb +3 -0
  27. data/lib/devise/test/controller_helpers.rb +1 -1
  28. data/lib/devise/version.rb +1 -1
  29. data/lib/generators/active_record/devise_generator.rb +4 -4
  30. data/lib/generators/devise/controllers_generator.rb +1 -1
  31. data/lib/generators/templates/devise.rb +12 -3
  32. data/lib/generators/templates/simple_form_for/registrations/edit.html.erb +1 -1
  33. data/lib/generators/templates/simple_form_for/registrations/new.html.erb +1 -1
  34. metadata +5 -305
  35. data/.gitignore +0 -10
  36. data/.travis.yml +0 -69
  37. data/.yardopts +0 -9
  38. data/CODE_OF_CONDUCT.md +0 -22
  39. data/CONTRIBUTING.md +0 -79
  40. data/Gemfile +0 -39
  41. data/Gemfile.lock +0 -202
  42. data/ISSUE_TEMPLATE.md +0 -19
  43. data/Rakefile +0 -37
  44. data/bin/test +0 -13
  45. data/devise.gemspec +0 -28
  46. data/devise.png +0 -0
  47. data/gemfiles/Gemfile.rails-4.1-stable +0 -32
  48. data/gemfiles/Gemfile.rails-4.1-stable.lock +0 -171
  49. data/gemfiles/Gemfile.rails-4.2-stable +0 -32
  50. data/gemfiles/Gemfile.rails-4.2-stable.lock +0 -192
  51. data/gemfiles/Gemfile.rails-5.0-stable +0 -33
  52. data/gemfiles/Gemfile.rails-5.0-stable.lock +0 -192
  53. data/gemfiles/Gemfile.rails-5.2-rc1 +0 -26
  54. data/gemfiles/Gemfile.rails-5.2-rc1.lock +0 -201
  55. data/guides/bug_report_templates/integration_test.rb +0 -106
  56. data/test/controllers/custom_registrations_controller_test.rb +0 -42
  57. data/test/controllers/custom_strategy_test.rb +0 -66
  58. data/test/controllers/helper_methods_test.rb +0 -24
  59. data/test/controllers/helpers_test.rb +0 -318
  60. data/test/controllers/inherited_controller_i18n_messages_test.rb +0 -53
  61. data/test/controllers/internal_helpers_test.rb +0 -129
  62. data/test/controllers/load_hooks_controller_test.rb +0 -21
  63. data/test/controllers/passwords_controller_test.rb +0 -34
  64. data/test/controllers/sessions_controller_test.rb +0 -108
  65. data/test/controllers/url_helpers_test.rb +0 -67
  66. data/test/delegator_test.rb +0 -21
  67. data/test/devise_test.rb +0 -109
  68. data/test/failure_app_test.rb +0 -346
  69. data/test/generators/active_record_generator_test.rb +0 -130
  70. data/test/generators/controllers_generator_test.rb +0 -50
  71. data/test/generators/devise_generator_test.rb +0 -41
  72. data/test/generators/install_generator_test.rb +0 -26
  73. data/test/generators/mongoid_generator_test.rb +0 -25
  74. data/test/generators/views_generator_test.rb +0 -105
  75. data/test/helpers/devise_helper_test.rb +0 -51
  76. data/test/integration/authenticatable_test.rb +0 -706
  77. data/test/integration/confirmable_test.rb +0 -326
  78. data/test/integration/database_authenticatable_test.rb +0 -110
  79. data/test/integration/http_authenticatable_test.rb +0 -114
  80. data/test/integration/lockable_test.rb +0 -242
  81. data/test/integration/mounted_engine_test.rb +0 -38
  82. data/test/integration/omniauthable_test.rb +0 -148
  83. data/test/integration/recoverable_test.rb +0 -349
  84. data/test/integration/registerable_test.rb +0 -365
  85. data/test/integration/rememberable_test.rb +0 -219
  86. data/test/integration/timeoutable_test.rb +0 -186
  87. data/test/integration/trackable_test.rb +0 -99
  88. data/test/mailers/confirmation_instructions_test.rb +0 -117
  89. data/test/mailers/email_changed_test.rb +0 -132
  90. data/test/mailers/mailer_test.rb +0 -20
  91. data/test/mailers/reset_password_instructions_test.rb +0 -98
  92. data/test/mailers/unlock_instructions_test.rb +0 -93
  93. data/test/mapping_test.rb +0 -136
  94. data/test/models/authenticatable_test.rb +0 -25
  95. data/test/models/confirmable_test.rb +0 -549
  96. data/test/models/database_authenticatable_test.rb +0 -290
  97. data/test/models/lockable_test.rb +0 -352
  98. data/test/models/omniauthable_test.rb +0 -9
  99. data/test/models/recoverable_test.rb +0 -263
  100. data/test/models/registerable_test.rb +0 -9
  101. data/test/models/rememberable_test.rb +0 -184
  102. data/test/models/serializable_test.rb +0 -60
  103. data/test/models/timeoutable_test.rb +0 -53
  104. data/test/models/trackable_test.rb +0 -80
  105. data/test/models/validatable_test.rb +0 -121
  106. data/test/models_test.rb +0 -155
  107. data/test/omniauth/config_test.rb +0 -61
  108. data/test/omniauth/url_helpers_test.rb +0 -53
  109. data/test/orm/active_record.rb +0 -24
  110. data/test/orm/mongoid.rb +0 -15
  111. data/test/parameter_sanitizer_test.rb +0 -105
  112. data/test/rails_app/Rakefile +0 -6
  113. data/test/rails_app/app/active_record/admin.rb +0 -8
  114. data/test/rails_app/app/active_record/shim.rb +0 -4
  115. data/test/rails_app/app/active_record/user.rb +0 -20
  116. data/test/rails_app/app/active_record/user_on_engine.rb +0 -9
  117. data/test/rails_app/app/active_record/user_on_main_app.rb +0 -9
  118. data/test/rails_app/app/active_record/user_with_validations.rb +0 -12
  119. data/test/rails_app/app/active_record/user_without_email.rb +0 -10
  120. data/test/rails_app/app/controllers/admins/sessions_controller.rb +0 -8
  121. data/test/rails_app/app/controllers/admins_controller.rb +0 -8
  122. data/test/rails_app/app/controllers/application_controller.rb +0 -13
  123. data/test/rails_app/app/controllers/application_with_fake_engine.rb +0 -32
  124. data/test/rails_app/app/controllers/custom/registrations_controller.rb +0 -33
  125. data/test/rails_app/app/controllers/home_controller.rb +0 -31
  126. data/test/rails_app/app/controllers/publisher/registrations_controller.rb +0 -4
  127. data/test/rails_app/app/controllers/publisher/sessions_controller.rb +0 -4
  128. data/test/rails_app/app/controllers/users/omniauth_callbacks_controller.rb +0 -16
  129. data/test/rails_app/app/controllers/users_controller.rb +0 -33
  130. data/test/rails_app/app/helpers/application_helper.rb +0 -5
  131. data/test/rails_app/app/mailers/users/from_proc_mailer.rb +0 -5
  132. data/test/rails_app/app/mailers/users/mailer.rb +0 -5
  133. data/test/rails_app/app/mailers/users/reply_to_mailer.rb +0 -6
  134. data/test/rails_app/app/mongoid/admin.rb +0 -31
  135. data/test/rails_app/app/mongoid/shim.rb +0 -25
  136. data/test/rails_app/app/mongoid/user.rb +0 -50
  137. data/test/rails_app/app/mongoid/user_on_engine.rb +0 -41
  138. data/test/rails_app/app/mongoid/user_on_main_app.rb +0 -41
  139. data/test/rails_app/app/mongoid/user_with_validations.rb +0 -37
  140. data/test/rails_app/app/mongoid/user_without_email.rb +0 -35
  141. data/test/rails_app/app/views/admins/index.html.erb +0 -1
  142. data/test/rails_app/app/views/admins/sessions/new.html.erb +0 -2
  143. data/test/rails_app/app/views/home/admin_dashboard.html.erb +0 -1
  144. data/test/rails_app/app/views/home/index.html.erb +0 -1
  145. data/test/rails_app/app/views/home/join.html.erb +0 -1
  146. data/test/rails_app/app/views/home/private.html.erb +0 -1
  147. data/test/rails_app/app/views/home/user_dashboard.html.erb +0 -1
  148. data/test/rails_app/app/views/layouts/application.html.erb +0 -24
  149. data/test/rails_app/app/views/users/edit_form.html.erb +0 -1
  150. data/test/rails_app/app/views/users/index.html.erb +0 -1
  151. data/test/rails_app/app/views/users/mailer/confirmation_instructions.erb +0 -1
  152. data/test/rails_app/app/views/users/sessions/new.html.erb +0 -1
  153. data/test/rails_app/bin/bundle +0 -3
  154. data/test/rails_app/bin/rails +0 -4
  155. data/test/rails_app/bin/rake +0 -4
  156. data/test/rails_app/config.ru +0 -4
  157. data/test/rails_app/config/application.rb +0 -48
  158. data/test/rails_app/config/boot.rb +0 -27
  159. data/test/rails_app/config/database.yml +0 -18
  160. data/test/rails_app/config/environment.rb +0 -7
  161. data/test/rails_app/config/environments/development.rb +0 -32
  162. data/test/rails_app/config/environments/production.rb +0 -88
  163. data/test/rails_app/config/environments/test.rb +0 -47
  164. data/test/rails_app/config/initializers/backtrace_silencers.rb +0 -9
  165. data/test/rails_app/config/initializers/devise.rb +0 -187
  166. data/test/rails_app/config/initializers/inflections.rb +0 -4
  167. data/test/rails_app/config/initializers/secret_token.rb +0 -5
  168. data/test/rails_app/config/initializers/session_store.rb +0 -3
  169. data/test/rails_app/config/routes.rb +0 -128
  170. data/test/rails_app/db/migrate/20100401102949_create_tables.rb +0 -77
  171. data/test/rails_app/db/schema.rb +0 -57
  172. data/test/rails_app/lib/lazy_load_test_module.rb +0 -5
  173. data/test/rails_app/lib/shared_admin.rb +0 -23
  174. data/test/rails_app/lib/shared_user.rb +0 -32
  175. data/test/rails_app/lib/shared_user_without_email.rb +0 -28
  176. data/test/rails_app/lib/shared_user_without_omniauth.rb +0 -15
  177. data/test/rails_app/public/404.html +0 -26
  178. data/test/rails_app/public/422.html +0 -26
  179. data/test/rails_app/public/500.html +0 -26
  180. data/test/rails_app/public/favicon.ico +0 -0
  181. data/test/rails_test.rb +0 -11
  182. data/test/routes_test.rb +0 -281
  183. data/test/secret_key_finder_test.rb +0 -121
  184. data/test/support/action_controller/record_identifier.rb +0 -12
  185. data/test/support/assertions.rb +0 -30
  186. data/test/support/helpers.rb +0 -83
  187. data/test/support/http_method_compatibility.rb +0 -53
  188. data/test/support/integration.rb +0 -95
  189. data/test/support/locale/en.yml +0 -8
  190. data/test/support/mongoid.yml +0 -6
  191. data/test/support/webrat/integrations/rails.rb +0 -35
  192. data/test/test/controller_helpers_test.rb +0 -193
  193. data/test/test/integration_helpers_test.rb +0 -34
  194. data/test/test_helper.rb +0 -36
  195. data/test/test_models.rb +0 -35
@@ -1,365 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'test_helper'
4
-
5
- class RegistrationTest < Devise::IntegrationTest
6
-
7
- test 'a guest admin should be able to sign in successfully' do
8
- get new_admin_session_path
9
- click_link 'Sign up'
10
-
11
- assert_template 'registrations/new'
12
-
13
- fill_in 'email', with: 'new_user@test.com'
14
- fill_in 'password', with: 'new_user123'
15
- fill_in 'password confirmation', with: 'new_user123'
16
- click_button 'Sign up'
17
-
18
- assert_contain 'You have signed up successfully'
19
- assert warden.authenticated?(:admin)
20
- assert_current_url "/admin_area/home"
21
-
22
- admin = Admin.to_adapter.find_first(order: [:id, :desc])
23
- assert_equal admin.email, 'new_user@test.com'
24
- end
25
-
26
- test 'a guest admin should be able to sign in and be redirected to a custom location' do
27
- Devise::RegistrationsController.any_instance.stubs(:after_sign_up_path_for).returns("/?custom=1")
28
- get new_admin_session_path
29
- click_link 'Sign up'
30
-
31
- fill_in 'email', with: 'new_user@test.com'
32
- fill_in 'password', with: 'new_user123'
33
- fill_in 'password confirmation', with: 'new_user123'
34
- click_button 'Sign up'
35
-
36
- assert_contain 'Welcome! You have signed up successfully.'
37
- assert warden.authenticated?(:admin)
38
- assert_current_url "/?custom=1"
39
- end
40
-
41
- test 'a guest admin should not see a warning about minimum password length' do
42
- get new_admin_session_path
43
- assert_not_contain 'characters minimum'
44
- end
45
-
46
- def user_sign_up
47
- ActionMailer::Base.deliveries.clear
48
-
49
- get new_user_registration_path
50
-
51
- fill_in 'email', with: 'new_user@test.com'
52
- fill_in 'password', with: 'new_user123'
53
- fill_in 'password confirmation', with: 'new_user123'
54
- click_button 'Sign up'
55
- end
56
-
57
- test 'a guest user should see a warning about minimum password length' do
58
- get new_user_registration_path
59
- assert_contain '7 characters minimum'
60
- end
61
-
62
- test 'a guest user should be able to sign up successfully and be blocked by confirmation' do
63
- user_sign_up
64
-
65
- assert_contain 'A message with a confirmation link has been sent to your email address. Please follow the link to activate your account.'
66
- assert_not_contain 'You have to confirm your account before continuing'
67
- assert_current_url "/"
68
-
69
- refute warden.authenticated?(:user)
70
-
71
- user = User.to_adapter.find_first(order: [:id, :desc])
72
- assert_equal user.email, 'new_user@test.com'
73
- refute user.confirmed?
74
- end
75
-
76
- test 'a guest user should receive the confirmation instructions from the default mailer' do
77
- user_sign_up
78
- assert_equal ['please-change-me@config-initializers-devise.com'], ActionMailer::Base.deliveries.first.from
79
- end
80
-
81
- test 'a guest user should receive the confirmation instructions from a custom mailer' do
82
- User.any_instance.stubs(:devise_mailer).returns(Users::Mailer)
83
- user_sign_up
84
- assert_equal ['custom@example.com'], ActionMailer::Base.deliveries.first.from
85
- end
86
-
87
- test 'a guest user should be blocked by confirmation and redirected to a custom path' do
88
- Devise::RegistrationsController.any_instance.stubs(:after_inactive_sign_up_path_for).returns("/?custom=1")
89
- get new_user_registration_path
90
-
91
- fill_in 'email', with: 'new_user@test.com'
92
- fill_in 'password', with: 'new_user123'
93
- fill_in 'password confirmation', with: 'new_user123'
94
- click_button 'Sign up'
95
-
96
- assert_current_url "/?custom=1"
97
- refute warden.authenticated?(:user)
98
- end
99
-
100
- test 'a guest user cannot sign up with invalid information' do
101
- # Dirty tracking behavior prevents email validations from being applied:
102
- # https://github.com/mongoid/mongoid/issues/756
103
- (pending "Fails on Mongoid < 2.1"; break) if defined?(Mongoid) && Mongoid::VERSION.to_f < 2.1
104
-
105
- get new_user_registration_path
106
-
107
- fill_in 'email', with: 'invalid_email'
108
- fill_in 'password', with: 'new_user123'
109
- fill_in 'password confirmation', with: 'new_user321'
110
- click_button 'Sign up'
111
-
112
- assert_template 'registrations/new'
113
- assert_have_selector '#error_explanation'
114
- assert_contain "Email is invalid"
115
- assert_contain "Password confirmation doesn't match Password"
116
- assert_contain "2 errors prohibited"
117
- assert_nil User.to_adapter.find_first
118
-
119
- refute warden.authenticated?(:user)
120
- end
121
-
122
- test 'a guest should not sign up with email/password that already exists' do
123
- # Dirty tracking behavior prevents email validations from being applied:
124
- # https://github.com/mongoid/mongoid/issues/756
125
- (pending "Fails on Mongoid < 2.1"; break) if defined?(Mongoid) && Mongoid::VERSION.to_f < 2.1
126
-
127
- create_user
128
- get new_user_registration_path
129
-
130
- fill_in 'email', with: 'user@test.com'
131
- fill_in 'password', with: '123456'
132
- fill_in 'password confirmation', with: '123456'
133
- click_button 'Sign up'
134
-
135
- assert_current_url '/users'
136
- assert_contain(/Email.*already.*taken/)
137
-
138
- refute warden.authenticated?(:user)
139
- end
140
-
141
- test 'a guest should not be able to change account' do
142
- get edit_user_registration_path
143
- assert_redirected_to new_user_session_path
144
- follow_redirect!
145
- assert_contain 'You need to sign in or sign up before continuing.'
146
- end
147
-
148
- test 'a signed in user should not be able to access sign up' do
149
- sign_in_as_user
150
- get new_user_registration_path
151
- assert_redirected_to root_path
152
- end
153
-
154
- test 'a signed in user should be able to edit their account' do
155
- sign_in_as_user
156
- get edit_user_registration_path
157
-
158
- fill_in 'email', with: 'user.new@example.com'
159
- fill_in 'current password', with: '12345678'
160
- click_button 'Update'
161
-
162
- assert_current_url '/'
163
- assert_contain 'Your account has been updated successfully.'
164
-
165
- assert_equal "user.new@example.com", User.to_adapter.find_first.email
166
- end
167
-
168
- test 'a signed in user should still be able to use the website after changing their password' do
169
- sign_in_as_user
170
- get edit_user_registration_path
171
-
172
- fill_in 'password', with: '1234567890'
173
- fill_in 'password confirmation', with: '1234567890'
174
- fill_in 'current password', with: '12345678'
175
- click_button 'Update'
176
-
177
- assert_contain 'Your account has been updated successfully.'
178
- get users_path
179
- assert warden.authenticated?(:user)
180
- end
181
-
182
- test 'a signed in user should not change their current user with invalid password' do
183
- sign_in_as_user
184
- get edit_user_registration_path
185
-
186
- fill_in 'email', with: 'user.new@example.com'
187
- fill_in 'current password', with: 'invalid'
188
- click_button 'Update'
189
-
190
- assert_template 'registrations/edit'
191
- assert_contain 'user@test.com'
192
- assert_have_selector 'form input[value="user.new@example.com"]'
193
-
194
- assert_equal "user@test.com", User.to_adapter.find_first.email
195
- end
196
-
197
- test 'a signed in user should be able to edit their password' do
198
- sign_in_as_user
199
- get edit_user_registration_path
200
-
201
- fill_in 'password', with: 'pass1234'
202
- fill_in 'password confirmation', with: 'pass1234'
203
- fill_in 'current password', with: '12345678'
204
- click_button 'Update'
205
-
206
- assert_current_url '/'
207
- assert_contain 'Your account has been updated successfully.'
208
-
209
- assert User.to_adapter.find_first.valid_password?('pass1234')
210
- end
211
-
212
- test 'a signed in user should not be able to edit their password with invalid confirmation' do
213
- sign_in_as_user
214
- get edit_user_registration_path
215
-
216
- fill_in 'password', with: 'pas123'
217
- fill_in 'password confirmation', with: ''
218
- fill_in 'current password', with: '12345678'
219
- click_button 'Update'
220
-
221
- assert_contain "Password confirmation doesn't match Password"
222
- refute User.to_adapter.find_first.valid_password?('pas123')
223
- end
224
-
225
- test 'a signed in user should see a warning about minimum password length' do
226
- sign_in_as_user
227
- get edit_user_registration_path
228
- assert_contain 'characters minimum'
229
- end
230
-
231
- test 'a signed in user should be able to cancel their account' do
232
- sign_in_as_user
233
- get edit_user_registration_path
234
-
235
- click_button "Cancel my account"
236
- assert_contain "Bye! Your account has been successfully cancelled. We hope to see you again soon."
237
-
238
- assert User.to_adapter.find_all.empty?
239
- end
240
-
241
- test 'a user should be able to cancel sign up by deleting data in the session' do
242
- get "/set"
243
- assert_equal "something", @request.session["devise.foo_bar"]
244
-
245
- get "/users/sign_up"
246
- assert_equal "something", @request.session["devise.foo_bar"]
247
-
248
- get "/users/cancel"
249
- assert_nil @request.session["devise.foo_bar"]
250
- assert_redirected_to new_user_registration_path
251
- end
252
-
253
- test 'a user with XML sign up stub' do
254
- get new_user_registration_path(format: 'xml')
255
- assert_response :success
256
- assert_match %(<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<user>), response.body
257
- assert_no_match(/<confirmation-token/, response.body)
258
- end
259
-
260
- test 'a user with JSON sign up stub' do
261
- get new_user_registration_path(format: 'json')
262
- assert_response :success
263
- assert_match %({"user":), response.body
264
- assert_no_match(/"confirmation_token"/, response.body)
265
- end
266
-
267
- test 'an admin sign up with valid information in XML format should return valid response' do
268
- post admin_registration_path(format: 'xml'), params: { admin: { email: 'new_user@test.com', password: 'new_user123', password_confirmation: 'new_user123' } }
269
- assert_response :success
270
- assert response.body.include? %(<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<admin>)
271
-
272
- admin = Admin.to_adapter.find_first(order: [:id, :desc])
273
- assert_equal admin.email, 'new_user@test.com'
274
- end
275
-
276
- test 'a user sign up with valid information in XML format should return valid response' do
277
- post user_registration_path(format: 'xml'), params: { user: { email: 'new_user@test.com', password: 'new_user123', password_confirmation: 'new_user123' } }
278
- assert_response :success
279
- assert response.body.include? %(<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<user>)
280
-
281
- user = User.to_adapter.find_first(order: [:id, :desc])
282
- assert_equal user.email, 'new_user@test.com'
283
- end
284
-
285
- test 'a user sign up with invalid information in XML format should return invalid response' do
286
- post user_registration_path(format: 'xml'), params: { user: { email: 'new_user@test.com', password: 'new_user123', password_confirmation: 'invalid' } }
287
- assert_response :unprocessable_entity
288
- assert response.body.include? %(<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<errors>)
289
- end
290
-
291
- test 'a user update information with valid data in XML format should return valid response' do
292
- user = sign_in_as_user
293
- put user_registration_path(format: 'xml'), params: { user: { current_password: '12345678', email: 'user.new@test.com' } }
294
- assert_response :success
295
- assert_equal user.reload.email, 'user.new@test.com'
296
- end
297
-
298
- test 'a user update information with invalid data in XML format should return invalid response' do
299
- user = sign_in_as_user
300
- put user_registration_path(format: 'xml'), params: { user: { current_password: 'invalid', email: 'user.new@test.com' } }
301
- assert_response :unprocessable_entity
302
- assert_equal user.reload.email, 'user@test.com'
303
- end
304
-
305
- test 'a user cancel their account in XML format should return valid response' do
306
- sign_in_as_user
307
- delete user_registration_path(format: 'xml')
308
- assert_response :success
309
- assert_equal User.to_adapter.find_all.size, 0
310
- end
311
- end
312
-
313
- class ReconfirmableRegistrationTest < Devise::IntegrationTest
314
- test 'a signed in admin should see a more appropriate flash message when editing their account if reconfirmable is enabled' do
315
- sign_in_as_admin
316
- get edit_admin_registration_path
317
-
318
- fill_in 'email', with: 'admin.new@example.com'
319
- fill_in 'current password', with: '123456'
320
- click_button 'Update'
321
-
322
- assert_current_url '/admin_area/home'
323
- assert_contain 'but we need to verify your new email address'
324
- assert_equal 'admin.new@example.com', Admin.to_adapter.find_first.unconfirmed_email
325
-
326
- get edit_admin_registration_path
327
- assert_contain 'Currently waiting confirmation for: admin.new@example.com'
328
- end
329
-
330
- test 'a signed in admin should not see a reconfirmation message if they did not change their password' do
331
- sign_in_as_admin
332
- get edit_admin_registration_path
333
-
334
- fill_in 'password', with: 'pas123'
335
- fill_in 'password confirmation', with: 'pas123'
336
- fill_in 'current password', with: '123456'
337
- click_button 'Update'
338
-
339
- assert_current_url '/admin_area/home'
340
- assert_contain 'Your account has been updated successfully.'
341
-
342
- assert Admin.to_adapter.find_first.valid_password?('pas123')
343
- end
344
-
345
- test 'a signed in admin should not see a reconfirmation message if they did not change their email, despite having an unconfirmed email' do
346
- sign_in_as_admin
347
-
348
- get edit_admin_registration_path
349
- fill_in 'email', with: 'admin.new@example.com'
350
- fill_in 'current password', with: '123456'
351
- click_button 'Update'
352
-
353
- get edit_admin_registration_path
354
- fill_in 'password', with: 'pas123'
355
- fill_in 'password confirmation', with: 'pas123'
356
- fill_in 'current password', with: '123456'
357
- click_button 'Update'
358
-
359
- assert_current_url '/admin_area/home'
360
- assert_contain 'Your account has been updated successfully.'
361
-
362
- assert_equal "admin.new@example.com", Admin.to_adapter.find_first.unconfirmed_email
363
- assert Admin.to_adapter.find_first.valid_password?('pas123')
364
- end
365
- end
@@ -1,219 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'test_helper'
4
-
5
- class RememberMeTest < Devise::IntegrationTest
6
- def create_user_and_remember(add_to_token='')
7
- user = create_user
8
- user.remember_me!
9
- raw_cookie = User.serialize_into_cookie(user).tap { |a| a[1] << add_to_token }
10
- cookies['remember_user_token'] = generate_signed_cookie(raw_cookie)
11
- user
12
- end
13
-
14
- def generate_signed_cookie(raw_cookie)
15
- request = if Devise::Test.rails51? || Devise::Test.rails52?
16
- ActionController::TestRequest.create(Class.new) # needs a "controller class"
17
- elsif Devise::Test.rails5?
18
- ActionController::TestRequest.create
19
- else
20
- ActionController::TestRequest.new
21
- end
22
- request.cookie_jar.signed['raw_cookie'] = raw_cookie
23
- request.cookie_jar['raw_cookie']
24
- end
25
-
26
- def signed_cookie(key)
27
- controller.send(:cookies).signed[key]
28
- end
29
-
30
- def cookie_expires(key)
31
- cookie = response.headers["Set-Cookie"].split("\n").grep(/^#{key}/).first
32
- expires = cookie.split(";").map(&:strip).grep(/^expires=/).first
33
- Time.parse(expires).utc
34
- end
35
-
36
- test 'do not remember the user if they have not checked remember me option' do
37
- sign_in_as_user
38
- assert_nil request.cookies["remember_user_cookie"]
39
- end
40
-
41
- test 'handle unverified requests gets rid of caches' do
42
- swap ApplicationController, allow_forgery_protection: true do
43
- post exhibit_user_url(1)
44
- refute warden.authenticated?(:user)
45
-
46
- create_user_and_remember
47
- post exhibit_user_url(1)
48
- assert_equal "User is not authenticated", response.body
49
- refute warden.authenticated?(:user)
50
- end
51
- end
52
-
53
- test 'handle unverified requests does not create cookies on sign in' do
54
- swap ApplicationController, allow_forgery_protection: true do
55
- get new_user_session_path
56
- assert request.session[:_csrf_token]
57
-
58
- post user_session_path, params: {
59
- authenticity_token: "oops",
60
- user: { email: "jose.valim@gmail.com", password: "123456", remember_me: "1" }
61
- }
62
- refute warden.authenticated?(:user)
63
- refute request.cookies['remember_user_token']
64
- end
65
- end
66
-
67
- test 'generate remember token after sign in' do
68
- sign_in_as_user remember_me: true
69
- assert request.cookies['remember_user_token']
70
- end
71
-
72
- test 'generate remember token after sign in setting cookie options' do
73
- # We test this by asserting the cookie is not sent after the redirect
74
- # since we changed the domain. This is the only difference with the
75
- # previous test.
76
- swap Devise, rememberable_options: { domain: "omg.somewhere.com" } do
77
- sign_in_as_user remember_me: true
78
- assert_nil request.cookies["remember_user_token"]
79
- end
80
- end
81
-
82
- test 'generate remember token with a custom key' do
83
- swap Devise, rememberable_options: { key: "v1lat_token" } do
84
- sign_in_as_user remember_me: true
85
- assert request.cookies["v1lat_token"]
86
- end
87
- end
88
-
89
- test 'generate remember token after sign in setting session options' do
90
- begin
91
- Rails.configuration.session_options[:domain] = "omg.somewhere.com"
92
- sign_in_as_user remember_me: true
93
- assert_nil request.cookies["remember_user_token"]
94
- ensure
95
- Rails.configuration.session_options.delete(:domain)
96
- end
97
- end
98
-
99
- test 'remember the user before sign in' do
100
- user = create_user_and_remember
101
- get users_path
102
- assert_response :success
103
- assert warden.authenticated?(:user)
104
- assert warden.user(:user) == user
105
- end
106
-
107
- test 'remember the user before sign up and redirect them to their home' do
108
- create_user_and_remember
109
- get new_user_registration_path
110
- assert warden.authenticated?(:user)
111
- assert_redirected_to root_path
112
- end
113
-
114
- test 'does not extend remember period through sign in' do
115
- swap Devise, extend_remember_period: true, remember_for: 1.year do
116
- user = create_user
117
- user.remember_me!
118
-
119
- user.remember_created_at = old = 10.days.ago
120
- user.save
121
-
122
- sign_in_as_user remember_me: true
123
- user.reload
124
-
125
- assert warden.user(:user) == user
126
- assert_equal old.to_i, user.remember_created_at.to_i
127
- end
128
- end
129
-
130
- test 'extends remember period when extend remember period config is true' do
131
- swap Devise, extend_remember_period: true, remember_for: 1.year do
132
- create_user_and_remember
133
- old_remember_token = nil
134
-
135
- travel_to 1.day.ago do
136
- get root_path
137
- old_remember_token = request.cookies['remember_user_token']
138
- end
139
-
140
- get root_path
141
- current_remember_token = request.cookies['remember_user_token']
142
-
143
- refute_equal old_remember_token, current_remember_token
144
- end
145
- end
146
-
147
- test 'does not extend remember period when extend period config is false' do
148
- swap Devise, extend_remember_period: false, remember_for: 1.year do
149
- create_user_and_remember
150
- old_remember_token = nil
151
-
152
- travel_to 1.day.ago do
153
- get root_path
154
- old_remember_token = request.cookies['remember_user_token']
155
- end
156
-
157
- get root_path
158
- current_remember_token = request.cookies['remember_user_token']
159
-
160
- assert_equal old_remember_token, current_remember_token
161
- end
162
- end
163
-
164
- test 'do not remember other scopes' do
165
- create_user_and_remember
166
- get root_path
167
- assert_response :success
168
- assert warden.authenticated?(:user)
169
- refute warden.authenticated?(:admin)
170
- end
171
-
172
- test 'do not remember with invalid token' do
173
- create_user_and_remember('add')
174
- get users_path
175
- refute warden.authenticated?(:user)
176
- assert_redirected_to new_user_session_path
177
- end
178
-
179
- test 'do not remember with expired token' do
180
- create_user_and_remember
181
- swap Devise, remember_for: 0.days do
182
- get users_path
183
- refute warden.authenticated?(:user)
184
- assert_redirected_to new_user_session_path
185
- end
186
- end
187
-
188
- test 'do not remember the user anymore after forget' do
189
- create_user_and_remember
190
- get users_path
191
- assert warden.authenticated?(:user)
192
-
193
- delete destroy_user_session_path
194
- refute warden.authenticated?(:user)
195
- assert_nil warden.cookies['remember_user_token']
196
-
197
- get users_path
198
- refute warden.authenticated?(:user)
199
- end
200
-
201
- test 'changing user password expires remember me token' do
202
- user = create_user_and_remember
203
- user.password = "another_password"
204
- user.password_confirmation = "another_password"
205
- user.save!
206
-
207
- get users_path
208
- refute warden.authenticated?(:user)
209
- end
210
-
211
- test 'valid sign in calls after_remembered callback' do
212
- user = create_user_and_remember
213
-
214
- User.expects(:serialize_from_cookie).returns user
215
- user.expects :after_remembered
216
-
217
- get new_user_registration_path
218
- end
219
- end