devise 3.2.2 → 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 (235) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +242 -978
  3. data/MIT-LICENSE +1 -1
  4. data/README.md +371 -100
  5. data/app/controllers/devise/confirmations_controller.rb +11 -5
  6. data/app/controllers/devise/omniauth_callbacks_controller.rb +12 -6
  7. data/app/controllers/devise/passwords_controller.rb +21 -8
  8. data/app/controllers/devise/registrations_controller.rb +59 -26
  9. data/app/controllers/devise/sessions_controller.rb +47 -17
  10. data/app/controllers/devise/unlocks_controller.rb +9 -4
  11. data/app/controllers/devise_controller.rb +67 -31
  12. data/app/helpers/devise_helper.rb +12 -19
  13. data/app/mailers/devise/mailer.rb +10 -0
  14. data/app/views/devise/confirmations/new.html.erb +9 -5
  15. data/app/views/devise/mailer/confirmation_instructions.html.erb +1 -1
  16. data/app/views/devise/mailer/email_changed.html.erb +7 -0
  17. data/app/views/devise/mailer/password_change.html.erb +3 -0
  18. data/app/views/devise/mailer/reset_password_instructions.html.erb +1 -1
  19. data/app/views/devise/mailer/unlock_instructions.html.erb +1 -1
  20. data/app/views/devise/passwords/edit.html.erb +16 -7
  21. data/app/views/devise/passwords/new.html.erb +9 -5
  22. data/app/views/devise/registrations/edit.html.erb +29 -15
  23. data/app/views/devise/registrations/new.html.erb +20 -9
  24. data/app/views/devise/sessions/new.html.erb +19 -10
  25. data/app/views/devise/shared/_error_messages.html.erb +15 -0
  26. data/app/views/devise/shared/{_links.erb → _links.html.erb} +9 -9
  27. data/app/views/devise/unlocks/new.html.erb +9 -5
  28. data/config/locales/en.yml +23 -17
  29. data/lib/devise/controllers/helpers.rb +112 -32
  30. data/lib/devise/controllers/rememberable.rb +15 -6
  31. data/lib/devise/controllers/scoped_views.rb +3 -1
  32. data/lib/devise/controllers/sign_in_out.rb +42 -26
  33. data/lib/devise/controllers/store_location.rb +31 -5
  34. data/lib/devise/controllers/url_helpers.rb +9 -7
  35. data/lib/devise/delegator.rb +2 -0
  36. data/lib/devise/encryptor.rb +24 -0
  37. data/lib/devise/failure_app.rb +125 -39
  38. data/lib/devise/hooks/activatable.rb +7 -6
  39. data/lib/devise/hooks/csrf_cleaner.rb +5 -1
  40. data/lib/devise/hooks/forgetable.rb +2 -0
  41. data/lib/devise/hooks/lockable.rb +7 -2
  42. data/lib/devise/hooks/proxy.rb +4 -2
  43. data/lib/devise/hooks/rememberable.rb +4 -2
  44. data/lib/devise/hooks/timeoutable.rb +16 -9
  45. data/lib/devise/hooks/trackable.rb +3 -1
  46. data/lib/devise/mailers/helpers.rb +15 -12
  47. data/lib/devise/mapping.rb +8 -2
  48. data/lib/devise/models/authenticatable.rb +82 -56
  49. data/lib/devise/models/confirmable.rb +125 -42
  50. data/lib/devise/models/database_authenticatable.rb +110 -32
  51. data/lib/devise/models/lockable.rb +30 -17
  52. data/lib/devise/models/omniauthable.rb +3 -1
  53. data/lib/devise/models/recoverable.rb +62 -26
  54. data/lib/devise/models/registerable.rb +4 -0
  55. data/lib/devise/models/rememberable.rb +62 -33
  56. data/lib/devise/models/timeoutable.rb +4 -8
  57. data/lib/devise/models/trackable.rb +20 -4
  58. data/lib/devise/models/validatable.rb +16 -9
  59. data/lib/devise/models.rb +3 -1
  60. data/lib/devise/modules.rb +12 -10
  61. data/lib/devise/omniauth/config.rb +2 -0
  62. data/lib/devise/omniauth/url_helpers.rb +14 -5
  63. data/lib/devise/omniauth.rb +2 -0
  64. data/lib/devise/orm/active_record.rb +5 -1
  65. data/lib/devise/orm/mongoid.rb +6 -2
  66. data/lib/devise/parameter_filter.rb +4 -0
  67. data/lib/devise/parameter_sanitizer.rb +139 -65
  68. data/lib/devise/rails/routes.rb +147 -116
  69. data/lib/devise/rails/warden_compat.rb +3 -10
  70. data/lib/devise/rails.rb +10 -13
  71. data/lib/devise/secret_key_finder.rb +27 -0
  72. data/lib/devise/strategies/authenticatable.rb +20 -9
  73. data/lib/devise/strategies/base.rb +3 -1
  74. data/lib/devise/strategies/database_authenticatable.rb +14 -6
  75. data/lib/devise/strategies/rememberable.rb +15 -3
  76. data/lib/devise/test/controller_helpers.rb +165 -0
  77. data/lib/devise/test/integration_helpers.rb +63 -0
  78. data/lib/devise/test_helpers.rb +7 -124
  79. data/lib/devise/time_inflector.rb +4 -2
  80. data/lib/devise/token_generator.rb +3 -41
  81. data/lib/devise/version.rb +3 -1
  82. data/lib/devise.rb +111 -84
  83. data/lib/generators/active_record/devise_generator.rb +49 -12
  84. data/lib/generators/active_record/templates/migration.rb +9 -7
  85. data/lib/generators/active_record/templates/migration_existing.rb +9 -7
  86. data/lib/generators/devise/controllers_generator.rb +46 -0
  87. data/lib/generators/devise/devise_generator.rb +7 -5
  88. data/lib/generators/devise/install_generator.rb +21 -0
  89. data/lib/generators/devise/orm_helpers.rb +10 -21
  90. data/lib/generators/devise/views_generator.rb +49 -28
  91. data/lib/generators/mongoid/devise_generator.rb +21 -19
  92. data/lib/generators/templates/README +5 -12
  93. data/lib/generators/templates/controllers/README +14 -0
  94. data/lib/generators/templates/controllers/confirmations_controller.rb +30 -0
  95. data/lib/generators/templates/controllers/omniauth_callbacks_controller.rb +30 -0
  96. data/lib/generators/templates/controllers/passwords_controller.rb +34 -0
  97. data/lib/generators/templates/controllers/registrations_controller.rb +62 -0
  98. data/lib/generators/templates/controllers/sessions_controller.rb +27 -0
  99. data/lib/generators/templates/controllers/unlocks_controller.rb +30 -0
  100. data/lib/generators/templates/devise.rb +81 -36
  101. data/lib/generators/templates/markerb/confirmation_instructions.markerb +1 -1
  102. data/lib/generators/templates/markerb/email_changed.markerb +7 -0
  103. data/lib/generators/templates/markerb/password_change.markerb +3 -0
  104. data/lib/generators/templates/markerb/reset_password_instructions.markerb +1 -1
  105. data/lib/generators/templates/markerb/unlock_instructions.markerb +1 -1
  106. data/lib/generators/templates/simple_form_for/confirmations/new.html.erb +6 -2
  107. data/lib/generators/templates/simple_form_for/passwords/edit.html.erb +9 -4
  108. data/lib/generators/templates/simple_form_for/passwords/new.html.erb +5 -2
  109. data/lib/generators/templates/simple_form_for/registrations/edit.html.erb +14 -6
  110. data/lib/generators/templates/simple_form_for/registrations/new.html.erb +12 -4
  111. data/lib/generators/templates/simple_form_for/sessions/new.html.erb +11 -6
  112. data/lib/generators/templates/simple_form_for/unlocks/new.html.erb +5 -2
  113. metadata +52 -280
  114. data/.gitignore +0 -10
  115. data/.travis.yml +0 -20
  116. data/.yardopts +0 -9
  117. data/CONTRIBUTING.md +0 -14
  118. data/Gemfile +0 -31
  119. data/Gemfile.lock +0 -160
  120. data/Rakefile +0 -35
  121. data/devise.gemspec +0 -27
  122. data/devise.png +0 -0
  123. data/gemfiles/Gemfile.rails-3.2.x +0 -31
  124. data/gemfiles/Gemfile.rails-3.2.x.lock +0 -159
  125. data/test/controllers/custom_strategy_test.rb +0 -62
  126. data/test/controllers/helpers_test.rb +0 -276
  127. data/test/controllers/internal_helpers_test.rb +0 -120
  128. data/test/controllers/passwords_controller_test.rb +0 -31
  129. data/test/controllers/sessions_controller_test.rb +0 -99
  130. data/test/controllers/url_helpers_test.rb +0 -59
  131. data/test/delegator_test.rb +0 -19
  132. data/test/devise_test.rb +0 -94
  133. data/test/failure_app_test.rb +0 -232
  134. data/test/generators/active_record_generator_test.rb +0 -103
  135. data/test/generators/devise_generator_test.rb +0 -39
  136. data/test/generators/install_generator_test.rb +0 -13
  137. data/test/generators/mongoid_generator_test.rb +0 -23
  138. data/test/generators/views_generator_test.rb +0 -67
  139. data/test/helpers/devise_helper_test.rb +0 -51
  140. data/test/integration/authenticatable_test.rb +0 -713
  141. data/test/integration/confirmable_test.rb +0 -284
  142. data/test/integration/database_authenticatable_test.rb +0 -84
  143. data/test/integration/http_authenticatable_test.rb +0 -105
  144. data/test/integration/lockable_test.rb +0 -239
  145. data/test/integration/omniauthable_test.rb +0 -133
  146. data/test/integration/recoverable_test.rb +0 -334
  147. data/test/integration/registerable_test.rb +0 -349
  148. data/test/integration/rememberable_test.rb +0 -167
  149. data/test/integration/timeoutable_test.rb +0 -183
  150. data/test/integration/trackable_test.rb +0 -92
  151. data/test/mailers/confirmation_instructions_test.rb +0 -115
  152. data/test/mailers/reset_password_instructions_test.rb +0 -96
  153. data/test/mailers/unlock_instructions_test.rb +0 -91
  154. data/test/mapping_test.rb +0 -127
  155. data/test/models/authenticatable_test.rb +0 -13
  156. data/test/models/confirmable_test.rb +0 -454
  157. data/test/models/database_authenticatable_test.rb +0 -249
  158. data/test/models/lockable_test.rb +0 -298
  159. data/test/models/omniauthable_test.rb +0 -7
  160. data/test/models/recoverable_test.rb +0 -184
  161. data/test/models/registerable_test.rb +0 -7
  162. data/test/models/rememberable_test.rb +0 -183
  163. data/test/models/serializable_test.rb +0 -49
  164. data/test/models/timeoutable_test.rb +0 -51
  165. data/test/models/trackable_test.rb +0 -13
  166. data/test/models/validatable_test.rb +0 -127
  167. data/test/models_test.rb +0 -144
  168. data/test/omniauth/config_test.rb +0 -57
  169. data/test/omniauth/url_helpers_test.rb +0 -54
  170. data/test/orm/active_record.rb +0 -10
  171. data/test/orm/mongoid.rb +0 -13
  172. data/test/parameter_sanitizer_test.rb +0 -81
  173. data/test/rails_app/Rakefile +0 -6
  174. data/test/rails_app/app/active_record/admin.rb +0 -6
  175. data/test/rails_app/app/active_record/shim.rb +0 -2
  176. data/test/rails_app/app/active_record/user.rb +0 -6
  177. data/test/rails_app/app/controllers/admins/sessions_controller.rb +0 -6
  178. data/test/rails_app/app/controllers/admins_controller.rb +0 -11
  179. data/test/rails_app/app/controllers/application_controller.rb +0 -9
  180. data/test/rails_app/app/controllers/home_controller.rb +0 -25
  181. data/test/rails_app/app/controllers/publisher/registrations_controller.rb +0 -2
  182. data/test/rails_app/app/controllers/publisher/sessions_controller.rb +0 -2
  183. data/test/rails_app/app/controllers/users/omniauth_callbacks_controller.rb +0 -14
  184. data/test/rails_app/app/controllers/users_controller.rb +0 -31
  185. data/test/rails_app/app/helpers/application_helper.rb +0 -3
  186. data/test/rails_app/app/mailers/users/mailer.rb +0 -12
  187. data/test/rails_app/app/mongoid/admin.rb +0 -29
  188. data/test/rails_app/app/mongoid/shim.rb +0 -23
  189. data/test/rails_app/app/mongoid/user.rb +0 -39
  190. data/test/rails_app/app/views/admins/index.html.erb +0 -1
  191. data/test/rails_app/app/views/admins/sessions/new.html.erb +0 -2
  192. data/test/rails_app/app/views/home/admin_dashboard.html.erb +0 -1
  193. data/test/rails_app/app/views/home/index.html.erb +0 -1
  194. data/test/rails_app/app/views/home/join.html.erb +0 -1
  195. data/test/rails_app/app/views/home/private.html.erb +0 -1
  196. data/test/rails_app/app/views/home/user_dashboard.html.erb +0 -1
  197. data/test/rails_app/app/views/layouts/application.html.erb +0 -24
  198. data/test/rails_app/app/views/users/edit_form.html.erb +0 -1
  199. data/test/rails_app/app/views/users/index.html.erb +0 -1
  200. data/test/rails_app/app/views/users/mailer/confirmation_instructions.erb +0 -1
  201. data/test/rails_app/app/views/users/sessions/new.html.erb +0 -1
  202. data/test/rails_app/bin/bundle +0 -3
  203. data/test/rails_app/bin/rails +0 -4
  204. data/test/rails_app/bin/rake +0 -4
  205. data/test/rails_app/config/application.rb +0 -40
  206. data/test/rails_app/config/boot.rb +0 -14
  207. data/test/rails_app/config/database.yml +0 -18
  208. data/test/rails_app/config/environment.rb +0 -5
  209. data/test/rails_app/config/environments/development.rb +0 -30
  210. data/test/rails_app/config/environments/production.rb +0 -80
  211. data/test/rails_app/config/environments/test.rb +0 -36
  212. data/test/rails_app/config/initializers/backtrace_silencers.rb +0 -7
  213. data/test/rails_app/config/initializers/devise.rb +0 -181
  214. data/test/rails_app/config/initializers/inflections.rb +0 -2
  215. data/test/rails_app/config/initializers/secret_token.rb +0 -8
  216. data/test/rails_app/config/initializers/session_store.rb +0 -1
  217. data/test/rails_app/config/routes.rb +0 -104
  218. data/test/rails_app/config.ru +0 -4
  219. data/test/rails_app/db/migrate/20100401102949_create_tables.rb +0 -71
  220. data/test/rails_app/db/schema.rb +0 -55
  221. data/test/rails_app/lib/shared_admin.rb +0 -17
  222. data/test/rails_app/lib/shared_user.rb +0 -29
  223. data/test/rails_app/public/404.html +0 -26
  224. data/test/rails_app/public/422.html +0 -26
  225. data/test/rails_app/public/500.html +0 -26
  226. data/test/rails_app/public/favicon.ico +0 -0
  227. data/test/routes_test.rb +0 -250
  228. data/test/support/assertions.rb +0 -40
  229. data/test/support/helpers.rb +0 -70
  230. data/test/support/integration.rb +0 -92
  231. data/test/support/locale/en.yml +0 -8
  232. data/test/support/webrat/integrations/rails.rb +0 -24
  233. data/test/test_helper.rb +0 -27
  234. data/test/test_helpers_test.rb +0 -173
  235. data/test/test_models.rb +0 -33
@@ -1,713 +0,0 @@
1
- require 'test_helper'
2
-
3
- class AuthenticationSanityTest < ActionDispatch::IntegrationTest
4
- test 'home should be accessible without sign in' do
5
- visit '/'
6
- assert_response :success
7
- assert_template 'home/index'
8
- end
9
-
10
- test 'sign in as user should not authenticate admin scope' do
11
- sign_in_as_user
12
- assert warden.authenticated?(:user)
13
- assert_not warden.authenticated?(:admin)
14
- end
15
-
16
- test 'sign in as admin should not authenticate user scope' do
17
- sign_in_as_admin
18
- assert warden.authenticated?(:admin)
19
- assert_not warden.authenticated?(:user)
20
- end
21
-
22
- test 'sign in as both user and admin at same time' do
23
- sign_in_as_user
24
- sign_in_as_admin
25
- assert warden.authenticated?(:user)
26
- assert warden.authenticated?(:admin)
27
- end
28
-
29
- test 'sign out as user should not touch admin authentication if sign_out_all_scopes is false' do
30
- swap Devise, :sign_out_all_scopes => false do
31
- sign_in_as_user
32
- sign_in_as_admin
33
- get destroy_user_session_path
34
- assert_not warden.authenticated?(:user)
35
- assert warden.authenticated?(:admin)
36
- end
37
- end
38
-
39
- test 'sign out as admin should not touch user authentication if sign_out_all_scopes is false' do
40
- swap Devise, :sign_out_all_scopes => false do
41
- sign_in_as_user
42
- sign_in_as_admin
43
-
44
- get destroy_admin_session_path
45
- assert_not warden.authenticated?(:admin)
46
- assert warden.authenticated?(:user)
47
- end
48
- end
49
-
50
- test 'sign out as user should also sign out admin if sign_out_all_scopes is true' do
51
- swap Devise, :sign_out_all_scopes => true do
52
- sign_in_as_user
53
- sign_in_as_admin
54
-
55
- get destroy_user_session_path
56
- assert_not warden.authenticated?(:user)
57
- assert_not warden.authenticated?(:admin)
58
- end
59
- end
60
-
61
- test 'sign out as admin should also sign out user if sign_out_all_scopes is true' do
62
- swap Devise, :sign_out_all_scopes => true do
63
- sign_in_as_user
64
- sign_in_as_admin
65
-
66
- get destroy_admin_session_path
67
- assert_not warden.authenticated?(:admin)
68
- assert_not warden.authenticated?(:user)
69
- end
70
- end
71
-
72
- test 'not signed in as admin should not be able to access admins actions' do
73
- get admins_path
74
- assert_redirected_to new_admin_session_path
75
- assert_not warden.authenticated?(:admin)
76
- end
77
-
78
- test 'signed in as user should not be able to access admins actions' do
79
- sign_in_as_user
80
- assert warden.authenticated?(:user)
81
- assert_not warden.authenticated?(:admin)
82
-
83
- get admins_path
84
- assert_redirected_to new_admin_session_path
85
- end
86
-
87
- test 'signed in as admin should be able to access admin actions' do
88
- sign_in_as_admin
89
- assert warden.authenticated?(:admin)
90
- assert_not warden.authenticated?(:user)
91
-
92
- get admins_path
93
-
94
- assert_response :success
95
- assert_template 'admins/index'
96
- assert_contain 'Welcome Admin'
97
- end
98
-
99
- test 'authenticated admin should not be able to sign as admin again' do
100
- sign_in_as_admin
101
- get new_admin_session_path
102
-
103
- assert_response :redirect
104
- assert_redirected_to admin_root_path
105
- assert warden.authenticated?(:admin)
106
- end
107
-
108
- test 'authenticated admin should be able to sign out' do
109
- sign_in_as_admin
110
- assert warden.authenticated?(:admin)
111
-
112
- get destroy_admin_session_path
113
- assert_response :redirect
114
- assert_redirected_to root_path
115
-
116
- get root_path
117
- assert_contain 'Signed out successfully'
118
- assert_not warden.authenticated?(:admin)
119
- end
120
-
121
- test 'unauthenticated admin does not set message on sign out' do
122
- get destroy_admin_session_path
123
- assert_response :redirect
124
- assert_redirected_to root_path
125
-
126
- get root_path
127
- assert_not_contain 'Signed out successfully'
128
- end
129
-
130
- test 'scope uses custom failure app' do
131
- put "/en/accounts/management"
132
- assert_equal "Oops, not found", response.body
133
- assert_equal 404, response.status
134
- end
135
- end
136
-
137
- class AuthenticationRoutesRestrictions < ActionDispatch::IntegrationTest
138
- test 'not signed in should not be able to access private route (authenticate denied)' do
139
- get private_path
140
- assert_redirected_to new_admin_session_path
141
- assert_not warden.authenticated?(:admin)
142
- end
143
-
144
- test 'signed in as user should not be able to access private route restricted to admins (authenticate denied)' do
145
- sign_in_as_user
146
- assert warden.authenticated?(:user)
147
- assert_not warden.authenticated?(:admin)
148
- get private_path
149
- assert_redirected_to new_admin_session_path
150
- end
151
-
152
- test 'signed in as admin should be able to access private route restricted to admins (authenticate accepted)' do
153
- sign_in_as_admin
154
- assert warden.authenticated?(:admin)
155
- assert_not warden.authenticated?(:user)
156
-
157
- get private_path
158
-
159
- assert_response :success
160
- assert_template 'home/private'
161
- assert_contain 'Private!'
162
- end
163
-
164
- test 'signed in as inactive admin should not be able to access private/active route restricted to active admins (authenticate denied)' do
165
- sign_in_as_admin(:active => false)
166
- assert warden.authenticated?(:admin)
167
- assert_not warden.authenticated?(:user)
168
-
169
- assert_raises ActionController::RoutingError do
170
- get "/private/active"
171
- end
172
- end
173
-
174
- test 'signed in as active admin should be able to access private/active route restricted to active admins (authenticate accepted)' do
175
- sign_in_as_admin(:active => true)
176
- assert warden.authenticated?(:admin)
177
- assert_not warden.authenticated?(:user)
178
-
179
- get private_active_path
180
-
181
- assert_response :success
182
- assert_template 'home/private'
183
- assert_contain 'Private!'
184
- end
185
-
186
- test 'signed in as admin should get admin dashboard (authenticated accepted)' do
187
- sign_in_as_admin
188
- assert warden.authenticated?(:admin)
189
- assert_not warden.authenticated?(:user)
190
-
191
- get dashboard_path
192
-
193
- assert_response :success
194
- assert_template 'home/admin_dashboard'
195
- assert_contain 'Admin dashboard'
196
- end
197
-
198
- test 'signed in as user should get user dashboard (authenticated accepted)' do
199
- sign_in_as_user
200
- assert warden.authenticated?(:user)
201
- assert_not warden.authenticated?(:admin)
202
-
203
- get dashboard_path
204
-
205
- assert_response :success
206
- assert_template 'home/user_dashboard'
207
- assert_contain 'User dashboard'
208
- end
209
-
210
- test 'not signed in should get no dashboard (authenticated denied)' do
211
- assert_raises ActionController::RoutingError do
212
- get dashboard_path
213
- end
214
- end
215
-
216
- test 'signed in as inactive admin should not be able to access dashboard/active route restricted to active admins (authenticated denied)' do
217
- sign_in_as_admin(:active => false)
218
- assert warden.authenticated?(:admin)
219
- assert_not warden.authenticated?(:user)
220
-
221
- assert_raises ActionController::RoutingError do
222
- get "/dashboard/active"
223
- end
224
- end
225
-
226
- test 'signed in as active admin should be able to access dashboard/active route restricted to active admins (authenticated accepted)' do
227
- sign_in_as_admin(:active => true)
228
- assert warden.authenticated?(:admin)
229
- assert_not warden.authenticated?(:user)
230
-
231
- get dashboard_active_path
232
-
233
- assert_response :success
234
- assert_template 'home/admin_dashboard'
235
- assert_contain 'Admin dashboard'
236
- end
237
-
238
- test 'signed in user should not see unauthenticated page (unauthenticated denied)' do
239
- sign_in_as_user
240
- assert warden.authenticated?(:user)
241
- assert_not warden.authenticated?(:admin)
242
-
243
- assert_raises ActionController::RoutingError do
244
- get join_path
245
- end
246
- end
247
-
248
- test 'not signed in users should see unautheticated page (unauthenticated accepted)' do
249
- get join_path
250
-
251
- assert_response :success
252
- assert_template 'home/join'
253
- assert_contain 'Join'
254
- end
255
- end
256
-
257
- class AuthenticationRedirectTest < ActionDispatch::IntegrationTest
258
- test 'redirect from warden shows sign in or sign up message' do
259
- get admins_path
260
-
261
- warden_path = new_admin_session_path
262
- assert_redirected_to warden_path
263
-
264
- get warden_path
265
- assert_contain 'You need to sign in or sign up before continuing.'
266
- end
267
-
268
- test 'redirect to default url if no other was configured' do
269
- sign_in_as_user
270
- assert_template 'home/index'
271
- assert_nil session[:"user_return_to"]
272
- end
273
-
274
- test 'redirect to requested url after sign in' do
275
- get users_path
276
- assert_redirected_to new_user_session_path
277
- assert_equal users_path, session[:"user_return_to"]
278
-
279
- follow_redirect!
280
- sign_in_as_user :visit => false
281
-
282
- assert_current_url '/users'
283
- assert_nil session[:"user_return_to"]
284
- end
285
-
286
- test 'redirect to last requested url overwriting the stored return_to option' do
287
- get expire_user_path(create_user)
288
- assert_redirected_to new_user_session_path
289
- assert_equal expire_user_path(create_user), session[:"user_return_to"]
290
-
291
- get users_path
292
- assert_redirected_to new_user_session_path
293
- assert_equal users_path, session[:"user_return_to"]
294
-
295
- follow_redirect!
296
- sign_in_as_user :visit => false
297
-
298
- assert_current_url '/users'
299
- assert_nil session[:"user_return_to"]
300
- end
301
-
302
- test 'xml http requests does not store urls for redirect' do
303
- get users_path, {}, 'HTTP_X_REQUESTED_WITH' => 'XMLHttpRequest'
304
- assert_equal 401, response.status
305
- assert_nil session[:"user_return_to"]
306
- end
307
-
308
- test 'redirect to configured home path for a given scope after sign in' do
309
- sign_in_as_admin
310
- assert_equal "/admin_area/home", @request.path
311
- end
312
-
313
- test 'require_no_authentication should set the already_authenticated flash message' do
314
- sign_in_as_user
315
- visit new_user_session_path
316
- assert_equal flash[:alert], I18n.t("devise.failure.already_authenticated")
317
- end
318
- end
319
-
320
- class AuthenticationSessionTest < ActionDispatch::IntegrationTest
321
- test 'destroyed account is signed out' do
322
- sign_in_as_user
323
- get '/users'
324
-
325
- User.destroy_all
326
- get '/users'
327
- assert_redirected_to new_user_session_path
328
- end
329
-
330
- test 'refreshes _csrf_token' do
331
- ApplicationController.allow_forgery_protection = true
332
-
333
- begin
334
- get new_user_session_path
335
- token = request.session[:_csrf_token]
336
-
337
- sign_in_as_user
338
- assert_not_equal request.session[:_csrf_token], token
339
- ensure
340
- ApplicationController.allow_forgery_protection = false
341
- end
342
- end
343
-
344
- test 'allows session to be set for a given scope' do
345
- sign_in_as_user
346
- get '/users'
347
- assert_equal "Cart", @controller.user_session[:cart]
348
- end
349
-
350
- test 'does not explode when class name is still stored in session' do
351
- # In order to test that old sessions do not break with the new scoped
352
- # deserialization, we need to serialize the session the old way. This is
353
- # done by removing the newly used scoped serialization method
354
- # (#user_serialize) and bringing back the old uncsoped #serialize method
355
- # that includes the record's class name in the serialization.
356
- begin
357
- Warden::SessionSerializer.class_eval do
358
- alias_method :original_serialize, :serialize
359
- alias_method :original_user_serialize, :user_serialize
360
- remove_method :user_serialize
361
-
362
- def serialize(record)
363
- klass = record.class
364
- array = klass.serialize_into_session(record)
365
- array.unshift(klass.name)
366
- end
367
- end
368
-
369
- sign_in_as_user
370
- assert warden.authenticated?(:user)
371
- ensure
372
- Warden::SessionSerializer.class_eval do
373
- alias_method :serialize, :original_serialize
374
- remove_method :original_serialize
375
- alias_method :user_serialize, :original_user_serialize
376
- remove_method :original_user_serialize
377
- end
378
- end
379
- end
380
-
381
- test 'session id is changed on sign in' do
382
- get '/users'
383
- session_id = request.session["session_id"]
384
-
385
- get '/users'
386
- assert_equal session_id, request.session["session_id"]
387
-
388
- sign_in_as_user
389
- assert_not_equal session_id, request.session["session_id"]
390
- end
391
- end
392
-
393
- class AuthenticationWithScopedViewsTest < ActionDispatch::IntegrationTest
394
- test 'renders the scoped view if turned on and view is available' do
395
- swap Devise, :scoped_views => true do
396
- assert_raise Webrat::NotFoundError do
397
- sign_in_as_user
398
- end
399
- assert_match /Special user view/, response.body
400
- end
401
- end
402
-
403
- test 'renders the scoped view if turned on in an specific controller' do
404
- begin
405
- Devise::SessionsController.scoped_views = true
406
- assert_raise Webrat::NotFoundError do
407
- sign_in_as_user
408
- end
409
-
410
- assert_match /Special user view/, response.body
411
- assert !Devise::PasswordsController.scoped_views?
412
- ensure
413
- Devise::SessionsController.send :remove_instance_variable, :@scoped_views
414
- end
415
- end
416
-
417
- test 'does not render the scoped view if turned off' do
418
- swap Devise, :scoped_views => false do
419
- assert_nothing_raised do
420
- sign_in_as_user
421
- end
422
- end
423
- end
424
-
425
- test 'does not render the scoped view if not available' do
426
- swap Devise, :scoped_views => true do
427
- assert_nothing_raised do
428
- sign_in_as_admin
429
- end
430
- end
431
- end
432
- end
433
-
434
- class AuthenticationOthersTest < ActionDispatch::IntegrationTest
435
- test 'handles unverified requests gets rid of caches' do
436
- swap ApplicationController, :allow_forgery_protection => true do
437
- post exhibit_user_url(1)
438
- assert_not warden.authenticated?(:user)
439
-
440
- sign_in_as_user
441
- assert warden.authenticated?(:user)
442
-
443
- post exhibit_user_url(1)
444
- assert_not warden.authenticated?(:user)
445
- assert_equal "User is not authenticated", response.body
446
- end
447
- end
448
-
449
- test 'uses the custom controller with the custom controller view' do
450
- get '/admin_area/sign_in'
451
- assert_contain 'Sign in'
452
- assert_contain 'Welcome to "admins/sessions" controller!'
453
- assert_contain 'Welcome to "sessions/new" view!'
454
- end
455
-
456
- test 'render 404 on roles without routes' do
457
- assert_raise ActionController::RoutingError do
458
- get '/admin_area/password/new'
459
- end
460
- end
461
-
462
- test 'does not intercept Rails 401 responses' do
463
- get '/unauthenticated'
464
- assert_equal 401, response.status
465
- end
466
-
467
- test 'render 404 on roles without mapping' do
468
- assert_raise AbstractController::ActionNotFound do
469
- get '/sign_in'
470
- end
471
- end
472
-
473
- test 'sign in with script name' do
474
- assert_nothing_raised do
475
- get new_user_session_path, {}, "SCRIPT_NAME" => "/omg"
476
- fill_in "email", :with => "user@test.com"
477
- end
478
- end
479
-
480
- test 'sign in stub in xml format' do
481
- get new_user_session_path(:format => 'xml')
482
- assert_match '<?xml version="1.0" encoding="UTF-8"?>', response.body
483
- assert_match /<user>.*<\/user>/m, response.body
484
- assert_match '<email></email>', response.body
485
- assert_match '<password nil="true"', response.body
486
- end
487
-
488
- test 'sign in stub in json format' do
489
- get new_user_session_path(:format => 'json')
490
- assert_match '{"user":{', response.body
491
- assert_match '"email":""', response.body
492
- assert_match '"password":null', response.body
493
- end
494
-
495
- test 'sign in stub in json with non attribute key' do
496
- swap Devise, :authentication_keys => [:other_key] do
497
- get new_user_session_path(:format => 'json')
498
- assert_match '{"user":{', response.body
499
- assert_match '"other_key":null', response.body
500
- assert_match '"password":null', response.body
501
- end
502
- end
503
-
504
- test 'uses the mapping from router' do
505
- sign_in_as_user :visit => "/as/sign_in"
506
- assert warden.authenticated?(:user)
507
- assert_not warden.authenticated?(:admin)
508
- end
509
-
510
- test 'sign in with xml format returns xml response' do
511
- create_user
512
- post user_session_path(:format => 'xml'), :user => {:email => "user@test.com", :password => '12345678'}
513
- assert_response :success
514
- assert response.body.include? %(<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<user>)
515
- end
516
-
517
- test 'sign in with xml format is idempotent' do
518
- get new_user_session_path(:format => 'xml')
519
- assert_response :success
520
-
521
- create_user
522
- post user_session_path(:format => 'xml'), :user => {:email => "user@test.com", :password => '12345678'}
523
- assert_response :success
524
-
525
- get new_user_session_path(:format => 'xml')
526
- assert_response :success
527
-
528
- post user_session_path(:format => 'xml'), :user => {:email => "user@test.com", :password => '12345678'}
529
- assert_response :success
530
- assert response.body.include? %(<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<user>)
531
- end
532
-
533
- test 'sign out with html redirects' do
534
- sign_in_as_user
535
- get destroy_user_session_path
536
- assert_response :redirect
537
- assert_current_url '/'
538
-
539
- sign_in_as_user
540
- get destroy_user_session_path(:format => 'html')
541
- assert_response :redirect
542
- assert_current_url '/'
543
- end
544
-
545
- test 'sign out with xml format returns no content' do
546
- sign_in_as_user
547
- get destroy_user_session_path(:format => 'xml')
548
- assert_response :no_content
549
- assert_not warden.authenticated?(:user)
550
- end
551
-
552
- test 'sign out with json format returns no content' do
553
- sign_in_as_user
554
- get destroy_user_session_path(:format => 'json')
555
- assert_response :no_content
556
- assert_not warden.authenticated?(:user)
557
- end
558
-
559
- test 'sign out with non-navigational format via XHR does not redirect' do
560
- swap Devise, :navigational_formats => ['*/*', :html] do
561
- sign_in_as_user
562
- xml_http_request :get, destroy_user_session_path, {}, { "HTTP_ACCEPT" => "application/json,text/javascript,*/*" } # NOTE: Bug is triggered by combination of XHR and */*.
563
- assert_response :no_content
564
- assert_not warden.authenticated?(:user)
565
- end
566
- end
567
-
568
- # Belt and braces ... Perhaps this test is not necessary?
569
- test 'sign out with navigational format via XHR does redirect' do
570
- swap Devise, :navigational_formats => ['*/*', :html] do
571
- sign_in_as_user
572
- xml_http_request :get, destroy_user_session_path, {}, { "HTTP_ACCEPT" => "text/html,*/*" }
573
- assert_response :redirect
574
- assert_not warden.authenticated?(:user)
575
- end
576
- end
577
- end
578
-
579
- class AuthenticationKeysTest < ActionDispatch::IntegrationTest
580
- test 'missing authentication keys cause authentication to abort' do
581
- swap Devise, :authentication_keys => [:subdomain] do
582
- sign_in_as_user
583
- assert_contain "Invalid email or password."
584
- assert_not warden.authenticated?(:user)
585
- end
586
- end
587
-
588
- test 'missing authentication keys cause authentication to abort unless marked as not required' do
589
- swap Devise, :authentication_keys => { :email => true, :subdomain => false } do
590
- sign_in_as_user
591
- assert warden.authenticated?(:user)
592
- end
593
- end
594
- end
595
-
596
- class AuthenticationRequestKeysTest < ActionDispatch::IntegrationTest
597
- test 'request keys are used on authentication' do
598
- host! 'foo.bar.baz'
599
-
600
- swap Devise, :request_keys => [:subdomain] do
601
- User.expects(:find_for_authentication).with(:subdomain => 'foo', :email => 'user@test.com').returns(create_user)
602
- sign_in_as_user
603
- assert warden.authenticated?(:user)
604
- end
605
- end
606
-
607
- test 'invalid request keys raises NoMethodError' do
608
- swap Devise, :request_keys => [:unknown_method] do
609
- assert_raise NoMethodError do
610
- sign_in_as_user
611
- end
612
-
613
- assert_not warden.authenticated?(:user)
614
- end
615
- end
616
-
617
- test 'blank request keys cause authentication to abort' do
618
- host! 'test.com'
619
-
620
- swap Devise, :request_keys => [:subdomain] do
621
- sign_in_as_user
622
- assert_contain "Invalid email or password."
623
- assert_not warden.authenticated?(:user)
624
- end
625
- end
626
-
627
- test 'blank request keys cause authentication to abort unless if marked as not required' do
628
- host! 'test.com'
629
-
630
- swap Devise, :request_keys => { :subdomain => false } do
631
- sign_in_as_user
632
- assert warden.authenticated?(:user)
633
- end
634
- end
635
- end
636
-
637
- class AuthenticationSignOutViaTest < ActionDispatch::IntegrationTest
638
- def sign_in!(scope)
639
- sign_in_as_admin(:visit => send("new_#{scope}_session_path"))
640
- assert warden.authenticated?(scope)
641
- end
642
-
643
- test 'allow sign out via delete when sign_out_via provides only delete' do
644
- sign_in!(:sign_out_via_delete)
645
- delete destroy_sign_out_via_delete_session_path
646
- assert_not warden.authenticated?(:sign_out_via_delete)
647
- end
648
-
649
- test 'do not allow sign out via get when sign_out_via provides only delete' do
650
- sign_in!(:sign_out_via_delete)
651
- assert_raise ActionController::RoutingError do
652
- get destroy_sign_out_via_delete_session_path
653
- end
654
- assert warden.authenticated?(:sign_out_via_delete)
655
- end
656
-
657
- test 'allow sign out via post when sign_out_via provides only post' do
658
- sign_in!(:sign_out_via_post)
659
- post destroy_sign_out_via_post_session_path
660
- assert_not warden.authenticated?(:sign_out_via_post)
661
- end
662
-
663
- test 'do not allow sign out via get when sign_out_via provides only post' do
664
- sign_in!(:sign_out_via_post)
665
- assert_raise ActionController::RoutingError do
666
- get destroy_sign_out_via_delete_session_path
667
- end
668
- assert warden.authenticated?(:sign_out_via_post)
669
- end
670
-
671
- test 'allow sign out via delete when sign_out_via provides delete and post' do
672
- sign_in!(:sign_out_via_delete_or_post)
673
- delete destroy_sign_out_via_delete_or_post_session_path
674
- assert_not warden.authenticated?(:sign_out_via_delete_or_post)
675
- end
676
-
677
- test 'allow sign out via post when sign_out_via provides delete and post' do
678
- sign_in!(:sign_out_via_delete_or_post)
679
- post destroy_sign_out_via_delete_or_post_session_path
680
- assert_not warden.authenticated?(:sign_out_via_delete_or_post)
681
- end
682
-
683
- test 'do not allow sign out via get when sign_out_via provides delete and post' do
684
- sign_in!(:sign_out_via_delete_or_post)
685
- assert_raise ActionController::RoutingError do
686
- get destroy_sign_out_via_delete_or_post_session_path
687
- end
688
- assert warden.authenticated?(:sign_out_via_delete_or_post)
689
- end
690
- end
691
-
692
- class DoubleAuthenticationRedirectTest < ActionDispatch::IntegrationTest
693
- test 'signed in as user redirects when visiting user sign in page' do
694
- sign_in_as_user
695
- get new_user_session_path(:format => :html)
696
- assert_redirected_to '/'
697
- end
698
-
699
- test 'signed in as admin redirects when visiting admin sign in page' do
700
- sign_in_as_admin
701
- get new_admin_session_path(:format => :html)
702
- assert_redirected_to '/admin_area/home'
703
- end
704
-
705
- test 'signed in as both user and admin redirects when visiting admin sign in page' do
706
- sign_in_as_user
707
- sign_in_as_admin
708
- get new_user_session_path(:format => :html)
709
- assert_redirected_to '/'
710
- get new_admin_session_path(:format => :html)
711
- assert_redirected_to '/admin_area/home'
712
- end
713
- end