devise 4.4.3 → 4.9.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (236) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +174 -4
  3. data/MIT-LICENSE +2 -1
  4. data/README.md +129 -65
  5. data/app/controllers/devise/confirmations_controller.rb +1 -0
  6. data/app/controllers/devise/passwords_controller.rb +3 -2
  7. data/app/controllers/devise/registrations_controller.rb +27 -9
  8. data/app/controllers/devise/sessions_controller.rb +2 -2
  9. data/app/controllers/devise/unlocks_controller.rb +1 -0
  10. data/app/controllers/devise_controller.rb +17 -3
  11. data/app/helpers/devise_helper.rb +21 -18
  12. data/app/mailers/devise/mailer.rb +5 -5
  13. data/app/views/devise/confirmations/new.html.erb +1 -1
  14. data/app/views/devise/passwords/edit.html.erb +3 -3
  15. data/app/views/devise/passwords/new.html.erb +1 -1
  16. data/app/views/devise/registrations/edit.html.erb +5 -5
  17. data/app/views/devise/registrations/new.html.erb +3 -3
  18. data/app/views/devise/sessions/new.html.erb +3 -3
  19. data/app/views/devise/shared/_error_messages.html.erb +15 -0
  20. data/app/views/devise/shared/_links.html.erb +8 -8
  21. data/app/views/devise/unlocks/new.html.erb +1 -1
  22. data/config/locales/en.yml +3 -2
  23. data/lib/devise/controllers/helpers.rb +10 -8
  24. data/lib/devise/controllers/responder.rb +35 -0
  25. data/lib/devise/controllers/sign_in_out.rb +9 -4
  26. data/lib/devise/controllers/url_helpers.rb +1 -1
  27. data/lib/devise/failure_app.rb +41 -8
  28. data/lib/devise/hooks/csrf_cleaner.rb +6 -1
  29. data/lib/devise/hooks/lockable.rb +2 -5
  30. data/lib/devise/hooks/timeoutable.rb +2 -2
  31. data/lib/devise/mapping.rb +1 -1
  32. data/lib/devise/models/authenticatable.rb +51 -48
  33. data/lib/devise/models/confirmable.rb +34 -40
  34. data/lib/devise/models/database_authenticatable.rb +54 -35
  35. data/lib/devise/models/lockable.rb +13 -5
  36. data/lib/devise/models/omniauthable.rb +2 -2
  37. data/lib/devise/models/recoverable.rb +8 -19
  38. data/lib/devise/models/registerable.rb +2 -0
  39. data/lib/devise/models/rememberable.rb +2 -2
  40. data/lib/devise/models/timeoutable.rb +1 -1
  41. data/lib/devise/models/trackable.rb +9 -2
  42. data/lib/devise/models/validatable.rb +4 -9
  43. data/lib/devise/models.rb +1 -0
  44. data/lib/devise/omniauth.rb +2 -5
  45. data/lib/devise/orm.rb +71 -0
  46. data/lib/devise/parameter_filter.rb +2 -0
  47. data/lib/devise/parameter_sanitizer.rb +13 -1
  48. data/lib/devise/rails/deprecated_constant_accessor.rb +39 -0
  49. data/lib/devise/rails/routes.rb +6 -6
  50. data/lib/devise/rails.rb +4 -0
  51. data/lib/devise/secret_key_finder.rb +2 -0
  52. data/lib/devise/strategies/authenticatable.rb +1 -1
  53. data/lib/devise/strategies/database_authenticatable.rb +6 -1
  54. data/lib/devise/test/controller_helpers.rb +5 -3
  55. data/lib/devise/test/integration_helpers.rb +1 -1
  56. data/lib/devise/test_helpers.rb +1 -1
  57. data/lib/devise/version.rb +1 -1
  58. data/lib/devise.rb +38 -11
  59. data/lib/generators/active_record/devise_generator.rb +26 -11
  60. data/lib/generators/devise/controllers_generator.rb +1 -1
  61. data/lib/generators/devise/devise_generator.rb +1 -1
  62. data/lib/generators/devise/install_generator.rb +1 -5
  63. data/lib/generators/devise/orm_helpers.rb +2 -2
  64. data/lib/generators/devise/views_generator.rb +1 -1
  65. data/lib/generators/mongoid/devise_generator.rb +5 -5
  66. data/lib/generators/templates/README +9 -1
  67. data/lib/generators/templates/controllers/omniauth_callbacks_controller.rb +1 -1
  68. data/lib/generators/templates/devise.rb +38 -8
  69. data/lib/generators/templates/simple_form_for/confirmations/new.html.erb +5 -1
  70. data/lib/generators/templates/simple_form_for/passwords/edit.html.erb +10 -2
  71. data/lib/generators/templates/simple_form_for/passwords/new.html.erb +4 -1
  72. data/lib/generators/templates/simple_form_for/registrations/edit.html.erb +12 -4
  73. data/lib/generators/templates/simple_form_for/registrations/new.html.erb +11 -3
  74. data/lib/generators/templates/simple_form_for/sessions/new.html.erb +7 -2
  75. data/lib/generators/templates/simple_form_for/unlocks/new.html.erb +4 -1
  76. metadata +23 -316
  77. data/.gitignore +0 -10
  78. data/.travis.yml +0 -68
  79. data/.yardopts +0 -9
  80. data/CODE_OF_CONDUCT.md +0 -22
  81. data/CONTRIBUTING.md +0 -79
  82. data/Gemfile +0 -39
  83. data/Gemfile.lock +0 -193
  84. data/ISSUE_TEMPLATE.md +0 -19
  85. data/Rakefile +0 -37
  86. data/bin/test +0 -13
  87. data/devise.gemspec +0 -28
  88. data/devise.png +0 -0
  89. data/gemfiles/Gemfile.rails-4.1-stable +0 -32
  90. data/gemfiles/Gemfile.rails-4.1-stable.lock +0 -171
  91. data/gemfiles/Gemfile.rails-4.2-stable +0 -32
  92. data/gemfiles/Gemfile.rails-4.2-stable.lock +0 -192
  93. data/gemfiles/Gemfile.rails-5.0-stable +0 -33
  94. data/gemfiles/Gemfile.rails-5.0-stable.lock +0 -192
  95. data/gemfiles/Gemfile.rails-5.2-rc1 +0 -26
  96. data/gemfiles/Gemfile.rails-5.2-rc1.lock +0 -201
  97. data/guides/bug_report_templates/integration_test.rb +0 -106
  98. data/test/controllers/custom_registrations_controller_test.rb +0 -42
  99. data/test/controllers/custom_strategy_test.rb +0 -66
  100. data/test/controllers/helper_methods_test.rb +0 -24
  101. data/test/controllers/helpers_test.rb +0 -318
  102. data/test/controllers/inherited_controller_i18n_messages_test.rb +0 -53
  103. data/test/controllers/internal_helpers_test.rb +0 -129
  104. data/test/controllers/load_hooks_controller_test.rb +0 -21
  105. data/test/controllers/passwords_controller_test.rb +0 -34
  106. data/test/controllers/sessions_controller_test.rb +0 -108
  107. data/test/controllers/url_helpers_test.rb +0 -67
  108. data/test/delegator_test.rb +0 -21
  109. data/test/devise_test.rb +0 -109
  110. data/test/failure_app_test.rb +0 -340
  111. data/test/generators/active_record_generator_test.rb +0 -130
  112. data/test/generators/controllers_generator_test.rb +0 -50
  113. data/test/generators/devise_generator_test.rb +0 -41
  114. data/test/generators/install_generator_test.rb +0 -26
  115. data/test/generators/mongoid_generator_test.rb +0 -25
  116. data/test/generators/views_generator_test.rb +0 -105
  117. data/test/helpers/devise_helper_test.rb +0 -51
  118. data/test/integration/authenticatable_test.rb +0 -706
  119. data/test/integration/confirmable_test.rb +0 -326
  120. data/test/integration/database_authenticatable_test.rb +0 -97
  121. data/test/integration/http_authenticatable_test.rb +0 -114
  122. data/test/integration/lockable_test.rb +0 -242
  123. data/test/integration/mounted_engine_test.rb +0 -38
  124. data/test/integration/omniauthable_test.rb +0 -148
  125. data/test/integration/recoverable_test.rb +0 -349
  126. data/test/integration/registerable_test.rb +0 -365
  127. data/test/integration/rememberable_test.rb +0 -219
  128. data/test/integration/timeoutable_test.rb +0 -186
  129. data/test/integration/trackable_test.rb +0 -99
  130. data/test/mailers/confirmation_instructions_test.rb +0 -117
  131. data/test/mailers/email_changed_test.rb +0 -132
  132. data/test/mailers/mailer_test.rb +0 -20
  133. data/test/mailers/reset_password_instructions_test.rb +0 -98
  134. data/test/mailers/unlock_instructions_test.rb +0 -93
  135. data/test/mapping_test.rb +0 -136
  136. data/test/models/authenticatable_test.rb +0 -25
  137. data/test/models/confirmable_test.rb +0 -549
  138. data/test/models/database_authenticatable_test.rb +0 -283
  139. data/test/models/lockable_test.rb +0 -352
  140. data/test/models/omniauthable_test.rb +0 -9
  141. data/test/models/recoverable_test.rb +0 -263
  142. data/test/models/registerable_test.rb +0 -9
  143. data/test/models/rememberable_test.rb +0 -184
  144. data/test/models/serializable_test.rb +0 -60
  145. data/test/models/timeoutable_test.rb +0 -53
  146. data/test/models/trackable_test.rb +0 -62
  147. data/test/models/validatable_test.rb +0 -121
  148. data/test/models_test.rb +0 -155
  149. data/test/omniauth/config_test.rb +0 -61
  150. data/test/omniauth/url_helpers_test.rb +0 -53
  151. data/test/orm/active_record.rb +0 -24
  152. data/test/orm/mongoid.rb +0 -15
  153. data/test/parameter_sanitizer_test.rb +0 -77
  154. data/test/rails_app/Rakefile +0 -6
  155. data/test/rails_app/app/active_record/admin.rb +0 -8
  156. data/test/rails_app/app/active_record/shim.rb +0 -4
  157. data/test/rails_app/app/active_record/user.rb +0 -20
  158. data/test/rails_app/app/active_record/user_on_engine.rb +0 -9
  159. data/test/rails_app/app/active_record/user_on_main_app.rb +0 -9
  160. data/test/rails_app/app/active_record/user_with_validations.rb +0 -12
  161. data/test/rails_app/app/active_record/user_without_email.rb +0 -10
  162. data/test/rails_app/app/controllers/admins/sessions_controller.rb +0 -8
  163. data/test/rails_app/app/controllers/admins_controller.rb +0 -8
  164. data/test/rails_app/app/controllers/application_controller.rb +0 -13
  165. data/test/rails_app/app/controllers/application_with_fake_engine.rb +0 -32
  166. data/test/rails_app/app/controllers/custom/registrations_controller.rb +0 -33
  167. data/test/rails_app/app/controllers/home_controller.rb +0 -31
  168. data/test/rails_app/app/controllers/publisher/registrations_controller.rb +0 -4
  169. data/test/rails_app/app/controllers/publisher/sessions_controller.rb +0 -4
  170. data/test/rails_app/app/controllers/users/omniauth_callbacks_controller.rb +0 -16
  171. data/test/rails_app/app/controllers/users_controller.rb +0 -33
  172. data/test/rails_app/app/helpers/application_helper.rb +0 -5
  173. data/test/rails_app/app/mailers/users/from_proc_mailer.rb +0 -5
  174. data/test/rails_app/app/mailers/users/mailer.rb +0 -5
  175. data/test/rails_app/app/mailers/users/reply_to_mailer.rb +0 -6
  176. data/test/rails_app/app/mongoid/admin.rb +0 -31
  177. data/test/rails_app/app/mongoid/shim.rb +0 -25
  178. data/test/rails_app/app/mongoid/user.rb +0 -50
  179. data/test/rails_app/app/mongoid/user_on_engine.rb +0 -41
  180. data/test/rails_app/app/mongoid/user_on_main_app.rb +0 -41
  181. data/test/rails_app/app/mongoid/user_with_validations.rb +0 -37
  182. data/test/rails_app/app/mongoid/user_without_email.rb +0 -35
  183. data/test/rails_app/app/views/admins/index.html.erb +0 -1
  184. data/test/rails_app/app/views/admins/sessions/new.html.erb +0 -2
  185. data/test/rails_app/app/views/home/admin_dashboard.html.erb +0 -1
  186. data/test/rails_app/app/views/home/index.html.erb +0 -1
  187. data/test/rails_app/app/views/home/join.html.erb +0 -1
  188. data/test/rails_app/app/views/home/private.html.erb +0 -1
  189. data/test/rails_app/app/views/home/user_dashboard.html.erb +0 -1
  190. data/test/rails_app/app/views/layouts/application.html.erb +0 -24
  191. data/test/rails_app/app/views/users/edit_form.html.erb +0 -1
  192. data/test/rails_app/app/views/users/index.html.erb +0 -1
  193. data/test/rails_app/app/views/users/mailer/confirmation_instructions.erb +0 -1
  194. data/test/rails_app/app/views/users/sessions/new.html.erb +0 -1
  195. data/test/rails_app/bin/bundle +0 -3
  196. data/test/rails_app/bin/rails +0 -4
  197. data/test/rails_app/bin/rake +0 -4
  198. data/test/rails_app/config/application.rb +0 -48
  199. data/test/rails_app/config/boot.rb +0 -27
  200. data/test/rails_app/config/database.yml +0 -18
  201. data/test/rails_app/config/environment.rb +0 -7
  202. data/test/rails_app/config/environments/development.rb +0 -32
  203. data/test/rails_app/config/environments/production.rb +0 -88
  204. data/test/rails_app/config/environments/test.rb +0 -47
  205. data/test/rails_app/config/initializers/backtrace_silencers.rb +0 -9
  206. data/test/rails_app/config/initializers/devise.rb +0 -182
  207. data/test/rails_app/config/initializers/inflections.rb +0 -4
  208. data/test/rails_app/config/initializers/secret_token.rb +0 -5
  209. data/test/rails_app/config/initializers/session_store.rb +0 -3
  210. data/test/rails_app/config/routes.rb +0 -128
  211. data/test/rails_app/config.ru +0 -4
  212. data/test/rails_app/db/migrate/20100401102949_create_tables.rb +0 -77
  213. data/test/rails_app/db/schema.rb +0 -57
  214. data/test/rails_app/lib/shared_admin.rb +0 -23
  215. data/test/rails_app/lib/shared_user.rb +0 -32
  216. data/test/rails_app/lib/shared_user_without_email.rb +0 -28
  217. data/test/rails_app/lib/shared_user_without_omniauth.rb +0 -15
  218. data/test/rails_app/public/404.html +0 -26
  219. data/test/rails_app/public/422.html +0 -26
  220. data/test/rails_app/public/500.html +0 -26
  221. data/test/rails_app/public/favicon.ico +0 -0
  222. data/test/rails_test.rb +0 -11
  223. data/test/routes_test.rb +0 -281
  224. data/test/secret_key_finder_test.rb +0 -97
  225. data/test/support/action_controller/record_identifier.rb +0 -12
  226. data/test/support/assertions.rb +0 -30
  227. data/test/support/helpers.rb +0 -83
  228. data/test/support/http_method_compatibility.rb +0 -53
  229. data/test/support/integration.rb +0 -95
  230. data/test/support/locale/en.yml +0 -8
  231. data/test/support/mongoid.yml +0 -6
  232. data/test/support/webrat/integrations/rails.rb +0 -35
  233. data/test/test/controller_helpers_test.rb +0 -193
  234. data/test/test/integration_helpers_test.rb +0 -34
  235. data/test/test_helper.rb +0 -36
  236. data/test/test_models.rb +0 -35
@@ -1,318 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'test_helper'
4
- require 'ostruct'
5
-
6
- class ControllerAuthenticatableTest < Devise::ControllerTestCase
7
- tests ApplicationController
8
-
9
- def setup
10
- @mock_warden = OpenStruct.new
11
- @controller.request.env['warden'] = @mock_warden
12
- end
13
-
14
- test 'provide access to warden instance' do
15
- assert_equal @mock_warden, @controller.warden
16
- end
17
-
18
- test 'proxy signed_in?(scope) to authenticate?' do
19
- @mock_warden.expects(:authenticate?).with(scope: :my_scope)
20
- @controller.signed_in?(:my_scope)
21
- end
22
-
23
- test 'proxy signed_in?(nil) to authenticate?' do
24
- Devise.mappings.keys.each do |scope| # :user, :admin, :manager
25
- @mock_warden.expects(:authenticate?).with(scope: scope)
26
- end
27
- @controller.signed_in?
28
- end
29
-
30
- test 'proxy [group]_signed_in? to authenticate? with each scope' do
31
- [:user, :admin].each do |scope|
32
- @mock_warden.expects(:authenticate?).with(scope: scope).returns(false)
33
- end
34
- @controller.commenter_signed_in?
35
- end
36
-
37
- test 'proxy current_user to authenticate with user scope' do
38
- @mock_warden.expects(:authenticate).with(scope: :user)
39
- @controller.current_user
40
- end
41
-
42
- test 'proxy current_admin to authenticate with admin scope' do
43
- @mock_warden.expects(:authenticate).with(scope: :admin)
44
- @controller.current_admin
45
- end
46
-
47
- test 'proxy current_[group] to authenticate with each scope' do
48
- [:user, :admin].each do |scope|
49
- @mock_warden.expects(:authenticate).with(scope: scope).returns(nil)
50
- end
51
- @controller.current_commenter
52
- end
53
-
54
- test 'proxy current_[plural_group] to authenticate with each scope' do
55
- [:user, :admin].each do |scope|
56
- @mock_warden.expects(:authenticate).with(scope: scope)
57
- end
58
- @controller.current_commenters
59
- end
60
-
61
- test 'proxy current_publisher_account to authenticate with namespaced publisher account scope' do
62
- @mock_warden.expects(:authenticate).with(scope: :publisher_account)
63
- @controller.current_publisher_account
64
- end
65
-
66
- test 'proxy authenticate_user! to authenticate with user scope' do
67
- @mock_warden.expects(:authenticate!).with(scope: :user)
68
- @controller.authenticate_user!
69
- end
70
-
71
- test 'proxy authenticate_user! options to authenticate with user scope' do
72
- @mock_warden.expects(:authenticate!).with(scope: :user, recall: "foo")
73
- @controller.authenticate_user!(recall: "foo")
74
- end
75
-
76
- test 'proxy authenticate_admin! to authenticate with admin scope' do
77
- @mock_warden.expects(:authenticate!).with(scope: :admin)
78
- @controller.authenticate_admin!
79
- end
80
-
81
- test 'proxy authenticate_[group]! to authenticate!? with each scope' do
82
- [:user, :admin].each do |scope|
83
- @mock_warden.expects(:authenticate!).with(scope: scope)
84
- @mock_warden.expects(:authenticate?).with(scope: scope).returns(false)
85
- end
86
- @controller.authenticate_commenter!
87
- end
88
-
89
- test 'proxy authenticate_publisher_account! to authenticate with namespaced publisher account scope' do
90
- @mock_warden.expects(:authenticate!).with(scope: :publisher_account)
91
- @controller.authenticate_publisher_account!
92
- end
93
-
94
- test 'proxy user_signed_in? to authenticate with user scope' do
95
- @mock_warden.expects(:authenticate).with(scope: :user).returns("user")
96
- assert @controller.user_signed_in?
97
- end
98
-
99
- test 'proxy admin_signed_in? to authenticatewith admin scope' do
100
- @mock_warden.expects(:authenticate).with(scope: :admin)
101
- refute @controller.admin_signed_in?
102
- end
103
-
104
- test 'proxy publisher_account_signed_in? to authenticate with namespaced publisher account scope' do
105
- @mock_warden.expects(:authenticate).with(scope: :publisher_account)
106
- @controller.publisher_account_signed_in?
107
- end
108
-
109
- test 'proxy user_session to session scope in warden' do
110
- @mock_warden.expects(:authenticate).with(scope: :user).returns(true)
111
- @mock_warden.expects(:session).with(:user).returns({})
112
- @controller.user_session
113
- end
114
-
115
- test 'proxy admin_session to session scope in warden' do
116
- @mock_warden.expects(:authenticate).with(scope: :admin).returns(true)
117
- @mock_warden.expects(:session).with(:admin).returns({})
118
- @controller.admin_session
119
- end
120
-
121
- test 'proxy publisher_account_session from namespaced scope to session scope in warden' do
122
- @mock_warden.expects(:authenticate).with(scope: :publisher_account).returns(true)
123
- @mock_warden.expects(:session).with(:publisher_account).returns({})
124
- @controller.publisher_account_session
125
- end
126
-
127
- test 'sign in proxy to set_user on warden' do
128
- user = User.new
129
- @mock_warden.expects(:user).returns(nil)
130
- @mock_warden.expects(:set_user).with(user, scope: :user).returns(true)
131
- @controller.sign_in(:user, user)
132
- end
133
-
134
- test 'sign in accepts a resource as argument' do
135
- user = User.new
136
- @mock_warden.expects(:user).returns(nil)
137
- @mock_warden.expects(:set_user).with(user, scope: :user).returns(true)
138
- @controller.sign_in(user)
139
- end
140
-
141
- test 'does not sign in again if the user is already in' do
142
- user = User.new
143
- @mock_warden.expects(:user).returns(user)
144
- @mock_warden.expects(:set_user).never
145
- assert @controller.sign_in(user)
146
- end
147
-
148
- test 'sign in again when the user is already in only if force is given' do
149
- user = User.new
150
- @mock_warden.expects(:user).returns(user)
151
- @mock_warden.expects(:set_user).with(user, scope: :user).returns(true)
152
- @controller.sign_in(user, force: true)
153
- end
154
-
155
- test 'bypass the sign in' do
156
- user = User.new
157
- @mock_warden.expects(:session_serializer).returns(serializer = mock())
158
- serializer.expects(:store).with(user, :user)
159
- @controller.bypass_sign_in(user)
160
- end
161
-
162
- test 'sign out clears up any signed in user from all scopes' do
163
- user = User.new
164
- @mock_warden.expects(:user).times(Devise.mappings.size)
165
- @mock_warden.expects(:logout).with().returns(true)
166
- @controller.instance_variable_set(:@current_user, user)
167
- @controller.instance_variable_set(:@current_admin, user)
168
- @controller.sign_out
169
- assert_nil @controller.instance_variable_get(:@current_user)
170
- assert_nil @controller.instance_variable_get(:@current_admin)
171
- end
172
-
173
- test 'sign out logs out and clears up any signed in user by scope' do
174
- user = User.new
175
- @mock_warden.expects(:user).with(scope: :user, run_callbacks: false).returns(user)
176
- @mock_warden.expects(:logout).with(:user).returns(true)
177
- @mock_warden.expects(:clear_strategies_cache!).with(scope: :user).returns(true)
178
- @controller.instance_variable_set(:@current_user, user)
179
- @controller.sign_out(:user)
180
- assert_nil @controller.instance_variable_get(:@current_user)
181
- end
182
-
183
- test 'sign out accepts a resource as argument' do
184
- @mock_warden.expects(:user).with(scope: :user, run_callbacks: false).returns(true)
185
- @mock_warden.expects(:logout).with(:user).returns(true)
186
- @mock_warden.expects(:clear_strategies_cache!).with(scope: :user).returns(true)
187
- @controller.sign_out(User.new)
188
- end
189
-
190
- test 'sign out without args proxy to sign out all scopes' do
191
- @mock_warden.expects(:user).times(Devise.mappings.size)
192
- @mock_warden.expects(:logout).with().returns(true)
193
- @mock_warden.expects(:clear_strategies_cache!).with().returns(true)
194
- @controller.sign_out
195
- end
196
-
197
- test 'sign out everybody proxy to logout on warden' do
198
- @mock_warden.expects(:user).times(Devise.mappings.size)
199
- @mock_warden.expects(:logout).with().returns(true)
200
- @controller.sign_out_all_scopes
201
- end
202
-
203
- test 'stored location for returns the location for a given scope' do
204
- assert_nil @controller.stored_location_for(:user)
205
- @controller.session[:"user_return_to"] = "/foo.bar"
206
- assert_equal "/foo.bar", @controller.stored_location_for(:user)
207
- end
208
-
209
- test 'stored location for accepts a resource as argument' do
210
- assert_nil @controller.stored_location_for(:user)
211
- @controller.session[:"user_return_to"] = "/foo.bar"
212
- assert_equal "/foo.bar", @controller.stored_location_for(User.new)
213
- end
214
-
215
- test 'stored location cleans information after reading' do
216
- @controller.session[:"user_return_to"] = "/foo.bar"
217
- assert_equal "/foo.bar", @controller.stored_location_for(:user)
218
- assert_nil @controller.session[:"user_return_to"]
219
- end
220
-
221
- test 'store location for stores a location to redirect back to' do
222
- assert_nil @controller.stored_location_for(:user)
223
- @controller.store_location_for(:user, "/foo.bar")
224
- assert_equal "/foo.bar", @controller.stored_location_for(:user)
225
- end
226
-
227
- test 'store bad location for stores a location to redirect back to' do
228
- assert_nil @controller.stored_location_for(:user)
229
- @controller.store_location_for(:user, "/foo.bar\">Carry")
230
- assert_nil @controller.stored_location_for(:user)
231
- end
232
-
233
- test 'store location for accepts a resource as argument' do
234
- @controller.store_location_for(User.new, "/foo.bar")
235
- assert_equal "/foo.bar", @controller.stored_location_for(User.new)
236
- end
237
-
238
- test 'store location for stores paths' do
239
- @controller.store_location_for(:user, "//host/foo.bar")
240
- assert_equal "/foo.bar", @controller.stored_location_for(:user)
241
- @controller.store_location_for(:user, "///foo.bar")
242
- assert_equal "/foo.bar", @controller.stored_location_for(:user)
243
- end
244
-
245
- test 'store location for stores query string' do
246
- @controller.store_location_for(:user, "/foo?bar=baz")
247
- assert_equal "/foo?bar=baz", @controller.stored_location_for(:user)
248
- end
249
-
250
- test 'store location for stores fragments' do
251
- @controller.store_location_for(:user, "/foo#bar")
252
- assert_equal "/foo#bar", @controller.stored_location_for(:user)
253
- end
254
-
255
- test 'after sign in path defaults to root path if none by was specified for the given scope' do
256
- assert_equal root_path, @controller.after_sign_in_path_for(:user)
257
- end
258
-
259
- test 'after sign in path defaults to the scoped root path' do
260
- assert_equal admin_root_path, @controller.after_sign_in_path_for(:admin)
261
- end
262
-
263
- test 'after sign out path defaults to the root path' do
264
- assert_equal root_path, @controller.after_sign_out_path_for(:admin)
265
- assert_equal root_path, @controller.after_sign_out_path_for(:user)
266
- end
267
-
268
- test 'sign in and redirect uses the stored location' do
269
- user = User.new
270
- @controller.session[:user_return_to] = "/foo.bar"
271
- @mock_warden.expects(:user).with(:user).returns(nil)
272
- @mock_warden.expects(:set_user).with(user, scope: :user).returns(true)
273
- @controller.expects(:redirect_to).with("/foo.bar")
274
- @controller.sign_in_and_redirect(user)
275
- end
276
-
277
- test 'sign in and redirect uses the configured after sign in path' do
278
- admin = Admin.new
279
- @mock_warden.expects(:user).with(:admin).returns(nil)
280
- @mock_warden.expects(:set_user).with(admin, scope: :admin).returns(true)
281
- @controller.expects(:redirect_to).with(admin_root_path)
282
- @controller.sign_in_and_redirect(admin)
283
- end
284
-
285
- test 'sign in and redirect does not sign in again if user is already signed' do
286
- admin = Admin.new
287
- @mock_warden.expects(:user).with(:admin).returns(admin)
288
- @mock_warden.expects(:set_user).never
289
- @controller.expects(:redirect_to).with(admin_root_path)
290
- @controller.sign_in_and_redirect(admin)
291
- end
292
-
293
- test 'sign out and redirect uses the configured after sign out path when signing out only the current scope' do
294
- swap Devise, sign_out_all_scopes: false do
295
- @mock_warden.expects(:user).with(scope: :admin, run_callbacks: false).returns(true)
296
- @mock_warden.expects(:logout).with(:admin).returns(true)
297
- @mock_warden.expects(:clear_strategies_cache!).with(scope: :admin).returns(true)
298
- @controller.expects(:redirect_to).with(admin_root_path)
299
- @controller.instance_eval "def after_sign_out_path_for(resource); admin_root_path; end"
300
- @controller.sign_out_and_redirect(:admin)
301
- end
302
- end
303
-
304
- test 'sign out and redirect uses the configured after sign out path when signing out all scopes' do
305
- swap Devise, sign_out_all_scopes: true do
306
- @mock_warden.expects(:user).times(Devise.mappings.size)
307
- @mock_warden.expects(:logout).with().returns(true)
308
- @mock_warden.expects(:clear_strategies_cache!).with().returns(true)
309
- @controller.expects(:redirect_to).with(admin_root_path)
310
- @controller.instance_eval "def after_sign_out_path_for(resource); admin_root_path; end"
311
- @controller.sign_out_and_redirect(:admin)
312
- end
313
- end
314
-
315
- test 'is not a devise controller' do
316
- refute @controller.devise_controller?
317
- end
318
- end
@@ -1,53 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'test_helper'
4
-
5
- class SessionsInheritedController < Devise::SessionsController
6
- def test_i18n_scope
7
- set_flash_message(:notice, :signed_in)
8
- end
9
- end
10
-
11
- class AnotherInheritedController < SessionsInheritedController
12
- protected
13
-
14
- def translation_scope
15
- 'another'
16
- end
17
- end
18
-
19
- class InheritedControllerTest < Devise::ControllerTestCase
20
- tests SessionsInheritedController
21
-
22
- def setup
23
- @mock_warden = OpenStruct.new
24
- @controller.request.env['warden'] = @mock_warden
25
- @controller.request.env['devise.mapping'] = Devise.mappings[:user]
26
- end
27
-
28
- test 'I18n scope is inherited from Devise::Sessions' do
29
- I18n.expects(:t).with do |message, options|
30
- message == 'user.signed_in' &&
31
- options[:scope] == 'devise.sessions'
32
- end
33
- @controller.test_i18n_scope
34
- end
35
- end
36
-
37
- class AnotherInheritedControllerTest < Devise::ControllerTestCase
38
- tests AnotherInheritedController
39
-
40
- def setup
41
- @mock_warden = OpenStruct.new
42
- @controller.request.env['warden'] = @mock_warden
43
- @controller.request.env['devise.mapping'] = Devise.mappings[:user]
44
- end
45
-
46
- test 'I18n scope is overridden' do
47
- I18n.expects(:t).with do |message, options|
48
- message == 'user.signed_in' &&
49
- options[:scope] == 'another'
50
- end
51
- @controller.test_i18n_scope
52
- end
53
- end
@@ -1,129 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'test_helper'
4
-
5
- class MyController < DeviseController
6
- end
7
-
8
- class HelpersTest < Devise::ControllerTestCase
9
- tests MyController
10
-
11
- def setup
12
- @mock_warden = OpenStruct.new
13
- @controller.request.env['warden'] = @mock_warden
14
- @controller.request.env['devise.mapping'] = Devise.mappings[:user]
15
- end
16
-
17
- test 'get resource name from env' do
18
- assert_equal :user, @controller.send(:resource_name)
19
- end
20
-
21
- test 'get resource class from env' do
22
- assert_equal User, @controller.send(:resource_class)
23
- end
24
-
25
- test 'get resource instance variable from env' do
26
- @controller.instance_variable_set(:@user, user = User.new)
27
- assert_equal user, @controller.send(:resource)
28
- end
29
-
30
- test 'set resource instance variable from env' do
31
- user = @controller.send(:resource_class).new
32
- @controller.send(:resource=, user)
33
-
34
- assert_equal user, @controller.send(:resource)
35
- assert_equal user, @controller.instance_variable_get(:@user)
36
- end
37
-
38
- test 'get resource params from request params using resource name as key' do
39
- user_params = {'email' => 'shirley@templar.com'}
40
-
41
- # Stub controller name so strong parameters can filter properly.
42
- # DeviseController does not allow any parameters by default.
43
- @controller.stubs(:controller_name).returns(:sessions_controller)
44
-
45
- params = ActionController::Parameters.new({'user' => user_params})
46
-
47
- @controller.stubs(:params).returns(params)
48
-
49
- res_params = @controller.send(:resource_params).permit!.to_h
50
- assert_equal user_params, res_params
51
- end
52
-
53
- test 'resources methods are not controller actions' do
54
- assert @controller.class.action_methods.delete_if { |m| m.include? 'commenter' }.empty?
55
- end
56
-
57
- test 'require no authentication tests current mapping' do
58
- @mock_warden.expects(:authenticate?).with(:rememberable, scope: :user).returns(true)
59
- @mock_warden.expects(:user).with(:user).returns(User.new)
60
- @controller.expects(:redirect_to).with(root_path)
61
- @controller.send :require_no_authentication
62
- end
63
-
64
- test 'require no authentication only checks if already authenticated if no inputs strategies are available' do
65
- Devise.mappings[:user].expects(:no_input_strategies).returns([])
66
- @mock_warden.expects(:authenticate?).never
67
- @mock_warden.expects(:authenticated?).with(:user).once.returns(true)
68
- @mock_warden.expects(:user).with(:user).returns(User.new)
69
- @controller.expects(:redirect_to).with(root_path)
70
- @controller.send :require_no_authentication
71
- end
72
-
73
- test 'require no authentication sets a flash message' do
74
- @mock_warden.expects(:authenticate?).with(:rememberable, scope: :user).returns(true)
75
- @mock_warden.expects(:user).with(:user).returns(User.new)
76
- @controller.expects(:redirect_to).with(root_path)
77
- @controller.send :require_no_authentication
78
- assert flash[:alert] == I18n.t("devise.failure.already_authenticated")
79
- end
80
-
81
- test 'signed in resource returns signed in resource for current scope' do
82
- @mock_warden.expects(:authenticate).with(scope: :user).returns(User.new)
83
- assert_kind_of User, @controller.send(:signed_in_resource)
84
- end
85
-
86
- test 'is a devise controller' do
87
- assert @controller.devise_controller?
88
- end
89
-
90
- test 'does not issue blank flash messages' do
91
- I18n.stubs(:t).returns(' ')
92
- @controller.send :set_flash_message, :notice, :send_instructions
93
- assert flash[:notice].nil?
94
- end
95
-
96
- test 'issues non-blank flash messages normally' do
97
- I18n.stubs(:t).returns('non-blank')
98
- @controller.send :set_flash_message, :notice, :send_instructions
99
- assert_equal 'non-blank', flash[:notice]
100
- end
101
-
102
- test 'issues non-blank flash.now messages normally' do
103
- I18n.stubs(:t).returns('non-blank')
104
- @controller.send :set_flash_message, :notice, :send_instructions, { now: true }
105
- assert_equal 'non-blank', flash.now[:notice]
106
- end
107
-
108
- test 'uses custom i18n options' do
109
- @controller.stubs(:devise_i18n_options).returns(default: "devise custom options")
110
- @controller.send :set_flash_message, :notice, :invalid_i18n_messagesend_instructions
111
- assert_equal 'devise custom options', flash[:notice]
112
- end
113
-
114
- test 'allows custom i18n options to override resource_name' do
115
- I18n.expects(:t).with("custom_resource_name.confirmed", anything)
116
- @controller.stubs(:devise_i18n_options).returns(resource_name: "custom_resource_name")
117
- @controller.send :set_flash_message, :notice, :confirmed
118
- end
119
-
120
- test 'navigational_formats not returning a wild card' do
121
- MyController.send(:public, :navigational_formats)
122
-
123
- swap Devise, navigational_formats: ['*/*', :html] do
124
- refute @controller.navigational_formats.include?("*/*")
125
- end
126
-
127
- MyController.send(:protected, :navigational_formats)
128
- end
129
- end
@@ -1,21 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'test_helper'
4
-
5
- class LoadHooksControllerTest < Devise::ControllerTestCase
6
- setup do
7
- ActiveSupport.on_load(:devise_controller) do
8
- define_method :defined_by_load_hook do
9
- puts 'I am defined dynamically by activesupport load hook'
10
- end
11
- end
12
- end
13
-
14
- teardown do
15
- DeviseController.class_eval { undef :defined_by_load_hook }
16
- end
17
-
18
- test 'load hook called when controller is loaded' do
19
- assert DeviseController.instance_methods.include? :defined_by_load_hook
20
- end
21
- end
@@ -1,34 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'test_helper'
4
-
5
- class PasswordsControllerTest < Devise::ControllerTestCase
6
- tests Devise::PasswordsController
7
- include Devise::Test::ControllerHelpers
8
-
9
- setup do
10
- request.env["devise.mapping"] = Devise.mappings[:user]
11
- @user = create_user.tap(&:confirm)
12
- @raw = @user.send_reset_password_instructions
13
- end
14
-
15
- def put_update_with_params
16
- put :update, params: { "user" => {
17
- "reset_password_token" => @raw, "password" => "1234567", "password_confirmation" => "1234567"
18
- }
19
- }
20
- end
21
-
22
- test 'redirect to after_sign_in_path_for if after_resetting_password_path_for is not overridden' do
23
- put_update_with_params
24
- assert_redirected_to "http://test.host/"
25
- end
26
-
27
- test 'redirect accordingly if after_resetting_password_path_for is overridden' do
28
- custom_path = "http://custom.path/"
29
- Devise::PasswordsController.any_instance.stubs(:after_resetting_password_path_for).with(@user).returns(custom_path)
30
-
31
- put_update_with_params
32
- assert_redirected_to custom_path
33
- end
34
- end
@@ -1,108 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'test_helper'
4
-
5
- class SessionsControllerTest < Devise::ControllerTestCase
6
- tests Devise::SessionsController
7
- include Devise::Test::ControllerHelpers
8
-
9
- test "#create doesn't raise unpermitted params when sign in fails" do
10
- begin
11
- subscriber = ActiveSupport::Notifications.subscribe %r{unpermitted_parameters} do |name, start, finish, id, payload|
12
- flunk "Unpermitted params: #{payload}"
13
- end
14
- request.env["devise.mapping"] = Devise.mappings[:user]
15
- request.session["user_return_to"] = 'foo.bar'
16
- create_user
17
- post :create, params: { user: {
18
- email: "wrong@email.com",
19
- password: "wrongpassword"
20
- }
21
- }
22
- assert_equal 200, @response.status
23
- ensure
24
- ActiveSupport::Notifications.unsubscribe(subscriber)
25
- end
26
- end
27
-
28
- test "#create works even with scoped views" do
29
- swap Devise, scoped_views: true do
30
- request.env["devise.mapping"] = Devise.mappings[:user]
31
- post :create
32
- assert_equal 200, @response.status
33
- assert_template "users/sessions/new"
34
- end
35
- end
36
-
37
- test "#create delete the url stored in the session if the requested format is navigational" do
38
- request.env["devise.mapping"] = Devise.mappings[:user]
39
- request.session["user_return_to"] = 'foo.bar'
40
-
41
- user = create_user
42
- user.confirm
43
- post :create, params: { user: {
44
- email: user.email,
45
- password: user.password
46
- }
47
- }
48
- assert_nil request.session["user_return_to"]
49
- end
50
-
51
- test "#create doesn't delete the url stored in the session if the requested format is not navigational" do
52
- request.env["devise.mapping"] = Devise.mappings[:user]
53
- request.session["user_return_to"] = 'foo.bar'
54
-
55
- user = create_user
56
- user.confirm
57
- post :create, params: { format: 'json', user: {
58
- email: user.email,
59
- password: user.password
60
- }
61
- }
62
-
63
- assert_equal 'foo.bar', request.session["user_return_to"]
64
- end
65
-
66
- test "#create doesn't raise exception after Warden authentication fails when TestHelpers included" do
67
- request.env["devise.mapping"] = Devise.mappings[:user]
68
- post :create, params: { user: {
69
- email: "nosuchuser@example.com",
70
- password: "wevdude"
71
- }
72
- }
73
- assert_equal 200, @response.status
74
- assert_template "devise/sessions/new"
75
- end
76
-
77
- test "#destroy doesn't set the flash if the requested format is not navigational" do
78
- request.env["devise.mapping"] = Devise.mappings[:user]
79
- user = create_user
80
- user.confirm
81
- post :create, params: { format: 'json', user: {
82
- email: user.email,
83
- password: user.password
84
- }
85
- }
86
- delete :destroy, format: 'json'
87
- assert flash[:notice].blank?, "flash[:notice] should be blank, not #{flash[:notice].inspect}"
88
- assert_equal 204, @response.status
89
- end
90
-
91
- if defined?(ActiveRecord) && ActiveRecord::Base.respond_to?(:mass_assignment_sanitizer)
92
- test "#new doesn't raise mass-assignment exception even if sign-in key is attr_protected" do
93
- request.env["devise.mapping"] = Devise.mappings[:user]
94
-
95
- ActiveRecord::Base.mass_assignment_sanitizer = :strict
96
- User.class_eval { attr_protected :email }
97
-
98
- begin
99
- assert_nothing_raised do
100
- get :new, user: { email: "allez viens!" }
101
- end
102
- ensure
103
- ActiveRecord::Base.mass_assignment_sanitizer = :logger
104
- User.class_eval { attr_accessible :email }
105
- end
106
- end
107
- end
108
- end