devise 4.4.0 → 4.7.3

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