devise 3.2.1 → 4.4.3
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 +58 -10
- data/CHANGELOG.md +199 -979
- data/CODE_OF_CONDUCT.md +22 -0
- data/CONTRIBUTING.md +73 -8
- data/Gemfile +19 -11
- data/Gemfile.lock +152 -119
- data/ISSUE_TEMPLATE.md +19 -0
- data/MIT-LICENSE +1 -1
- data/README.md +347 -93
- data/Rakefile +4 -2
- data/app/controllers/devise/confirmations_controller.rb +11 -5
- data/app/controllers/devise/omniauth_callbacks_controller.rb +12 -6
- data/app/controllers/devise/passwords_controller.rb +20 -8
- data/app/controllers/devise/registrations_controller.rb +34 -19
- data/app/controllers/devise/sessions_controller.rb +47 -17
- data/app/controllers/devise/unlocks_controller.rb +9 -4
- data/app/controllers/devise_controller.rb +67 -31
- data/app/helpers/devise_helper.rb +4 -2
- data/app/mailers/devise/mailer.rb +10 -0
- data/app/views/devise/confirmations/new.html.erb +8 -4
- data/app/views/devise/mailer/confirmation_instructions.html.erb +1 -1
- data/app/views/devise/mailer/email_changed.html.erb +7 -0
- data/app/views/devise/mailer/password_change.html.erb +3 -0
- data/app/views/devise/mailer/reset_password_instructions.html.erb +1 -1
- data/app/views/devise/mailer/unlock_instructions.html.erb +1 -1
- 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 +28 -14
- 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} +2 -2
- data/app/views/devise/unlocks/new.html.erb +8 -4
- data/bin/test +13 -0
- data/config/locales/en.yml +22 -17
- data/devise.gemspec +7 -6
- data/gemfiles/Gemfile.rails-4.1-stable +32 -0
- data/gemfiles/Gemfile.rails-4.1-stable.lock +171 -0
- data/gemfiles/Gemfile.rails-4.2-stable +32 -0
- data/gemfiles/Gemfile.rails-4.2-stable.lock +192 -0
- data/gemfiles/Gemfile.rails-5.0-stable +33 -0
- data/gemfiles/Gemfile.rails-5.0-stable.lock +192 -0
- data/gemfiles/Gemfile.rails-5.2-rc1 +26 -0
- data/gemfiles/Gemfile.rails-5.2-rc1.lock +201 -0
- data/guides/bug_report_templates/integration_test.rb +106 -0
- data/lib/devise.rb +107 -84
- data/lib/devise/controllers/helpers.rb +111 -31
- data/lib/devise/controllers/rememberable.rb +15 -6
- data/lib/devise/controllers/scoped_views.rb +3 -1
- data/lib/devise/controllers/sign_in_out.rb +39 -26
- data/lib/devise/controllers/store_location.rb +31 -2
- data/lib/devise/controllers/url_helpers.rb +9 -7
- data/lib/devise/delegator.rb +2 -0
- data/lib/devise/encryptor.rb +24 -0
- data/lib/devise/failure_app.rb +98 -39
- data/lib/devise/hooks/activatable.rb +7 -6
- data/lib/devise/hooks/csrf_cleaner.rb +5 -1
- data/lib/devise/hooks/forgetable.rb +2 -0
- data/lib/devise/hooks/lockable.rb +7 -2
- data/lib/devise/hooks/proxy.rb +4 -2
- data/lib/devise/hooks/rememberable.rb +4 -2
- data/lib/devise/hooks/timeoutable.rb +16 -9
- data/lib/devise/hooks/trackable.rb +3 -1
- data/lib/devise/mailers/helpers.rb +15 -12
- data/lib/devise/mapping.rb +8 -2
- data/lib/devise/models.rb +3 -1
- data/lib/devise/models/authenticatable.rb +63 -36
- data/lib/devise/models/confirmable.rb +121 -41
- data/lib/devise/models/database_authenticatable.rb +66 -23
- data/lib/devise/models/lockable.rb +30 -17
- data/lib/devise/models/omniauthable.rb +3 -1
- data/lib/devise/models/recoverable.rb +62 -26
- data/lib/devise/models/registerable.rb +2 -0
- data/lib/devise/models/rememberable.rb +62 -33
- data/lib/devise/models/timeoutable.rb +4 -8
- data/lib/devise/models/trackable.rb +12 -3
- data/lib/devise/models/validatable.rb +16 -9
- data/lib/devise/modules.rb +12 -10
- data/lib/devise/omniauth.rb +2 -0
- data/lib/devise/omniauth/config.rb +2 -0
- data/lib/devise/omniauth/url_helpers.rb +14 -5
- data/lib/devise/orm/active_record.rb +5 -1
- data/lib/devise/orm/mongoid.rb +6 -2
- data/lib/devise/parameter_filter.rb +2 -0
- data/lib/devise/parameter_sanitizer.rb +131 -69
- data/lib/devise/rails.rb +10 -13
- data/lib/devise/rails/routes.rb +147 -116
- data/lib/devise/rails/warden_compat.rb +3 -10
- data/lib/devise/secret_key_finder.rb +25 -0
- data/lib/devise/strategies/authenticatable.rb +20 -9
- data/lib/devise/strategies/base.rb +3 -1
- data/lib/devise/strategies/database_authenticatable.rb +8 -5
- data/lib/devise/strategies/rememberable.rb +15 -3
- data/lib/devise/test/controller_helpers.rb +165 -0
- data/lib/devise/test/integration_helpers.rb +63 -0
- data/lib/devise/test_helpers.rb +7 -124
- data/lib/devise/time_inflector.rb +4 -2
- data/lib/devise/token_generator.rb +3 -41
- data/lib/devise/version.rb +3 -1
- data/lib/generators/active_record/devise_generator.rb +47 -10
- data/lib/generators/active_record/templates/migration.rb +9 -7
- data/lib/generators/active_record/templates/migration_existing.rb +9 -7
- data/lib/generators/devise/controllers_generator.rb +46 -0
- data/lib/generators/devise/devise_generator.rb +9 -5
- data/lib/generators/devise/install_generator.rb +22 -0
- data/lib/generators/devise/orm_helpers.rb +8 -19
- data/lib/generators/devise/views_generator.rb +51 -28
- data/lib/generators/mongoid/devise_generator.rb +22 -19
- data/lib/generators/templates/README +5 -12
- data/lib/generators/templates/controllers/README +14 -0
- data/lib/generators/templates/controllers/confirmations_controller.rb +30 -0
- data/lib/generators/templates/controllers/omniauth_callbacks_controller.rb +30 -0
- data/lib/generators/templates/controllers/passwords_controller.rb +34 -0
- data/lib/generators/templates/controllers/registrations_controller.rb +62 -0
- data/lib/generators/templates/controllers/sessions_controller.rb +27 -0
- data/lib/generators/templates/controllers/unlocks_controller.rb +30 -0
- data/lib/generators/templates/devise.rb +64 -35
- data/lib/generators/templates/markerb/confirmation_instructions.markerb +1 -1
- data/lib/generators/templates/markerb/email_changed.markerb +7 -0
- 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/confirmations/new.html.erb +2 -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 +6 -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 +2 -2
- data/test/controllers/custom_registrations_controller_test.rb +42 -0
- data/test/controllers/custom_strategy_test.rb +10 -6
- data/test/controllers/helper_methods_test.rb +24 -0
- data/test/controllers/helpers_test.rb +88 -40
- data/test/controllers/inherited_controller_i18n_messages_test.rb +53 -0
- data/test/controllers/internal_helpers_test.rb +31 -22
- data/test/controllers/load_hooks_controller_test.rb +21 -0
- data/test/controllers/passwords_controller_test.rb +8 -5
- data/test/controllers/sessions_controller_test.rb +42 -33
- data/test/controllers/url_helpers_test.rb +13 -5
- data/test/delegator_test.rb +3 -1
- data/test/devise_test.rb +34 -19
- data/test/failure_app_test.rb +150 -42
- data/test/generators/active_record_generator_test.rb +58 -31
- data/test/generators/controllers_generator_test.rb +50 -0
- data/test/generators/devise_generator_test.rb +4 -2
- data/test/generators/install_generator_test.rb +16 -3
- data/test/generators/mongoid_generator_test.rb +5 -3
- data/test/generators/views_generator_test.rb +40 -2
- data/test/helpers/devise_helper_test.rb +20 -20
- data/test/integration/authenticatable_test.rb +134 -141
- data/test/integration/confirmable_test.rb +109 -67
- data/test/integration/database_authenticatable_test.rb +36 -23
- data/test/integration/http_authenticatable_test.rb +29 -20
- data/test/integration/lockable_test.rb +52 -49
- data/test/integration/mounted_engine_test.rb +38 -0
- data/test/integration/omniauthable_test.rb +30 -15
- data/test/integration/recoverable_test.rb +76 -61
- data/test/integration/registerable_test.rb +107 -91
- data/test/integration/rememberable_test.rb +82 -30
- data/test/integration/timeoutable_test.rb +48 -40
- data/test/integration/trackable_test.rb +15 -8
- data/test/mailers/confirmation_instructions_test.rb +16 -14
- data/test/mailers/email_changed_test.rb +132 -0
- data/test/mailers/mailer_test.rb +20 -0
- data/test/mailers/reset_password_instructions_test.rb +13 -11
- data/test/mailers/unlock_instructions_test.rb +12 -10
- data/test/mapping_test.rb +15 -6
- data/test/models/authenticatable_test.rb +15 -3
- data/test/models/confirmable_test.rb +190 -95
- data/test/models/database_authenticatable_test.rb +75 -41
- data/test/models/lockable_test.rb +115 -61
- data/test/models/omniauthable_test.rb +3 -1
- data/test/models/recoverable_test.rb +116 -37
- data/test/models/registerable_test.rb +3 -1
- data/test/models/rememberable_test.rb +95 -94
- data/test/models/serializable_test.rb +19 -8
- data/test/models/timeoutable_test.rb +10 -8
- data/test/models/trackable_test.rb +50 -1
- data/test/models/validatable_test.rb +24 -30
- data/test/models_test.rb +19 -8
- data/test/omniauth/config_test.rb +15 -11
- data/test/omniauth/url_helpers_test.rb +8 -9
- data/test/orm/active_record.rb +16 -2
- data/test/orm/mongoid.rb +4 -2
- data/test/parameter_sanitizer_test.rb +53 -57
- data/test/rails_app/app/active_record/admin.rb +2 -0
- data/test/rails_app/app/active_record/shim.rb +3 -1
- data/test/rails_app/app/active_record/user.rb +14 -0
- data/test/rails_app/app/active_record/user_on_engine.rb +9 -0
- data/test/rails_app/app/active_record/user_on_main_app.rb +9 -0
- data/test/rails_app/app/active_record/user_with_validations.rb +12 -0
- data/test/rails_app/app/active_record/user_without_email.rb +10 -0
- data/test/rails_app/app/controllers/admins/sessions_controller.rb +3 -1
- data/test/rails_app/app/controllers/admins_controller.rb +3 -6
- data/test/rails_app/app/controllers/application_controller.rb +7 -3
- data/test/rails_app/app/controllers/application_with_fake_engine.rb +32 -0
- data/test/rails_app/app/controllers/custom/registrations_controller.rb +33 -0
- data/test/rails_app/app/controllers/home_controller.rb +7 -1
- data/test/rails_app/app/controllers/publisher/registrations_controller.rb +3 -1
- data/test/rails_app/app/controllers/publisher/sessions_controller.rb +3 -1
- data/test/rails_app/app/controllers/users/omniauth_callbacks_controller.rb +7 -5
- data/test/rails_app/app/controllers/users_controller.rb +8 -6
- data/test/rails_app/app/helpers/application_helper.rb +2 -0
- data/test/rails_app/app/mailers/users/from_proc_mailer.rb +5 -0
- data/test/rails_app/app/mailers/users/mailer.rb +3 -10
- data/test/rails_app/app/mailers/users/reply_to_mailer.rb +6 -0
- data/test/rails_app/app/mongoid/admin.rb +13 -11
- data/test/rails_app/app/mongoid/shim.rb +4 -2
- data/test/rails_app/app/mongoid/user.rb +30 -19
- data/test/rails_app/app/mongoid/user_on_engine.rb +41 -0
- data/test/rails_app/app/mongoid/user_on_main_app.rb +41 -0
- data/test/rails_app/app/mongoid/user_with_validations.rb +37 -0
- data/test/rails_app/app/mongoid/user_without_email.rb +35 -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/config/application.rb +13 -5
- data/test/rails_app/config/boot.rb +17 -4
- data/test/rails_app/config/environment.rb +2 -0
- data/test/rails_app/config/environments/development.rb +2 -0
- data/test/rails_app/config/environments/production.rb +10 -2
- data/test/rails_app/config/environments/test.rb +14 -3
- data/test/rails_app/config/initializers/backtrace_silencers.rb +2 -0
- data/test/rails_app/config/initializers/devise.rb +22 -21
- data/test/rails_app/config/initializers/inflections.rb +2 -0
- data/test/rails_app/config/initializers/secret_token.rb +3 -6
- data/test/rails_app/config/initializers/session_store.rb +2 -0
- data/test/rails_app/config/routes.rb +67 -43
- data/test/rails_app/db/migrate/20100401102949_create_tables.rb +16 -10
- data/test/rails_app/db/schema.rb +2 -0
- data/test/rails_app/lib/shared_admin.rb +10 -4
- data/test/rails_app/lib/shared_user.rb +4 -1
- data/test/rails_app/lib/shared_user_without_email.rb +28 -0
- data/test/rails_app/lib/shared_user_without_omniauth.rb +15 -0
- data/test/rails_test.rb +11 -0
- data/test/routes_test.rb +92 -61
- data/test/secret_key_finder_test.rb +97 -0
- data/test/support/action_controller/record_identifier.rb +12 -0
- data/test/support/assertions.rb +4 -14
- data/test/support/helpers.rb +23 -10
- data/test/support/http_method_compatibility.rb +53 -0
- data/test/support/integration.rb +19 -16
- data/test/support/mongoid.yml +6 -0
- data/test/support/webrat/integrations/rails.rb +11 -0
- data/test/{test_helpers_test.rb → test/controller_helpers_test.rb} +60 -40
- data/test/test/integration_helpers_test.rb +34 -0
- data/test/test_helper.rb +9 -0
- data/test/test_models.rb +8 -6
- metadata +123 -53
- data/gemfiles/Gemfile.rails-3.2.x +0 -31
- data/gemfiles/Gemfile.rails-3.2.x.lock +0 -159
@@ -0,0 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Since webrat uses ActionController::RecordIdentifier class that was moved to
|
4
|
+
# ActionView namespace in Rails 4.1+
|
5
|
+
|
6
|
+
unless defined?(ActionController::RecordIdentifier)
|
7
|
+
require 'action_view/record_identifier'
|
8
|
+
|
9
|
+
module ActionController
|
10
|
+
RecordIdentifier = ActionView::RecordIdentifier
|
11
|
+
end
|
12
|
+
end
|
data/test/support/assertions.rb
CHANGED
@@ -1,18 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'active_support/test_case'
|
2
4
|
|
3
5
|
class ActiveSupport::TestCase
|
4
|
-
def assert_not(assertion)
|
5
|
-
assert !assertion
|
6
|
-
end
|
7
|
-
|
8
6
|
def assert_blank(assertion)
|
9
7
|
assert assertion.blank?
|
10
8
|
end
|
11
9
|
|
12
|
-
def
|
13
|
-
assert
|
10
|
+
def assert_present(assertion)
|
11
|
+
assert assertion.present?
|
14
12
|
end
|
15
|
-
alias :assert_present :assert_not_blank
|
16
13
|
|
17
14
|
def assert_email_sent(address = nil, &block)
|
18
15
|
assert_difference('ActionMailer::Base.deliveries.size', &block)
|
@@ -25,13 +22,6 @@ class ActiveSupport::TestCase
|
|
25
22
|
assert_no_difference('ActionMailer::Base.deliveries.size', &block)
|
26
23
|
end
|
27
24
|
|
28
|
-
def assert_same_content(result, expected)
|
29
|
-
assert expected.size == result.size, "the arrays doesn't have the same size"
|
30
|
-
expected.each do |element|
|
31
|
-
assert result.include?(element), "The array doesn't include '#{element}'."
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
25
|
def assert_raise_with_message(exception_klass, message, &block)
|
36
26
|
exception = assert_raise exception_klass, &block
|
37
27
|
assert_equal exception.message, message,
|
data/test/support/helpers.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'active_support/test_case'
|
2
4
|
|
3
5
|
class ActiveSupport::TestCase
|
@@ -8,12 +10,15 @@ class ActiveSupport::TestCase
|
|
8
10
|
end
|
9
11
|
|
10
12
|
def store_translations(locale, translations, &block)
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
13
|
+
# Calling 'available_locales' before storing the translations to ensure
|
14
|
+
# that the I18n backend will be initialized before we store our custom
|
15
|
+
# translations, so they will always override the translations for the
|
16
|
+
# YML file.
|
17
|
+
I18n.available_locales
|
18
|
+
I18n.backend.store_translations(locale, translations)
|
19
|
+
yield
|
20
|
+
ensure
|
21
|
+
I18n.reload!
|
17
22
|
end
|
18
23
|
|
19
24
|
def generate_unique_email
|
@@ -23,10 +28,10 @@ class ActiveSupport::TestCase
|
|
23
28
|
end
|
24
29
|
|
25
30
|
def valid_attributes(attributes={})
|
26
|
-
{ :
|
27
|
-
:
|
28
|
-
:
|
29
|
-
:
|
31
|
+
{ username: "usertest",
|
32
|
+
email: generate_unique_email,
|
33
|
+
password: '12345678',
|
34
|
+
password_confirmation: '12345678' }.update(attributes)
|
30
35
|
end
|
31
36
|
|
32
37
|
def new_user(attributes={})
|
@@ -43,6 +48,14 @@ class ActiveSupport::TestCase
|
|
43
48
|
Admin.create!(valid_attributes)
|
44
49
|
end
|
45
50
|
|
51
|
+
def create_user_without_email(attributes={})
|
52
|
+
UserWithoutEmail.create!(valid_attributes(attributes))
|
53
|
+
end
|
54
|
+
|
55
|
+
def create_user_with_validations(attributes={})
|
56
|
+
UserWithValidations.create!(valid_attributes(attributes))
|
57
|
+
end
|
58
|
+
|
46
59
|
# Execute the block setting the given values and restoring old values after
|
47
60
|
# the block is executed.
|
48
61
|
def swap(object, new_values)
|
@@ -0,0 +1,53 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Devise
|
4
|
+
class IntegrationTest < ActionDispatch::IntegrationTest
|
5
|
+
# %w( get post patch put head delete xml_http_request
|
6
|
+
# xhr get_via_redirect post_via_redirect
|
7
|
+
# ).each do |method|
|
8
|
+
%w( get post put ).each do |method|
|
9
|
+
if Rails.version >= '5.0.0'
|
10
|
+
define_method(method) do |url, options={}|
|
11
|
+
if options.empty?
|
12
|
+
super url
|
13
|
+
else
|
14
|
+
super url, options
|
15
|
+
end
|
16
|
+
end
|
17
|
+
else
|
18
|
+
define_method(method) do |url, options={}|
|
19
|
+
if options[:xhr]==true
|
20
|
+
xml_http_request __method__, url, options[:params] || {}, options[:headers]
|
21
|
+
else
|
22
|
+
super url, options[:params] || {}, options[:headers]
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
class ControllerTestCase < ActionController::TestCase
|
30
|
+
# %w( get post patch put head delete xml_http_request
|
31
|
+
# xhr get_via_redirect post_via_redirect
|
32
|
+
# ).each do |method|
|
33
|
+
%w( get post put ).each do |method|
|
34
|
+
if Rails.version >= '5.0.0'
|
35
|
+
define_method(method) do |action, options={}|
|
36
|
+
if options.empty?
|
37
|
+
super action
|
38
|
+
else
|
39
|
+
super action, options
|
40
|
+
end
|
41
|
+
end
|
42
|
+
else
|
43
|
+
define_method(method) do |action, options={}|
|
44
|
+
if options[:xhr]==true
|
45
|
+
xml_http_request __method__, action, options[:params] || {}, options[:headers]
|
46
|
+
else
|
47
|
+
super action, options[:params] || {}, options[:headers]
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
data/test/support/integration.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'action_dispatch/testing/integration'
|
2
4
|
|
3
5
|
class ActionDispatch::IntegrationTest
|
@@ -8,15 +10,16 @@ class ActionDispatch::IntegrationTest
|
|
8
10
|
def create_user(options={})
|
9
11
|
@user ||= begin
|
10
12
|
user = User.create!(
|
11
|
-
:
|
12
|
-
:
|
13
|
-
:
|
14
|
-
:
|
15
|
-
:
|
13
|
+
username: 'usertest',
|
14
|
+
email: options[:email] || 'user@test.com',
|
15
|
+
password: options[:password] || '12345678',
|
16
|
+
password_confirmation: options[:password] || '12345678',
|
17
|
+
created_at: Time.now.utc
|
16
18
|
)
|
17
19
|
user.update_attribute(:confirmation_sent_at, options[:confirmation_sent_at]) if options[:confirmation_sent_at]
|
18
|
-
user.confirm
|
20
|
+
user.confirm unless options[:confirm] == false
|
19
21
|
user.lock_access! if options[:locked] == true
|
22
|
+
User.validations_performed = false
|
20
23
|
user
|
21
24
|
end
|
22
25
|
end
|
@@ -24,11 +27,11 @@ class ActionDispatch::IntegrationTest
|
|
24
27
|
def create_admin(options={})
|
25
28
|
@admin ||= begin
|
26
29
|
admin = Admin.create!(
|
27
|
-
:
|
28
|
-
:
|
29
|
-
:
|
30
|
+
email: options[:email] || 'admin@test.com',
|
31
|
+
password: '123456', password_confirmation: '123456',
|
32
|
+
active: options[:active]
|
30
33
|
)
|
31
|
-
admin.confirm
|
34
|
+
admin.confirm unless options[:confirm] == false
|
32
35
|
admin
|
33
36
|
end
|
34
37
|
end
|
@@ -36,21 +39,21 @@ class ActionDispatch::IntegrationTest
|
|
36
39
|
def sign_in_as_user(options={}, &block)
|
37
40
|
user = create_user(options)
|
38
41
|
visit_with_option options[:visit], new_user_session_path
|
39
|
-
fill_in 'email', :
|
40
|
-
fill_in 'password', :
|
42
|
+
fill_in 'email', with: options[:email] || 'user@test.com'
|
43
|
+
fill_in 'password', with: options[:password] || '12345678'
|
41
44
|
check 'remember me' if options[:remember_me] == true
|
42
45
|
yield if block_given?
|
43
|
-
click_button '
|
46
|
+
click_button 'Log In'
|
44
47
|
user
|
45
48
|
end
|
46
49
|
|
47
50
|
def sign_in_as_admin(options={}, &block)
|
48
51
|
admin = create_admin(options)
|
49
52
|
visit_with_option options[:visit], new_admin_session_path
|
50
|
-
fill_in 'email', :
|
51
|
-
fill_in 'password', :
|
53
|
+
fill_in 'email', with: 'admin@test.com'
|
54
|
+
fill_in 'password', with: '123456'
|
52
55
|
yield if block_given?
|
53
|
-
click_button '
|
56
|
+
click_button 'Log In'
|
54
57
|
admin
|
55
58
|
end
|
56
59
|
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'webrat/core/elements/form'
|
2
4
|
require 'action_dispatch/testing/integration'
|
3
5
|
|
@@ -14,6 +16,15 @@ module Webrat
|
|
14
16
|
::Rails.logger
|
15
17
|
end
|
16
18
|
end
|
19
|
+
|
20
|
+
class RailsAdapter
|
21
|
+
protected
|
22
|
+
|
23
|
+
def do_request(http_method, url, data, headers)
|
24
|
+
update_protocol(url)
|
25
|
+
integration_session.send(http_method, normalize_url(url), params: data, headers: headers)
|
26
|
+
end
|
27
|
+
end
|
17
28
|
end
|
18
29
|
|
19
30
|
module ActionDispatch #:nodoc:
|
@@ -1,14 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'test_helper'
|
2
4
|
|
3
|
-
class
|
5
|
+
class TestControllerHelpersTest < Devise::ControllerTestCase
|
4
6
|
tests UsersController
|
5
|
-
include Devise::
|
6
|
-
|
7
|
-
class CustomFailureApp < Devise::FailureApp
|
8
|
-
def redirect
|
9
|
-
self.status = 306
|
10
|
-
end
|
11
|
-
end
|
7
|
+
include Devise::Test::ControllerHelpers
|
12
8
|
|
13
9
|
test "redirects if attempting to access a page unauthenticated" do
|
14
10
|
get :index
|
@@ -17,7 +13,7 @@ class TestHelpersTest < ActionController::TestCase
|
|
17
13
|
end
|
18
14
|
|
19
15
|
test "redirects if attempting to access a page with an unconfirmed account" do
|
20
|
-
swap Devise, :
|
16
|
+
swap Devise, allow_unconfirmed_access_for: 0.days do
|
21
17
|
user = create_user
|
22
18
|
assert !user.active_for_authentication?
|
23
19
|
|
@@ -28,19 +24,19 @@ class TestHelpersTest < ActionController::TestCase
|
|
28
24
|
end
|
29
25
|
|
30
26
|
test "returns nil if accessing current_user with an unconfirmed account" do
|
31
|
-
swap Devise, :
|
27
|
+
swap Devise, allow_unconfirmed_access_for: 0.days do
|
32
28
|
user = create_user
|
33
29
|
assert !user.active_for_authentication?
|
34
30
|
|
35
31
|
sign_in user
|
36
|
-
get :accept, :id
|
32
|
+
get :accept, params: { id: user }
|
37
33
|
assert_nil assigns(:current_user)
|
38
34
|
end
|
39
35
|
end
|
40
36
|
|
41
37
|
test "does not redirect with valid user" do
|
42
38
|
user = create_user
|
43
|
-
user.confirm
|
39
|
+
user.confirm
|
44
40
|
|
45
41
|
sign_in user
|
46
42
|
get :index
|
@@ -52,7 +48,7 @@ class TestHelpersTest < ActionController::TestCase
|
|
52
48
|
assert_response :redirect
|
53
49
|
|
54
50
|
user = create_user
|
55
|
-
user.confirm
|
51
|
+
user.confirm
|
56
52
|
|
57
53
|
sign_in user
|
58
54
|
get :index
|
@@ -61,7 +57,7 @@ class TestHelpersTest < ActionController::TestCase
|
|
61
57
|
|
62
58
|
test "redirects if valid user signed out" do
|
63
59
|
user = create_user
|
64
|
-
user.confirm
|
60
|
+
user.confirm
|
65
61
|
|
66
62
|
sign_in user
|
67
63
|
get :index
|
@@ -72,12 +68,30 @@ class TestHelpersTest < ActionController::TestCase
|
|
72
68
|
end
|
73
69
|
|
74
70
|
test "respects custom failure app" do
|
75
|
-
|
76
|
-
|
71
|
+
custom_failure_app = Class.new(Devise::FailureApp) do
|
72
|
+
def redirect
|
73
|
+
self.status = 300
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
swap Devise.warden_config, failure_app: custom_failure_app do
|
77
78
|
get :index
|
78
|
-
assert_response
|
79
|
-
|
80
|
-
|
79
|
+
assert_response 300
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
test "passes given headers from the failure app to the response" do
|
84
|
+
custom_failure_app = Class.new(Devise::FailureApp) do
|
85
|
+
def respond
|
86
|
+
self.status = 401
|
87
|
+
self.response.headers["CUSTOMHEADER"] = 1
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
swap Devise.warden_config, failure_app: custom_failure_app do
|
92
|
+
sign_in create_user
|
93
|
+
get :index
|
94
|
+
assert_equal 1, @response.headers["CUSTOMHEADER"]
|
81
95
|
end
|
82
96
|
end
|
83
97
|
|
@@ -86,6 +100,11 @@ class TestHelpersTest < ActionController::TestCase
|
|
86
100
|
assert_equal response.body, "<html><body>You are being <a href=\"http://test.host/users/sign_in\">redirected</a>.</body></html>"
|
87
101
|
end
|
88
102
|
|
103
|
+
test "returns the content type of a failure app" do
|
104
|
+
get :index, params: { format: :xml }
|
105
|
+
assert response.content_type.include?('application/xml')
|
106
|
+
end
|
107
|
+
|
89
108
|
test "defined Warden after_authentication callback should not be called when sign_in is called" do
|
90
109
|
begin
|
91
110
|
Warden::Manager.after_authentication do |user, auth, opts|
|
@@ -93,7 +112,7 @@ class TestHelpersTest < ActionController::TestCase
|
|
93
112
|
end
|
94
113
|
|
95
114
|
user = create_user
|
96
|
-
user.confirm
|
115
|
+
user.confirm
|
97
116
|
sign_in user
|
98
117
|
ensure
|
99
118
|
Warden::Manager._after_set_user.pop
|
@@ -106,7 +125,7 @@ class TestHelpersTest < ActionController::TestCase
|
|
106
125
|
flunk "callback was called while it should not"
|
107
126
|
end
|
108
127
|
user = create_user
|
109
|
-
user.confirm
|
128
|
+
user.confirm
|
110
129
|
|
111
130
|
sign_in user
|
112
131
|
sign_out user
|
@@ -134,7 +153,7 @@ class TestHelpersTest < ActionController::TestCase
|
|
134
153
|
|
135
154
|
test "allows to sign in with different users" do
|
136
155
|
first_user = create_user
|
137
|
-
first_user.confirm
|
156
|
+
first_user.confirm
|
138
157
|
|
139
158
|
sign_in first_user
|
140
159
|
get :index
|
@@ -142,32 +161,33 @@ class TestHelpersTest < ActionController::TestCase
|
|
142
161
|
sign_out first_user
|
143
162
|
|
144
163
|
second_user = create_user
|
145
|
-
second_user.confirm
|
164
|
+
second_user.confirm
|
146
165
|
|
147
166
|
sign_in second_user
|
148
167
|
get :index
|
149
168
|
assert_match /User ##{second_user.id}/, @response.body
|
150
169
|
end
|
151
170
|
|
171
|
+
test "creates a new warden proxy if the request object has changed" do
|
172
|
+
old_warden_proxy = warden
|
152
173
|
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
self.status = 401
|
160
|
-
self.response.headers["CUSTOMHEADER"] = 1
|
161
|
-
end
|
162
|
-
end
|
163
|
-
Devise.warden_config[:failure_app] = CustomTestFailureApp
|
164
|
-
user = create_user
|
165
|
-
sign_in user
|
166
|
-
get :index
|
167
|
-
assert_equal 1, @response.headers["CUSTOMHEADER"]
|
168
|
-
ensure
|
169
|
-
Devise.warden_config[:failure_app] = old_failure_app
|
174
|
+
@request = if Devise::Test.rails51? || Devise::Test.rails52?
|
175
|
+
ActionController::TestRequest.create(Class.new) # needs a "controller class"
|
176
|
+
elsif Devise::Test.rails5?
|
177
|
+
ActionController::TestRequest.create
|
178
|
+
else
|
179
|
+
ActionController::TestRequest.new
|
170
180
|
end
|
181
|
+
|
182
|
+
new_warden_proxy = warden
|
183
|
+
|
184
|
+
assert_not_equal old_warden_proxy, new_warden_proxy
|
171
185
|
end
|
172
186
|
|
187
|
+
test "doesn't create a new warden proxy if the request object hasn't changed" do
|
188
|
+
old_warden_proxy = warden
|
189
|
+
new_warden_proxy = warden
|
190
|
+
|
191
|
+
assert_equal old_warden_proxy, new_warden_proxy
|
192
|
+
end
|
173
193
|
end
|