devise 2.1.2 → 3.5.10
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 +7 -0
- data/.travis.yml +39 -10
- data/.yardopts +9 -0
- data/{CHANGELOG.rdoc → CHANGELOG.md} +445 -112
- data/CODE_OF_CONDUCT.md +22 -0
- data/CONTRIBUTING.md +16 -0
- data/Gemfile +10 -15
- data/Gemfile.lock +151 -129
- data/MIT-LICENSE +1 -1
- data/README.md +256 -96
- data/Rakefile +4 -2
- data/app/controllers/devise/confirmations_controller.rb +15 -7
- data/app/controllers/devise/omniauth_callbacks_controller.rb +6 -2
- data/app/controllers/devise/passwords_controller.rb +33 -9
- data/app/controllers/devise/registrations_controller.rb +66 -26
- data/app/controllers/devise/sessions_controller.rb +52 -21
- data/app/controllers/devise/unlocks_controller.rb +11 -6
- data/app/controllers/devise_controller.rb +65 -58
- data/app/helpers/devise_helper.rb +2 -2
- data/app/mailers/devise/mailer.rb +19 -10
- data/app/views/devise/confirmations/new.html.erb +8 -4
- data/app/views/devise/mailer/confirmation_instructions.html.erb +2 -2
- data/app/views/devise/mailer/password_change.html.erb +3 -0
- data/app/views/devise/mailer/reset_password_instructions.html.erb +2 -2
- data/app/views/devise/mailer/unlock_instructions.html.erb +2 -2
- data/app/views/devise/passwords/edit.html.erb +15 -6
- data/app/views/devise/passwords/new.html.erb +8 -4
- data/app/views/devise/registrations/edit.html.erb +29 -15
- data/app/views/devise/registrations/new.html.erb +19 -8
- data/app/views/devise/sessions/new.html.erb +17 -8
- data/app/views/devise/shared/{_links.erb → _links.html.erb} +4 -4
- data/app/views/devise/unlocks/new.html.erb +8 -4
- data/config/locales/en.yml +51 -47
- data/devise.gemspec +8 -6
- data/devise.png +0 -0
- data/gemfiles/Gemfile.rails-3.2-stable +29 -0
- data/gemfiles/Gemfile.rails-3.2-stable.lock +172 -0
- data/gemfiles/Gemfile.rails-4.0-stable +30 -0
- data/gemfiles/Gemfile.rails-4.0-stable.lock +166 -0
- data/gemfiles/Gemfile.rails-4.1-stable +30 -0
- data/gemfiles/Gemfile.rails-4.1-stable.lock +171 -0
- data/gemfiles/Gemfile.rails-4.2-stable +30 -0
- data/gemfiles/Gemfile.rails-4.2-stable.lock +193 -0
- data/lib/devise/controllers/helpers.rb +126 -108
- data/lib/devise/controllers/rememberable.rb +19 -17
- data/lib/devise/controllers/scoped_views.rb +1 -1
- data/lib/devise/controllers/sign_in_out.rb +96 -0
- data/lib/devise/controllers/store_location.rb +58 -0
- data/lib/devise/controllers/url_helpers.rb +7 -7
- data/lib/devise/encryptor.rb +22 -0
- data/lib/devise/failure_app.rb +85 -25
- data/lib/devise/hooks/activatable.rb +5 -6
- data/lib/devise/hooks/csrf_cleaner.rb +7 -0
- data/lib/devise/hooks/forgetable.rb +1 -1
- data/lib/devise/hooks/lockable.rb +2 -2
- data/lib/devise/hooks/proxy.rb +21 -0
- data/lib/devise/hooks/rememberable.rb +5 -4
- data/lib/devise/hooks/timeoutable.rb +16 -8
- data/lib/devise/hooks/trackable.rb +1 -1
- data/lib/devise/mailers/helpers.rb +27 -23
- data/lib/devise/mapping.rb +11 -7
- data/lib/devise/models/authenticatable.rb +82 -66
- data/lib/devise/models/confirmable.rb +142 -55
- data/lib/devise/models/database_authenticatable.rb +59 -15
- data/lib/devise/models/lockable.rb +41 -30
- data/lib/devise/models/omniauthable.rb +3 -3
- data/lib/devise/models/recoverable.rb +56 -41
- data/lib/devise/models/rememberable.rb +65 -27
- data/lib/devise/models/timeoutable.rb +2 -8
- data/lib/devise/models/trackable.rb +6 -4
- data/lib/devise/models/validatable.rb +9 -9
- data/lib/devise/models.rb +4 -13
- data/lib/devise/modules.rb +10 -11
- data/lib/devise/omniauth/url_helpers.rb +2 -2
- data/lib/devise/orm/active_record.rb +1 -1
- data/lib/devise/orm/mongoid.rb +1 -1
- data/lib/devise/{param_filter.rb → parameter_filter.rb} +10 -11
- data/lib/devise/parameter_sanitizer.rb +99 -0
- data/lib/devise/rails/routes.rb +173 -115
- data/lib/devise/rails/warden_compat.rb +10 -31
- data/lib/devise/rails.rb +14 -12
- data/lib/devise/strategies/authenticatable.rb +26 -26
- data/lib/devise/strategies/base.rb +1 -1
- data/lib/devise/strategies/database_authenticatable.rb +8 -4
- data/lib/devise/strategies/rememberable.rb +15 -5
- data/lib/devise/test_helpers.rb +7 -5
- data/lib/devise/time_inflector.rb +14 -0
- data/lib/devise/token_generator.rb +70 -0
- data/lib/devise/version.rb +1 -1
- data/lib/devise.rb +110 -52
- data/lib/generators/active_record/devise_generator.rb +34 -18
- data/lib/generators/active_record/templates/migration.rb +5 -6
- data/lib/generators/active_record/templates/migration_existing.rb +5 -6
- data/lib/generators/devise/controllers_generator.rb +44 -0
- data/lib/generators/devise/devise_generator.rb +5 -3
- data/lib/generators/devise/install_generator.rb +5 -0
- data/lib/generators/devise/orm_helpers.rb +25 -6
- data/lib/generators/devise/views_generator.rb +52 -22
- data/lib/generators/mongoid/devise_generator.rb +21 -26
- data/lib/generators/templates/README +9 -5
- 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 +80 -43
- data/lib/generators/templates/markerb/confirmation_instructions.markerb +2 -2
- 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 +2 -2
- data/lib/generators/templates/simple_form_for/confirmations/new.html.erb +3 -2
- data/lib/generators/templates/simple_form_for/passwords/edit.html.erb +4 -4
- data/lib/generators/templates/simple_form_for/passwords/new.html.erb +2 -2
- data/lib/generators/templates/simple_form_for/registrations/edit.html.erb +11 -6
- data/lib/generators/templates/simple_form_for/registrations/new.html.erb +4 -4
- data/lib/generators/templates/simple_form_for/sessions/new.html.erb +6 -6
- data/lib/generators/templates/simple_form_for/unlocks/new.html.erb +3 -2
- data/script/cached-bundle +49 -0
- data/script/s3-put +71 -0
- data/test/controllers/custom_registrations_controller_test.rb +40 -0
- data/test/controllers/helper_methods_test.rb +21 -0
- data/test/controllers/helpers_test.rb +95 -32
- data/test/controllers/inherited_controller_i18n_messages_test.rb +51 -0
- data/test/controllers/internal_helpers_test.rb +39 -14
- data/test/controllers/load_hooks_controller_test.rb +19 -0
- data/test/controllers/passwords_controller_test.rb +31 -0
- data/test/controllers/sessions_controller_test.rb +66 -6
- data/test/controllers/url_helpers_test.rb +10 -4
- data/test/delegator_test.rb +1 -1
- data/test/devise_test.rb +45 -10
- data/test/failure_app_test.rb +121 -27
- data/test/generators/active_record_generator_test.rb +48 -8
- data/test/generators/controllers_generator_test.rb +48 -0
- data/test/generators/devise_generator_test.rb +2 -2
- data/test/generators/mongoid_generator_test.rb +3 -3
- data/test/generators/views_generator_test.rb +54 -3
- data/test/helpers/devise_helper_test.rb +18 -20
- data/test/integration/authenticatable_test.rb +161 -65
- data/test/integration/confirmable_test.rb +146 -77
- data/test/integration/database_authenticatable_test.rb +43 -30
- data/test/integration/http_authenticatable_test.rb +30 -22
- data/test/integration/lockable_test.rb +64 -49
- data/test/integration/omniauthable_test.rb +17 -15
- data/test/integration/recoverable_test.rb +111 -70
- data/test/integration/registerable_test.rb +114 -79
- data/test/integration/rememberable_test.rb +87 -31
- data/test/integration/timeoutable_test.rb +77 -33
- data/test/integration/trackable_test.rb +5 -5
- data/test/mailers/confirmation_instructions_test.rb +28 -8
- data/test/mailers/reset_password_instructions_test.rb +21 -8
- data/test/mailers/unlock_instructions_test.rb +20 -6
- data/test/mapping_test.rb +12 -5
- data/test/models/authenticatable_test.rb +17 -1
- data/test/models/confirmable_test.rb +216 -62
- data/test/models/database_authenticatable_test.rb +129 -49
- data/test/models/lockable_test.rb +132 -45
- data/test/models/recoverable_test.rb +100 -54
- data/test/models/rememberable_test.rb +89 -94
- data/test/models/serializable_test.rb +12 -11
- data/test/models/timeoutable_test.rb +6 -1
- data/test/models/trackable_test.rb +28 -0
- data/test/models/validatable_test.rb +31 -21
- data/test/models_test.rb +22 -48
- data/test/omniauth/config_test.rb +4 -4
- data/test/omniauth/url_helpers_test.rb +7 -4
- data/test/orm/active_record.rb +1 -0
- data/test/orm/mongoid.rb +2 -3
- data/test/parameter_sanitizer_test.rb +81 -0
- data/test/rails_app/Rakefile +0 -4
- data/test/rails_app/app/active_record/shim.rb +1 -1
- 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/sessions_controller.rb +1 -1
- data/test/rails_app/app/controllers/admins_controller.rb +0 -5
- data/test/rails_app/app/controllers/application_controller.rb +6 -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 +1 -1
- data/test/rails_app/app/controllers/publisher/registrations_controller.rb +1 -1
- data/test/rails_app/app/controllers/publisher/sessions_controller.rb +1 -1
- data/test/rails_app/app/controllers/users/omniauth_callbacks_controller.rb +4 -4
- data/test/rails_app/app/controllers/users_controller.rb +12 -4
- data/test/rails_app/app/mailers/users/from_proc_mailer.rb +3 -0
- data/test/rails_app/app/mailers/users/mailer.rb +1 -1
- data/test/rails_app/app/mailers/users/reply_to_mailer.rb +4 -0
- data/test/rails_app/app/mongoid/admin.rb +12 -10
- data/test/rails_app/app/mongoid/shim.rb +4 -5
- data/test/rails_app/app/mongoid/user.rb +19 -22
- 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/app/views/admins/sessions/new.html.erb +1 -1
- data/test/rails_app/app/views/home/admin_dashboard.html.erb +1 -1
- data/test/rails_app/app/views/home/index.html.erb +1 -1
- data/test/rails_app/app/views/home/join.html.erb +1 -1
- data/test/rails_app/app/views/home/user_dashboard.html.erb +1 -1
- data/test/rails_app/app/views/layouts/application.html.erb +1 -1
- data/test/rails_app/app/views/users/edit_form.html.erb +1 -0
- data/test/rails_app/bin/bundle +3 -0
- data/test/rails_app/bin/rails +4 -0
- data/test/rails_app/bin/rake +4 -0
- data/test/rails_app/config/application.rb +4 -5
- data/test/rails_app/config/boot.rb +9 -3
- data/test/rails_app/config/environment.rb +2 -2
- data/test/rails_app/config/environments/development.rb +19 -7
- data/test/rails_app/config/environments/production.rb +68 -17
- data/test/rails_app/config/environments/test.rb +24 -16
- data/test/rails_app/config/initializers/devise.rb +22 -20
- data/test/rails_app/config/initializers/secret_token.rb +8 -2
- data/test/rails_app/config/initializers/session_store.rb +1 -0
- data/test/rails_app/config/routes.rb +71 -46
- data/test/rails_app/db/migrate/20100401102949_create_tables.rb +9 -12
- data/test/rails_app/db/schema.rb +21 -18
- data/test/rails_app/lib/shared_admin.rb +7 -4
- data/test/rails_app/lib/shared_user.rb +6 -3
- 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 +94 -78
- data/test/support/action_controller/record_identifier.rb +10 -0
- data/test/support/assertions.rb +2 -3
- data/test/support/helpers.rb +18 -32
- data/test/support/integration.rb +17 -16
- data/test/support/locale/en.yml +4 -0
- data/test/support/mongoid.yml +6 -0
- data/test/test_helper.rb +8 -1
- data/test/test_helpers_test.rb +64 -20
- data/test/test_models.rb +33 -0
- data/test/time_helpers.rb +137 -0
- metadata +172 -51
- data/app/views/devise/_links.erb +0 -3
- data/gemfiles/Gemfile.rails-3.1.x +0 -35
- data/gemfiles/Gemfile.rails-3.1.x.lock +0 -167
- data/lib/devise/models/token_authenticatable.rb +0 -77
- data/lib/devise/strategies/token_authenticatable.rb +0 -56
- data/test/indifferent_hash.rb +0 -33
- data/test/integration/token_authenticatable_test.rb +0 -161
- data/test/models/token_authenticatable_test.rb +0 -55
- data/test/rails_app/script/rails +0 -10
@@ -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 < ActionController::TestCase
|
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 < ActionController::TestCase
|
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
|
@@ -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
|
@@ -34,18 +34,28 @@ class HelpersTest < ActionController::TestCase
|
|
34
34
|
end
|
35
35
|
|
36
36
|
test 'get resource params from request params using resource name as key' do
|
37
|
-
user_params = {'
|
38
|
-
|
37
|
+
user_params = {'email' => 'shirley@templar.com'}
|
38
|
+
|
39
|
+
params = if Devise.rails4?
|
40
|
+
# Stub controller name so strong parameters can filter properly.
|
41
|
+
# DeviseController does not allow any parameters by default.
|
42
|
+
@controller.stubs(:controller_name).returns(:sessions_controller)
|
43
|
+
|
44
|
+
ActionController::Parameters.new({'user' => user_params})
|
45
|
+
else
|
46
|
+
HashWithIndifferentAccess.new({'user' => user_params})
|
47
|
+
end
|
48
|
+
@controller.stubs(:params).returns(params)
|
39
49
|
|
40
|
-
assert_equal user_params, @controller.resource_params
|
50
|
+
assert_equal user_params, @controller.send(:resource_params)
|
41
51
|
end
|
42
52
|
|
43
53
|
test 'resources methods are not controller actions' do
|
44
|
-
assert @controller.class.action_methods.empty?
|
54
|
+
assert @controller.class.action_methods.delete_if { |m| m.include? 'commenter' }.empty?
|
45
55
|
end
|
46
56
|
|
47
57
|
test 'require no authentication tests current mapping' do
|
48
|
-
@mock_warden.expects(:authenticate?).with(:rememberable, :
|
58
|
+
@mock_warden.expects(:authenticate?).with(:rememberable, scope: :user).returns(true)
|
49
59
|
@mock_warden.expects(:user).with(:user).returns(User.new)
|
50
60
|
@controller.expects(:redirect_to).with(root_path)
|
51
61
|
@controller.send :require_no_authentication
|
@@ -61,7 +71,7 @@ class HelpersTest < ActionController::TestCase
|
|
61
71
|
end
|
62
72
|
|
63
73
|
test 'require no authentication sets a flash message' do
|
64
|
-
@mock_warden.expects(:authenticate?).with(:rememberable, :
|
74
|
+
@mock_warden.expects(:authenticate?).with(:rememberable, scope: :user).returns(true)
|
65
75
|
@mock_warden.expects(:user).with(:user).returns(User.new)
|
66
76
|
@controller.expects(:redirect_to).with(root_path)
|
67
77
|
@controller.send :require_no_authentication
|
@@ -69,8 +79,8 @@ class HelpersTest < ActionController::TestCase
|
|
69
79
|
end
|
70
80
|
|
71
81
|
test 'signed in resource returns signed in resource for current scope' do
|
72
|
-
@mock_warden.expects(:authenticate).with(:
|
73
|
-
assert_kind_of User, @controller.signed_in_resource
|
82
|
+
@mock_warden.expects(:authenticate).with(scope: :user).returns(User.new)
|
83
|
+
assert_kind_of User, @controller.send(:signed_in_resource)
|
74
84
|
end
|
75
85
|
|
76
86
|
test 'is a devise controller' do
|
@@ -89,16 +99,31 @@ class HelpersTest < ActionController::TestCase
|
|
89
99
|
assert_equal 'non-blank', flash[:notice]
|
90
100
|
end
|
91
101
|
|
102
|
+
test 'issues non-blank flash.now messages normally' do
|
103
|
+
I18n.stubs(:t).returns('non-blank')
|
104
|
+
@controller.send :set_flash_message, :notice, :send_instructions, { now: true }
|
105
|
+
assert_equal 'non-blank', flash.now[:notice]
|
106
|
+
end
|
107
|
+
|
92
108
|
test 'uses custom i18n options' do
|
93
|
-
@controller.stubs(:devise_i18n_options).returns(:
|
109
|
+
@controller.stubs(:devise_i18n_options).returns(default: "devise custom options")
|
94
110
|
@controller.send :set_flash_message, :notice, :invalid_i18n_messagesend_instructions
|
95
111
|
assert_equal 'devise custom options', flash[:notice]
|
96
112
|
end
|
97
113
|
|
114
|
+
test 'allows custom i18n options to override resource_name' do
|
115
|
+
I18n.expects(:t).with("custom_resource_name.confirmed", anything)
|
116
|
+
@controller.stubs(:devise_i18n_options).returns(resource_name: "custom_resource_name")
|
117
|
+
@controller.send :set_flash_message, :notice, :confirmed
|
118
|
+
end
|
119
|
+
|
98
120
|
test 'navigational_formats not returning a wild card' do
|
99
121
|
MyController.send(:public, :navigational_formats)
|
100
|
-
|
101
|
-
|
122
|
+
|
123
|
+
swap Devise, navigational_formats: ['*/*', :html] do
|
124
|
+
assert_not @controller.navigational_formats.include?("*/*")
|
125
|
+
end
|
126
|
+
|
102
127
|
MyController.send(:protected, :navigational_formats)
|
103
128
|
end
|
104
129
|
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class LoadHooksControllerTest < ActionController::TestCase
|
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
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class PasswordsControllerTest < ActionController::TestCase
|
4
|
+
tests Devise::PasswordsController
|
5
|
+
include Devise::TestHelpers
|
6
|
+
|
7
|
+
setup do
|
8
|
+
request.env["devise.mapping"] = Devise.mappings[:user]
|
9
|
+
@user = create_user.tap(&:confirm)
|
10
|
+
@raw = @user.send_reset_password_instructions
|
11
|
+
end
|
12
|
+
|
13
|
+
def put_update_with_params
|
14
|
+
put :update, "user" => {
|
15
|
+
"reset_password_token" => @raw, "password" => "1234567", "password_confirmation" => "1234567"
|
16
|
+
}
|
17
|
+
end
|
18
|
+
|
19
|
+
test 'redirect to after_sign_in_path_for if after_resetting_password_path_for is not overridden' do
|
20
|
+
put_update_with_params
|
21
|
+
assert_redirected_to "http://test.host/"
|
22
|
+
end
|
23
|
+
|
24
|
+
test 'redirect accordingly if after_resetting_password_path_for is overridden' do
|
25
|
+
custom_path = "http://custom.path/"
|
26
|
+
Devise::PasswordsController.any_instance.stubs(:after_resetting_password_path_for).with(@user).returns(custom_path)
|
27
|
+
|
28
|
+
put_update_with_params
|
29
|
+
assert_redirected_to custom_path
|
30
|
+
end
|
31
|
+
end
|
@@ -4,8 +4,26 @@ class SessionsControllerTest < ActionController::TestCase
|
|
4
4
|
tests Devise::SessionsController
|
5
5
|
include Devise::TestHelpers
|
6
6
|
|
7
|
+
test "#create doesn't raise unpermitted params when sign in fails" do
|
8
|
+
begin
|
9
|
+
subscriber = ActiveSupport::Notifications.subscribe /unpermitted_parameters/ do |name, start, finish, id, payload|
|
10
|
+
flunk "Unpermitted params: #{payload}"
|
11
|
+
end
|
12
|
+
request.env["devise.mapping"] = Devise.mappings[:user]
|
13
|
+
request.session["user_return_to"] = 'foo.bar'
|
14
|
+
create_user
|
15
|
+
post :create, user: {
|
16
|
+
email: "wrong@email.com",
|
17
|
+
password: "wrongpassword"
|
18
|
+
}
|
19
|
+
assert_equal 200, @response.status
|
20
|
+
ensure
|
21
|
+
ActiveSupport::Notifications.unsubscribe(subscriber)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
7
25
|
test "#create works even with scoped views" do
|
8
|
-
swap Devise, :
|
26
|
+
swap Devise, scoped_views: true do
|
9
27
|
request.env["devise.mapping"] = Devise.mappings[:user]
|
10
28
|
post :create
|
11
29
|
assert_equal 200, @response.status
|
@@ -13,16 +31,58 @@ class SessionsControllerTest < ActionController::TestCase
|
|
13
31
|
end
|
14
32
|
end
|
15
33
|
|
34
|
+
test "#create delete the url stored in the session if the requested format is navigational" do
|
35
|
+
request.env["devise.mapping"] = Devise.mappings[:user]
|
36
|
+
request.session["user_return_to"] = 'foo.bar'
|
37
|
+
|
38
|
+
user = create_user
|
39
|
+
user.confirm
|
40
|
+
post :create, user: {
|
41
|
+
email: user.email,
|
42
|
+
password: user.password
|
43
|
+
}
|
44
|
+
|
45
|
+
assert_nil request.session["user_return_to"]
|
46
|
+
end
|
47
|
+
|
48
|
+
test "#create doesn't delete the url stored in the session if the requested format is not navigational" do
|
49
|
+
request.env["devise.mapping"] = Devise.mappings[:user]
|
50
|
+
request.session["user_return_to"] = 'foo.bar'
|
51
|
+
|
52
|
+
user = create_user
|
53
|
+
user.confirm
|
54
|
+
post :create, format: 'json', user: {
|
55
|
+
email: user.email,
|
56
|
+
password: user.password
|
57
|
+
}
|
58
|
+
|
59
|
+
assert_equal 'foo.bar', request.session["user_return_to"]
|
60
|
+
end
|
61
|
+
|
16
62
|
test "#create doesn't raise exception after Warden authentication fails when TestHelpers included" do
|
17
63
|
request.env["devise.mapping"] = Devise.mappings[:user]
|
18
|
-
post :create, :
|
19
|
-
:
|
20
|
-
:
|
64
|
+
post :create, user: {
|
65
|
+
email: "nosuchuser@example.com",
|
66
|
+
password: "wevdude"
|
21
67
|
}
|
22
68
|
assert_equal 200, @response.status
|
23
69
|
assert_template "devise/sessions/new"
|
24
70
|
end
|
25
71
|
|
72
|
+
test "#destroy doesn't set the flash if the requested format is not navigational" do
|
73
|
+
request.env["devise.mapping"] = Devise.mappings[:user]
|
74
|
+
user = create_user
|
75
|
+
user.confirm
|
76
|
+
post :create, format: 'json', user: {
|
77
|
+
email: user.email,
|
78
|
+
password: user.password
|
79
|
+
}
|
80
|
+
|
81
|
+
delete :destroy, format: 'json'
|
82
|
+
assert flash[:notice].blank?, "flash[:notice] should be blank, not #{flash[:notice].inspect}"
|
83
|
+
assert_equal 204, @response.status
|
84
|
+
end
|
85
|
+
|
26
86
|
if defined?(ActiveRecord) && ActiveRecord::Base.respond_to?(:mass_assignment_sanitizer)
|
27
87
|
test "#new doesn't raise mass-assignment exception even if sign-in key is attr_protected" do
|
28
88
|
request.env["devise.mapping"] = Devise.mappings[:user]
|
@@ -32,7 +92,7 @@ class SessionsControllerTest < ActionController::TestCase
|
|
32
92
|
|
33
93
|
begin
|
34
94
|
assert_nothing_raised ActiveModel::MassAssignmentSecurity::Error do
|
35
|
-
get :new, :
|
95
|
+
get :new, user: { email: "allez viens!" }
|
36
96
|
end
|
37
97
|
ensure
|
38
98
|
ActiveRecord::Base.mass_assignment_sanitizer = :logger
|
@@ -40,4 +100,4 @@ class SessionsControllerTest < ActionController::TestCase
|
|
40
100
|
end
|
41
101
|
end
|
42
102
|
end
|
43
|
-
end
|
103
|
+
end
|
@@ -13,11 +13,17 @@ 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
|
-
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", :
|
23
|
+
assert_equal @controller.send(:"#{prepend_path}#{name}_path", :user, param: 123),
|
24
|
+
send(:"#{prepend_path}user_#{name}_path", param: 123)
|
25
|
+
assert_equal @controller.send(:"#{prepend_path}#{name}_url", :user, param: 123),
|
26
|
+
send(:"#{prepend_path}user_#{name}_url", param: 123)
|
21
27
|
|
22
28
|
@request.path = nil
|
23
29
|
# With an object
|
data/test/delegator_test.rb
CHANGED
@@ -14,6 +14,6 @@ class DelegatorTest < ActiveSupport::TestCase
|
|
14
14
|
end
|
15
15
|
|
16
16
|
test 'failure_app returns associated failure app by scope in the given environment' do
|
17
|
-
assert_kind_of Proc, delegator.failure_app({"warden.options" => {:
|
17
|
+
assert_kind_of Proc, delegator.failure_app({"warden.options" => {scope: "manager"}})
|
18
18
|
end
|
19
19
|
end
|
data/test/devise_test.rb
CHANGED
@@ -3,16 +3,27 @@ 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
|
|
13
13
|
class DeviseTest < ActiveSupport::TestCase
|
14
|
+
test 'bcrypt on the class' do
|
15
|
+
password = "super secret"
|
16
|
+
klass = Struct.new(:pepper, :stretches).new("blahblah", 2)
|
17
|
+
hash = Devise::Encryptor.digest(klass, password)
|
18
|
+
assert_equal ::BCrypt::Password.create(hash), hash
|
19
|
+
|
20
|
+
klass = Struct.new(:pepper, :stretches).new("bla", 2)
|
21
|
+
hash = Devise::Encryptor.digest(klass, password)
|
22
|
+
assert_not_equal ::BCrypt::Password.new(hash), hash
|
23
|
+
end
|
24
|
+
|
14
25
|
test 'model options can be configured through Devise' do
|
15
|
-
swap Devise, :
|
26
|
+
swap Devise, allow_unconfirmed_access_for: 113, pepper: "foo" do
|
16
27
|
assert_equal 113, Devise.allow_unconfirmed_access_for
|
17
28
|
assert_equal "foo", Devise.pepper
|
18
29
|
end
|
@@ -31,14 +42,27 @@ class DeviseTest < ActiveSupport::TestCase
|
|
31
42
|
|
32
43
|
test 'warden manager user configuration through a block' do
|
33
44
|
Devise.yield_and_restore do
|
34
|
-
|
45
|
+
executed = false
|
35
46
|
Devise.warden do |config|
|
36
|
-
|
47
|
+
executed = true
|
37
48
|
assert_kind_of Warden::Config, config
|
38
49
|
end
|
39
50
|
|
40
51
|
Devise.configure_warden!
|
41
|
-
assert
|
52
|
+
assert executed
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
test 'warden manager user configuration through multiple blocks' do
|
57
|
+
Devise.yield_and_restore do
|
58
|
+
executed = 0
|
59
|
+
|
60
|
+
3.times do
|
61
|
+
Devise.warden { |config| executed += 1 }
|
62
|
+
end
|
63
|
+
|
64
|
+
Devise.configure_warden!
|
65
|
+
assert_equal 3, executed
|
42
66
|
end
|
43
67
|
end
|
44
68
|
|
@@ -49,17 +73,17 @@ class DeviseTest < ActiveSupport::TestCase
|
|
49
73
|
assert_not defined?(Devise::Models::Coconut)
|
50
74
|
Devise::ALL.delete(:coconut)
|
51
75
|
|
52
|
-
assert_nothing_raised(Exception) { Devise.add_module(:banana, :
|
76
|
+
assert_nothing_raised(Exception) { Devise.add_module(:banana, strategy: :fruits) }
|
53
77
|
assert_equal :fruits, Devise::STRATEGIES[:banana]
|
54
78
|
Devise::ALL.delete(:banana)
|
55
79
|
Devise::STRATEGIES.delete(:banana)
|
56
80
|
|
57
|
-
assert_nothing_raised(Exception) { Devise.add_module(:kivi, :
|
81
|
+
assert_nothing_raised(Exception) { Devise.add_module(:kivi, controller: :fruits) }
|
58
82
|
assert_equal :fruits, Devise::CONTROLLERS[:kivi]
|
59
83
|
Devise::ALL.delete(:kivi)
|
60
84
|
Devise::CONTROLLERS.delete(:kivi)
|
61
85
|
end
|
62
|
-
|
86
|
+
|
63
87
|
test 'should complain when comparing empty or different sized passes' do
|
64
88
|
[nil, ""].each do |empty|
|
65
89
|
assert_not Devise.secure_compare(empty, "something")
|
@@ -68,5 +92,16 @@ class DeviseTest < ActiveSupport::TestCase
|
|
68
92
|
end
|
69
93
|
assert_not Devise.secure_compare("size_1", "size_four")
|
70
94
|
end
|
71
|
-
|
95
|
+
|
96
|
+
test 'Devise.email_regexp should match valid email addresses' do
|
97
|
+
valid_emails = ["test@example.com", "jo@jo.co", "f4$_m@you.com", "testing.example@example.com.ua"]
|
98
|
+
non_valid_emails = ["rex", "test@go,com", "test user@example.com", "test_user@example server.com", "test_user@example.com."]
|
99
|
+
|
100
|
+
valid_emails.each do |email|
|
101
|
+
assert_match Devise.email_regexp, email
|
102
|
+
end
|
103
|
+
non_valid_emails.each do |email|
|
104
|
+
assert_no_match Devise.email_regexp, email
|
105
|
+
end
|
106
|
+
end
|
72
107
|
end
|