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
@@ -12,6 +12,8 @@ Devise.setup do |config|
|
|
12
12
|
# note that it will be overwritten if you use your own mailer class with default "from" parameter.
|
13
13
|
config.mailer_sender = "please-change-me@config-initializers-devise.com"
|
14
14
|
|
15
|
+
|
16
|
+
config.parent_controller = "ApplicationWithFakeEngine"
|
15
17
|
# Configure the class responsible to send e-mails.
|
16
18
|
# config.mailer = "Devise::Mailer"
|
17
19
|
|
@@ -29,7 +31,7 @@ Devise.setup do |config|
|
|
29
31
|
# session. If you need permissions, you should implement that in a before filter.
|
30
32
|
# You can also supply hash where the value is a boolean expliciting if authentication
|
31
33
|
# should be aborted or not if the value is not present. By default is empty.
|
32
|
-
# config.authentication_keys = [
|
34
|
+
# config.authentication_keys = [:email]
|
33
35
|
|
34
36
|
# Configure parameters from the request object used for authentication. Each entry
|
35
37
|
# given should be a request method and it will automatically be passed to
|
@@ -41,12 +43,12 @@ Devise.setup do |config|
|
|
41
43
|
# Configure which authentication keys should be case-insensitive.
|
42
44
|
# These keys will be downcased upon creating or modifying a user and when used
|
43
45
|
# to authenticate or find a user. Default is :email.
|
44
|
-
config.case_insensitive_keys = [
|
46
|
+
config.case_insensitive_keys = [:email]
|
45
47
|
|
46
48
|
# Configure which authentication keys should have whitespace stripped.
|
47
49
|
# These keys will have whitespace before and after removed upon creating or
|
48
50
|
# modifying a user and when used to authenticate or find a user. Default is :email.
|
49
|
-
config.strip_whitespace_keys = [
|
51
|
+
config.strip_whitespace_keys = [:email]
|
50
52
|
|
51
53
|
# Tell if authentication through request.params is enabled. True by default.
|
52
54
|
# config.params_authenticatable = true
|
@@ -75,21 +77,18 @@ Devise.setup do |config|
|
|
75
77
|
# config.allow_unconfirmed_access_for = 2.days
|
76
78
|
|
77
79
|
# Defines which key will be used when confirming an account
|
78
|
-
# config.confirmation_keys = [
|
80
|
+
# config.confirmation_keys = [:email]
|
79
81
|
|
80
82
|
# ==> Configuration for :rememberable
|
81
83
|
# The time the user will be remembered without asking for credentials again.
|
82
84
|
# config.remember_for = 2.weeks
|
83
85
|
|
84
|
-
# If true, a valid remember token can be re-used between multiple browsers.
|
85
|
-
# config.remember_across_browsers = true
|
86
|
-
|
87
86
|
# If true, extends the user's remember period when remembered via cookie.
|
88
87
|
# config.extend_remember_period = false
|
89
88
|
|
90
89
|
# ==> Configuration for :validatable
|
91
|
-
# Range for password length. Default is 8..
|
92
|
-
# config.password_length = 8..
|
90
|
+
# Range for password length. Default is 8..72.
|
91
|
+
# config.password_length = 8..72
|
93
92
|
|
94
93
|
# Regex to use to validate the email address
|
95
94
|
# config.email_regexp = /^([\w\.%\+\-]+)@([\w\-]+\.)+([\w]{2,})$/i
|
@@ -106,7 +105,7 @@ Devise.setup do |config|
|
|
106
105
|
# config.lock_strategy = :failed_attempts
|
107
106
|
|
108
107
|
# Defines which key will be used when locking and unlocking an account
|
109
|
-
# config.unlock_keys = [
|
108
|
+
# config.unlock_keys = [:email]
|
110
109
|
|
111
110
|
# Defines which strategy will be used to unlock an account.
|
112
111
|
# :email = Sends an unlock link to the user email
|
@@ -125,19 +124,19 @@ Devise.setup do |config|
|
|
125
124
|
# ==> Configuration for :recoverable
|
126
125
|
#
|
127
126
|
# Defines which key will be used when recovering the password for an account
|
128
|
-
# config.reset_password_keys = [
|
127
|
+
# config.reset_password_keys = [:email]
|
129
128
|
|
130
129
|
# Time interval you can reset your password with a reset password key.
|
131
130
|
# Don't put a too small interval or your users won't have the time to
|
132
131
|
# change their passwords.
|
133
132
|
config.reset_password_within = 2.hours
|
134
133
|
|
135
|
-
#
|
136
|
-
|
134
|
+
# When set to false, does not sign a user in automatically after their password is
|
135
|
+
# reset. Defaults to true, so a user is signed in automatically after a reset.
|
136
|
+
# config.sign_in_after_reset_password = true
|
137
137
|
|
138
|
-
#
|
139
|
-
|
140
|
-
# config.token_authentication_key = :auth_token
|
138
|
+
# Set up a pepper to generate the encrypted password.
|
139
|
+
config.pepper = "d142367154e5beacca404b1a6a4f8bc52c6fdcfa3ccc3cf8eb49f3458a688ee6ac3b9fae488432a3bfca863b8a90008368a9f3a3dfbe5a962e64b6ab8f3a3a1a"
|
141
140
|
|
142
141
|
# ==> Scopes configuration
|
143
142
|
# Turn scoped views on. Before rendering "sessions/new", it will first check for
|
@@ -1,8 +1,3 @@
|
|
1
1
|
config = Rails.application.config
|
2
2
|
|
3
|
-
|
4
|
-
config.secret_key_base = 'd588e99efff13a86461fd6ab82327823ad2f8feb5dc217ce652cdd9f0dfc5eb4b5a62a92d24d2574d7d51dfb1ea8dd453ea54e00cf672159a13104a135422a10'
|
5
|
-
else
|
6
|
-
config.secret_token = 'ea942c41850d502f2c8283e26bdc57829f471bb18224ddff0a192c4f32cdf6cb5aa0d82b3a7a7adbeb640c4b06f3aa1cd5f098162d8240f669b39d6b49680571'
|
7
|
-
config.session_store :cookie_store, key: "_my_app"
|
8
|
-
end
|
3
|
+
config.secret_key_base = 'd588e99efff13a86461fd6ab82327823ad2f8feb5dc217ce652cdd9f0dfc5eb4b5a62a92d24d2574d7d51dfb1ea8dd453ea54e00cf672159a13104a135422a10'
|
@@ -13,19 +13,35 @@ Rails.application.routes.draw do
|
|
13
13
|
end
|
14
14
|
end
|
15
15
|
|
16
|
-
resources :admins, only: [:index]
|
17
|
-
get :expire, on: :member
|
18
|
-
end
|
16
|
+
resources :admins, only: [:index]
|
19
17
|
|
20
18
|
# Users scope
|
21
19
|
devise_for :users, controllers: { omniauth_callbacks: "users/omniauth_callbacks" }
|
22
20
|
|
21
|
+
devise_for :user_on_main_apps,
|
22
|
+
class_name: 'UserOnMainApp',
|
23
|
+
router_name: :main_app,
|
24
|
+
module: :devise
|
25
|
+
|
26
|
+
devise_for :user_on_engines,
|
27
|
+
class_name: 'UserOnEngine',
|
28
|
+
router_name: :fake_engine,
|
29
|
+
module: :devise
|
30
|
+
|
31
|
+
devise_for :user_without_email,
|
32
|
+
class_name: 'UserWithoutEmail',
|
33
|
+
router_name: :main_app,
|
34
|
+
module: :devise
|
35
|
+
|
23
36
|
as :user do
|
24
37
|
get "/as/sign_in", to: "devise/sessions#new"
|
25
38
|
end
|
26
39
|
|
27
40
|
get "/sign_in", to: "devise/sessions#new"
|
28
41
|
|
42
|
+
# Routes for custom controller testing
|
43
|
+
devise_for :user, only: [:registrations], controllers: { registrations: "custom/registrations" }, as: :custom, path: :custom
|
44
|
+
|
29
45
|
# Admin scope
|
30
46
|
devise_for :admin, path: "admin_area", controllers: { sessions: :"admins/sessions" }, skip: :passwords
|
31
47
|
|
@@ -63,6 +79,10 @@ Rails.application.routes.draw do
|
|
63
79
|
devise_for :homebase_admin, class_name: "Admin", path: "homebase"
|
64
80
|
end
|
65
81
|
|
82
|
+
scope(subdomain: 'sub') do
|
83
|
+
devise_for :subdomain_users, class_name: "User", only: [:sessions]
|
84
|
+
end
|
85
|
+
|
66
86
|
devise_for :skip_admin, class_name: "Admin", skip: :all
|
67
87
|
|
68
88
|
# Routes for format=false testing
|
@@ -33,7 +33,7 @@ class CreateTables < ActiveRecord::Migration
|
|
33
33
|
t.string :unlock_token # Only if unlock strategy is :email or :both
|
34
34
|
t.datetime :locked_at
|
35
35
|
|
36
|
-
t.timestamps
|
36
|
+
t.timestamps null: false
|
37
37
|
end
|
38
38
|
|
39
39
|
create_table :admins do |t|
|
@@ -60,7 +60,7 @@ class CreateTables < ActiveRecord::Migration
|
|
60
60
|
## Attribute for testing route blocks
|
61
61
|
t.boolean :active, default: false
|
62
62
|
|
63
|
-
t.timestamps
|
63
|
+
t.timestamps null: false
|
64
64
|
end
|
65
65
|
end
|
66
66
|
|
@@ -4,7 +4,7 @@ module SharedUser
|
|
4
4
|
included do
|
5
5
|
devise :database_authenticatable, :confirmable, :lockable, :recoverable,
|
6
6
|
:registerable, :rememberable, :timeoutable,
|
7
|
-
:trackable, :validatable, :omniauthable
|
7
|
+
:trackable, :validatable, :omniauthable, password_length: 7..72
|
8
8
|
|
9
9
|
attr_accessor :other_key
|
10
10
|
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module SharedUserWithoutEmail
|
2
|
+
extend ActiveSupport::Concern
|
3
|
+
|
4
|
+
included do
|
5
|
+
# NOTE: This is missing :validatable and :confirmable, as they both require
|
6
|
+
# an email field at the moment. It is also missing :omniauthable because that
|
7
|
+
# adds unnecessary complexity to the setup
|
8
|
+
devise :database_authenticatable, :lockable, :recoverable,
|
9
|
+
:registerable, :rememberable, :timeoutable,
|
10
|
+
:trackable
|
11
|
+
end
|
12
|
+
|
13
|
+
# This test stub is a bit rubbish because it's tied very closely to the
|
14
|
+
# implementation where we care about this one case. However, completely
|
15
|
+
# removing the email field breaks "recoverable" tests completely, so we are
|
16
|
+
# just taking the approach here that "email" is something that is a not an
|
17
|
+
# ActiveRecord field.
|
18
|
+
def email_changed?
|
19
|
+
raise NoMethodError
|
20
|
+
end
|
21
|
+
|
22
|
+
def respond_to?(method_name, include_all=false)
|
23
|
+
return false if method_name.to_sym == :email_changed?
|
24
|
+
super(method_name, include_all)
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module SharedUserWithoutOmniauth
|
2
|
+
extend ActiveSupport::Concern
|
3
|
+
|
4
|
+
included do
|
5
|
+
devise :database_authenticatable, :confirmable, :lockable, :recoverable,
|
6
|
+
:registerable, :rememberable, :timeoutable,
|
7
|
+
:trackable, :validatable
|
8
|
+
end
|
9
|
+
|
10
|
+
def raw_confirmation_token
|
11
|
+
@raw_confirmation_token
|
12
|
+
end
|
13
|
+
end
|
data/test/rails_test.rb
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class RailsTest < ActiveSupport::TestCase
|
4
|
+
test 'correct initializer position' do
|
5
|
+
initializer = Devise::Engine.initializers.detect { |i| i.name == 'devise.omniauth' }
|
6
|
+
assert_equal :load_config_initializers, initializer.after
|
7
|
+
assert_equal :build_middleware_stack, initializer.before
|
8
|
+
end
|
9
|
+
end
|
data/test/routes_test.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
|
-
ExpectedRoutingError =
|
3
|
+
ExpectedRoutingError = MiniTest::Assertion
|
4
4
|
|
5
5
|
class DefaultRoutingTest < ActionController::TestCase
|
6
6
|
test 'map new user session' do
|
@@ -96,12 +96,12 @@ class DefaultRoutingTest < ActionController::TestCase
|
|
96
96
|
test 'map omniauth callbacks' do
|
97
97
|
assert_recognizes({controller: 'users/omniauth_callbacks', action: 'facebook'}, {path: 'users/auth/facebook/callback', method: :get})
|
98
98
|
assert_recognizes({controller: 'users/omniauth_callbacks', action: 'facebook'}, {path: 'users/auth/facebook/callback', method: :post})
|
99
|
-
assert_named_route "/users/auth/facebook/callback", :
|
99
|
+
assert_named_route "/users/auth/facebook/callback", :user_facebook_omniauth_callback_path
|
100
100
|
|
101
101
|
# named open_id
|
102
102
|
assert_recognizes({controller: 'users/omniauth_callbacks', action: 'google'}, {path: 'users/auth/google/callback', method: :get})
|
103
103
|
assert_recognizes({controller: 'users/omniauth_callbacks', action: 'google'}, {path: 'users/auth/google/callback', method: :post})
|
104
|
-
assert_named_route "/users/auth/google/callback", :
|
104
|
+
assert_named_route "/users/auth/google/callback", :user_google_omniauth_callback_path
|
105
105
|
|
106
106
|
assert_raise ExpectedRoutingError do
|
107
107
|
assert_recognizes({controller: 'ysers/omniauth_callbacks', action: 'twitter'}, {path: 'users/auth/twitter/callback', method: :get})
|
@@ -202,37 +202,52 @@ class CustomizedRoutingTest < ActionController::TestCase
|
|
202
202
|
end
|
203
203
|
|
204
204
|
test 'map with format false for sessions' do
|
205
|
-
|
205
|
+
expected_params = {controller: 'devise/sessions', action: 'new'}
|
206
|
+
expected_params[:format] = false if Devise.rails5?
|
207
|
+
|
208
|
+
assert_recognizes(expected_params, {path: '/htmlonly_admin/sign_in', method: :get})
|
206
209
|
assert_raise ExpectedRoutingError do
|
207
|
-
assert_recognizes(
|
210
|
+
assert_recognizes(expected_params, {path: '/htmlonly_admin/sign_in.xml', method: :get})
|
208
211
|
end
|
209
212
|
end
|
210
213
|
|
211
214
|
test 'map with format false for passwords' do
|
212
|
-
|
215
|
+
expected_params = {controller: 'devise/passwords', action: 'create'}
|
216
|
+
expected_params[:format] = false if Devise.rails5?
|
217
|
+
|
218
|
+
assert_recognizes(expected_params, {path: '/htmlonly_admin/password', method: :post})
|
213
219
|
assert_raise ExpectedRoutingError do
|
214
|
-
assert_recognizes(
|
220
|
+
assert_recognizes(expected_params, {path: '/htmlonly_admin/password.xml', method: :post})
|
215
221
|
end
|
216
222
|
end
|
217
223
|
|
218
224
|
test 'map with format false for registrations' do
|
219
|
-
|
225
|
+
expected_params = {controller: 'devise/registrations', action: 'new'}
|
226
|
+
expected_params[:format] = false if Devise.rails5?
|
227
|
+
|
228
|
+
assert_recognizes(expected_params, {path: '/htmlonly_admin/sign_up', method: :get})
|
220
229
|
assert_raise ExpectedRoutingError do
|
221
|
-
assert_recognizes(
|
230
|
+
assert_recognizes(expected_params, {path: '/htmlonly_admin/sign_up.xml', method: :get})
|
222
231
|
end
|
223
232
|
end
|
224
233
|
|
225
234
|
test 'map with format false for confirmations' do
|
226
|
-
|
235
|
+
expected_params = {controller: 'devise/confirmations', action: 'show'}
|
236
|
+
expected_params[:format] = false if Devise.rails5?
|
237
|
+
|
238
|
+
assert_recognizes(expected_params, {path: '/htmlonly_users/confirmation', method: :get})
|
227
239
|
assert_raise ExpectedRoutingError do
|
228
|
-
assert_recognizes(
|
240
|
+
assert_recognizes(expected_params, {path: '/htmlonly_users/confirmation.xml', method: :get})
|
229
241
|
end
|
230
242
|
end
|
231
243
|
|
232
244
|
test 'map with format false for unlocks' do
|
233
|
-
|
245
|
+
expected_params = {controller: 'devise/unlocks', action: 'show'}
|
246
|
+
expected_params[:format] = false if Devise.rails5?
|
247
|
+
|
248
|
+
assert_recognizes(expected_params, {path: '/htmlonly_users/unlock', method: :get})
|
234
249
|
assert_raise ExpectedRoutingError do
|
235
|
-
assert_recognizes(
|
250
|
+
assert_recognizes(expected_params, {path: '/htmlonly_users/unlock.xml', method: :get})
|
236
251
|
end
|
237
252
|
end
|
238
253
|
|
@@ -241,11 +256,13 @@ class CustomizedRoutingTest < ActionController::TestCase
|
|
241
256
|
end
|
242
257
|
|
243
258
|
test 'checks if mapping has proper configuration for omniauth callback' do
|
244
|
-
assert_raise ArgumentError do
|
245
|
-
|
246
|
-
|
259
|
+
e = assert_raise ArgumentError do
|
260
|
+
routes = ActionDispatch::Routing::RouteSet.new
|
261
|
+
routes.draw do
|
262
|
+
devise_for :not_omniauthable, class_name: 'Admin', controllers: {omniauth_callbacks: "users/omniauth_callbacks"}
|
247
263
|
end
|
248
264
|
end
|
265
|
+
assert_match "Mapping omniauth_callbacks on a resource that is not omniauthable", e.message
|
249
266
|
end
|
250
267
|
end
|
251
268
|
|
data/test/support/assertions.rb
CHANGED
@@ -9,10 +9,9 @@ class ActiveSupport::TestCase
|
|
9
9
|
assert assertion.blank?
|
10
10
|
end
|
11
11
|
|
12
|
-
def
|
13
|
-
assert
|
12
|
+
def assert_present(assertion)
|
13
|
+
assert assertion.present?
|
14
14
|
end
|
15
|
-
alias :assert_present :assert_not_blank
|
16
15
|
|
17
16
|
def assert_email_sent(address = nil, &block)
|
18
17
|
assert_difference('ActionMailer::Base.deliveries.size', &block)
|
data/test/support/helpers.rb
CHANGED
@@ -8,12 +8,15 @@ class ActiveSupport::TestCase
|
|
8
8
|
end
|
9
9
|
|
10
10
|
def store_translations(locale, translations, &block)
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
11
|
+
# Calling 'available_locales' before storing the translations to ensure
|
12
|
+
# that the I18n backend will be initialized before we store our custom
|
13
|
+
# translations, so they will always override the translations for the
|
14
|
+
# YML file.
|
15
|
+
I18n.available_locales
|
16
|
+
I18n.backend.store_translations(locale, translations)
|
17
|
+
yield
|
18
|
+
ensure
|
19
|
+
I18n.reload!
|
17
20
|
end
|
18
21
|
|
19
22
|
def generate_unique_email
|
@@ -43,6 +46,10 @@ class ActiveSupport::TestCase
|
|
43
46
|
Admin.create!(valid_attributes)
|
44
47
|
end
|
45
48
|
|
49
|
+
def create_user_without_email(attributes={})
|
50
|
+
UserWithoutEmail.create!(valid_attributes(attributes))
|
51
|
+
end
|
52
|
+
|
46
53
|
# Execute the block setting the given values and restoring old values after
|
47
54
|
# the block is executed.
|
48
55
|
def swap(object, new_values)
|
@@ -0,0 +1,51 @@
|
|
1
|
+
module Devise
|
2
|
+
class IntegrationTest < ActionDispatch::IntegrationTest
|
3
|
+
# %w( get post patch put head delete xml_http_request
|
4
|
+
# xhr get_via_redirect post_via_redirect
|
5
|
+
# ).each do |method|
|
6
|
+
%w( get post put ).each do |method|
|
7
|
+
if Rails.version >= '5.0.0'
|
8
|
+
define_method(method) do |url, options={}|
|
9
|
+
if options.empty?
|
10
|
+
super url
|
11
|
+
else
|
12
|
+
super url, options
|
13
|
+
end
|
14
|
+
end
|
15
|
+
else
|
16
|
+
define_method(method) do |url, options={}|
|
17
|
+
if options[:xhr]==true
|
18
|
+
xml_http_request __method__, url, options[:params] || {}, options[:headers]
|
19
|
+
else
|
20
|
+
super url, options[:params] || {}, options[:headers]
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
class ControllerTestCase < ActionController::TestCase
|
28
|
+
# %w( get post patch put head delete xml_http_request
|
29
|
+
# xhr get_via_redirect post_via_redirect
|
30
|
+
# ).each do |method|
|
31
|
+
%w( get post put ).each do |method|
|
32
|
+
if Rails.version >= '5.0.0'
|
33
|
+
define_method(method) do |action, options={}|
|
34
|
+
if options.empty?
|
35
|
+
super action
|
36
|
+
else
|
37
|
+
super action, options
|
38
|
+
end
|
39
|
+
end
|
40
|
+
else
|
41
|
+
define_method(method) do |action, options={}|
|
42
|
+
if options[:xhr]==true
|
43
|
+
xml_http_request __method__, action, options[:params] || {}, options[:headers]
|
44
|
+
else
|
45
|
+
super action, options[:params] || {}, options[:headers]
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
data/test/support/integration.rb
CHANGED
@@ -15,7 +15,7 @@ class ActionDispatch::IntegrationTest
|
|
15
15
|
created_at: Time.now.utc
|
16
16
|
)
|
17
17
|
user.update_attribute(:confirmation_sent_at, options[:confirmation_sent_at]) if options[:confirmation_sent_at]
|
18
|
-
user.confirm
|
18
|
+
user.confirm unless options[:confirm] == false
|
19
19
|
user.lock_access! if options[:locked] == true
|
20
20
|
user
|
21
21
|
end
|
@@ -28,7 +28,7 @@ class ActionDispatch::IntegrationTest
|
|
28
28
|
password: '123456', password_confirmation: '123456',
|
29
29
|
active: options[:active]
|
30
30
|
)
|
31
|
-
admin.confirm
|
31
|
+
admin.confirm unless options[:confirm] == false
|
32
32
|
admin
|
33
33
|
end
|
34
34
|
end
|
@@ -40,7 +40,7 @@ class ActionDispatch::IntegrationTest
|
|
40
40
|
fill_in 'password', with: options[:password] || '12345678'
|
41
41
|
check 'remember me' if options[:remember_me] == true
|
42
42
|
yield if block_given?
|
43
|
-
click_button '
|
43
|
+
click_button 'Log In'
|
44
44
|
user
|
45
45
|
end
|
46
46
|
|
@@ -50,7 +50,7 @@ class ActionDispatch::IntegrationTest
|
|
50
50
|
fill_in 'email', with: 'admin@test.com'
|
51
51
|
fill_in 'password', with: '123456'
|
52
52
|
yield if block_given?
|
53
|
-
click_button '
|
53
|
+
click_button 'Log In'
|
54
54
|
admin
|
55
55
|
end
|
56
56
|
|
@@ -14,6 +14,15 @@ module Webrat
|
|
14
14
|
::Rails.logger
|
15
15
|
end
|
16
16
|
end
|
17
|
+
|
18
|
+
class RailsAdapter
|
19
|
+
protected
|
20
|
+
|
21
|
+
def do_request(http_method, url, data, headers)
|
22
|
+
update_protocol(url)
|
23
|
+
integration_session.send(http_method, normalize_url(url), params: data, headers: headers)
|
24
|
+
end
|
25
|
+
end
|
17
26
|
end
|
18
27
|
|
19
28
|
module ActionDispatch #:nodoc:
|
data/test/test_helper.rb
CHANGED
@@ -17,6 +17,12 @@ Webrat.configure do |config|
|
|
17
17
|
config.open_error_files = false
|
18
18
|
end
|
19
19
|
|
20
|
+
if ActiveSupport.respond_to?(:test_order)
|
21
|
+
ActiveSupport.test_order = :random
|
22
|
+
end
|
23
|
+
|
24
|
+
OmniAuth.config.logger = Logger.new('/dev/null')
|
25
|
+
|
20
26
|
# Add support to load paths so we can overwrite broken webrat setup
|
21
27
|
$:.unshift File.expand_path('../support', __FILE__)
|
22
28
|
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
|
@@ -25,3 +31,4 @@ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
|
|
25
31
|
require "rails/generators/test_case"
|
26
32
|
require "generators/devise/install_generator"
|
27
33
|
require "generators/devise/views_generator"
|
34
|
+
require "generators/devise/controllers_generator"
|
data/test/test_helpers_test.rb
CHANGED
@@ -1,15 +1,9 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
|
-
class TestHelpersTest <
|
3
|
+
class TestHelpersTest < Devise::ControllerTestCase
|
4
4
|
tests UsersController
|
5
5
|
include Devise::TestHelpers
|
6
6
|
|
7
|
-
class CustomFailureApp < Devise::FailureApp
|
8
|
-
def redirect
|
9
|
-
self.status = 306
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
7
|
test "redirects if attempting to access a page unauthenticated" do
|
14
8
|
get :index
|
15
9
|
assert_redirected_to new_user_session_path
|
@@ -33,14 +27,14 @@ class TestHelpersTest < ActionController::TestCase
|
|
33
27
|
assert !user.active_for_authentication?
|
34
28
|
|
35
29
|
sign_in user
|
36
|
-
get :accept, id: user
|
30
|
+
get :accept, params: { id: user }
|
37
31
|
assert_nil assigns(:current_user)
|
38
32
|
end
|
39
33
|
end
|
40
34
|
|
41
35
|
test "does not redirect with valid user" do
|
42
36
|
user = create_user
|
43
|
-
user.confirm
|
37
|
+
user.confirm
|
44
38
|
|
45
39
|
sign_in user
|
46
40
|
get :index
|
@@ -52,7 +46,7 @@ class TestHelpersTest < ActionController::TestCase
|
|
52
46
|
assert_response :redirect
|
53
47
|
|
54
48
|
user = create_user
|
55
|
-
user.confirm
|
49
|
+
user.confirm
|
56
50
|
|
57
51
|
sign_in user
|
58
52
|
get :index
|
@@ -61,7 +55,7 @@ class TestHelpersTest < ActionController::TestCase
|
|
61
55
|
|
62
56
|
test "redirects if valid user signed out" do
|
63
57
|
user = create_user
|
64
|
-
user.confirm
|
58
|
+
user.confirm
|
65
59
|
|
66
60
|
sign_in user
|
67
61
|
get :index
|
@@ -72,12 +66,30 @@ class TestHelpersTest < ActionController::TestCase
|
|
72
66
|
end
|
73
67
|
|
74
68
|
test "respects custom failure app" do
|
75
|
-
|
76
|
-
|
69
|
+
custom_failure_app = Class.new(Devise::FailureApp) do
|
70
|
+
def redirect
|
71
|
+
self.status = 300
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
swap Devise.warden_config, failure_app: custom_failure_app do
|
77
76
|
get :index
|
78
|
-
assert_response
|
79
|
-
|
80
|
-
|
77
|
+
assert_response 300
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
test "passes given headers from the failure app to the response" do
|
82
|
+
custom_failure_app = Class.new(Devise::FailureApp) do
|
83
|
+
def respond
|
84
|
+
self.status = 401
|
85
|
+
self.response.headers["CUSTOMHEADER"] = 1
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
swap Devise.warden_config, failure_app: custom_failure_app do
|
90
|
+
sign_in create_user
|
91
|
+
get :index
|
92
|
+
assert_equal 1, @response.headers["CUSTOMHEADER"]
|
81
93
|
end
|
82
94
|
end
|
83
95
|
|
@@ -93,7 +105,7 @@ class TestHelpersTest < ActionController::TestCase
|
|
93
105
|
end
|
94
106
|
|
95
107
|
user = create_user
|
96
|
-
user.confirm
|
108
|
+
user.confirm
|
97
109
|
sign_in user
|
98
110
|
ensure
|
99
111
|
Warden::Manager._after_set_user.pop
|
@@ -106,7 +118,7 @@ class TestHelpersTest < ActionController::TestCase
|
|
106
118
|
flunk "callback was called while it should not"
|
107
119
|
end
|
108
120
|
user = create_user
|
109
|
-
user.confirm
|
121
|
+
user.confirm
|
110
122
|
|
111
123
|
sign_in user
|
112
124
|
sign_out user
|
@@ -134,7 +146,7 @@ class TestHelpersTest < ActionController::TestCase
|
|
134
146
|
|
135
147
|
test "allows to sign in with different users" do
|
136
148
|
first_user = create_user
|
137
|
-
first_user.confirm
|
149
|
+
first_user.confirm
|
138
150
|
|
139
151
|
sign_in first_user
|
140
152
|
get :index
|
@@ -142,32 +154,25 @@ class TestHelpersTest < ActionController::TestCase
|
|
142
154
|
sign_out first_user
|
143
155
|
|
144
156
|
second_user = create_user
|
145
|
-
second_user.confirm
|
157
|
+
second_user.confirm
|
146
158
|
|
147
159
|
sign_in second_user
|
148
160
|
get :index
|
149
161
|
assert_match /User ##{second_user.id}/, @response.body
|
150
162
|
end
|
151
163
|
|
164
|
+
test "creates a new warden proxy if the request object has changed" do
|
165
|
+
old_warden_proxy = warden
|
166
|
+
@request = Devise.rails5? ? ActionController::TestRequest.create : ActionController::TestRequest.new
|
167
|
+
new_warden_proxy = warden
|
152
168
|
|
153
|
-
|
154
|
-
|
155
|
-
begin
|
156
|
-
old_failure_app = Devise.warden_config[:failure_app]
|
157
|
-
class CustomTestFailureApp < Devise::FailureApp
|
158
|
-
def respond
|
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
|
170
|
-
end
|
169
|
+
assert_not_equal old_warden_proxy, new_warden_proxy
|
171
170
|
end
|
172
171
|
|
172
|
+
test "doesn't create a new warden proxy if the request object hasn't changed" do
|
173
|
+
old_warden_proxy = warden
|
174
|
+
new_warden_proxy = warden
|
175
|
+
|
176
|
+
assert_equal old_warden_proxy, new_warden_proxy
|
177
|
+
end
|
173
178
|
end
|