devise 4.5.0 → 4.6.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of devise might be problematic. Click here for more details.
- checksums.yaml +5 -5
- data/CHANGELOG.md +30 -1
- data/MIT-LICENSE +1 -1
- data/README.md +18 -0
- data/app/controllers/devise/passwords_controller.rb +1 -0
- data/app/controllers/devise/registrations_controller.rb +25 -7
- data/app/helpers/devise_helper.rb +10 -19
- data/app/views/devise/confirmations/new.html.erb +1 -1
- data/app/views/devise/passwords/edit.html.erb +1 -1
- data/app/views/devise/passwords/new.html.erb +1 -1
- data/app/views/devise/registrations/edit.html.erb +1 -1
- data/app/views/devise/registrations/new.html.erb +1 -1
- data/app/views/devise/sessions/new.html.erb +2 -2
- data/app/views/devise/shared/_error_messages.html.erb +15 -0
- data/app/views/devise/shared/_links.html.erb +7 -7
- data/app/views/devise/unlocks/new.html.erb +1 -1
- data/config/locales/en.yml +1 -0
- data/lib/devise.rb +4 -0
- data/lib/devise/controllers/helpers.rb +1 -1
- data/lib/devise/failure_app.rb +28 -3
- data/lib/devise/models/authenticatable.rb +7 -15
- data/lib/devise/models/confirmable.rb +4 -1
- data/lib/devise/models/database_authenticatable.rb +41 -6
- data/lib/devise/models/lockable.rb +2 -2
- data/lib/devise/models/registerable.rb +2 -0
- data/lib/devise/strategies/database_authenticatable.rb +3 -0
- data/lib/devise/test/controller_helpers.rb +1 -1
- data/lib/devise/version.rb +1 -1
- data/lib/generators/active_record/devise_generator.rb +4 -4
- data/lib/generators/devise/controllers_generator.rb +1 -1
- data/lib/generators/templates/devise.rb +12 -3
- data/lib/generators/templates/simple_form_for/registrations/edit.html.erb +1 -1
- data/lib/generators/templates/simple_form_for/registrations/new.html.erb +1 -1
- metadata +5 -305
- data/.gitignore +0 -10
- data/.travis.yml +0 -69
- data/.yardopts +0 -9
- data/CODE_OF_CONDUCT.md +0 -22
- data/CONTRIBUTING.md +0 -79
- data/Gemfile +0 -39
- data/Gemfile.lock +0 -202
- data/ISSUE_TEMPLATE.md +0 -19
- data/Rakefile +0 -37
- data/bin/test +0 -13
- data/devise.gemspec +0 -28
- data/devise.png +0 -0
- data/gemfiles/Gemfile.rails-4.1-stable +0 -32
- data/gemfiles/Gemfile.rails-4.1-stable.lock +0 -171
- data/gemfiles/Gemfile.rails-4.2-stable +0 -32
- data/gemfiles/Gemfile.rails-4.2-stable.lock +0 -192
- data/gemfiles/Gemfile.rails-5.0-stable +0 -33
- data/gemfiles/Gemfile.rails-5.0-stable.lock +0 -192
- data/gemfiles/Gemfile.rails-5.2-rc1 +0 -26
- data/gemfiles/Gemfile.rails-5.2-rc1.lock +0 -201
- data/guides/bug_report_templates/integration_test.rb +0 -106
- data/test/controllers/custom_registrations_controller_test.rb +0 -42
- data/test/controllers/custom_strategy_test.rb +0 -66
- data/test/controllers/helper_methods_test.rb +0 -24
- data/test/controllers/helpers_test.rb +0 -318
- data/test/controllers/inherited_controller_i18n_messages_test.rb +0 -53
- data/test/controllers/internal_helpers_test.rb +0 -129
- data/test/controllers/load_hooks_controller_test.rb +0 -21
- data/test/controllers/passwords_controller_test.rb +0 -34
- data/test/controllers/sessions_controller_test.rb +0 -108
- data/test/controllers/url_helpers_test.rb +0 -67
- data/test/delegator_test.rb +0 -21
- data/test/devise_test.rb +0 -109
- data/test/failure_app_test.rb +0 -346
- data/test/generators/active_record_generator_test.rb +0 -130
- data/test/generators/controllers_generator_test.rb +0 -50
- data/test/generators/devise_generator_test.rb +0 -41
- data/test/generators/install_generator_test.rb +0 -26
- data/test/generators/mongoid_generator_test.rb +0 -25
- data/test/generators/views_generator_test.rb +0 -105
- data/test/helpers/devise_helper_test.rb +0 -51
- data/test/integration/authenticatable_test.rb +0 -706
- data/test/integration/confirmable_test.rb +0 -326
- data/test/integration/database_authenticatable_test.rb +0 -110
- data/test/integration/http_authenticatable_test.rb +0 -114
- data/test/integration/lockable_test.rb +0 -242
- data/test/integration/mounted_engine_test.rb +0 -38
- data/test/integration/omniauthable_test.rb +0 -148
- data/test/integration/recoverable_test.rb +0 -349
- data/test/integration/registerable_test.rb +0 -365
- data/test/integration/rememberable_test.rb +0 -219
- data/test/integration/timeoutable_test.rb +0 -186
- data/test/integration/trackable_test.rb +0 -99
- data/test/mailers/confirmation_instructions_test.rb +0 -117
- data/test/mailers/email_changed_test.rb +0 -132
- data/test/mailers/mailer_test.rb +0 -20
- data/test/mailers/reset_password_instructions_test.rb +0 -98
- data/test/mailers/unlock_instructions_test.rb +0 -93
- data/test/mapping_test.rb +0 -136
- data/test/models/authenticatable_test.rb +0 -25
- data/test/models/confirmable_test.rb +0 -549
- data/test/models/database_authenticatable_test.rb +0 -290
- data/test/models/lockable_test.rb +0 -352
- data/test/models/omniauthable_test.rb +0 -9
- data/test/models/recoverable_test.rb +0 -263
- data/test/models/registerable_test.rb +0 -9
- data/test/models/rememberable_test.rb +0 -184
- data/test/models/serializable_test.rb +0 -60
- data/test/models/timeoutable_test.rb +0 -53
- data/test/models/trackable_test.rb +0 -80
- data/test/models/validatable_test.rb +0 -121
- data/test/models_test.rb +0 -155
- data/test/omniauth/config_test.rb +0 -61
- data/test/omniauth/url_helpers_test.rb +0 -53
- data/test/orm/active_record.rb +0 -24
- data/test/orm/mongoid.rb +0 -15
- data/test/parameter_sanitizer_test.rb +0 -105
- data/test/rails_app/Rakefile +0 -6
- data/test/rails_app/app/active_record/admin.rb +0 -8
- data/test/rails_app/app/active_record/shim.rb +0 -4
- data/test/rails_app/app/active_record/user.rb +0 -20
- data/test/rails_app/app/active_record/user_on_engine.rb +0 -9
- data/test/rails_app/app/active_record/user_on_main_app.rb +0 -9
- data/test/rails_app/app/active_record/user_with_validations.rb +0 -12
- data/test/rails_app/app/active_record/user_without_email.rb +0 -10
- data/test/rails_app/app/controllers/admins/sessions_controller.rb +0 -8
- data/test/rails_app/app/controllers/admins_controller.rb +0 -8
- data/test/rails_app/app/controllers/application_controller.rb +0 -13
- data/test/rails_app/app/controllers/application_with_fake_engine.rb +0 -32
- data/test/rails_app/app/controllers/custom/registrations_controller.rb +0 -33
- data/test/rails_app/app/controllers/home_controller.rb +0 -31
- data/test/rails_app/app/controllers/publisher/registrations_controller.rb +0 -4
- data/test/rails_app/app/controllers/publisher/sessions_controller.rb +0 -4
- data/test/rails_app/app/controllers/users/omniauth_callbacks_controller.rb +0 -16
- data/test/rails_app/app/controllers/users_controller.rb +0 -33
- data/test/rails_app/app/helpers/application_helper.rb +0 -5
- data/test/rails_app/app/mailers/users/from_proc_mailer.rb +0 -5
- data/test/rails_app/app/mailers/users/mailer.rb +0 -5
- data/test/rails_app/app/mailers/users/reply_to_mailer.rb +0 -6
- data/test/rails_app/app/mongoid/admin.rb +0 -31
- data/test/rails_app/app/mongoid/shim.rb +0 -25
- data/test/rails_app/app/mongoid/user.rb +0 -50
- data/test/rails_app/app/mongoid/user_on_engine.rb +0 -41
- data/test/rails_app/app/mongoid/user_on_main_app.rb +0 -41
- data/test/rails_app/app/mongoid/user_with_validations.rb +0 -37
- data/test/rails_app/app/mongoid/user_without_email.rb +0 -35
- data/test/rails_app/app/views/admins/index.html.erb +0 -1
- data/test/rails_app/app/views/admins/sessions/new.html.erb +0 -2
- data/test/rails_app/app/views/home/admin_dashboard.html.erb +0 -1
- data/test/rails_app/app/views/home/index.html.erb +0 -1
- data/test/rails_app/app/views/home/join.html.erb +0 -1
- data/test/rails_app/app/views/home/private.html.erb +0 -1
- data/test/rails_app/app/views/home/user_dashboard.html.erb +0 -1
- data/test/rails_app/app/views/layouts/application.html.erb +0 -24
- data/test/rails_app/app/views/users/edit_form.html.erb +0 -1
- data/test/rails_app/app/views/users/index.html.erb +0 -1
- data/test/rails_app/app/views/users/mailer/confirmation_instructions.erb +0 -1
- data/test/rails_app/app/views/users/sessions/new.html.erb +0 -1
- data/test/rails_app/bin/bundle +0 -3
- data/test/rails_app/bin/rails +0 -4
- data/test/rails_app/bin/rake +0 -4
- data/test/rails_app/config.ru +0 -4
- data/test/rails_app/config/application.rb +0 -48
- data/test/rails_app/config/boot.rb +0 -27
- data/test/rails_app/config/database.yml +0 -18
- data/test/rails_app/config/environment.rb +0 -7
- data/test/rails_app/config/environments/development.rb +0 -32
- data/test/rails_app/config/environments/production.rb +0 -88
- data/test/rails_app/config/environments/test.rb +0 -47
- data/test/rails_app/config/initializers/backtrace_silencers.rb +0 -9
- data/test/rails_app/config/initializers/devise.rb +0 -187
- data/test/rails_app/config/initializers/inflections.rb +0 -4
- data/test/rails_app/config/initializers/secret_token.rb +0 -5
- data/test/rails_app/config/initializers/session_store.rb +0 -3
- data/test/rails_app/config/routes.rb +0 -128
- data/test/rails_app/db/migrate/20100401102949_create_tables.rb +0 -77
- data/test/rails_app/db/schema.rb +0 -57
- data/test/rails_app/lib/lazy_load_test_module.rb +0 -5
- data/test/rails_app/lib/shared_admin.rb +0 -23
- data/test/rails_app/lib/shared_user.rb +0 -32
- data/test/rails_app/lib/shared_user_without_email.rb +0 -28
- data/test/rails_app/lib/shared_user_without_omniauth.rb +0 -15
- data/test/rails_app/public/404.html +0 -26
- data/test/rails_app/public/422.html +0 -26
- data/test/rails_app/public/500.html +0 -26
- data/test/rails_app/public/favicon.ico +0 -0
- data/test/rails_test.rb +0 -11
- data/test/routes_test.rb +0 -281
- data/test/secret_key_finder_test.rb +0 -121
- data/test/support/action_controller/record_identifier.rb +0 -12
- data/test/support/assertions.rb +0 -30
- data/test/support/helpers.rb +0 -83
- data/test/support/http_method_compatibility.rb +0 -53
- data/test/support/integration.rb +0 -95
- data/test/support/locale/en.yml +0 -8
- data/test/support/mongoid.yml +0 -6
- data/test/support/webrat/integrations/rails.rb +0 -35
- data/test/test/controller_helpers_test.rb +0 -193
- data/test/test/integration_helpers_test.rb +0 -34
- data/test/test_helper.rb +0 -36
- data/test/test_models.rb +0 -35
@@ -1,53 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'test_helper'
|
4
|
-
|
5
|
-
class SessionsInheritedController < Devise::SessionsController
|
6
|
-
def test_i18n_scope
|
7
|
-
set_flash_message(:notice, :signed_in)
|
8
|
-
end
|
9
|
-
end
|
10
|
-
|
11
|
-
class AnotherInheritedController < SessionsInheritedController
|
12
|
-
protected
|
13
|
-
|
14
|
-
def translation_scope
|
15
|
-
'another'
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
class InheritedControllerTest < Devise::ControllerTestCase
|
20
|
-
tests SessionsInheritedController
|
21
|
-
|
22
|
-
def setup
|
23
|
-
@mock_warden = OpenStruct.new
|
24
|
-
@controller.request.env['warden'] = @mock_warden
|
25
|
-
@controller.request.env['devise.mapping'] = Devise.mappings[:user]
|
26
|
-
end
|
27
|
-
|
28
|
-
test 'I18n scope is inherited from Devise::Sessions' do
|
29
|
-
I18n.expects(:t).with do |message, options|
|
30
|
-
message == 'user.signed_in' &&
|
31
|
-
options[:scope] == 'devise.sessions'
|
32
|
-
end
|
33
|
-
@controller.test_i18n_scope
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
class AnotherInheritedControllerTest < Devise::ControllerTestCase
|
38
|
-
tests AnotherInheritedController
|
39
|
-
|
40
|
-
def setup
|
41
|
-
@mock_warden = OpenStruct.new
|
42
|
-
@controller.request.env['warden'] = @mock_warden
|
43
|
-
@controller.request.env['devise.mapping'] = Devise.mappings[:user]
|
44
|
-
end
|
45
|
-
|
46
|
-
test 'I18n scope is overridden' do
|
47
|
-
I18n.expects(:t).with do |message, options|
|
48
|
-
message == 'user.signed_in' &&
|
49
|
-
options[:scope] == 'another'
|
50
|
-
end
|
51
|
-
@controller.test_i18n_scope
|
52
|
-
end
|
53
|
-
end
|
@@ -1,129 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'test_helper'
|
4
|
-
|
5
|
-
class MyController < DeviseController
|
6
|
-
end
|
7
|
-
|
8
|
-
class HelpersTest < Devise::ControllerTestCase
|
9
|
-
tests MyController
|
10
|
-
|
11
|
-
def setup
|
12
|
-
@mock_warden = OpenStruct.new
|
13
|
-
@controller.request.env['warden'] = @mock_warden
|
14
|
-
@controller.request.env['devise.mapping'] = Devise.mappings[:user]
|
15
|
-
end
|
16
|
-
|
17
|
-
test 'get resource name from env' do
|
18
|
-
assert_equal :user, @controller.send(:resource_name)
|
19
|
-
end
|
20
|
-
|
21
|
-
test 'get resource class from env' do
|
22
|
-
assert_equal User, @controller.send(:resource_class)
|
23
|
-
end
|
24
|
-
|
25
|
-
test 'get resource instance variable from env' do
|
26
|
-
@controller.instance_variable_set(:@user, user = User.new)
|
27
|
-
assert_equal user, @controller.send(:resource)
|
28
|
-
end
|
29
|
-
|
30
|
-
test 'set resource instance variable from env' do
|
31
|
-
user = @controller.send(:resource_class).new
|
32
|
-
@controller.send(:resource=, user)
|
33
|
-
|
34
|
-
assert_equal user, @controller.send(:resource)
|
35
|
-
assert_equal user, @controller.instance_variable_get(:@user)
|
36
|
-
end
|
37
|
-
|
38
|
-
test 'get resource params from request params using resource name as key' do
|
39
|
-
user_params = {'email' => 'shirley@templar.com'}
|
40
|
-
|
41
|
-
# Stub controller name so strong parameters can filter properly.
|
42
|
-
# DeviseController does not allow any parameters by default.
|
43
|
-
@controller.stubs(:controller_name).returns(:sessions_controller)
|
44
|
-
|
45
|
-
params = ActionController::Parameters.new({'user' => user_params})
|
46
|
-
|
47
|
-
@controller.stubs(:params).returns(params)
|
48
|
-
|
49
|
-
res_params = @controller.send(:resource_params).permit!.to_h
|
50
|
-
assert_equal user_params, res_params
|
51
|
-
end
|
52
|
-
|
53
|
-
test 'resources methods are not controller actions' do
|
54
|
-
assert @controller.class.action_methods.delete_if { |m| m.include? 'commenter' }.empty?
|
55
|
-
end
|
56
|
-
|
57
|
-
test 'require no authentication tests current mapping' do
|
58
|
-
@mock_warden.expects(:authenticate?).with(:rememberable, scope: :user).returns(true)
|
59
|
-
@mock_warden.expects(:user).with(:user).returns(User.new)
|
60
|
-
@controller.expects(:redirect_to).with(root_path)
|
61
|
-
@controller.send :require_no_authentication
|
62
|
-
end
|
63
|
-
|
64
|
-
test 'require no authentication only checks if already authenticated if no inputs strategies are available' do
|
65
|
-
Devise.mappings[:user].expects(:no_input_strategies).returns([])
|
66
|
-
@mock_warden.expects(:authenticate?).never
|
67
|
-
@mock_warden.expects(:authenticated?).with(:user).once.returns(true)
|
68
|
-
@mock_warden.expects(:user).with(:user).returns(User.new)
|
69
|
-
@controller.expects(:redirect_to).with(root_path)
|
70
|
-
@controller.send :require_no_authentication
|
71
|
-
end
|
72
|
-
|
73
|
-
test 'require no authentication sets a flash message' do
|
74
|
-
@mock_warden.expects(:authenticate?).with(:rememberable, scope: :user).returns(true)
|
75
|
-
@mock_warden.expects(:user).with(:user).returns(User.new)
|
76
|
-
@controller.expects(:redirect_to).with(root_path)
|
77
|
-
@controller.send :require_no_authentication
|
78
|
-
assert flash[:alert] == I18n.t("devise.failure.already_authenticated")
|
79
|
-
end
|
80
|
-
|
81
|
-
test 'signed in resource returns signed in resource for current scope' do
|
82
|
-
@mock_warden.expects(:authenticate).with(scope: :user).returns(User.new)
|
83
|
-
assert_kind_of User, @controller.send(:signed_in_resource)
|
84
|
-
end
|
85
|
-
|
86
|
-
test 'is a devise controller' do
|
87
|
-
assert @controller.devise_controller?
|
88
|
-
end
|
89
|
-
|
90
|
-
test 'does not issue blank flash messages' do
|
91
|
-
I18n.stubs(:t).returns(' ')
|
92
|
-
@controller.send :set_flash_message, :notice, :send_instructions
|
93
|
-
assert flash[:notice].nil?
|
94
|
-
end
|
95
|
-
|
96
|
-
test 'issues non-blank flash messages normally' do
|
97
|
-
I18n.stubs(:t).returns('non-blank')
|
98
|
-
@controller.send :set_flash_message, :notice, :send_instructions
|
99
|
-
assert_equal 'non-blank', flash[:notice]
|
100
|
-
end
|
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
|
-
|
108
|
-
test 'uses custom i18n options' do
|
109
|
-
@controller.stubs(:devise_i18n_options).returns(default: "devise custom options")
|
110
|
-
@controller.send :set_flash_message, :notice, :invalid_i18n_messagesend_instructions
|
111
|
-
assert_equal 'devise custom options', flash[:notice]
|
112
|
-
end
|
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
|
-
|
120
|
-
test 'navigational_formats not returning a wild card' do
|
121
|
-
MyController.send(:public, :navigational_formats)
|
122
|
-
|
123
|
-
swap Devise, navigational_formats: ['*/*', :html] do
|
124
|
-
refute @controller.navigational_formats.include?("*/*")
|
125
|
-
end
|
126
|
-
|
127
|
-
MyController.send(:protected, :navigational_formats)
|
128
|
-
end
|
129
|
-
end
|
@@ -1,21 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'test_helper'
|
4
|
-
|
5
|
-
class LoadHooksControllerTest < Devise::ControllerTestCase
|
6
|
-
setup do
|
7
|
-
ActiveSupport.on_load(:devise_controller) do
|
8
|
-
define_method :defined_by_load_hook do
|
9
|
-
puts 'I am defined dynamically by activesupport load hook'
|
10
|
-
end
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
teardown do
|
15
|
-
DeviseController.class_eval { undef :defined_by_load_hook }
|
16
|
-
end
|
17
|
-
|
18
|
-
test 'load hook called when controller is loaded' do
|
19
|
-
assert DeviseController.instance_methods.include? :defined_by_load_hook
|
20
|
-
end
|
21
|
-
end
|
@@ -1,34 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'test_helper'
|
4
|
-
|
5
|
-
class PasswordsControllerTest < Devise::ControllerTestCase
|
6
|
-
tests Devise::PasswordsController
|
7
|
-
include Devise::Test::ControllerHelpers
|
8
|
-
|
9
|
-
setup do
|
10
|
-
request.env["devise.mapping"] = Devise.mappings[:user]
|
11
|
-
@user = create_user.tap(&:confirm)
|
12
|
-
@raw = @user.send_reset_password_instructions
|
13
|
-
end
|
14
|
-
|
15
|
-
def put_update_with_params
|
16
|
-
put :update, params: { "user" => {
|
17
|
-
"reset_password_token" => @raw, "password" => "1234567", "password_confirmation" => "1234567"
|
18
|
-
}
|
19
|
-
}
|
20
|
-
end
|
21
|
-
|
22
|
-
test 'redirect to after_sign_in_path_for if after_resetting_password_path_for is not overridden' do
|
23
|
-
put_update_with_params
|
24
|
-
assert_redirected_to "http://test.host/"
|
25
|
-
end
|
26
|
-
|
27
|
-
test 'redirect accordingly if after_resetting_password_path_for is overridden' do
|
28
|
-
custom_path = "http://custom.path/"
|
29
|
-
Devise::PasswordsController.any_instance.stubs(:after_resetting_password_path_for).with(@user).returns(custom_path)
|
30
|
-
|
31
|
-
put_update_with_params
|
32
|
-
assert_redirected_to custom_path
|
33
|
-
end
|
34
|
-
end
|
@@ -1,108 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'test_helper'
|
4
|
-
|
5
|
-
class SessionsControllerTest < Devise::ControllerTestCase
|
6
|
-
tests Devise::SessionsController
|
7
|
-
include Devise::Test::ControllerHelpers
|
8
|
-
|
9
|
-
test "#create doesn't raise unpermitted params when sign in fails" do
|
10
|
-
begin
|
11
|
-
subscriber = ActiveSupport::Notifications.subscribe %r{unpermitted_parameters} do |name, start, finish, id, payload|
|
12
|
-
flunk "Unpermitted params: #{payload}"
|
13
|
-
end
|
14
|
-
request.env["devise.mapping"] = Devise.mappings[:user]
|
15
|
-
request.session["user_return_to"] = 'foo.bar'
|
16
|
-
create_user
|
17
|
-
post :create, params: { user: {
|
18
|
-
email: "wrong@email.com",
|
19
|
-
password: "wrongpassword"
|
20
|
-
}
|
21
|
-
}
|
22
|
-
assert_equal 200, @response.status
|
23
|
-
ensure
|
24
|
-
ActiveSupport::Notifications.unsubscribe(subscriber)
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
test "#create works even with scoped views" do
|
29
|
-
swap Devise, scoped_views: true do
|
30
|
-
request.env["devise.mapping"] = Devise.mappings[:user]
|
31
|
-
post :create
|
32
|
-
assert_equal 200, @response.status
|
33
|
-
assert_template "users/sessions/new"
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
test "#create delete the url stored in the session if the requested format is navigational" do
|
38
|
-
request.env["devise.mapping"] = Devise.mappings[:user]
|
39
|
-
request.session["user_return_to"] = 'foo.bar'
|
40
|
-
|
41
|
-
user = create_user
|
42
|
-
user.confirm
|
43
|
-
post :create, params: { user: {
|
44
|
-
email: user.email,
|
45
|
-
password: user.password
|
46
|
-
}
|
47
|
-
}
|
48
|
-
assert_nil request.session["user_return_to"]
|
49
|
-
end
|
50
|
-
|
51
|
-
test "#create doesn't delete the url stored in the session if the requested format is not navigational" do
|
52
|
-
request.env["devise.mapping"] = Devise.mappings[:user]
|
53
|
-
request.session["user_return_to"] = 'foo.bar'
|
54
|
-
|
55
|
-
user = create_user
|
56
|
-
user.confirm
|
57
|
-
post :create, params: { format: 'json', user: {
|
58
|
-
email: user.email,
|
59
|
-
password: user.password
|
60
|
-
}
|
61
|
-
}
|
62
|
-
|
63
|
-
assert_equal 'foo.bar', request.session["user_return_to"]
|
64
|
-
end
|
65
|
-
|
66
|
-
test "#create doesn't raise exception after Warden authentication fails when TestHelpers included" do
|
67
|
-
request.env["devise.mapping"] = Devise.mappings[:user]
|
68
|
-
post :create, params: { user: {
|
69
|
-
email: "nosuchuser@example.com",
|
70
|
-
password: "wevdude"
|
71
|
-
}
|
72
|
-
}
|
73
|
-
assert_equal 200, @response.status
|
74
|
-
assert_template "devise/sessions/new"
|
75
|
-
end
|
76
|
-
|
77
|
-
test "#destroy doesn't set the flash if the requested format is not navigational" do
|
78
|
-
request.env["devise.mapping"] = Devise.mappings[:user]
|
79
|
-
user = create_user
|
80
|
-
user.confirm
|
81
|
-
post :create, params: { format: 'json', user: {
|
82
|
-
email: user.email,
|
83
|
-
password: user.password
|
84
|
-
}
|
85
|
-
}
|
86
|
-
delete :destroy, format: 'json'
|
87
|
-
assert flash[:notice].blank?, "flash[:notice] should be blank, not #{flash[:notice].inspect}"
|
88
|
-
assert_equal 204, @response.status
|
89
|
-
end
|
90
|
-
|
91
|
-
if defined?(ActiveRecord) && ActiveRecord::Base.respond_to?(:mass_assignment_sanitizer)
|
92
|
-
test "#new doesn't raise mass-assignment exception even if sign-in key is attr_protected" do
|
93
|
-
request.env["devise.mapping"] = Devise.mappings[:user]
|
94
|
-
|
95
|
-
ActiveRecord::Base.mass_assignment_sanitizer = :strict
|
96
|
-
User.class_eval { attr_protected :email }
|
97
|
-
|
98
|
-
begin
|
99
|
-
assert_nothing_raised do
|
100
|
-
get :new, user: { email: "allez viens!" }
|
101
|
-
end
|
102
|
-
ensure
|
103
|
-
ActiveRecord::Base.mass_assignment_sanitizer = :logger
|
104
|
-
User.class_eval { attr_accessible :email }
|
105
|
-
end
|
106
|
-
end
|
107
|
-
end
|
108
|
-
end
|
@@ -1,67 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'test_helper'
|
4
|
-
|
5
|
-
class RoutesTest < Devise::ControllerTestCase
|
6
|
-
tests ApplicationController
|
7
|
-
|
8
|
-
def assert_path_and_url(name, prepend_path=nil)
|
9
|
-
@request.path = '/users/session'
|
10
|
-
prepend_path = "#{prepend_path}_" if prepend_path
|
11
|
-
|
12
|
-
# Resource param
|
13
|
-
assert_equal @controller.send(:"#{prepend_path}#{name}_path", :user),
|
14
|
-
send(:"#{prepend_path}user_#{name}_path")
|
15
|
-
assert_equal @controller.send(:"#{prepend_path}#{name}_url", :user),
|
16
|
-
send(:"#{prepend_path}user_#{name}_url")
|
17
|
-
|
18
|
-
# With string
|
19
|
-
assert_equal @controller.send(:"#{prepend_path}#{name}_path", "user"),
|
20
|
-
send(:"#{prepend_path}user_#{name}_path")
|
21
|
-
assert_equal @controller.send(:"#{prepend_path}#{name}_url", "user"),
|
22
|
-
send(:"#{prepend_path}user_#{name}_url")
|
23
|
-
|
24
|
-
# Default url params
|
25
|
-
assert_equal @controller.send(:"#{prepend_path}#{name}_path", :user, param: 123),
|
26
|
-
send(:"#{prepend_path}user_#{name}_path", param: 123)
|
27
|
-
assert_equal @controller.send(:"#{prepend_path}#{name}_url", :user, param: 123),
|
28
|
-
send(:"#{prepend_path}user_#{name}_url", param: 123)
|
29
|
-
|
30
|
-
@request.path = nil
|
31
|
-
# With an object
|
32
|
-
assert_equal @controller.send(:"#{prepend_path}#{name}_path", User.new),
|
33
|
-
send(:"#{prepend_path}user_#{name}_path")
|
34
|
-
assert_equal @controller.send(:"#{prepend_path}#{name}_url", User.new),
|
35
|
-
send(:"#{prepend_path}user_#{name}_url")
|
36
|
-
end
|
37
|
-
|
38
|
-
|
39
|
-
test 'should alias session to mapped user session' do
|
40
|
-
assert_path_and_url :session
|
41
|
-
assert_path_and_url :session, :new
|
42
|
-
assert_path_and_url :session, :destroy
|
43
|
-
end
|
44
|
-
|
45
|
-
test 'should alias password to mapped user password' do
|
46
|
-
assert_path_and_url :password
|
47
|
-
assert_path_and_url :password, :new
|
48
|
-
assert_path_and_url :password, :edit
|
49
|
-
end
|
50
|
-
|
51
|
-
test 'should alias confirmation to mapped user confirmation' do
|
52
|
-
assert_path_and_url :confirmation
|
53
|
-
assert_path_and_url :confirmation, :new
|
54
|
-
end
|
55
|
-
|
56
|
-
test 'should alias unlock to mapped user unlock' do
|
57
|
-
assert_path_and_url :unlock
|
58
|
-
assert_path_and_url :unlock, :new
|
59
|
-
end
|
60
|
-
|
61
|
-
test 'should alias registration to mapped user registration' do
|
62
|
-
assert_path_and_url :registration
|
63
|
-
assert_path_and_url :registration, :new
|
64
|
-
assert_path_and_url :registration, :edit
|
65
|
-
assert_path_and_url :registration, :cancel
|
66
|
-
end
|
67
|
-
end
|
data/test/delegator_test.rb
DELETED
@@ -1,21 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'test_helper'
|
4
|
-
|
5
|
-
class DelegatorTest < ActiveSupport::TestCase
|
6
|
-
def delegator
|
7
|
-
Devise::Delegator.new
|
8
|
-
end
|
9
|
-
|
10
|
-
test 'failure_app returns default failure app if no warden options in env' do
|
11
|
-
assert_equal Devise::FailureApp, delegator.failure_app({})
|
12
|
-
end
|
13
|
-
|
14
|
-
test 'failure_app returns default failure app if no scope in warden options' do
|
15
|
-
assert_equal Devise::FailureApp, delegator.failure_app({"warden.options" => {}})
|
16
|
-
end
|
17
|
-
|
18
|
-
test 'failure_app returns associated failure app by scope in the given environment' do
|
19
|
-
assert_kind_of Proc, delegator.failure_app({"warden.options" => {scope: "manager"}})
|
20
|
-
end
|
21
|
-
end
|
data/test/devise_test.rb
DELETED
@@ -1,109 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'test_helper'
|
4
|
-
|
5
|
-
module Devise
|
6
|
-
def self.yield_and_restore
|
7
|
-
@@warden_configured = nil
|
8
|
-
c, b = @@warden_config, @@warden_config_blocks
|
9
|
-
yield
|
10
|
-
ensure
|
11
|
-
@@warden_config, @@warden_config_blocks = c, b
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
class DeviseTest < ActiveSupport::TestCase
|
16
|
-
test 'bcrypt on the class' do
|
17
|
-
password = "super secret"
|
18
|
-
klass = Struct.new(:pepper, :stretches).new("blahblah", 2)
|
19
|
-
hash = Devise::Encryptor.digest(klass, password)
|
20
|
-
assert_equal ::BCrypt::Password.create(hash), hash
|
21
|
-
|
22
|
-
klass = Struct.new(:pepper, :stretches).new("bla", 2)
|
23
|
-
hash = Devise::Encryptor.digest(klass, password)
|
24
|
-
assert_not_equal ::BCrypt::Password.new(hash), hash
|
25
|
-
end
|
26
|
-
|
27
|
-
test 'model options can be configured through Devise' do
|
28
|
-
swap Devise, allow_unconfirmed_access_for: 113, pepper: "foo" do
|
29
|
-
assert_equal 113, Devise.allow_unconfirmed_access_for
|
30
|
-
assert_equal "foo", Devise.pepper
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
test 'setup block yields self' do
|
35
|
-
Devise.setup do |config|
|
36
|
-
assert_equal Devise, config
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
test 'stores warden configuration' do
|
41
|
-
assert_kind_of Devise::Delegator, Devise.warden_config.failure_app
|
42
|
-
assert_equal :user, Devise.warden_config.default_scope
|
43
|
-
end
|
44
|
-
|
45
|
-
test 'warden manager user configuration through a block' do
|
46
|
-
Devise.yield_and_restore do
|
47
|
-
executed = false
|
48
|
-
Devise.warden do |config|
|
49
|
-
executed = true
|
50
|
-
assert_kind_of Warden::Config, config
|
51
|
-
end
|
52
|
-
|
53
|
-
Devise.configure_warden!
|
54
|
-
assert executed
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
test 'warden manager user configuration through multiple blocks' do
|
59
|
-
Devise.yield_and_restore do
|
60
|
-
executed = 0
|
61
|
-
|
62
|
-
3.times do
|
63
|
-
Devise.warden { |config| executed += 1 }
|
64
|
-
end
|
65
|
-
|
66
|
-
Devise.configure_warden!
|
67
|
-
assert_equal 3, executed
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
test 'add new module using the helper method' do
|
72
|
-
Devise.add_module(:coconut)
|
73
|
-
assert_equal 1, Devise::ALL.select { |v| v == :coconut }.size
|
74
|
-
refute Devise::STRATEGIES.include?(:coconut)
|
75
|
-
refute defined?(Devise::Models::Coconut)
|
76
|
-
Devise::ALL.delete(:coconut)
|
77
|
-
|
78
|
-
Devise.add_module(:banana, strategy: :fruits)
|
79
|
-
assert_equal :fruits, Devise::STRATEGIES[:banana]
|
80
|
-
Devise::ALL.delete(:banana)
|
81
|
-
Devise::STRATEGIES.delete(:banana)
|
82
|
-
|
83
|
-
Devise.add_module(:kivi, controller: :fruits)
|
84
|
-
assert_equal :fruits, Devise::CONTROLLERS[:kivi]
|
85
|
-
Devise::ALL.delete(:kivi)
|
86
|
-
Devise::CONTROLLERS.delete(:kivi)
|
87
|
-
end
|
88
|
-
|
89
|
-
test 'should complain when comparing empty or different sized passes' do
|
90
|
-
[nil, ""].each do |empty|
|
91
|
-
refute Devise.secure_compare(empty, "something")
|
92
|
-
refute Devise.secure_compare("something", empty)
|
93
|
-
refute Devise.secure_compare(empty, empty)
|
94
|
-
end
|
95
|
-
refute Devise.secure_compare("size_1", "size_four")
|
96
|
-
end
|
97
|
-
|
98
|
-
test 'Devise.email_regexp should match valid email addresses' do
|
99
|
-
valid_emails = ["test@example.com", "jo@jo.co", "f4$_m@you.com", "testing.example@example.com.ua", "test@tt", "test@valid---domain.com"]
|
100
|
-
non_valid_emails = ["rex", "test user@example.com", "test_user@example server.com"]
|
101
|
-
|
102
|
-
valid_emails.each do |email|
|
103
|
-
assert_match Devise.email_regexp, email
|
104
|
-
end
|
105
|
-
non_valid_emails.each do |email|
|
106
|
-
assert_no_match Devise.email_regexp, email
|
107
|
-
end
|
108
|
-
end
|
109
|
-
end
|