devise 4.3.0 → 4.9.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (259) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +205 -2
  3. data/MIT-LICENSE +2 -1
  4. data/README.md +214 -57
  5. data/app/controllers/devise/confirmations_controller.rb +3 -0
  6. data/app/controllers/devise/omniauth_callbacks_controller.rb +3 -1
  7. data/app/controllers/devise/passwords_controller.rb +5 -2
  8. data/app/controllers/devise/registrations_controller.rb +32 -12
  9. data/app/controllers/devise/sessions_controller.rb +4 -2
  10. data/app/controllers/devise/unlocks_controller.rb +3 -0
  11. data/app/controllers/devise_controller.rb +6 -3
  12. data/app/helpers/devise_helper.rb +23 -18
  13. data/app/mailers/devise/mailer.rb +7 -5
  14. data/app/views/devise/confirmations/new.html.erb +2 -2
  15. data/app/views/devise/passwords/edit.html.erb +3 -3
  16. data/app/views/devise/passwords/new.html.erb +2 -2
  17. data/app/views/devise/registrations/edit.html.erb +6 -6
  18. data/app/views/devise/registrations/new.html.erb +4 -4
  19. data/app/views/devise/sessions/new.html.erb +4 -4
  20. data/app/views/devise/shared/_error_messages.html.erb +15 -0
  21. data/app/views/devise/shared/_links.html.erb +8 -8
  22. data/app/views/devise/unlocks/new.html.erb +2 -2
  23. data/config/locales/en.yml +3 -2
  24. data/lib/devise/controllers/helpers.rb +10 -8
  25. data/lib/devise/controllers/rememberable.rb +2 -0
  26. data/lib/devise/controllers/responder.rb +35 -0
  27. data/lib/devise/controllers/scoped_views.rb +2 -0
  28. data/lib/devise/controllers/sign_in_out.rb +14 -4
  29. data/lib/devise/controllers/store_location.rb +24 -6
  30. data/lib/devise/controllers/url_helpers.rb +3 -1
  31. data/lib/devise/delegator.rb +2 -0
  32. data/lib/devise/encryptor.rb +2 -0
  33. data/lib/devise/failure_app.rb +33 -7
  34. data/lib/devise/hooks/activatable.rb +2 -0
  35. data/lib/devise/hooks/csrf_cleaner.rb +8 -1
  36. data/lib/devise/hooks/forgetable.rb +2 -0
  37. data/lib/devise/hooks/lockable.rb +4 -5
  38. data/lib/devise/hooks/proxy.rb +2 -0
  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 +2 -0
  43. data/lib/devise/mapping.rb +3 -1
  44. data/lib/devise/models/authenticatable.rb +55 -50
  45. data/lib/devise/models/confirmable.rb +36 -40
  46. data/lib/devise/models/database_authenticatable.rb +57 -36
  47. data/lib/devise/models/lockable.rb +18 -4
  48. data/lib/devise/models/omniauthable.rb +4 -2
  49. data/lib/devise/models/recoverable.rb +10 -19
  50. data/lib/devise/models/registerable.rb +4 -0
  51. data/lib/devise/models/rememberable.rb +5 -3
  52. data/lib/devise/models/timeoutable.rb +3 -1
  53. data/lib/devise/models/trackable.rb +15 -1
  54. data/lib/devise/models/validatable.rb +7 -10
  55. data/lib/devise/models.rb +3 -0
  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 +2 -0
  59. data/lib/devise/omniauth.rb +4 -5
  60. data/lib/devise/orm/active_record.rb +2 -0
  61. data/lib/devise/orm/mongoid.rb +2 -0
  62. data/lib/devise/orm.rb +71 -0
  63. data/lib/devise/parameter_filter.rb +4 -0
  64. data/lib/devise/parameter_sanitizer.rb +15 -1
  65. data/lib/devise/rails/deprecated_constant_accessor.rb +39 -0
  66. data/lib/devise/rails/routes.rb +8 -6
  67. data/lib/devise/rails/warden_compat.rb +2 -0
  68. data/lib/devise/rails.rb +3 -5
  69. data/lib/devise/secret_key_finder.rb +27 -0
  70. data/lib/devise/strategies/authenticatable.rb +3 -1
  71. data/lib/devise/strategies/base.rb +2 -0
  72. data/lib/devise/strategies/database_authenticatable.rb +8 -1
  73. data/lib/devise/strategies/rememberable.rb +2 -0
  74. data/lib/devise/test/controller_helpers.rb +6 -1
  75. data/lib/devise/test/integration_helpers.rb +3 -1
  76. data/lib/devise/test_helpers.rb +2 -0
  77. data/lib/devise/time_inflector.rb +2 -0
  78. data/lib/devise/token_generator.rb +2 -0
  79. data/lib/devise/version.rb +3 -1
  80. data/lib/devise.rb +38 -12
  81. data/lib/generators/active_record/devise_generator.rb +40 -12
  82. data/lib/generators/active_record/templates/migration.rb +3 -1
  83. data/lib/generators/active_record/templates/migration_existing.rb +2 -0
  84. data/lib/generators/devise/controllers_generator.rb +3 -1
  85. data/lib/generators/devise/devise_generator.rb +5 -3
  86. data/lib/generators/devise/install_generator.rb +3 -5
  87. data/lib/generators/devise/orm_helpers.rb +9 -3
  88. data/lib/generators/devise/views_generator.rb +8 -9
  89. data/lib/generators/mongoid/devise_generator.rb +7 -5
  90. data/lib/generators/templates/README +9 -1
  91. data/lib/generators/templates/controllers/confirmations_controller.rb +2 -0
  92. data/lib/generators/templates/controllers/omniauth_callbacks_controller.rb +3 -1
  93. data/lib/generators/templates/controllers/passwords_controller.rb +2 -0
  94. data/lib/generators/templates/controllers/registrations_controller.rb +2 -0
  95. data/lib/generators/templates/controllers/sessions_controller.rb +2 -0
  96. data/lib/generators/templates/controllers/unlocks_controller.rb +2 -0
  97. data/lib/generators/templates/devise.rb +43 -7
  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 +12 -4
  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 +24 -307
  106. data/.gitignore +0 -10
  107. data/.travis.yml +0 -58
  108. data/.yardopts +0 -9
  109. data/CODE_OF_CONDUCT.md +0 -22
  110. data/CONTRIBUTING.md +0 -79
  111. data/Gemfile +0 -40
  112. data/Gemfile.lock +0 -194
  113. data/Rakefile +0 -36
  114. data/bin/test +0 -13
  115. data/devise.gemspec +0 -26
  116. data/devise.png +0 -0
  117. data/gemfiles/Gemfile.rails-4.1-stable +0 -30
  118. data/gemfiles/Gemfile.rails-4.1-stable.lock +0 -171
  119. data/gemfiles/Gemfile.rails-4.2-stable +0 -30
  120. data/gemfiles/Gemfile.rails-4.2-stable.lock +0 -192
  121. data/gemfiles/Gemfile.rails-5.0-stable +0 -34
  122. data/gemfiles/Gemfile.rails-5.0-stable.lock +0 -193
  123. data/guides/bug_report_templates/integration_test.rb +0 -104
  124. data/test/controllers/custom_registrations_controller_test.rb +0 -40
  125. data/test/controllers/custom_strategy_test.rb +0 -64
  126. data/test/controllers/helper_methods_test.rb +0 -22
  127. data/test/controllers/helpers_test.rb +0 -316
  128. data/test/controllers/inherited_controller_i18n_messages_test.rb +0 -51
  129. data/test/controllers/internal_helpers_test.rb +0 -127
  130. data/test/controllers/load_hooks_controller_test.rb +0 -19
  131. data/test/controllers/passwords_controller_test.rb +0 -32
  132. data/test/controllers/sessions_controller_test.rb +0 -106
  133. data/test/controllers/url_helpers_test.rb +0 -65
  134. data/test/delegator_test.rb +0 -19
  135. data/test/devise_test.rb +0 -107
  136. data/test/failure_app_test.rb +0 -338
  137. data/test/generators/active_record_generator_test.rb +0 -83
  138. data/test/generators/controllers_generator_test.rb +0 -48
  139. data/test/generators/devise_generator_test.rb +0 -39
  140. data/test/generators/install_generator_test.rb +0 -24
  141. data/test/generators/mongoid_generator_test.rb +0 -23
  142. data/test/generators/views_generator_test.rb +0 -103
  143. data/test/helpers/devise_helper_test.rb +0 -49
  144. data/test/integration/authenticatable_test.rb +0 -698
  145. data/test/integration/confirmable_test.rb +0 -324
  146. data/test/integration/database_authenticatable_test.rb +0 -95
  147. data/test/integration/http_authenticatable_test.rb +0 -106
  148. data/test/integration/lockable_test.rb +0 -240
  149. data/test/integration/mounted_engine_test.rb +0 -36
  150. data/test/integration/omniauthable_test.rb +0 -135
  151. data/test/integration/recoverable_test.rb +0 -347
  152. data/test/integration/registerable_test.rb +0 -363
  153. data/test/integration/rememberable_test.rb +0 -217
  154. data/test/integration/timeoutable_test.rb +0 -184
  155. data/test/integration/trackable_test.rb +0 -92
  156. data/test/mailers/confirmation_instructions_test.rb +0 -115
  157. data/test/mailers/email_changed_test.rb +0 -130
  158. data/test/mailers/mailer_test.rb +0 -18
  159. data/test/mailers/reset_password_instructions_test.rb +0 -96
  160. data/test/mailers/unlock_instructions_test.rb +0 -91
  161. data/test/mapping_test.rb +0 -134
  162. data/test/models/authenticatable_test.rb +0 -23
  163. data/test/models/confirmable_test.rb +0 -536
  164. data/test/models/database_authenticatable_test.rb +0 -281
  165. data/test/models/lockable_test.rb +0 -350
  166. data/test/models/omniauthable_test.rb +0 -7
  167. data/test/models/recoverable_test.rb +0 -261
  168. data/test/models/registerable_test.rb +0 -7
  169. data/test/models/rememberable_test.rb +0 -182
  170. data/test/models/serializable_test.rb +0 -54
  171. data/test/models/timeoutable_test.rb +0 -51
  172. data/test/models/trackable_test.rb +0 -41
  173. data/test/models/validatable_test.rb +0 -119
  174. data/test/models_test.rb +0 -153
  175. data/test/omniauth/config_test.rb +0 -59
  176. data/test/omniauth/url_helpers_test.rb +0 -51
  177. data/test/orm/active_record.rb +0 -17
  178. data/test/orm/mongoid.rb +0 -13
  179. data/test/parameter_sanitizer_test.rb +0 -75
  180. data/test/rails_app/Rakefile +0 -6
  181. data/test/rails_app/app/active_record/admin.rb +0 -6
  182. data/test/rails_app/app/active_record/shim.rb +0 -2
  183. data/test/rails_app/app/active_record/user.rb +0 -7
  184. data/test/rails_app/app/active_record/user_on_engine.rb +0 -7
  185. data/test/rails_app/app/active_record/user_on_main_app.rb +0 -7
  186. data/test/rails_app/app/active_record/user_without_email.rb +0 -8
  187. data/test/rails_app/app/controllers/admins/sessions_controller.rb +0 -6
  188. data/test/rails_app/app/controllers/admins_controller.rb +0 -6
  189. data/test/rails_app/app/controllers/application_controller.rb +0 -11
  190. data/test/rails_app/app/controllers/application_with_fake_engine.rb +0 -30
  191. data/test/rails_app/app/controllers/custom/registrations_controller.rb +0 -31
  192. data/test/rails_app/app/controllers/home_controller.rb +0 -29
  193. data/test/rails_app/app/controllers/publisher/registrations_controller.rb +0 -2
  194. data/test/rails_app/app/controllers/publisher/sessions_controller.rb +0 -2
  195. data/test/rails_app/app/controllers/users/omniauth_callbacks_controller.rb +0 -14
  196. data/test/rails_app/app/controllers/users_controller.rb +0 -31
  197. data/test/rails_app/app/helpers/application_helper.rb +0 -3
  198. data/test/rails_app/app/mailers/users/from_proc_mailer.rb +0 -3
  199. data/test/rails_app/app/mailers/users/mailer.rb +0 -3
  200. data/test/rails_app/app/mailers/users/reply_to_mailer.rb +0 -4
  201. data/test/rails_app/app/mongoid/admin.rb +0 -29
  202. data/test/rails_app/app/mongoid/shim.rb +0 -23
  203. data/test/rails_app/app/mongoid/user.rb +0 -39
  204. data/test/rails_app/app/mongoid/user_on_engine.rb +0 -39
  205. data/test/rails_app/app/mongoid/user_on_main_app.rb +0 -39
  206. data/test/rails_app/app/mongoid/user_without_email.rb +0 -33
  207. data/test/rails_app/app/views/admins/index.html.erb +0 -1
  208. data/test/rails_app/app/views/admins/sessions/new.html.erb +0 -2
  209. data/test/rails_app/app/views/home/admin_dashboard.html.erb +0 -1
  210. data/test/rails_app/app/views/home/index.html.erb +0 -1
  211. data/test/rails_app/app/views/home/join.html.erb +0 -1
  212. data/test/rails_app/app/views/home/private.html.erb +0 -1
  213. data/test/rails_app/app/views/home/user_dashboard.html.erb +0 -1
  214. data/test/rails_app/app/views/layouts/application.html.erb +0 -24
  215. data/test/rails_app/app/views/users/edit_form.html.erb +0 -1
  216. data/test/rails_app/app/views/users/index.html.erb +0 -1
  217. data/test/rails_app/app/views/users/mailer/confirmation_instructions.erb +0 -1
  218. data/test/rails_app/app/views/users/sessions/new.html.erb +0 -1
  219. data/test/rails_app/bin/bundle +0 -3
  220. data/test/rails_app/bin/rails +0 -4
  221. data/test/rails_app/bin/rake +0 -4
  222. data/test/rails_app/config/application.rb +0 -44
  223. data/test/rails_app/config/boot.rb +0 -20
  224. data/test/rails_app/config/database.yml +0 -18
  225. data/test/rails_app/config/environment.rb +0 -5
  226. data/test/rails_app/config/environments/development.rb +0 -30
  227. data/test/rails_app/config/environments/production.rb +0 -86
  228. data/test/rails_app/config/environments/test.rb +0 -45
  229. data/test/rails_app/config/initializers/backtrace_silencers.rb +0 -7
  230. data/test/rails_app/config/initializers/devise.rb +0 -180
  231. data/test/rails_app/config/initializers/inflections.rb +0 -2
  232. data/test/rails_app/config/initializers/secret_token.rb +0 -3
  233. data/test/rails_app/config/initializers/session_store.rb +0 -1
  234. data/test/rails_app/config/routes.rb +0 -126
  235. data/test/rails_app/config.ru +0 -4
  236. data/test/rails_app/db/migrate/20100401102949_create_tables.rb +0 -75
  237. data/test/rails_app/db/schema.rb +0 -55
  238. data/test/rails_app/lib/shared_admin.rb +0 -21
  239. data/test/rails_app/lib/shared_user.rb +0 -30
  240. data/test/rails_app/lib/shared_user_without_email.rb +0 -26
  241. data/test/rails_app/lib/shared_user_without_omniauth.rb +0 -13
  242. data/test/rails_app/public/404.html +0 -26
  243. data/test/rails_app/public/422.html +0 -26
  244. data/test/rails_app/public/500.html +0 -26
  245. data/test/rails_app/public/favicon.ico +0 -0
  246. data/test/rails_test.rb +0 -9
  247. data/test/routes_test.rb +0 -279
  248. data/test/support/action_controller/record_identifier.rb +0 -10
  249. data/test/support/assertions.rb +0 -28
  250. data/test/support/helpers.rb +0 -77
  251. data/test/support/http_method_compatibility.rb +0 -51
  252. data/test/support/integration.rb +0 -92
  253. data/test/support/locale/en.yml +0 -8
  254. data/test/support/mongoid.yml +0 -6
  255. data/test/support/webrat/integrations/rails.rb +0 -33
  256. data/test/test/controller_helpers_test.rb +0 -186
  257. data/test/test/integration_helpers_test.rb +0 -32
  258. data/test/test_helper.rb +0 -34
  259. data/test/test_models.rb +0 -33
@@ -1,65 +0,0 @@
1
- require 'test_helper'
2
-
3
- class RoutesTest < Devise::ControllerTestCase
4
- tests ApplicationController
5
-
6
- def assert_path_and_url(name, prepend_path=nil)
7
- @request.path = '/users/session'
8
- prepend_path = "#{prepend_path}_" if prepend_path
9
-
10
- # Resource param
11
- assert_equal @controller.send(:"#{prepend_path}#{name}_path", :user),
12
- send(:"#{prepend_path}user_#{name}_path")
13
- assert_equal @controller.send(:"#{prepend_path}#{name}_url", :user),
14
- send(:"#{prepend_path}user_#{name}_url")
15
-
16
- # With string
17
- assert_equal @controller.send(:"#{prepend_path}#{name}_path", "user"),
18
- send(:"#{prepend_path}user_#{name}_path")
19
- assert_equal @controller.send(:"#{prepend_path}#{name}_url", "user"),
20
- send(:"#{prepend_path}user_#{name}_url")
21
-
22
- # Default url params
23
- assert_equal @controller.send(:"#{prepend_path}#{name}_path", :user, param: 123),
24
- send(:"#{prepend_path}user_#{name}_path", param: 123)
25
- assert_equal @controller.send(:"#{prepend_path}#{name}_url", :user, param: 123),
26
- send(:"#{prepend_path}user_#{name}_url", param: 123)
27
-
28
- @request.path = nil
29
- # With an object
30
- assert_equal @controller.send(:"#{prepend_path}#{name}_path", User.new),
31
- send(:"#{prepend_path}user_#{name}_path")
32
- assert_equal @controller.send(:"#{prepend_path}#{name}_url", User.new),
33
- send(:"#{prepend_path}user_#{name}_url")
34
- end
35
-
36
-
37
- test 'should alias session to mapped user session' do
38
- assert_path_and_url :session
39
- assert_path_and_url :session, :new
40
- assert_path_and_url :session, :destroy
41
- end
42
-
43
- test 'should alias password to mapped user password' do
44
- assert_path_and_url :password
45
- assert_path_and_url :password, :new
46
- assert_path_and_url :password, :edit
47
- end
48
-
49
- test 'should alias confirmation to mapped user confirmation' do
50
- assert_path_and_url :confirmation
51
- assert_path_and_url :confirmation, :new
52
- end
53
-
54
- test 'should alias unlock to mapped user unlock' do
55
- assert_path_and_url :unlock
56
- assert_path_and_url :unlock, :new
57
- end
58
-
59
- test 'should alias registration to mapped user registration' do
60
- assert_path_and_url :registration
61
- assert_path_and_url :registration, :new
62
- assert_path_and_url :registration, :edit
63
- assert_path_and_url :registration, :cancel
64
- end
65
- end
@@ -1,19 +0,0 @@
1
- require 'test_helper'
2
-
3
- class DelegatorTest < ActiveSupport::TestCase
4
- def delegator
5
- Devise::Delegator.new
6
- end
7
-
8
- test 'failure_app returns default failure app if no warden options in env' do
9
- assert_equal Devise::FailureApp, delegator.failure_app({})
10
- end
11
-
12
- test 'failure_app returns default failure app if no scope in warden options' do
13
- assert_equal Devise::FailureApp, delegator.failure_app({"warden.options" => {}})
14
- end
15
-
16
- test 'failure_app returns associated failure app by scope in the given environment' do
17
- assert_kind_of Proc, delegator.failure_app({"warden.options" => {scope: "manager"}})
18
- end
19
- end
data/test/devise_test.rb DELETED
@@ -1,107 +0,0 @@
1
- require 'test_helper'
2
-
3
- module Devise
4
- def self.yield_and_restore
5
- @@warden_configured = nil
6
- c, b = @@warden_config, @@warden_config_blocks
7
- yield
8
- ensure
9
- @@warden_config, @@warden_config_blocks = c, b
10
- end
11
- end
12
-
13
- class DeviseTest < ActiveSupport::TestCase
14
- test 'bcrypt on the class' do
15
- password = "super secret"
16
- klass = Struct.new(:pepper, :stretches).new("blahblah", 2)
17
- hash = Devise::Encryptor.digest(klass, password)
18
- assert_equal ::BCrypt::Password.create(hash), hash
19
-
20
- klass = Struct.new(:pepper, :stretches).new("bla", 2)
21
- hash = Devise::Encryptor.digest(klass, password)
22
- assert_not_equal ::BCrypt::Password.new(hash), hash
23
- end
24
-
25
- test 'model options can be configured through Devise' do
26
- swap Devise, allow_unconfirmed_access_for: 113, pepper: "foo" do
27
- assert_equal 113, Devise.allow_unconfirmed_access_for
28
- assert_equal "foo", Devise.pepper
29
- end
30
- end
31
-
32
- test 'setup block yields self' do
33
- Devise.setup do |config|
34
- assert_equal Devise, config
35
- end
36
- end
37
-
38
- test 'stores warden configuration' do
39
- assert_kind_of Devise::Delegator, Devise.warden_config.failure_app
40
- assert_equal :user, Devise.warden_config.default_scope
41
- end
42
-
43
- test 'warden manager user configuration through a block' do
44
- Devise.yield_and_restore do
45
- executed = false
46
- Devise.warden do |config|
47
- executed = true
48
- assert_kind_of Warden::Config, config
49
- end
50
-
51
- Devise.configure_warden!
52
- assert executed
53
- end
54
- end
55
-
56
- test 'warden manager user configuration through multiple blocks' do
57
- Devise.yield_and_restore do
58
- executed = 0
59
-
60
- 3.times do
61
- Devise.warden { |config| executed += 1 }
62
- end
63
-
64
- Devise.configure_warden!
65
- assert_equal 3, executed
66
- end
67
- end
68
-
69
- test 'add new module using the helper method' do
70
- Devise.add_module(:coconut)
71
- assert_equal 1, Devise::ALL.select { |v| v == :coconut }.size
72
- refute Devise::STRATEGIES.include?(:coconut)
73
- refute defined?(Devise::Models::Coconut)
74
- Devise::ALL.delete(:coconut)
75
-
76
- Devise.add_module(:banana, strategy: :fruits)
77
- assert_equal :fruits, Devise::STRATEGIES[:banana]
78
- Devise::ALL.delete(:banana)
79
- Devise::STRATEGIES.delete(:banana)
80
-
81
- Devise.add_module(:kivi, controller: :fruits)
82
- assert_equal :fruits, Devise::CONTROLLERS[:kivi]
83
- Devise::ALL.delete(:kivi)
84
- Devise::CONTROLLERS.delete(:kivi)
85
- end
86
-
87
- test 'should complain when comparing empty or different sized passes' do
88
- [nil, ""].each do |empty|
89
- refute Devise.secure_compare(empty, "something")
90
- refute Devise.secure_compare("something", empty)
91
- refute Devise.secure_compare(empty, empty)
92
- end
93
- refute Devise.secure_compare("size_1", "size_four")
94
- end
95
-
96
- test 'Devise.email_regexp should match valid email addresses' do
97
- valid_emails = ["test@example.com", "jo@jo.co", "f4$_m@you.com", "testing.example@example.com.ua", "test@tt", "test@valid---domain.com"]
98
- non_valid_emails = ["rex", "test user@example.com", "test_user@example server.com"]
99
-
100
- valid_emails.each do |email|
101
- assert_match Devise.email_regexp, email
102
- end
103
- non_valid_emails.each do |email|
104
- assert_no_match Devise.email_regexp, email
105
- end
106
- end
107
- end
@@ -1,338 +0,0 @@
1
- require 'test_helper'
2
- require 'ostruct'
3
-
4
- class FailureTest < ActiveSupport::TestCase
5
- class RootFailureApp < Devise::FailureApp
6
- def fake_app
7
- Object.new
8
- end
9
- end
10
-
11
- class FailureWithSubdomain < RootFailureApp
12
- routes = ActionDispatch::Routing::RouteSet.new
13
-
14
- routes.draw do
15
- scope subdomain: 'sub' do
16
- root to: 'foo#bar'
17
- end
18
- end
19
-
20
- include routes.url_helpers
21
- end
22
-
23
- class FailureWithI18nOptions < Devise::FailureApp
24
- def i18n_options(options)
25
- options.merge(name: 'Steve')
26
- end
27
- end
28
-
29
- class FakeEngineApp < Devise::FailureApp
30
- class FakeEngine
31
- def new_user_on_engine_session_url _
32
- '/user_on_engines/sign_in'
33
- end
34
- end
35
-
36
- def main_app
37
- raise 'main_app router called instead of fake_engine'
38
- end
39
-
40
- def fake_engine
41
- @fake_engine ||= FakeEngine.new
42
- end
43
- end
44
-
45
- def self.context(name, &block)
46
- instance_eval(&block)
47
- end
48
-
49
- def call_failure(env_params={})
50
- env = {
51
- 'REQUEST_URI' => 'http://test.host/',
52
- 'HTTP_HOST' => 'test.host',
53
- 'REQUEST_METHOD' => 'GET',
54
- 'warden.options' => { scope: :user },
55
- 'rack.session' => {},
56
- 'action_dispatch.request.formats' => Array(env_params.delete('formats') || Mime[:html]),
57
- 'rack.input' => "",
58
- 'warden' => OpenStruct.new(message: nil)
59
- }.merge!(env_params)
60
-
61
- # Passing nil for action_dispatch.request.formats prevents the default from being used in Rails 5, need to remove it
62
- if env.has_key?('action_dispatch.request.formats') && env['action_dispatch.request.formats'].nil?
63
- env.delete 'action_dispatch.request.formats' unless env['action_dispatch.request.formats']
64
- end
65
-
66
- @response = (env.delete(:app) || Devise::FailureApp).call(env).to_a
67
- @request = ActionDispatch::Request.new(env)
68
- end
69
-
70
- context 'When redirecting' do
71
- test 'returns to the default redirect location' do
72
- call_failure
73
- assert_equal 302, @response.first
74
- assert_equal 'You need to sign in or sign up before continuing.', @request.flash[:alert]
75
- assert_equal 'http://test.host/users/sign_in', @response.second['Location']
76
- end
77
-
78
- test 'returns to the default redirect location considering subdomain' do
79
- call_failure('warden.options' => { scope: :subdomain_user })
80
- assert_equal 302, @response.first
81
- assert_equal 'You need to sign in or sign up before continuing.', @request.flash[:alert]
82
- assert_equal 'http://sub.test.host/subdomain_users/sign_in', @response.second['Location']
83
- end
84
-
85
- test 'returns to the default redirect location for wildcard requests' do
86
- call_failure 'action_dispatch.request.formats' => nil, 'HTTP_ACCEPT' => '*/*'
87
- assert_equal 302, @response.first
88
- assert_equal 'http://test.host/users/sign_in', @response.second['Location']
89
- end
90
-
91
- test 'returns to the root path if no session path is available' do
92
- swap Devise, router_name: :fake_app do
93
- call_failure app: RootFailureApp
94
- assert_equal 302, @response.first
95
- assert_equal 'You need to sign in or sign up before continuing.', @request.flash[:alert]
96
- assert_equal 'http://test.host/', @response.second['Location']
97
- end
98
- end
99
-
100
- test 'returns to the root path considering subdomain if no session path is available' do
101
- swap Devise, router_name: :fake_app do
102
- call_failure app: FailureWithSubdomain
103
- assert_equal 302, @response.first
104
- assert_equal 'You need to sign in or sign up before continuing.', @request.flash[:alert]
105
- assert_equal 'http://sub.test.host/', @response.second['Location']
106
- end
107
- end
108
-
109
- test 'returns to the default redirect location considering the router for supplied scope' do
110
- call_failure app: FakeEngineApp, 'warden.options' => { scope: :user_on_engine }
111
- assert_equal 302, @response.first
112
- assert_equal 'You need to sign in or sign up before continuing.', @request.flash[:alert]
113
- assert_equal 'http://test.host/user_on_engines/sign_in', @response.second['Location']
114
- end
115
-
116
- if Rails.application.config.respond_to?(:relative_url_root)
117
- test 'returns to the default redirect location considering the relative url root' do
118
- swap Rails.application.config, relative_url_root: "/sample" do
119
- call_failure
120
- assert_equal 302, @response.first
121
- assert_equal 'http://test.host/sample/users/sign_in', @response.second['Location']
122
- end
123
- end
124
-
125
- test 'returns to the default redirect location considering the relative url root and subdomain' do
126
- swap Rails.application.config, relative_url_root: "/sample" do
127
- call_failure('warden.options' => { scope: :subdomain_user })
128
- assert_equal 302, @response.first
129
- assert_equal 'http://sub.test.host/sample/subdomain_users/sign_in', @response.second['Location']
130
- end
131
- end
132
- end
133
-
134
- if Rails.application.config.action_controller.respond_to?(:relative_url_root)
135
- test "returns to the default redirect location considering action_controller's relative url root" do
136
- swap Rails.application.config.action_controller, relative_url_root: "/sample" do
137
- call_failure
138
- assert_equal 302, @response.first
139
- assert_equal 'http://test.host/sample/users/sign_in', @response.second['Location']
140
- end
141
- end
142
-
143
- test "returns to the default redirect location considering action_controller's relative url root and subdomain" do
144
- swap Rails.application.config.action_controller, relative_url_root: "/sample" do
145
- call_failure('warden.options' => { scope: :subdomain_user })
146
- assert_equal 302, @response.first
147
- assert_equal 'http://sub.test.host/sample/subdomain_users/sign_in', @response.second['Location']
148
- end
149
- end
150
- end
151
-
152
- test 'uses the proxy failure message as symbol' do
153
- call_failure('warden' => OpenStruct.new(message: :invalid))
154
- assert_equal 'Invalid Email or password.', @request.flash[:alert]
155
- assert_equal 'http://test.host/users/sign_in', @response.second["Location"]
156
- end
157
-
158
- test 'supports authentication_keys as a Hash for the flash message' do
159
- swap Devise, authentication_keys: { email: true, login: true } do
160
- call_failure('warden' => OpenStruct.new(message: :invalid))
161
- assert_equal 'Invalid Email, Login or password.', @request.flash[:alert]
162
- end
163
- end
164
-
165
- test 'uses custom i18n options' do
166
- call_failure('warden' => OpenStruct.new(message: :does_not_exist), app: FailureWithI18nOptions)
167
- assert_equal 'User Steve does not exist', @request.flash[:alert]
168
- end
169
-
170
- test 'uses the proxy failure message as string' do
171
- call_failure('warden' => OpenStruct.new(message: 'Hello world'))
172
- assert_equal 'Hello world', @request.flash[:alert]
173
- assert_equal 'http://test.host/users/sign_in', @response.second["Location"]
174
- end
175
-
176
- test 'set content type to default text/html' do
177
- call_failure
178
- assert_equal 'text/html; charset=utf-8', @response.second['Content-Type']
179
- end
180
-
181
- test 'set up a default message' do
182
- call_failure
183
- assert_match(/You are being/, @response.last.body)
184
- assert_match(/redirected/, @response.last.body)
185
- assert_match(/users\/sign_in/, @response.last.body)
186
- end
187
-
188
- test 'works for any navigational format' do
189
- swap Devise, navigational_formats: [:xml] do
190
- call_failure('formats' => Mime[:xml])
191
- assert_equal 302, @response.first
192
- end
193
- end
194
-
195
- test 'redirects the correct format if it is a non-html format request' do
196
- swap Devise, navigational_formats: [:js] do
197
- call_failure('formats' => Mime[:js])
198
- assert_equal 'http://test.host/users/sign_in.js', @response.second["Location"]
199
- end
200
- end
201
- end
202
-
203
- context 'For HTTP request' do
204
- test 'return 401 status' do
205
- call_failure('formats' => Mime[:xml])
206
- assert_equal 401, @response.first
207
- end
208
-
209
- test 'return appropriate body for xml' do
210
- call_failure('formats' => Mime[:xml])
211
- result = %(<?xml version="1.0" encoding="UTF-8"?>\n<errors>\n <error>You need to sign in or sign up before continuing.</error>\n</errors>\n)
212
- assert_equal result, @response.last.body
213
- end
214
-
215
- test 'return appropriate body for json' do
216
- call_failure('formats' => Mime[:json])
217
- result = %({"error":"You need to sign in or sign up before continuing."})
218
- assert_equal result, @response.last.body
219
- end
220
-
221
- test 'return 401 status for unknown formats' do
222
- call_failure 'formats' => []
223
- assert_equal 401, @response.first
224
- end
225
-
226
- test 'return WWW-authenticate headers if model allows' do
227
- call_failure('formats' => Mime[:xml])
228
- assert_equal 'Basic realm="Application"', @response.second["WWW-Authenticate"]
229
- end
230
-
231
- test 'does not return WWW-authenticate headers if model does not allow' do
232
- swap Devise, http_authenticatable: false do
233
- call_failure('formats' => Mime[:xml])
234
- assert_nil @response.second["WWW-Authenticate"]
235
- end
236
- end
237
-
238
- test 'works for any non navigational format' do
239
- swap Devise, navigational_formats: [] do
240
- call_failure('formats' => Mime[:html])
241
- assert_equal 401, @response.first
242
- end
243
- end
244
-
245
- test 'uses the failure message as response body' do
246
- call_failure('formats' => Mime[:xml], 'warden' => OpenStruct.new(message: :invalid))
247
- assert_match '<error>Invalid Email or password.</error>', @response.third.body
248
- end
249
-
250
- context 'on ajax call' do
251
- context 'when http_authenticatable_on_xhr is false' do
252
- test 'dont return 401 with navigational formats' do
253
- swap Devise, http_authenticatable_on_xhr: false do
254
- call_failure('formats' => Mime[:html], 'HTTP_X_REQUESTED_WITH' => 'XMLHttpRequest')
255
- assert_equal 302, @response.first
256
- assert_equal 'http://test.host/users/sign_in', @response.second["Location"]
257
- end
258
- end
259
-
260
- test 'dont return 401 with non navigational formats' do
261
- swap Devise, http_authenticatable_on_xhr: false do
262
- call_failure('formats' => Mime[:json], 'HTTP_X_REQUESTED_WITH' => 'XMLHttpRequest')
263
- assert_equal 302, @response.first
264
- assert_equal 'http://test.host/users/sign_in.json', @response.second["Location"]
265
- end
266
- end
267
- end
268
-
269
- context 'when http_authenticatable_on_xhr is true' do
270
- test 'return 401' do
271
- swap Devise, http_authenticatable_on_xhr: true do
272
- call_failure('formats' => Mime[:html], 'HTTP_X_REQUESTED_WITH' => 'XMLHttpRequest')
273
- assert_equal 401, @response.first
274
- end
275
- end
276
-
277
- test 'skip WWW-Authenticate header' do
278
- swap Devise, http_authenticatable_on_xhr: true do
279
- call_failure('formats' => Mime[:html], 'HTTP_X_REQUESTED_WITH' => 'XMLHttpRequest')
280
- assert_nil @response.second['WWW-Authenticate']
281
- end
282
- end
283
- end
284
- end
285
- end
286
-
287
- context 'With recall' do
288
- test 'calls the original controller if invalid email or password' do
289
- env = {
290
- "warden.options" => { recall: "devise/sessions#new", attempted_path: "/users/sign_in" },
291
- "devise.mapping" => Devise.mappings[:user],
292
- "warden" => stub_everything
293
- }
294
- call_failure(env)
295
- assert @response.third.body.include?('<h2>Log in</h2>')
296
- assert @response.third.body.include?('Invalid Email or password.')
297
- end
298
-
299
- test 'calls the original controller if not confirmed email' do
300
- env = {
301
- "warden.options" => { recall: "devise/sessions#new", attempted_path: "/users/sign_in", message: :unconfirmed },
302
- "devise.mapping" => Devise.mappings[:user],
303
- "warden" => stub_everything
304
- }
305
- call_failure(env)
306
- assert @response.third.body.include?('<h2>Log in</h2>')
307
- assert @response.third.body.include?('You have to confirm your email address before continuing.')
308
- end
309
-
310
- test 'calls the original controller if inactive account' do
311
- env = {
312
- "warden.options" => { recall: "devise/sessions#new", attempted_path: "/users/sign_in", message: :inactive },
313
- "devise.mapping" => Devise.mappings[:user],
314
- "warden" => stub_everything
315
- }
316
- call_failure(env)
317
- assert @response.third.body.include?('<h2>Log in</h2>')
318
- assert @response.third.body.include?('Your account is not activated yet.')
319
- end
320
-
321
- if Rails.application.config.respond_to?(:relative_url_root)
322
- test 'calls the original controller with the proper environment considering the relative url root' do
323
- swap Rails.application.config, relative_url_root: "/sample" do
324
- env = {
325
- "warden.options" => { recall: "devise/sessions#new", attempted_path: "/sample/users/sign_in"},
326
- "devise.mapping" => Devise.mappings[:user],
327
- "warden" => stub_everything
328
- }
329
- call_failure(env)
330
- assert @response.third.body.include?('<h2>Log in</h2>')
331
- assert @response.third.body.include?('Invalid Email or password.')
332
- assert_equal @request.env["SCRIPT_NAME"], '/sample'
333
- assert_equal @request.env["PATH_INFO"], '/users/sign_in'
334
- end
335
- end
336
- end
337
- end
338
- end
@@ -1,83 +0,0 @@
1
- require "test_helper"
2
-
3
- if DEVISE_ORM == :active_record
4
- require "generators/active_record/devise_generator"
5
-
6
- class ActiveRecordGeneratorTest < Rails::Generators::TestCase
7
- tests ActiveRecord::Generators::DeviseGenerator
8
- destination File.expand_path("../../tmp", __FILE__)
9
- setup :prepare_destination
10
-
11
- test "all files are properly created with rails31 migration syntax" do
12
- run_generator %w(monster)
13
- assert_migration "db/migrate/devise_create_monsters.rb", /def change/
14
- end
15
-
16
- test "all files for namespaced model are properly created" do
17
- run_generator %w(admin/monster)
18
- assert_migration "db/migrate/devise_create_admin_monsters.rb", /def change/
19
- end
20
-
21
- test "update model migration when model exists" do
22
- run_generator %w(monster)
23
- assert_file "app/models/monster.rb"
24
- run_generator %w(monster)
25
- assert_migration "db/migrate/add_devise_to_monsters.rb"
26
- end
27
-
28
- test "all files are properly deleted" do
29
- run_generator %w(monster)
30
- run_generator %w(monster)
31
- assert_migration "db/migrate/devise_create_monsters.rb"
32
- assert_migration "db/migrate/add_devise_to_monsters.rb"
33
- run_generator %w(monster), behavior: :revoke
34
- assert_no_migration "db/migrate/add_devise_to_monsters.rb"
35
- assert_migration "db/migrate/devise_create_monsters.rb"
36
- run_generator %w(monster), behavior: :revoke
37
- assert_no_file "app/models/monster.rb"
38
- assert_no_migration "db/migrate/devise_create_monsters.rb"
39
- end
40
-
41
- test "use string column type for ip addresses" do
42
- run_generator %w(monster)
43
- assert_migration "db/migrate/devise_create_monsters.rb", /t.string :current_sign_in_ip/
44
- assert_migration "db/migrate/devise_create_monsters.rb", /t.string :last_sign_in_ip/
45
- end
46
- end
47
-
48
- module RailsEngine
49
- class Engine < Rails::Engine
50
- isolate_namespace RailsEngine
51
- end
52
- end
53
-
54
- def simulate_inside_engine(engine, namespace)
55
- if Rails::Generators.respond_to?(:namespace=)
56
- swap Rails::Generators, namespace: namespace do
57
- yield
58
- end
59
- else
60
- swap Rails, application: engine.instance do
61
- yield
62
- end
63
- end
64
- end
65
-
66
- class ActiveRecordEngineGeneratorTest < Rails::Generators::TestCase
67
- tests ActiveRecord::Generators::DeviseGenerator
68
- destination File.expand_path("../../tmp", __FILE__)
69
- setup :prepare_destination
70
-
71
- test "all files are properly created in rails 4.0" do
72
- simulate_inside_engine(RailsEngine::Engine, RailsEngine) do
73
- run_generator ["monster"]
74
-
75
- assert_file "app/models/rails_engine/monster.rb", /devise/
76
- assert_file "app/models/rails_engine/monster.rb" do |content|
77
- assert_no_match %r{attr_accessible :email}, content
78
- end
79
- end
80
- end
81
-
82
- end
83
- end
@@ -1,48 +0,0 @@
1
- require "test_helper"
2
-
3
- class ControllersGeneratorTest < Rails::Generators::TestCase
4
- tests Devise::Generators::ControllersGenerator
5
- destination File.expand_path("../../tmp", __FILE__)
6
- setup :prepare_destination
7
-
8
- test "Assert no controllers are created with no params" do
9
- capture(:stderr) { run_generator }
10
- assert_no_file "app/controllers/sessions_controller.rb"
11
- assert_no_file "app/controllers/registrations_controller.rb"
12
- assert_no_file "app/controllers/confirmations_controller.rb"
13
- assert_no_file "app/controllers/passwords_controller.rb"
14
- assert_no_file "app/controllers/unlocks_controller.rb"
15
- assert_no_file "app/controllers/omniauth_callbacks_controller.rb"
16
- end
17
-
18
- test "Assert all controllers are properly created with scope param" do
19
- run_generator %w(users)
20
- assert_class_names 'users'
21
-
22
- run_generator %w(admins)
23
- assert_class_names 'admins'
24
- end
25
-
26
- test "Assert specified controllers with scope" do
27
- run_generator %w(users -c sessions)
28
- assert_file "app/controllers/users/sessions_controller.rb"
29
- assert_no_file "app/controllers/users/registrations_controller.rb"
30
- assert_no_file "app/controllers/users/confirmations_controller.rb"
31
- assert_no_file "app/controllers/users/passwords_controller.rb"
32
- assert_no_file "app/controllers/users/unlocks_controller.rb"
33
- assert_no_file "app/controllers/users/omniauth_callbacks_controller.rb"
34
- end
35
-
36
- private
37
-
38
- def assert_class_names(scope, options = {})
39
- base_dir = "app/controllers#{scope.blank? ? '' : ('/' + scope)}"
40
- scope_prefix = scope.blank? ? '' : (scope.camelize + '::')
41
- controllers = options[:controllers] ||
42
- %w(confirmations passwords registrations sessions unlocks omniauth_callbacks)
43
-
44
- controllers.each do |c|
45
- assert_file "#{base_dir}/#{c}_controller.rb", /#{scope_prefix + c.camelize}/
46
- end
47
- end
48
- end