devise 3.2.4 → 4.0.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.
- checksums.yaml +4 -4
- data/.gitignore +0 -1
- data/.travis.yml +33 -17
- data/CHANGELOG.md +57 -1033
- data/CODE_OF_CONDUCT.md +22 -0
- data/CONTRIBUTING.md +2 -0
- data/Gemfile +5 -5
- data/Gemfile.lock +138 -115
- data/MIT-LICENSE +1 -1
- data/README.md +124 -65
- data/Rakefile +2 -1
- data/app/controllers/devise/confirmations_controller.rb +7 -3
- data/app/controllers/devise/omniauth_callbacks_controller.rb +8 -4
- data/app/controllers/devise/passwords_controller.rb +16 -6
- data/app/controllers/devise/registrations_controller.rb +22 -10
- data/app/controllers/devise/sessions_controller.rb +42 -14
- data/app/controllers/devise/unlocks_controller.rb +5 -2
- data/app/controllers/devise_controller.rb +63 -29
- data/app/mailers/devise/mailer.rb +4 -0
- data/app/views/devise/confirmations/new.html.erb +7 -3
- data/app/views/devise/mailer/password_change.html.erb +3 -0
- data/app/views/devise/passwords/edit.html.erb +14 -5
- data/app/views/devise/passwords/new.html.erb +7 -3
- data/app/views/devise/registrations/edit.html.erb +19 -9
- data/app/views/devise/registrations/new.html.erb +18 -7
- data/app/views/devise/sessions/new.html.erb +16 -7
- data/app/views/devise/shared/{_links.erb → _links.html.erb} +2 -2
- data/app/views/devise/unlocks/new.html.erb +7 -3
- data/bin/test +13 -0
- data/config/locales/en.yml +19 -16
- data/devise.gemspec +3 -4
- data/gemfiles/{Gemfile.rails-3.2-stable → Gemfile.rails-4.1-stable} +6 -6
- data/gemfiles/Gemfile.rails-4.1-stable.lock +167 -0
- data/gemfiles/{Gemfile.rails-head → Gemfile.rails-4.2-stable} +6 -6
- data/gemfiles/Gemfile.rails-4.2-stable.lock +189 -0
- data/gemfiles/Gemfile.rails-5.0-beta +37 -0
- data/gemfiles/Gemfile.rails-5.0-beta.lock +199 -0
- data/lib/devise/controllers/helpers.rb +94 -27
- data/lib/devise/controllers/rememberable.rb +9 -2
- data/lib/devise/controllers/sign_in_out.rb +2 -9
- data/lib/devise/controllers/store_location.rb +11 -3
- data/lib/devise/controllers/url_helpers.rb +7 -7
- data/lib/devise/encryptor.rb +22 -0
- data/lib/devise/failure_app.rb +72 -23
- data/lib/devise/hooks/activatable.rb +3 -4
- data/lib/devise/hooks/csrf_cleaner.rb +3 -1
- data/lib/devise/hooks/timeoutable.rb +13 -8
- data/lib/devise/mailers/helpers.rb +1 -1
- data/lib/devise/mapping.rb +6 -2
- data/lib/devise/models/authenticatable.rb +32 -28
- data/lib/devise/models/confirmable.rb +55 -22
- data/lib/devise/models/database_authenticatable.rb +32 -19
- data/lib/devise/models/lockable.rb +5 -5
- data/lib/devise/models/recoverable.rb +44 -20
- data/lib/devise/models/rememberable.rb +54 -27
- data/lib/devise/models/timeoutable.rb +0 -6
- data/lib/devise/models/trackable.rb +5 -3
- data/lib/devise/models/validatable.rb +3 -3
- data/lib/devise/models.rb +1 -1
- data/lib/devise/omniauth/url_helpers.rb +62 -4
- data/lib/devise/parameter_sanitizer.rb +176 -61
- data/lib/devise/rails/routes.rb +76 -59
- data/lib/devise/rails/warden_compat.rb +1 -10
- data/lib/devise/rails.rb +2 -11
- data/lib/devise/strategies/authenticatable.rb +15 -6
- data/lib/devise/strategies/database_authenticatable.rb +5 -4
- data/lib/devise/strategies/rememberable.rb +13 -3
- data/lib/devise/test_helpers.rb +12 -7
- data/lib/devise/token_generator.rb +1 -41
- data/lib/devise/version.rb +1 -1
- data/lib/devise.rb +150 -58
- data/lib/generators/active_record/devise_generator.rb +28 -4
- data/lib/generators/active_record/templates/migration.rb +3 -3
- data/lib/generators/active_record/templates/migration_existing.rb +3 -3
- data/lib/generators/devise/controllers_generator.rb +44 -0
- data/lib/generators/devise/install_generator.rb +15 -0
- data/lib/generators/devise/orm_helpers.rb +1 -18
- data/lib/generators/devise/views_generator.rb +14 -3
- data/lib/generators/templates/README +1 -1
- data/lib/generators/templates/controllers/README +14 -0
- data/lib/generators/templates/controllers/confirmations_controller.rb +28 -0
- data/lib/generators/templates/controllers/omniauth_callbacks_controller.rb +28 -0
- data/lib/generators/templates/controllers/passwords_controller.rb +32 -0
- data/lib/generators/templates/controllers/registrations_controller.rb +60 -0
- data/lib/generators/templates/controllers/sessions_controller.rb +25 -0
- data/lib/generators/templates/controllers/unlocks_controller.rb +28 -0
- data/lib/generators/templates/devise.rb +36 -28
- data/lib/generators/templates/markerb/confirmation_instructions.markerb +1 -1
- data/lib/generators/templates/markerb/password_change.markerb +3 -0
- data/lib/generators/templates/markerb/reset_password_instructions.markerb +1 -1
- data/lib/generators/templates/markerb/unlock_instructions.markerb +1 -1
- data/lib/generators/templates/simple_form_for/passwords/edit.html.erb +1 -1
- data/lib/generators/templates/simple_form_for/registrations/new.html.erb +1 -1
- data/lib/generators/templates/simple_form_for/sessions/new.html.erb +2 -2
- data/test/controllers/custom_registrations_controller_test.rb +40 -0
- data/test/controllers/custom_strategy_test.rb +7 -5
- data/test/controllers/helper_methods_test.rb +22 -0
- data/test/controllers/helpers_test.rb +41 -1
- data/test/controllers/inherited_controller_i18n_messages_test.rb +51 -0
- data/test/controllers/internal_helpers_test.rb +19 -15
- data/test/controllers/load_hooks_controller_test.rb +19 -0
- data/test/controllers/passwords_controller_test.rb +5 -4
- data/test/controllers/sessions_controller_test.rb +24 -21
- data/test/controllers/url_helpers_test.rb +7 -1
- data/test/devise_test.rb +48 -8
- data/test/failure_app_test.rb +107 -19
- data/test/generators/active_record_generator_test.rb +6 -26
- data/test/generators/controllers_generator_test.rb +48 -0
- data/test/generators/install_generator_test.rb +14 -3
- data/test/generators/views_generator_test.rb +8 -1
- data/test/helpers/devise_helper_test.rb +10 -12
- data/test/integration/authenticatable_test.rb +37 -21
- data/test/integration/confirmable_test.rb +54 -14
- data/test/integration/database_authenticatable_test.rb +12 -1
- data/test/integration/http_authenticatable_test.rb +4 -5
- data/test/integration/lockable_test.rb +10 -9
- data/test/integration/omniauthable_test.rb +13 -11
- data/test/integration/recoverable_test.rb +28 -15
- data/test/integration/registerable_test.rb +41 -33
- data/test/integration/rememberable_test.rb +51 -7
- data/test/integration/timeoutable_test.rb +23 -22
- data/test/integration/trackable_test.rb +3 -3
- data/test/mailers/confirmation_instructions_test.rb +10 -10
- data/test/mailers/reset_password_instructions_test.rb +8 -8
- data/test/mailers/unlock_instructions_test.rb +8 -8
- data/test/mapping_test.rb +7 -0
- data/test/models/authenticatable_test.rb +11 -1
- data/test/models/confirmable_test.rb +91 -42
- data/test/models/database_authenticatable_test.rb +26 -6
- data/test/models/lockable_test.rb +29 -17
- data/test/models/recoverable_test.rb +74 -7
- data/test/models/rememberable_test.rb +68 -94
- data/test/models/trackable_test.rb +28 -0
- data/test/models/validatable_test.rb +9 -17
- data/test/models_test.rb +15 -6
- data/test/omniauth/url_helpers_test.rb +4 -7
- data/test/orm/active_record.rb +6 -1
- data/test/parameter_sanitizer_test.rb +103 -53
- data/test/rails_app/app/active_record/user.rb +1 -0
- data/test/rails_app/app/active_record/user_on_engine.rb +7 -0
- data/test/rails_app/app/active_record/user_on_main_app.rb +7 -0
- data/test/rails_app/app/active_record/user_without_email.rb +8 -0
- data/test/rails_app/app/controllers/admins_controller.rb +1 -6
- data/test/rails_app/app/controllers/application_controller.rb +5 -2
- data/test/rails_app/app/controllers/application_with_fake_engine.rb +30 -0
- data/test/rails_app/app/controllers/custom/registrations_controller.rb +31 -0
- data/test/rails_app/app/controllers/home_controller.rb +5 -1
- data/test/rails_app/app/controllers/users/omniauth_callbacks_controller.rb +3 -3
- data/test/rails_app/app/controllers/users_controller.rb +6 -6
- data/test/rails_app/app/mailers/users/from_proc_mailer.rb +3 -0
- data/test/rails_app/app/mailers/users/mailer.rb +0 -9
- data/test/rails_app/app/mailers/users/reply_to_mailer.rb +4 -0
- data/test/rails_app/app/mongoid/user_on_engine.rb +39 -0
- data/test/rails_app/app/mongoid/user_on_main_app.rb +39 -0
- data/test/rails_app/app/mongoid/user_without_email.rb +33 -0
- data/test/rails_app/config/application.rb +3 -3
- data/test/rails_app/config/boot.rb +4 -4
- data/test/rails_app/config/environments/production.rb +6 -2
- data/test/rails_app/config/environments/test.rb +13 -3
- data/test/rails_app/config/initializers/devise.rb +15 -16
- data/test/rails_app/config/initializers/secret_token.rb +1 -6
- data/test/rails_app/config/routes.rb +23 -3
- data/test/rails_app/db/migrate/20100401102949_create_tables.rb +2 -2
- data/test/rails_app/lib/shared_user.rb +1 -1
- data/test/rails_app/lib/shared_user_without_email.rb +26 -0
- data/test/rails_app/lib/shared_user_without_omniauth.rb +13 -0
- data/test/rails_test.rb +9 -0
- data/test/routes_test.rb +33 -16
- data/test/support/assertions.rb +2 -3
- data/test/support/helpers.rb +13 -6
- data/test/support/http_method_compatibility.rb +51 -0
- data/test/support/integration.rb +4 -4
- data/test/support/webrat/integrations/rails.rb +9 -0
- data/test/test_helper.rb +7 -0
- data/test/test_helpers_test.rb +43 -38
- data/test/test_models.rb +3 -3
- metadata +77 -23
- data/gemfiles/Gemfile.rails-4.0-stable +0 -29
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class ApiController < ActionController::Metal
|
4
|
+
include Devise::Controllers::Helpers
|
5
|
+
end
|
6
|
+
|
7
|
+
class HelperMethodsTest < Devise::ControllerTestCase
|
8
|
+
tests ApiController
|
9
|
+
|
10
|
+
test 'includes Devise::Controllers::Helpers' do
|
11
|
+
assert_includes @controller.class.ancestors, Devise::Controllers::Helpers
|
12
|
+
end
|
13
|
+
|
14
|
+
test 'does not respond_to helper or helper_method' do
|
15
|
+
refute_respond_to @controller.class, :helper
|
16
|
+
refute_respond_to @controller.class, :helper_method
|
17
|
+
end
|
18
|
+
|
19
|
+
test 'defines methods like current_user' do
|
20
|
+
assert_respond_to @controller, :current_user
|
21
|
+
end
|
22
|
+
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
require 'ostruct'
|
3
3
|
|
4
|
-
class ControllerAuthenticatableTest <
|
4
|
+
class ControllerAuthenticatableTest < Devise::ControllerTestCase
|
5
5
|
tests ApplicationController
|
6
6
|
|
7
7
|
def setup
|
@@ -25,6 +25,13 @@ class ControllerAuthenticatableTest < ActionController::TestCase
|
|
25
25
|
@controller.signed_in?
|
26
26
|
end
|
27
27
|
|
28
|
+
test 'proxy [group]_signed_in? to authenticate? with each scope' do
|
29
|
+
[:user, :admin].each do |scope|
|
30
|
+
@mock_warden.expects(:authenticate?).with(scope: scope).returns(false)
|
31
|
+
end
|
32
|
+
@controller.commenter_signed_in?
|
33
|
+
end
|
34
|
+
|
28
35
|
test 'proxy current_user to authenticate with user scope' do
|
29
36
|
@mock_warden.expects(:authenticate).with(scope: :user)
|
30
37
|
@controller.current_user
|
@@ -35,6 +42,20 @@ class ControllerAuthenticatableTest < ActionController::TestCase
|
|
35
42
|
@controller.current_admin
|
36
43
|
end
|
37
44
|
|
45
|
+
test 'proxy current_[group] to authenticate with each scope' do
|
46
|
+
[:user, :admin].each do |scope|
|
47
|
+
@mock_warden.expects(:authenticate).with(scope: scope).returns(nil)
|
48
|
+
end
|
49
|
+
@controller.current_commenter
|
50
|
+
end
|
51
|
+
|
52
|
+
test 'proxy current_[plural_group] to authenticate with each scope' do
|
53
|
+
[:user, :admin].each do |scope|
|
54
|
+
@mock_warden.expects(:authenticate).with(scope: scope)
|
55
|
+
end
|
56
|
+
@controller.current_commenters
|
57
|
+
end
|
58
|
+
|
38
59
|
test 'proxy current_publisher_account to authenticate with namespaced publisher account scope' do
|
39
60
|
@mock_warden.expects(:authenticate).with(scope: :publisher_account)
|
40
61
|
@controller.current_publisher_account
|
@@ -55,6 +76,14 @@ class ControllerAuthenticatableTest < ActionController::TestCase
|
|
55
76
|
@controller.authenticate_admin!
|
56
77
|
end
|
57
78
|
|
79
|
+
test 'proxy authenticate_[group]! to authenticate!? with each scope' do
|
80
|
+
[:user, :admin].each do |scope|
|
81
|
+
@mock_warden.expects(:authenticate!).with(scope: scope)
|
82
|
+
@mock_warden.expects(:authenticate?).with(scope: scope).returns(false)
|
83
|
+
end
|
84
|
+
@controller.authenticate_commenter!
|
85
|
+
end
|
86
|
+
|
58
87
|
test 'proxy authenticate_publisher_account! to authenticate with namespaced publisher account scope' do
|
59
88
|
@mock_warden.expects(:authenticate!).with(scope: :publisher_account)
|
60
89
|
@controller.authenticate_publisher_account!
|
@@ -193,6 +222,12 @@ class ControllerAuthenticatableTest < ActionController::TestCase
|
|
193
222
|
assert_equal "/foo.bar", @controller.stored_location_for(:user)
|
194
223
|
end
|
195
224
|
|
225
|
+
test 'store bad location for stores a location to redirect back to' do
|
226
|
+
assert_nil @controller.stored_location_for(:user)
|
227
|
+
@controller.store_location_for(:user, "/foo.bar\">Carry")
|
228
|
+
assert_nil @controller.stored_location_for(:user)
|
229
|
+
end
|
230
|
+
|
196
231
|
test 'store location for accepts a resource as argument' do
|
197
232
|
@controller.store_location_for(User.new, "/foo.bar")
|
198
233
|
assert_equal "/foo.bar", @controller.stored_location_for(User.new)
|
@@ -210,6 +245,11 @@ class ControllerAuthenticatableTest < ActionController::TestCase
|
|
210
245
|
assert_equal "/foo?bar=baz", @controller.stored_location_for(:user)
|
211
246
|
end
|
212
247
|
|
248
|
+
test 'store location for stores fragments' do
|
249
|
+
@controller.store_location_for(:user, "/foo#bar")
|
250
|
+
assert_equal "/foo#bar", @controller.stored_location_for(:user)
|
251
|
+
end
|
252
|
+
|
213
253
|
test 'after sign in path defaults to root path if none by was specified for the given scope' do
|
214
254
|
assert_equal root_path, @controller.after_sign_in_path_for(:user)
|
215
255
|
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class SessionsInheritedController < Devise::SessionsController
|
4
|
+
def test_i18n_scope
|
5
|
+
set_flash_message(:notice, :signed_in)
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
class AnotherInheritedController < SessionsInheritedController
|
10
|
+
protected
|
11
|
+
|
12
|
+
def translation_scope
|
13
|
+
'another'
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
class InheritedControllerTest < Devise::ControllerTestCase
|
18
|
+
tests SessionsInheritedController
|
19
|
+
|
20
|
+
def setup
|
21
|
+
@mock_warden = OpenStruct.new
|
22
|
+
@controller.request.env['warden'] = @mock_warden
|
23
|
+
@controller.request.env['devise.mapping'] = Devise.mappings[:user]
|
24
|
+
end
|
25
|
+
|
26
|
+
test 'I18n scope is inherited from Devise::Sessions' do
|
27
|
+
I18n.expects(:t).with do |message, options|
|
28
|
+
message == 'user.signed_in' &&
|
29
|
+
options[:scope] == 'devise.sessions'
|
30
|
+
end
|
31
|
+
@controller.test_i18n_scope
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
class AnotherInheritedControllerTest < Devise::ControllerTestCase
|
36
|
+
tests AnotherInheritedController
|
37
|
+
|
38
|
+
def setup
|
39
|
+
@mock_warden = OpenStruct.new
|
40
|
+
@controller.request.env['warden'] = @mock_warden
|
41
|
+
@controller.request.env['devise.mapping'] = Devise.mappings[:user]
|
42
|
+
end
|
43
|
+
|
44
|
+
test 'I18n scope is overridden' do
|
45
|
+
I18n.expects(:t).with do |message, options|
|
46
|
+
message == 'user.signed_in' &&
|
47
|
+
options[:scope] == 'another'
|
48
|
+
end
|
49
|
+
@controller.test_i18n_scope
|
50
|
+
end
|
51
|
+
end
|
@@ -3,7 +3,7 @@ require 'test_helper'
|
|
3
3
|
class MyController < DeviseController
|
4
4
|
end
|
5
5
|
|
6
|
-
class HelpersTest <
|
6
|
+
class HelpersTest < Devise::ControllerTestCase
|
7
7
|
tests MyController
|
8
8
|
|
9
9
|
def setup
|
@@ -13,16 +13,16 @@ class HelpersTest < ActionController::TestCase
|
|
13
13
|
end
|
14
14
|
|
15
15
|
test 'get resource name from env' do
|
16
|
-
assert_equal :user, @controller.resource_name
|
16
|
+
assert_equal :user, @controller.send(:resource_name)
|
17
17
|
end
|
18
18
|
|
19
19
|
test 'get resource class from env' do
|
20
|
-
assert_equal User, @controller.resource_class
|
20
|
+
assert_equal User, @controller.send(:resource_class)
|
21
21
|
end
|
22
22
|
|
23
23
|
test 'get resource instance variable from env' do
|
24
24
|
@controller.instance_variable_set(:@user, user = User.new)
|
25
|
-
assert_equal user, @controller.resource
|
25
|
+
assert_equal user, @controller.send(:resource)
|
26
26
|
end
|
27
27
|
|
28
28
|
test 'set resource instance variable from env' do
|
@@ -36,22 +36,20 @@ class HelpersTest < ActionController::TestCase
|
|
36
36
|
test 'get resource params from request params using resource name as key' do
|
37
37
|
user_params = {'email' => 'shirley@templar.com'}
|
38
38
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
39
|
+
# Stub controller name so strong parameters can filter properly.
|
40
|
+
# DeviseController does not allow any parameters by default.
|
41
|
+
@controller.stubs(:controller_name).returns(:sessions_controller)
|
42
|
+
|
43
|
+
params = ActionController::Parameters.new({'user' => user_params})
|
43
44
|
|
44
|
-
ActionController::Parameters.new({'user' => user_params})
|
45
|
-
else
|
46
|
-
HashWithIndifferentAccess.new({'user' => user_params})
|
47
|
-
end
|
48
45
|
@controller.stubs(:params).returns(params)
|
49
46
|
|
50
|
-
|
47
|
+
res_params = @controller.send(:resource_params).permit!.to_h
|
48
|
+
assert_equal user_params, res_params
|
51
49
|
end
|
52
50
|
|
53
51
|
test 'resources methods are not controller actions' do
|
54
|
-
assert @controller.class.action_methods.empty?
|
52
|
+
assert @controller.class.action_methods.delete_if { |m| m.include? 'commenter' }.empty?
|
55
53
|
end
|
56
54
|
|
57
55
|
test 'require no authentication tests current mapping' do
|
@@ -80,7 +78,7 @@ class HelpersTest < ActionController::TestCase
|
|
80
78
|
|
81
79
|
test 'signed in resource returns signed in resource for current scope' do
|
82
80
|
@mock_warden.expects(:authenticate).with(scope: :user).returns(User.new)
|
83
|
-
assert_kind_of User, @controller.signed_in_resource
|
81
|
+
assert_kind_of User, @controller.send(:signed_in_resource)
|
84
82
|
end
|
85
83
|
|
86
84
|
test 'is a devise controller' do
|
@@ -99,6 +97,12 @@ class HelpersTest < ActionController::TestCase
|
|
99
97
|
assert_equal 'non-blank', flash[:notice]
|
100
98
|
end
|
101
99
|
|
100
|
+
test 'issues non-blank flash.now messages normally' do
|
101
|
+
I18n.stubs(:t).returns('non-blank')
|
102
|
+
@controller.send :set_flash_message, :notice, :send_instructions, { now: true }
|
103
|
+
assert_equal 'non-blank', flash.now[:notice]
|
104
|
+
end
|
105
|
+
|
102
106
|
test 'uses custom i18n options' do
|
103
107
|
@controller.stubs(:devise_i18n_options).returns(default: "devise custom options")
|
104
108
|
@controller.send :set_flash_message, :notice, :invalid_i18n_messagesend_instructions
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class LoadHooksControllerTest < Devise::ControllerTestCase
|
4
|
+
setup do
|
5
|
+
ActiveSupport.on_load(:devise_controller) do
|
6
|
+
define_method :defined_by_load_hook do
|
7
|
+
puts 'I am defined dynamically by activesupport load hook'
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
teardown do
|
13
|
+
DeviseController.class_eval { undef :defined_by_load_hook }
|
14
|
+
end
|
15
|
+
|
16
|
+
test 'load hook called when controller is loaded' do
|
17
|
+
assert DeviseController.instance_methods.include? :defined_by_load_hook
|
18
|
+
end
|
19
|
+
end
|
@@ -1,18 +1,19 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
|
-
class PasswordsControllerTest <
|
3
|
+
class PasswordsControllerTest < Devise::ControllerTestCase
|
4
4
|
tests Devise::PasswordsController
|
5
5
|
include Devise::TestHelpers
|
6
6
|
|
7
7
|
setup do
|
8
8
|
request.env["devise.mapping"] = Devise.mappings[:user]
|
9
|
-
@user = create_user.tap(&:confirm
|
9
|
+
@user = create_user.tap(&:confirm)
|
10
10
|
@raw = @user.send_reset_password_instructions
|
11
11
|
end
|
12
12
|
|
13
13
|
def put_update_with_params
|
14
|
-
put :update, "user" => {
|
15
|
-
|
14
|
+
put :update, params: { "user" => {
|
15
|
+
"reset_password_token" => @raw, "password" => "1234567", "password_confirmation" => "1234567"
|
16
|
+
}
|
16
17
|
}
|
17
18
|
end
|
18
19
|
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
|
-
class SessionsControllerTest <
|
3
|
+
class SessionsControllerTest < Devise::ControllerTestCase
|
4
4
|
tests Devise::SessionsController
|
5
5
|
include Devise::TestHelpers
|
6
6
|
|
@@ -12,9 +12,10 @@ class SessionsControllerTest < ActionController::TestCase
|
|
12
12
|
request.env["devise.mapping"] = Devise.mappings[:user]
|
13
13
|
request.session["user_return_to"] = 'foo.bar'
|
14
14
|
create_user
|
15
|
-
post :create, user: {
|
16
|
-
|
17
|
-
|
15
|
+
post :create, params: { user: {
|
16
|
+
email: "wrong@email.com",
|
17
|
+
password: "wrongpassword"
|
18
|
+
}
|
18
19
|
}
|
19
20
|
assert_equal 200, @response.status
|
20
21
|
ensure
|
@@ -36,12 +37,12 @@ class SessionsControllerTest < ActionController::TestCase
|
|
36
37
|
request.session["user_return_to"] = 'foo.bar'
|
37
38
|
|
38
39
|
user = create_user
|
39
|
-
user.confirm
|
40
|
-
post :create, user: {
|
41
|
-
|
42
|
-
|
40
|
+
user.confirm
|
41
|
+
post :create, params: { user: {
|
42
|
+
email: user.email,
|
43
|
+
password: user.password
|
44
|
+
}
|
43
45
|
}
|
44
|
-
|
45
46
|
assert_nil request.session["user_return_to"]
|
46
47
|
end
|
47
48
|
|
@@ -50,10 +51,11 @@ class SessionsControllerTest < ActionController::TestCase
|
|
50
51
|
request.session["user_return_to"] = 'foo.bar'
|
51
52
|
|
52
53
|
user = create_user
|
53
|
-
user.confirm
|
54
|
-
post :create, format: 'json', user: {
|
55
|
-
|
56
|
-
|
54
|
+
user.confirm
|
55
|
+
post :create, params: { format: 'json', user: {
|
56
|
+
email: user.email,
|
57
|
+
password: user.password
|
58
|
+
}
|
57
59
|
}
|
58
60
|
|
59
61
|
assert_equal 'foo.bar', request.session["user_return_to"]
|
@@ -61,9 +63,10 @@ class SessionsControllerTest < ActionController::TestCase
|
|
61
63
|
|
62
64
|
test "#create doesn't raise exception after Warden authentication fails when TestHelpers included" do
|
63
65
|
request.env["devise.mapping"] = Devise.mappings[:user]
|
64
|
-
post :create, user: {
|
65
|
-
|
66
|
-
|
66
|
+
post :create, params: { user: {
|
67
|
+
email: "nosuchuser@example.com",
|
68
|
+
password: "wevdude"
|
69
|
+
}
|
67
70
|
}
|
68
71
|
assert_equal 200, @response.status
|
69
72
|
assert_template "devise/sessions/new"
|
@@ -72,12 +75,12 @@ class SessionsControllerTest < ActionController::TestCase
|
|
72
75
|
test "#destroy doesn't set the flash if the requested format is not navigational" do
|
73
76
|
request.env["devise.mapping"] = Devise.mappings[:user]
|
74
77
|
user = create_user
|
75
|
-
user.confirm
|
76
|
-
post :create, format: 'json', user: {
|
77
|
-
|
78
|
-
|
78
|
+
user.confirm
|
79
|
+
post :create, params: { format: 'json', user: {
|
80
|
+
email: user.email,
|
81
|
+
password: user.password
|
82
|
+
}
|
79
83
|
}
|
80
|
-
|
81
84
|
delete :destroy, format: 'json'
|
82
85
|
assert flash[:notice].blank?, "flash[:notice] should be blank, not #{flash[:notice].inspect}"
|
83
86
|
assert_equal 204, @response.status
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
|
-
class RoutesTest <
|
3
|
+
class RoutesTest < Devise::ControllerTestCase
|
4
4
|
tests ApplicationController
|
5
5
|
|
6
6
|
def assert_path_and_url(name, prepend_path=nil)
|
@@ -13,6 +13,12 @@ class RoutesTest < ActionController::TestCase
|
|
13
13
|
assert_equal @controller.send(:"#{prepend_path}#{name}_url", :user),
|
14
14
|
send(:"#{prepend_path}user_#{name}_url")
|
15
15
|
|
16
|
+
# With string
|
17
|
+
assert_equal @controller.send(:"#{prepend_path}#{name}_path", "user"),
|
18
|
+
send(:"#{prepend_path}user_#{name}_path")
|
19
|
+
assert_equal @controller.send(:"#{prepend_path}#{name}_url", "user"),
|
20
|
+
send(:"#{prepend_path}user_#{name}_url")
|
21
|
+
|
16
22
|
# Default url params
|
17
23
|
assert_equal @controller.send(:"#{prepend_path}#{name}_path", :user, param: 123),
|
18
24
|
send(:"#{prepend_path}user_#{name}_path", param: 123)
|
data/test/devise_test.rb
CHANGED
@@ -3,10 +3,10 @@ require 'test_helper'
|
|
3
3
|
module Devise
|
4
4
|
def self.yield_and_restore
|
5
5
|
@@warden_configured = nil
|
6
|
-
c, b = @@warden_config, @@
|
6
|
+
c, b = @@warden_config, @@warden_config_blocks
|
7
7
|
yield
|
8
8
|
ensure
|
9
|
-
@@warden_config, @@
|
9
|
+
@@warden_config, @@warden_config_blocks = c, b
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
@@ -14,11 +14,11 @@ class DeviseTest < ActiveSupport::TestCase
|
|
14
14
|
test 'bcrypt on the class' do
|
15
15
|
password = "super secret"
|
16
16
|
klass = Struct.new(:pepper, :stretches).new("blahblah", 2)
|
17
|
-
hash = Devise.
|
17
|
+
hash = Devise::Encryptor.digest(klass, password)
|
18
18
|
assert_equal ::BCrypt::Password.create(hash), hash
|
19
19
|
|
20
20
|
klass = Struct.new(:pepper, :stretches).new("bla", 2)
|
21
|
-
hash = Devise.
|
21
|
+
hash = Devise::Encryptor.digest(klass, password)
|
22
22
|
assert_not_equal ::BCrypt::Password.new(hash), hash
|
23
23
|
end
|
24
24
|
|
@@ -35,6 +35,33 @@ class DeviseTest < ActiveSupport::TestCase
|
|
35
35
|
end
|
36
36
|
end
|
37
37
|
|
38
|
+
test 'setup block warns about defaults changing' do
|
39
|
+
Devise.app_set_configs = Set.new
|
40
|
+
|
41
|
+
ActiveSupport::Deprecation.expects(:warn).with() { |value| value =~ /email_regexp/ }
|
42
|
+
ActiveSupport::Deprecation.expects(:warn).with() { |value| value =~ /reconfirmable/ }
|
43
|
+
ActiveSupport::Deprecation.expects(:warn).with() { |value| value =~ /sign_out_via/ }
|
44
|
+
ActiveSupport::Deprecation.expects(:warn).with() { |value| value =~ /skip_session_storage/ }
|
45
|
+
ActiveSupport::Deprecation.expects(:warn).with() { |value| value =~ /strip_whitespace_keys/ }
|
46
|
+
|
47
|
+
Devise.setup do
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
test 'setup block doest not warns when the change is explicit set' do
|
52
|
+
ActiveSupport::Deprecation.expects(:warn).never
|
53
|
+
|
54
|
+
swap Devise,
|
55
|
+
email_regexp: /@/,
|
56
|
+
reconfirmable: false,
|
57
|
+
sign_out_via: :get,
|
58
|
+
skip_session_storage: [],
|
59
|
+
strip_whitespace_keys: [] do
|
60
|
+
Devise.setup do
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
38
65
|
test 'stores warden configuration' do
|
39
66
|
assert_kind_of Devise::Delegator, Devise.warden_config.failure_app
|
40
67
|
assert_equal :user, Devise.warden_config.default_scope
|
@@ -42,14 +69,27 @@ class DeviseTest < ActiveSupport::TestCase
|
|
42
69
|
|
43
70
|
test 'warden manager user configuration through a block' do
|
44
71
|
Devise.yield_and_restore do
|
45
|
-
|
72
|
+
executed = false
|
46
73
|
Devise.warden do |config|
|
47
|
-
|
74
|
+
executed = true
|
48
75
|
assert_kind_of Warden::Config, config
|
49
76
|
end
|
50
77
|
|
51
78
|
Devise.configure_warden!
|
52
|
-
assert
|
79
|
+
assert executed
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
test 'warden manager user configuration through multiple blocks' do
|
84
|
+
Devise.yield_and_restore do
|
85
|
+
executed = 0
|
86
|
+
|
87
|
+
3.times do
|
88
|
+
Devise.warden { |config| executed += 1 }
|
89
|
+
end
|
90
|
+
|
91
|
+
Devise.configure_warden!
|
92
|
+
assert_equal 3, executed
|
53
93
|
end
|
54
94
|
end
|
55
95
|
|
@@ -82,7 +122,7 @@ class DeviseTest < ActiveSupport::TestCase
|
|
82
122
|
|
83
123
|
test 'Devise.email_regexp should match valid email addresses' do
|
84
124
|
valid_emails = ["test@example.com", "jo@jo.co", "f4$_m@you.com", "testing.example@example.com.ua"]
|
85
|
-
non_valid_emails = ["rex", "test@go,com", "test user@example.com", "test_user@example server.com"]
|
125
|
+
non_valid_emails = ["rex", "test@go,com", "test user@example.com", "test_user@example server.com", "test_user@example.com."]
|
86
126
|
|
87
127
|
valid_emails.each do |email|
|
88
128
|
assert_match Devise.email_regexp, email
|