devise 3.5.10 → 4.7.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (257) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +265 -1129
  3. data/MIT-LICENSE +2 -1
  4. data/README.md +291 -96
  5. data/app/controllers/devise/confirmations_controller.rb +3 -1
  6. data/app/controllers/devise/omniauth_callbacks_controller.rb +8 -6
  7. data/app/controllers/devise/passwords_controller.rb +7 -4
  8. data/app/controllers/devise/registrations_controller.rb +39 -18
  9. data/app/controllers/devise/sessions_controller.rb +9 -7
  10. data/app/controllers/devise/unlocks_controller.rb +4 -2
  11. data/app/controllers/devise_controller.rb +25 -12
  12. data/app/helpers/devise_helper.rb +23 -18
  13. data/app/mailers/devise/mailer.rb +10 -4
  14. data/app/views/devise/confirmations/new.html.erb +2 -2
  15. data/app/views/devise/mailer/email_changed.html.erb +7 -0
  16. data/app/views/devise/passwords/edit.html.erb +3 -3
  17. data/app/views/devise/passwords/new.html.erb +2 -2
  18. data/app/views/devise/registrations/edit.html.erb +9 -5
  19. data/app/views/devise/registrations/new.html.erb +4 -4
  20. data/app/views/devise/sessions/new.html.erb +4 -4
  21. data/app/views/devise/shared/_error_messages.html.erb +15 -0
  22. data/app/views/devise/shared/_links.html.erb +7 -7
  23. data/app/views/devise/unlocks/new.html.erb +2 -2
  24. data/config/locales/en.yml +5 -2
  25. data/lib/devise/controllers/helpers.rb +30 -27
  26. data/lib/devise/controllers/rememberable.rb +3 -1
  27. data/lib/devise/controllers/scoped_views.rb +2 -0
  28. data/lib/devise/controllers/sign_in_out.rb +37 -14
  29. data/lib/devise/controllers/store_location.rb +25 -7
  30. data/lib/devise/controllers/url_helpers.rb +3 -1
  31. data/lib/devise/delegator.rb +2 -0
  32. data/lib/devise/encryptor.rb +6 -4
  33. data/lib/devise/failure_app.rb +75 -38
  34. data/lib/devise/hooks/activatable.rb +2 -0
  35. data/lib/devise/hooks/csrf_cleaner.rb +2 -0
  36. data/lib/devise/hooks/forgetable.rb +2 -0
  37. data/lib/devise/hooks/lockable.rb +6 -1
  38. data/lib/devise/hooks/proxy.rb +3 -1
  39. data/lib/devise/hooks/rememberable.rb +2 -0
  40. data/lib/devise/hooks/timeoutable.rb +4 -2
  41. data/lib/devise/hooks/trackable.rb +2 -0
  42. data/lib/devise/mailers/helpers.rb +7 -4
  43. data/lib/devise/mapping.rb +3 -1
  44. data/lib/devise/models/authenticatable.rb +57 -31
  45. data/lib/devise/models/confirmable.rb +90 -29
  46. data/lib/devise/models/database_authenticatable.rb +93 -22
  47. data/lib/devise/models/lockable.rb +11 -5
  48. data/lib/devise/models/omniauthable.rb +2 -0
  49. data/lib/devise/models/recoverable.rb +33 -21
  50. data/lib/devise/models/registerable.rb +4 -0
  51. data/lib/devise/models/rememberable.rb +6 -11
  52. data/lib/devise/models/timeoutable.rb +2 -0
  53. data/lib/devise/models/trackable.rb +15 -1
  54. data/lib/devise/models/validatable.rb +10 -3
  55. data/lib/devise/models.rb +3 -1
  56. data/lib/devise/modules.rb +2 -0
  57. data/lib/devise/omniauth/config.rb +2 -0
  58. data/lib/devise/omniauth/url_helpers.rb +14 -5
  59. data/lib/devise/omniauth.rb +2 -0
  60. data/lib/devise/orm/active_record.rb +5 -1
  61. data/lib/devise/orm/mongoid.rb +6 -2
  62. data/lib/devise/parameter_filter.rb +4 -0
  63. data/lib/devise/parameter_sanitizer.rb +139 -65
  64. data/lib/devise/rails/routes.rb +48 -37
  65. data/lib/devise/rails/warden_compat.rb +3 -10
  66. data/lib/devise/rails.rb +7 -16
  67. data/lib/devise/secret_key_finder.rb +27 -0
  68. data/lib/devise/strategies/authenticatable.rb +3 -1
  69. data/lib/devise/strategies/base.rb +2 -0
  70. data/lib/devise/strategies/database_authenticatable.rb +11 -4
  71. data/lib/devise/strategies/rememberable.rb +2 -0
  72. data/lib/devise/test/controller_helpers.rb +167 -0
  73. data/lib/devise/test/integration_helpers.rb +63 -0
  74. data/lib/devise/test_helpers.rb +7 -124
  75. data/lib/devise/time_inflector.rb +2 -0
  76. data/lib/devise/token_generator.rb +3 -41
  77. data/lib/devise/version.rb +3 -1
  78. data/lib/devise.rb +57 -40
  79. data/lib/generators/active_record/devise_generator.rb +29 -10
  80. data/lib/generators/active_record/templates/migration.rb +4 -2
  81. data/lib/generators/active_record/templates/migration_existing.rb +4 -2
  82. data/lib/generators/devise/controllers_generator.rb +3 -1
  83. data/lib/generators/devise/devise_generator.rb +5 -3
  84. data/lib/generators/devise/install_generator.rb +18 -5
  85. data/lib/generators/devise/orm_helpers.rb +10 -21
  86. data/lib/generators/devise/views_generator.rb +8 -9
  87. data/lib/generators/mongoid/devise_generator.rb +7 -5
  88. data/lib/generators/templates/README +9 -8
  89. data/lib/generators/templates/controllers/confirmations_controller.rb +2 -0
  90. data/lib/generators/templates/controllers/omniauth_callbacks_controller.rb +3 -1
  91. data/lib/generators/templates/controllers/passwords_controller.rb +2 -0
  92. data/lib/generators/templates/controllers/registrations_controller.rb +6 -4
  93. data/lib/generators/templates/controllers/sessions_controller.rb +4 -2
  94. data/lib/generators/templates/controllers/unlocks_controller.rb +2 -0
  95. data/lib/generators/templates/devise.rb +63 -21
  96. data/lib/generators/templates/markerb/email_changed.markerb +7 -0
  97. data/lib/generators/templates/markerb/password_change.markerb +2 -2
  98. data/lib/generators/templates/simple_form_for/confirmations/new.html.erb +5 -1
  99. data/lib/generators/templates/simple_form_for/passwords/edit.html.erb +10 -2
  100. data/lib/generators/templates/simple_form_for/passwords/new.html.erb +4 -1
  101. data/lib/generators/templates/simple_form_for/registrations/edit.html.erb +11 -3
  102. data/lib/generators/templates/simple_form_for/registrations/new.html.erb +11 -3
  103. data/lib/generators/templates/simple_form_for/sessions/new.html.erb +7 -2
  104. data/lib/generators/templates/simple_form_for/unlocks/new.html.erb +4 -1
  105. metadata +15 -314
  106. data/.gitignore +0 -10
  107. data/.travis.yml +0 -44
  108. data/.yardopts +0 -9
  109. data/CODE_OF_CONDUCT.md +0 -22
  110. data/CONTRIBUTING.md +0 -16
  111. data/Gemfile +0 -30
  112. data/Gemfile.lock +0 -187
  113. data/Rakefile +0 -36
  114. data/devise.gemspec +0 -27
  115. data/devise.png +0 -0
  116. data/gemfiles/Gemfile.rails-3.2-stable +0 -29
  117. data/gemfiles/Gemfile.rails-3.2-stable.lock +0 -172
  118. data/gemfiles/Gemfile.rails-4.0-stable +0 -30
  119. data/gemfiles/Gemfile.rails-4.0-stable.lock +0 -166
  120. data/gemfiles/Gemfile.rails-4.1-stable +0 -30
  121. data/gemfiles/Gemfile.rails-4.1-stable.lock +0 -171
  122. data/gemfiles/Gemfile.rails-4.2-stable +0 -30
  123. data/gemfiles/Gemfile.rails-4.2-stable.lock +0 -193
  124. data/script/cached-bundle +0 -49
  125. data/script/s3-put +0 -71
  126. data/test/controllers/custom_registrations_controller_test.rb +0 -40
  127. data/test/controllers/custom_strategy_test.rb +0 -62
  128. data/test/controllers/helper_methods_test.rb +0 -21
  129. data/test/controllers/helpers_test.rb +0 -316
  130. data/test/controllers/inherited_controller_i18n_messages_test.rb +0 -51
  131. data/test/controllers/internal_helpers_test.rb +0 -129
  132. data/test/controllers/load_hooks_controller_test.rb +0 -19
  133. data/test/controllers/passwords_controller_test.rb +0 -31
  134. data/test/controllers/sessions_controller_test.rb +0 -103
  135. data/test/controllers/url_helpers_test.rb +0 -65
  136. data/test/delegator_test.rb +0 -19
  137. data/test/devise_test.rb +0 -107
  138. data/test/failure_app_test.rb +0 -315
  139. data/test/generators/active_record_generator_test.rb +0 -109
  140. data/test/generators/controllers_generator_test.rb +0 -48
  141. data/test/generators/devise_generator_test.rb +0 -39
  142. data/test/generators/install_generator_test.rb +0 -13
  143. data/test/generators/mongoid_generator_test.rb +0 -23
  144. data/test/generators/views_generator_test.rb +0 -103
  145. data/test/helpers/devise_helper_test.rb +0 -49
  146. data/test/integration/authenticatable_test.rb +0 -729
  147. data/test/integration/confirmable_test.rb +0 -324
  148. data/test/integration/database_authenticatable_test.rb +0 -95
  149. data/test/integration/http_authenticatable_test.rb +0 -105
  150. data/test/integration/lockable_test.rb +0 -239
  151. data/test/integration/omniauthable_test.rb +0 -135
  152. data/test/integration/recoverable_test.rb +0 -347
  153. data/test/integration/registerable_test.rb +0 -359
  154. data/test/integration/rememberable_test.rb +0 -214
  155. data/test/integration/timeoutable_test.rb +0 -184
  156. data/test/integration/trackable_test.rb +0 -92
  157. data/test/mailers/confirmation_instructions_test.rb +0 -115
  158. data/test/mailers/reset_password_instructions_test.rb +0 -96
  159. data/test/mailers/unlock_instructions_test.rb +0 -91
  160. data/test/mapping_test.rb +0 -134
  161. data/test/models/authenticatable_test.rb +0 -23
  162. data/test/models/confirmable_test.rb +0 -511
  163. data/test/models/database_authenticatable_test.rb +0 -269
  164. data/test/models/lockable_test.rb +0 -350
  165. data/test/models/omniauthable_test.rb +0 -7
  166. data/test/models/recoverable_test.rb +0 -251
  167. data/test/models/registerable_test.rb +0 -7
  168. data/test/models/rememberable_test.rb +0 -169
  169. data/test/models/serializable_test.rb +0 -49
  170. data/test/models/timeoutable_test.rb +0 -51
  171. data/test/models/trackable_test.rb +0 -41
  172. data/test/models/validatable_test.rb +0 -127
  173. data/test/models_test.rb +0 -153
  174. data/test/omniauth/config_test.rb +0 -57
  175. data/test/omniauth/url_helpers_test.rb +0 -54
  176. data/test/orm/active_record.rb +0 -10
  177. data/test/orm/mongoid.rb +0 -13
  178. data/test/parameter_sanitizer_test.rb +0 -81
  179. data/test/rails_app/Rakefile +0 -6
  180. data/test/rails_app/app/active_record/admin.rb +0 -6
  181. data/test/rails_app/app/active_record/shim.rb +0 -2
  182. data/test/rails_app/app/active_record/user.rb +0 -6
  183. data/test/rails_app/app/active_record/user_on_engine.rb +0 -7
  184. data/test/rails_app/app/active_record/user_on_main_app.rb +0 -7
  185. data/test/rails_app/app/active_record/user_without_email.rb +0 -8
  186. data/test/rails_app/app/controllers/admins/sessions_controller.rb +0 -6
  187. data/test/rails_app/app/controllers/admins_controller.rb +0 -6
  188. data/test/rails_app/app/controllers/application_controller.rb +0 -12
  189. data/test/rails_app/app/controllers/application_with_fake_engine.rb +0 -30
  190. data/test/rails_app/app/controllers/custom/registrations_controller.rb +0 -31
  191. data/test/rails_app/app/controllers/home_controller.rb +0 -25
  192. data/test/rails_app/app/controllers/publisher/registrations_controller.rb +0 -2
  193. data/test/rails_app/app/controllers/publisher/sessions_controller.rb +0 -2
  194. data/test/rails_app/app/controllers/users/omniauth_callbacks_controller.rb +0 -14
  195. data/test/rails_app/app/controllers/users_controller.rb +0 -31
  196. data/test/rails_app/app/helpers/application_helper.rb +0 -3
  197. data/test/rails_app/app/mailers/users/from_proc_mailer.rb +0 -3
  198. data/test/rails_app/app/mailers/users/mailer.rb +0 -3
  199. data/test/rails_app/app/mailers/users/reply_to_mailer.rb +0 -4
  200. data/test/rails_app/app/mongoid/admin.rb +0 -29
  201. data/test/rails_app/app/mongoid/shim.rb +0 -23
  202. data/test/rails_app/app/mongoid/user.rb +0 -39
  203. data/test/rails_app/app/mongoid/user_on_engine.rb +0 -39
  204. data/test/rails_app/app/mongoid/user_on_main_app.rb +0 -39
  205. data/test/rails_app/app/mongoid/user_without_email.rb +0 -33
  206. data/test/rails_app/app/views/admins/index.html.erb +0 -1
  207. data/test/rails_app/app/views/admins/sessions/new.html.erb +0 -2
  208. data/test/rails_app/app/views/home/admin_dashboard.html.erb +0 -1
  209. data/test/rails_app/app/views/home/index.html.erb +0 -1
  210. data/test/rails_app/app/views/home/join.html.erb +0 -1
  211. data/test/rails_app/app/views/home/private.html.erb +0 -1
  212. data/test/rails_app/app/views/home/user_dashboard.html.erb +0 -1
  213. data/test/rails_app/app/views/layouts/application.html.erb +0 -24
  214. data/test/rails_app/app/views/users/edit_form.html.erb +0 -1
  215. data/test/rails_app/app/views/users/index.html.erb +0 -1
  216. data/test/rails_app/app/views/users/mailer/confirmation_instructions.erb +0 -1
  217. data/test/rails_app/app/views/users/sessions/new.html.erb +0 -1
  218. data/test/rails_app/bin/bundle +0 -3
  219. data/test/rails_app/bin/rails +0 -4
  220. data/test/rails_app/bin/rake +0 -4
  221. data/test/rails_app/config/application.rb +0 -40
  222. data/test/rails_app/config/boot.rb +0 -14
  223. data/test/rails_app/config/database.yml +0 -18
  224. data/test/rails_app/config/environment.rb +0 -5
  225. data/test/rails_app/config/environments/development.rb +0 -30
  226. data/test/rails_app/config/environments/production.rb +0 -84
  227. data/test/rails_app/config/environments/test.rb +0 -41
  228. data/test/rails_app/config/initializers/backtrace_silencers.rb +0 -7
  229. data/test/rails_app/config/initializers/devise.rb +0 -180
  230. data/test/rails_app/config/initializers/inflections.rb +0 -2
  231. data/test/rails_app/config/initializers/secret_token.rb +0 -8
  232. data/test/rails_app/config/initializers/session_store.rb +0 -1
  233. data/test/rails_app/config/routes.rb +0 -125
  234. data/test/rails_app/config.ru +0 -4
  235. data/test/rails_app/db/migrate/20100401102949_create_tables.rb +0 -71
  236. data/test/rails_app/db/schema.rb +0 -55
  237. data/test/rails_app/lib/shared_admin.rb +0 -17
  238. data/test/rails_app/lib/shared_user.rb +0 -29
  239. data/test/rails_app/lib/shared_user_without_email.rb +0 -26
  240. data/test/rails_app/lib/shared_user_without_omniauth.rb +0 -13
  241. data/test/rails_app/public/404.html +0 -26
  242. data/test/rails_app/public/422.html +0 -26
  243. data/test/rails_app/public/500.html +0 -26
  244. data/test/rails_app/public/favicon.ico +0 -0
  245. data/test/rails_test.rb +0 -9
  246. data/test/routes_test.rb +0 -264
  247. data/test/support/action_controller/record_identifier.rb +0 -10
  248. data/test/support/assertions.rb +0 -39
  249. data/test/support/helpers.rb +0 -77
  250. data/test/support/integration.rb +0 -92
  251. data/test/support/locale/en.yml +0 -8
  252. data/test/support/mongoid.yml +0 -6
  253. data/test/support/webrat/integrations/rails.rb +0 -24
  254. data/test/test_helper.rb +0 -34
  255. data/test/test_helpers_test.rb +0 -178
  256. data/test/test_models.rb +0 -33
  257. data/test/time_helpers.rb +0 -137
@@ -1,729 +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 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_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 'Log 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 subdomain 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
714
-
715
- class DoubleSignOutRedirectTest < ActionDispatch::IntegrationTest
716
- test 'sign out after already having signed out redirects to sign in' do
717
- sign_in_as_user
718
-
719
- post destroy_sign_out_via_delete_or_post_session_path
720
-
721
- get root_path
722
- assert_contain 'Signed out successfully.'
723
-
724
- post destroy_sign_out_via_delete_or_post_session_path
725
-
726
- get root_path
727
- assert_contain 'Signed out successfully.'
728
- end
729
- end