devise 4.4.3 → 4.7.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (222) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +98 -4
  3. data/MIT-LICENSE +2 -1
  4. data/README.md +96 -59
  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 +4 -4
  21. data/lib/devise/controllers/helpers.rb +8 -8
  22. data/lib/devise/controllers/sign_in_out.rb +6 -3
  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 +18 -3
  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 +9 -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/routes.rb +6 -6
  39. data/lib/devise/secret_key_finder.rb +2 -0
  40. data/lib/devise/strategies/authenticatable.rb +1 -1
  41. data/lib/devise/strategies/database_authenticatable.rb +6 -1
  42. data/lib/devise/test/controller_helpers.rb +4 -2
  43. data/lib/devise/test/integration_helpers.rb +1 -1
  44. data/lib/devise/version.rb +1 -1
  45. data/lib/generators/active_record/devise_generator.rb +9 -9
  46. data/lib/generators/devise/controllers_generator.rb +1 -1
  47. data/lib/generators/devise/devise_generator.rb +1 -1
  48. data/lib/generators/devise/install_generator.rb +1 -5
  49. data/lib/generators/devise/orm_helpers.rb +2 -2
  50. data/lib/generators/devise/views_generator.rb +1 -1
  51. data/lib/generators/mongoid/devise_generator.rb +5 -5
  52. data/lib/generators/templates/README +9 -1
  53. data/lib/generators/templates/controllers/omniauth_callbacks_controller.rb +1 -1
  54. data/lib/generators/templates/devise.rb +34 -6
  55. data/lib/generators/templates/simple_form_for/confirmations/new.html.erb +5 -1
  56. data/lib/generators/templates/simple_form_for/passwords/edit.html.erb +10 -2
  57. data/lib/generators/templates/simple_form_for/passwords/new.html.erb +4 -1
  58. data/lib/generators/templates/simple_form_for/registrations/edit.html.erb +11 -3
  59. data/lib/generators/templates/simple_form_for/registrations/new.html.erb +11 -3
  60. data/lib/generators/templates/simple_form_for/sessions/new.html.erb +7 -2
  61. data/lib/generators/templates/simple_form_for/unlocks/new.html.erb +4 -1
  62. metadata +7 -312
  63. data/.gitignore +0 -10
  64. data/.travis.yml +0 -68
  65. data/.yardopts +0 -9
  66. data/CODE_OF_CONDUCT.md +0 -22
  67. data/CONTRIBUTING.md +0 -79
  68. data/Gemfile +0 -39
  69. data/Gemfile.lock +0 -193
  70. data/ISSUE_TEMPLATE.md +0 -19
  71. data/Rakefile +0 -37
  72. data/bin/test +0 -13
  73. data/devise.gemspec +0 -28
  74. data/devise.png +0 -0
  75. data/gemfiles/Gemfile.rails-4.1-stable +0 -32
  76. data/gemfiles/Gemfile.rails-4.1-stable.lock +0 -171
  77. data/gemfiles/Gemfile.rails-4.2-stable +0 -32
  78. data/gemfiles/Gemfile.rails-4.2-stable.lock +0 -192
  79. data/gemfiles/Gemfile.rails-5.0-stable +0 -33
  80. data/gemfiles/Gemfile.rails-5.0-stable.lock +0 -192
  81. data/gemfiles/Gemfile.rails-5.2-rc1 +0 -26
  82. data/gemfiles/Gemfile.rails-5.2-rc1.lock +0 -201
  83. data/guides/bug_report_templates/integration_test.rb +0 -106
  84. data/test/controllers/custom_registrations_controller_test.rb +0 -42
  85. data/test/controllers/custom_strategy_test.rb +0 -66
  86. data/test/controllers/helper_methods_test.rb +0 -24
  87. data/test/controllers/helpers_test.rb +0 -318
  88. data/test/controllers/inherited_controller_i18n_messages_test.rb +0 -53
  89. data/test/controllers/internal_helpers_test.rb +0 -129
  90. data/test/controllers/load_hooks_controller_test.rb +0 -21
  91. data/test/controllers/passwords_controller_test.rb +0 -34
  92. data/test/controllers/sessions_controller_test.rb +0 -108
  93. data/test/controllers/url_helpers_test.rb +0 -67
  94. data/test/delegator_test.rb +0 -21
  95. data/test/devise_test.rb +0 -109
  96. data/test/failure_app_test.rb +0 -340
  97. data/test/generators/active_record_generator_test.rb +0 -130
  98. data/test/generators/controllers_generator_test.rb +0 -50
  99. data/test/generators/devise_generator_test.rb +0 -41
  100. data/test/generators/install_generator_test.rb +0 -26
  101. data/test/generators/mongoid_generator_test.rb +0 -25
  102. data/test/generators/views_generator_test.rb +0 -105
  103. data/test/helpers/devise_helper_test.rb +0 -51
  104. data/test/integration/authenticatable_test.rb +0 -706
  105. data/test/integration/confirmable_test.rb +0 -326
  106. data/test/integration/database_authenticatable_test.rb +0 -97
  107. data/test/integration/http_authenticatable_test.rb +0 -114
  108. data/test/integration/lockable_test.rb +0 -242
  109. data/test/integration/mounted_engine_test.rb +0 -38
  110. data/test/integration/omniauthable_test.rb +0 -148
  111. data/test/integration/recoverable_test.rb +0 -349
  112. data/test/integration/registerable_test.rb +0 -365
  113. data/test/integration/rememberable_test.rb +0 -219
  114. data/test/integration/timeoutable_test.rb +0 -186
  115. data/test/integration/trackable_test.rb +0 -99
  116. data/test/mailers/confirmation_instructions_test.rb +0 -117
  117. data/test/mailers/email_changed_test.rb +0 -132
  118. data/test/mailers/mailer_test.rb +0 -20
  119. data/test/mailers/reset_password_instructions_test.rb +0 -98
  120. data/test/mailers/unlock_instructions_test.rb +0 -93
  121. data/test/mapping_test.rb +0 -136
  122. data/test/models/authenticatable_test.rb +0 -25
  123. data/test/models/confirmable_test.rb +0 -549
  124. data/test/models/database_authenticatable_test.rb +0 -283
  125. data/test/models/lockable_test.rb +0 -352
  126. data/test/models/omniauthable_test.rb +0 -9
  127. data/test/models/recoverable_test.rb +0 -263
  128. data/test/models/registerable_test.rb +0 -9
  129. data/test/models/rememberable_test.rb +0 -184
  130. data/test/models/serializable_test.rb +0 -60
  131. data/test/models/timeoutable_test.rb +0 -53
  132. data/test/models/trackable_test.rb +0 -62
  133. data/test/models/validatable_test.rb +0 -121
  134. data/test/models_test.rb +0 -155
  135. data/test/omniauth/config_test.rb +0 -61
  136. data/test/omniauth/url_helpers_test.rb +0 -53
  137. data/test/orm/active_record.rb +0 -24
  138. data/test/orm/mongoid.rb +0 -15
  139. data/test/parameter_sanitizer_test.rb +0 -77
  140. data/test/rails_app/Rakefile +0 -6
  141. data/test/rails_app/app/active_record/admin.rb +0 -8
  142. data/test/rails_app/app/active_record/shim.rb +0 -4
  143. data/test/rails_app/app/active_record/user.rb +0 -20
  144. data/test/rails_app/app/active_record/user_on_engine.rb +0 -9
  145. data/test/rails_app/app/active_record/user_on_main_app.rb +0 -9
  146. data/test/rails_app/app/active_record/user_with_validations.rb +0 -12
  147. data/test/rails_app/app/active_record/user_without_email.rb +0 -10
  148. data/test/rails_app/app/controllers/admins/sessions_controller.rb +0 -8
  149. data/test/rails_app/app/controllers/admins_controller.rb +0 -8
  150. data/test/rails_app/app/controllers/application_controller.rb +0 -13
  151. data/test/rails_app/app/controllers/application_with_fake_engine.rb +0 -32
  152. data/test/rails_app/app/controllers/custom/registrations_controller.rb +0 -33
  153. data/test/rails_app/app/controllers/home_controller.rb +0 -31
  154. data/test/rails_app/app/controllers/publisher/registrations_controller.rb +0 -4
  155. data/test/rails_app/app/controllers/publisher/sessions_controller.rb +0 -4
  156. data/test/rails_app/app/controllers/users/omniauth_callbacks_controller.rb +0 -16
  157. data/test/rails_app/app/controllers/users_controller.rb +0 -33
  158. data/test/rails_app/app/helpers/application_helper.rb +0 -5
  159. data/test/rails_app/app/mailers/users/from_proc_mailer.rb +0 -5
  160. data/test/rails_app/app/mailers/users/mailer.rb +0 -5
  161. data/test/rails_app/app/mailers/users/reply_to_mailer.rb +0 -6
  162. data/test/rails_app/app/mongoid/admin.rb +0 -31
  163. data/test/rails_app/app/mongoid/shim.rb +0 -25
  164. data/test/rails_app/app/mongoid/user.rb +0 -50
  165. data/test/rails_app/app/mongoid/user_on_engine.rb +0 -41
  166. data/test/rails_app/app/mongoid/user_on_main_app.rb +0 -41
  167. data/test/rails_app/app/mongoid/user_with_validations.rb +0 -37
  168. data/test/rails_app/app/mongoid/user_without_email.rb +0 -35
  169. data/test/rails_app/app/views/admins/index.html.erb +0 -1
  170. data/test/rails_app/app/views/admins/sessions/new.html.erb +0 -2
  171. data/test/rails_app/app/views/home/admin_dashboard.html.erb +0 -1
  172. data/test/rails_app/app/views/home/index.html.erb +0 -1
  173. data/test/rails_app/app/views/home/join.html.erb +0 -1
  174. data/test/rails_app/app/views/home/private.html.erb +0 -1
  175. data/test/rails_app/app/views/home/user_dashboard.html.erb +0 -1
  176. data/test/rails_app/app/views/layouts/application.html.erb +0 -24
  177. data/test/rails_app/app/views/users/edit_form.html.erb +0 -1
  178. data/test/rails_app/app/views/users/index.html.erb +0 -1
  179. data/test/rails_app/app/views/users/mailer/confirmation_instructions.erb +0 -1
  180. data/test/rails_app/app/views/users/sessions/new.html.erb +0 -1
  181. data/test/rails_app/bin/bundle +0 -3
  182. data/test/rails_app/bin/rails +0 -4
  183. data/test/rails_app/bin/rake +0 -4
  184. data/test/rails_app/config.ru +0 -4
  185. data/test/rails_app/config/application.rb +0 -48
  186. data/test/rails_app/config/boot.rb +0 -27
  187. data/test/rails_app/config/database.yml +0 -18
  188. data/test/rails_app/config/environment.rb +0 -7
  189. data/test/rails_app/config/environments/development.rb +0 -32
  190. data/test/rails_app/config/environments/production.rb +0 -88
  191. data/test/rails_app/config/environments/test.rb +0 -47
  192. data/test/rails_app/config/initializers/backtrace_silencers.rb +0 -9
  193. data/test/rails_app/config/initializers/devise.rb +0 -182
  194. data/test/rails_app/config/initializers/inflections.rb +0 -4
  195. data/test/rails_app/config/initializers/secret_token.rb +0 -5
  196. data/test/rails_app/config/initializers/session_store.rb +0 -3
  197. data/test/rails_app/config/routes.rb +0 -128
  198. data/test/rails_app/db/migrate/20100401102949_create_tables.rb +0 -77
  199. data/test/rails_app/db/schema.rb +0 -57
  200. data/test/rails_app/lib/shared_admin.rb +0 -23
  201. data/test/rails_app/lib/shared_user.rb +0 -32
  202. data/test/rails_app/lib/shared_user_without_email.rb +0 -28
  203. data/test/rails_app/lib/shared_user_without_omniauth.rb +0 -15
  204. data/test/rails_app/public/404.html +0 -26
  205. data/test/rails_app/public/422.html +0 -26
  206. data/test/rails_app/public/500.html +0 -26
  207. data/test/rails_app/public/favicon.ico +0 -0
  208. data/test/rails_test.rb +0 -11
  209. data/test/routes_test.rb +0 -281
  210. data/test/secret_key_finder_test.rb +0 -97
  211. data/test/support/action_controller/record_identifier.rb +0 -12
  212. data/test/support/assertions.rb +0 -30
  213. data/test/support/helpers.rb +0 -83
  214. data/test/support/http_method_compatibility.rb +0 -53
  215. data/test/support/integration.rb +0 -95
  216. data/test/support/locale/en.yml +0 -8
  217. data/test/support/mongoid.yml +0 -6
  218. data/test/support/webrat/integrations/rails.rb +0 -35
  219. data/test/test/controller_helpers_test.rb +0 -193
  220. data/test/test/integration_helpers_test.rb +0 -34
  221. data/test/test_helper.rb +0 -36
  222. data/test/test_models.rb +0 -35
@@ -1,106 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- begin
4
- require 'bundler/inline'
5
- rescue LoadError => e
6
- $stderr.puts 'Bundler version 1.10 or later is required. Please update your Bundler'
7
- raise e
8
- end
9
-
10
- gemfile(true) do
11
- source 'https://rubygems.org'
12
- # Activate the gem you are reporting the issue against.
13
- gem 'rails', '~> 4.2.0'
14
- gem 'devise', '~> 4.0'
15
- gem 'sqlite3'
16
- gem 'byebug'
17
- end
18
-
19
- require 'rack/test'
20
- require 'action_controller/railtie'
21
- require 'active_record'
22
- require 'devise/rails/routes'
23
- require 'devise/rails/warden_compat'
24
-
25
- ActiveRecord::Base.establish_connection( adapter: :sqlite3, database: ':memory:')
26
-
27
- class DeviseCreateUsers < ActiveRecord::Migration
28
- def change
29
- create_table(:users) do |t|
30
- t.string :email, null: false
31
- t.string :encrypted_password, null: true
32
- t.timestamps null: false
33
- end
34
-
35
- end
36
- end
37
-
38
- Devise.setup do |config|
39
- require 'devise/orm/active_record'
40
- config.secret_key = 'secret_key_base'
41
- end
42
-
43
- class TestApp < Rails::Application
44
- config.root = File.dirname(__FILE__)
45
- config.session_store :cookie_store, key: 'cookie_store_key'
46
- secrets.secret_token = 'secret_token'
47
- secrets.secret_key_base = 'secret_key_base'
48
- config.eager_load = false
49
-
50
- config.middleware.use Warden::Manager do |config|
51
- Devise.warden_config = config
52
- end
53
-
54
- config.logger = Logger.new($stdout)
55
- Rails.logger = config.logger
56
-
57
- end
58
-
59
- Rails.application.initialize!
60
-
61
- DeviseCreateUsers.migrate(:up)
62
-
63
- class User < ActiveRecord::Base
64
- devise :database_authenticatable
65
- end
66
-
67
- Rails.application.routes.draw do
68
- devise_for :users
69
-
70
- get '/' => 'test#index'
71
- end
72
-
73
- class ApplicationController < ActionController::Base
74
- end
75
-
76
- class TestController < ApplicationController
77
- include Rails.application.routes.url_helpers
78
-
79
- before_filter :authenticate_user!
80
-
81
- def index
82
- render plain: 'Home'
83
- end
84
- end
85
-
86
- require 'minitest/autorun'
87
-
88
- class BugTest < ActionDispatch::IntegrationTest
89
- include Rack::Test::Methods
90
- include Warden::Test::Helpers
91
-
92
- def test_returns_success
93
- Warden.test_mode!
94
-
95
- login_as User.create!(email: 'test@test.com', password: 'test123456', password_confirmation: 'test123456')
96
-
97
- get '/'
98
- assert last_response.ok?
99
- end
100
-
101
- private
102
-
103
- def app
104
- Rails.application
105
- end
106
- end
@@ -1,42 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'test_helper'
4
-
5
- class CustomRegistrationsControllerTest < Devise::ControllerTestCase
6
- tests Custom::RegistrationsController
7
-
8
- include Devise::Test::ControllerHelpers
9
-
10
- setup do
11
- request.env["devise.mapping"] = Devise.mappings[:user]
12
- @password = 'password'
13
- @user = create_user(password: @password, password_confirmation: @password).tap(&:confirm)
14
- end
15
-
16
- test "yield resource to block on create success" do
17
- post :create, params: { user: { email: "user@example.org", password: "password", password_confirmation: "password" } }
18
- assert @controller.create_block_called?, "create failed to yield resource to provided block"
19
- end
20
-
21
- test "yield resource to block on create failure" do
22
- post :create, params: { user: { } }
23
- assert @controller.create_block_called?, "create failed to yield resource to provided block"
24
- end
25
-
26
- test "yield resource to block on update success" do
27
- sign_in @user
28
- put :update, params: { user: { current_password: @password } }
29
- assert @controller.update_block_called?, "update failed to yield resource to provided block"
30
- end
31
-
32
- test "yield resource to block on update failure" do
33
- sign_in @user
34
- put :update, params: { user: { } }
35
- assert @controller.update_block_called?, "update failed to yield resource to provided block"
36
- end
37
-
38
- test "yield resource to block on new" do
39
- get :new
40
- assert @controller.new_block_called?, "new failed to yield resource to provided block"
41
- end
42
- end
@@ -1,66 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'test_helper'
4
- require 'ostruct'
5
- require 'warden/strategies/base'
6
- require 'devise/test_helpers'
7
-
8
- class CustomStrategyController < ActionController::Base
9
- def new
10
- warden.authenticate!(:custom_strategy)
11
- end
12
- end
13
-
14
- # These tests are to prove that a warden strategy can successfully
15
- # return a custom response, including a specific status code and
16
- # custom http response headers. This does work in production,
17
- # however, at the time of writing this, the Devise test helpers do
18
- # not recognise the custom response and proceed to calling the
19
- # Failure App. This makes it impossible to write tests for a
20
- # strategy that return a custom response with Devise.
21
- class CustomStrategy < Warden::Strategies::Base
22
- def authenticate!
23
- custom_headers = { "X-FOO" => "BAR" }
24
- response = Rack::Response.new("BAD REQUEST", 400, custom_headers)
25
- custom! response.finish
26
- end
27
- end
28
-
29
- class CustomStrategyTest < Devise::ControllerTestCase
30
- tests CustomStrategyController
31
-
32
- include Devise::Test::ControllerHelpers
33
-
34
- setup do
35
- Warden::Strategies.add(:custom_strategy, CustomStrategy)
36
- end
37
-
38
- teardown do
39
- Warden::Strategies._strategies.delete(:custom_strategy)
40
- end
41
-
42
- test "custom strategy can return its own status code" do
43
- ret = get :new
44
-
45
- # check the returned rack array
46
- # assert ret.is_a?(Array)
47
- # assert_equal 400, ret.first
48
- assert ret.is_a?(ActionDispatch::TestResponse)
49
-
50
- # check the saved response as well. This is purely so that the response is available to the testing framework
51
- # for verification. In production, the above array would be delivered directly to Rack.
52
- assert_response 400
53
- end
54
-
55
- test "custom strategy can return custom headers" do
56
- ret = get :new
57
-
58
- # check the returned rack array
59
- # assert ret.is_a?(Array)
60
- # assert_equal ret.third['X-FOO'], 'BAR'
61
- assert ret.is_a?(ActionDispatch::TestResponse)
62
-
63
- # check the saved response headers as well.
64
- assert_equal response.headers['X-FOO'], 'BAR'
65
- end
66
- end
@@ -1,24 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'test_helper'
4
-
5
- class ApiController < ActionController::Metal
6
- include Devise::Controllers::Helpers
7
- end
8
-
9
- class HelperMethodsTest < Devise::ControllerTestCase
10
- tests ApiController
11
-
12
- test 'includes Devise::Controllers::Helpers' do
13
- assert_includes @controller.class.ancestors, Devise::Controllers::Helpers
14
- end
15
-
16
- test 'does not respond_to helper or helper_method' do
17
- refute_respond_to @controller.class, :helper
18
- refute_respond_to @controller.class, :helper_method
19
- end
20
-
21
- test 'defines methods like current_user' do
22
- assert_respond_to @controller, :current_user
23
- end
24
- end
@@ -1,318 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'test_helper'
4
- require 'ostruct'
5
-
6
- class ControllerAuthenticatableTest < Devise::ControllerTestCase
7
- tests ApplicationController
8
-
9
- def setup
10
- @mock_warden = OpenStruct.new
11
- @controller.request.env['warden'] = @mock_warden
12
- end
13
-
14
- test 'provide access to warden instance' do
15
- assert_equal @mock_warden, @controller.warden
16
- end
17
-
18
- test 'proxy signed_in?(scope) to authenticate?' do
19
- @mock_warden.expects(:authenticate?).with(scope: :my_scope)
20
- @controller.signed_in?(:my_scope)
21
- end
22
-
23
- test 'proxy signed_in?(nil) to authenticate?' do
24
- Devise.mappings.keys.each do |scope| # :user, :admin, :manager
25
- @mock_warden.expects(:authenticate?).with(scope: scope)
26
- end
27
- @controller.signed_in?
28
- end
29
-
30
- test 'proxy [group]_signed_in? to authenticate? with each scope' do
31
- [:user, :admin].each do |scope|
32
- @mock_warden.expects(:authenticate?).with(scope: scope).returns(false)
33
- end
34
- @controller.commenter_signed_in?
35
- end
36
-
37
- test 'proxy current_user to authenticate with user scope' do
38
- @mock_warden.expects(:authenticate).with(scope: :user)
39
- @controller.current_user
40
- end
41
-
42
- test 'proxy current_admin to authenticate with admin scope' do
43
- @mock_warden.expects(:authenticate).with(scope: :admin)
44
- @controller.current_admin
45
- end
46
-
47
- test 'proxy current_[group] to authenticate with each scope' do
48
- [:user, :admin].each do |scope|
49
- @mock_warden.expects(:authenticate).with(scope: scope).returns(nil)
50
- end
51
- @controller.current_commenter
52
- end
53
-
54
- test 'proxy current_[plural_group] to authenticate with each scope' do
55
- [:user, :admin].each do |scope|
56
- @mock_warden.expects(:authenticate).with(scope: scope)
57
- end
58
- @controller.current_commenters
59
- end
60
-
61
- test 'proxy current_publisher_account to authenticate with namespaced publisher account scope' do
62
- @mock_warden.expects(:authenticate).with(scope: :publisher_account)
63
- @controller.current_publisher_account
64
- end
65
-
66
- test 'proxy authenticate_user! to authenticate with user scope' do
67
- @mock_warden.expects(:authenticate!).with(scope: :user)
68
- @controller.authenticate_user!
69
- end
70
-
71
- test 'proxy authenticate_user! options to authenticate with user scope' do
72
- @mock_warden.expects(:authenticate!).with(scope: :user, recall: "foo")
73
- @controller.authenticate_user!(recall: "foo")
74
- end
75
-
76
- test 'proxy authenticate_admin! to authenticate with admin scope' do
77
- @mock_warden.expects(:authenticate!).with(scope: :admin)
78
- @controller.authenticate_admin!
79
- end
80
-
81
- test 'proxy authenticate_[group]! to authenticate!? with each scope' do
82
- [:user, :admin].each do |scope|
83
- @mock_warden.expects(:authenticate!).with(scope: scope)
84
- @mock_warden.expects(:authenticate?).with(scope: scope).returns(false)
85
- end
86
- @controller.authenticate_commenter!
87
- end
88
-
89
- test 'proxy authenticate_publisher_account! to authenticate with namespaced publisher account scope' do
90
- @mock_warden.expects(:authenticate!).with(scope: :publisher_account)
91
- @controller.authenticate_publisher_account!
92
- end
93
-
94
- test 'proxy user_signed_in? to authenticate with user scope' do
95
- @mock_warden.expects(:authenticate).with(scope: :user).returns("user")
96
- assert @controller.user_signed_in?
97
- end
98
-
99
- test 'proxy admin_signed_in? to authenticatewith admin scope' do
100
- @mock_warden.expects(:authenticate).with(scope: :admin)
101
- refute @controller.admin_signed_in?
102
- end
103
-
104
- test 'proxy publisher_account_signed_in? to authenticate with namespaced publisher account scope' do
105
- @mock_warden.expects(:authenticate).with(scope: :publisher_account)
106
- @controller.publisher_account_signed_in?
107
- end
108
-
109
- test 'proxy user_session to session scope in warden' do
110
- @mock_warden.expects(:authenticate).with(scope: :user).returns(true)
111
- @mock_warden.expects(:session).with(:user).returns({})
112
- @controller.user_session
113
- end
114
-
115
- test 'proxy admin_session to session scope in warden' do
116
- @mock_warden.expects(:authenticate).with(scope: :admin).returns(true)
117
- @mock_warden.expects(:session).with(:admin).returns({})
118
- @controller.admin_session
119
- end
120
-
121
- test 'proxy publisher_account_session from namespaced scope to session scope in warden' do
122
- @mock_warden.expects(:authenticate).with(scope: :publisher_account).returns(true)
123
- @mock_warden.expects(:session).with(:publisher_account).returns({})
124
- @controller.publisher_account_session
125
- end
126
-
127
- test 'sign in proxy to set_user on warden' do
128
- user = User.new
129
- @mock_warden.expects(:user).returns(nil)
130
- @mock_warden.expects(:set_user).with(user, scope: :user).returns(true)
131
- @controller.sign_in(:user, user)
132
- end
133
-
134
- test 'sign in accepts a resource as argument' do
135
- user = User.new
136
- @mock_warden.expects(:user).returns(nil)
137
- @mock_warden.expects(:set_user).with(user, scope: :user).returns(true)
138
- @controller.sign_in(user)
139
- end
140
-
141
- test 'does not sign in again if the user is already in' do
142
- user = User.new
143
- @mock_warden.expects(:user).returns(user)
144
- @mock_warden.expects(:set_user).never
145
- assert @controller.sign_in(user)
146
- end
147
-
148
- test 'sign in again when the user is already in only if force is given' do
149
- user = User.new
150
- @mock_warden.expects(:user).returns(user)
151
- @mock_warden.expects(:set_user).with(user, scope: :user).returns(true)
152
- @controller.sign_in(user, force: true)
153
- end
154
-
155
- test 'bypass the sign in' do
156
- user = User.new
157
- @mock_warden.expects(:session_serializer).returns(serializer = mock())
158
- serializer.expects(:store).with(user, :user)
159
- @controller.bypass_sign_in(user)
160
- end
161
-
162
- test 'sign out clears up any signed in user from all scopes' do
163
- user = User.new
164
- @mock_warden.expects(:user).times(Devise.mappings.size)
165
- @mock_warden.expects(:logout).with().returns(true)
166
- @controller.instance_variable_set(:@current_user, user)
167
- @controller.instance_variable_set(:@current_admin, user)
168
- @controller.sign_out
169
- assert_nil @controller.instance_variable_get(:@current_user)
170
- assert_nil @controller.instance_variable_get(:@current_admin)
171
- end
172
-
173
- test 'sign out logs out and clears up any signed in user by scope' do
174
- user = User.new
175
- @mock_warden.expects(:user).with(scope: :user, run_callbacks: false).returns(user)
176
- @mock_warden.expects(:logout).with(:user).returns(true)
177
- @mock_warden.expects(:clear_strategies_cache!).with(scope: :user).returns(true)
178
- @controller.instance_variable_set(:@current_user, user)
179
- @controller.sign_out(:user)
180
- assert_nil @controller.instance_variable_get(:@current_user)
181
- end
182
-
183
- test 'sign out accepts a resource as argument' do
184
- @mock_warden.expects(:user).with(scope: :user, run_callbacks: false).returns(true)
185
- @mock_warden.expects(:logout).with(:user).returns(true)
186
- @mock_warden.expects(:clear_strategies_cache!).with(scope: :user).returns(true)
187
- @controller.sign_out(User.new)
188
- end
189
-
190
- test 'sign out without args proxy to sign out all scopes' do
191
- @mock_warden.expects(:user).times(Devise.mappings.size)
192
- @mock_warden.expects(:logout).with().returns(true)
193
- @mock_warden.expects(:clear_strategies_cache!).with().returns(true)
194
- @controller.sign_out
195
- end
196
-
197
- test 'sign out everybody proxy to logout on warden' do
198
- @mock_warden.expects(:user).times(Devise.mappings.size)
199
- @mock_warden.expects(:logout).with().returns(true)
200
- @controller.sign_out_all_scopes
201
- end
202
-
203
- test 'stored location for returns the location for a given scope' do
204
- assert_nil @controller.stored_location_for(:user)
205
- @controller.session[:"user_return_to"] = "/foo.bar"
206
- assert_equal "/foo.bar", @controller.stored_location_for(:user)
207
- end
208
-
209
- test 'stored location for accepts a resource as argument' do
210
- assert_nil @controller.stored_location_for(:user)
211
- @controller.session[:"user_return_to"] = "/foo.bar"
212
- assert_equal "/foo.bar", @controller.stored_location_for(User.new)
213
- end
214
-
215
- test 'stored location cleans information after reading' do
216
- @controller.session[:"user_return_to"] = "/foo.bar"
217
- assert_equal "/foo.bar", @controller.stored_location_for(:user)
218
- assert_nil @controller.session[:"user_return_to"]
219
- end
220
-
221
- test 'store location for stores a location to redirect back to' do
222
- assert_nil @controller.stored_location_for(:user)
223
- @controller.store_location_for(:user, "/foo.bar")
224
- assert_equal "/foo.bar", @controller.stored_location_for(:user)
225
- end
226
-
227
- test 'store bad location for stores a location to redirect back to' do
228
- assert_nil @controller.stored_location_for(:user)
229
- @controller.store_location_for(:user, "/foo.bar\">Carry")
230
- assert_nil @controller.stored_location_for(:user)
231
- end
232
-
233
- test 'store location for accepts a resource as argument' do
234
- @controller.store_location_for(User.new, "/foo.bar")
235
- assert_equal "/foo.bar", @controller.stored_location_for(User.new)
236
- end
237
-
238
- test 'store location for stores paths' do
239
- @controller.store_location_for(:user, "//host/foo.bar")
240
- assert_equal "/foo.bar", @controller.stored_location_for(:user)
241
- @controller.store_location_for(:user, "///foo.bar")
242
- assert_equal "/foo.bar", @controller.stored_location_for(:user)
243
- end
244
-
245
- test 'store location for stores query string' do
246
- @controller.store_location_for(:user, "/foo?bar=baz")
247
- assert_equal "/foo?bar=baz", @controller.stored_location_for(:user)
248
- end
249
-
250
- test 'store location for stores fragments' do
251
- @controller.store_location_for(:user, "/foo#bar")
252
- assert_equal "/foo#bar", @controller.stored_location_for(:user)
253
- end
254
-
255
- test 'after sign in path defaults to root path if none by was specified for the given scope' do
256
- assert_equal root_path, @controller.after_sign_in_path_for(:user)
257
- end
258
-
259
- test 'after sign in path defaults to the scoped root path' do
260
- assert_equal admin_root_path, @controller.after_sign_in_path_for(:admin)
261
- end
262
-
263
- test 'after sign out path defaults to the root path' do
264
- assert_equal root_path, @controller.after_sign_out_path_for(:admin)
265
- assert_equal root_path, @controller.after_sign_out_path_for(:user)
266
- end
267
-
268
- test 'sign in and redirect uses the stored location' do
269
- user = User.new
270
- @controller.session[:user_return_to] = "/foo.bar"
271
- @mock_warden.expects(:user).with(:user).returns(nil)
272
- @mock_warden.expects(:set_user).with(user, scope: :user).returns(true)
273
- @controller.expects(:redirect_to).with("/foo.bar")
274
- @controller.sign_in_and_redirect(user)
275
- end
276
-
277
- test 'sign in and redirect uses the configured after sign in path' do
278
- admin = Admin.new
279
- @mock_warden.expects(:user).with(:admin).returns(nil)
280
- @mock_warden.expects(:set_user).with(admin, scope: :admin).returns(true)
281
- @controller.expects(:redirect_to).with(admin_root_path)
282
- @controller.sign_in_and_redirect(admin)
283
- end
284
-
285
- test 'sign in and redirect does not sign in again if user is already signed' do
286
- admin = Admin.new
287
- @mock_warden.expects(:user).with(:admin).returns(admin)
288
- @mock_warden.expects(:set_user).never
289
- @controller.expects(:redirect_to).with(admin_root_path)
290
- @controller.sign_in_and_redirect(admin)
291
- end
292
-
293
- test 'sign out and redirect uses the configured after sign out path when signing out only the current scope' do
294
- swap Devise, sign_out_all_scopes: false do
295
- @mock_warden.expects(:user).with(scope: :admin, run_callbacks: false).returns(true)
296
- @mock_warden.expects(:logout).with(:admin).returns(true)
297
- @mock_warden.expects(:clear_strategies_cache!).with(scope: :admin).returns(true)
298
- @controller.expects(:redirect_to).with(admin_root_path)
299
- @controller.instance_eval "def after_sign_out_path_for(resource); admin_root_path; end"
300
- @controller.sign_out_and_redirect(:admin)
301
- end
302
- end
303
-
304
- test 'sign out and redirect uses the configured after sign out path when signing out all scopes' do
305
- swap Devise, sign_out_all_scopes: true do
306
- @mock_warden.expects(:user).times(Devise.mappings.size)
307
- @mock_warden.expects(:logout).with().returns(true)
308
- @mock_warden.expects(:clear_strategies_cache!).with().returns(true)
309
- @controller.expects(:redirect_to).with(admin_root_path)
310
- @controller.instance_eval "def after_sign_out_path_for(resource); admin_root_path; end"
311
- @controller.sign_out_and_redirect(:admin)
312
- end
313
- end
314
-
315
- test 'is not a devise controller' do
316
- refute @controller.devise_controller?
317
- end
318
- end