devise 4.5.0 → 4.6.0

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

Potentially problematic release.


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

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