devise 1.1.3 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +10 -0
- data/.travis.yml +1 -0
- data/CHANGELOG.rdoc +94 -0
- data/Gemfile +24 -13
- data/Gemfile.lock +119 -75
- data/MIT-LICENSE +1 -1
- data/README.rdoc +144 -101
- data/Rakefile +3 -24
- data/app/controllers/devise/confirmations_controller.rb +1 -1
- data/app/controllers/devise/omniauth_callbacks_controller.rb +26 -0
- data/app/controllers/devise/passwords_controller.rb +1 -1
- data/app/controllers/devise/registrations_controller.rb +60 -7
- data/app/controllers/devise/sessions_controller.rb +6 -4
- data/app/controllers/devise/unlocks_controller.rb +1 -1
- data/app/helpers/devise_helper.rb +10 -2
- data/app/mailers/devise/mailer.rb +27 -10
- data/app/views/devise/confirmations/new.html.erb +1 -1
- data/app/views/devise/passwords/edit.html.erb +2 -2
- 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 +1 -1
- data/app/views/devise/shared/_links.erb +6 -0
- data/app/views/devise/unlocks/new.html.erb +1 -1
- data/config/locales/en.yml +11 -2
- data/devise.gemspec +25 -0
- data/lib/devise/controllers/helpers.rb +119 -116
- data/lib/devise/controllers/internal_helpers.rb +29 -8
- data/lib/devise/controllers/rememberable.rb +52 -0
- data/lib/devise/controllers/scoped_views.rb +4 -6
- data/lib/devise/controllers/url_helpers.rb +3 -5
- data/lib/devise/encryptors/authlogic_sha512.rb +1 -1
- data/lib/devise/encryptors/base.rb +1 -1
- data/lib/devise/encryptors/restful_authentication_sha1.rb +4 -4
- data/lib/devise/failure_app.rb +46 -10
- data/lib/devise/hooks/activatable.rb +2 -2
- data/lib/devise/hooks/forgetable.rb +1 -3
- data/lib/devise/hooks/rememberable.rb +5 -42
- data/lib/devise/hooks/timeoutable.rb +1 -1
- data/lib/devise/mapping.rb +18 -7
- data/lib/devise/models/authenticatable.rb +73 -31
- data/lib/devise/models/confirmable.rb +16 -20
- data/lib/devise/models/database_authenticatable.rb +27 -37
- data/lib/devise/models/encryptable.rb +72 -0
- data/lib/devise/models/lockable.rb +27 -21
- data/lib/devise/models/omniauthable.rb +23 -0
- data/lib/devise/models/recoverable.rb +13 -3
- data/lib/devise/models/registerable.rb +13 -0
- data/lib/devise/models/rememberable.rb +39 -34
- data/lib/devise/models/timeoutable.rb +20 -3
- data/lib/devise/models/token_authenticatable.rb +22 -10
- data/lib/devise/models/validatable.rb +16 -4
- data/lib/devise/models.rb +4 -16
- data/lib/devise/modules.rb +15 -8
- data/lib/devise/omniauth/config.rb +18 -0
- data/lib/devise/omniauth/url_helpers.rb +33 -0
- data/lib/devise/omniauth.rb +32 -0
- data/lib/devise/orm/active_record.rb +2 -0
- data/lib/devise/orm/mongoid.rb +4 -2
- data/lib/devise/rails/routes.rb +67 -20
- data/lib/devise/rails/warden_compat.rb +101 -15
- data/lib/devise/rails.rb +33 -44
- data/lib/devise/schema.rb +16 -16
- data/lib/devise/strategies/authenticatable.rb +48 -7
- data/lib/devise/strategies/database_authenticatable.rb +1 -1
- data/lib/devise/strategies/rememberable.rb +6 -5
- data/lib/devise/strategies/token_authenticatable.rb +6 -2
- data/lib/devise/test_helpers.rb +13 -3
- data/lib/devise/version.rb +1 -1
- data/lib/devise.rb +162 -50
- data/lib/generators/active_record/devise_generator.rb +2 -2
- data/lib/generators/active_record/templates/migration.rb +2 -0
- data/lib/generators/devise/devise_generator.rb +3 -1
- data/lib/generators/devise/orm_helpers.rb +1 -1
- data/lib/generators/devise/views_generator.rb +8 -45
- data/lib/generators/mongoid/devise_generator.rb +2 -2
- data/lib/generators/templates/devise.rb +82 -39
- data/test/controllers/helpers_test.rb +78 -72
- data/test/controllers/internal_helpers_test.rb +29 -8
- data/test/controllers/url_helpers_test.rb +2 -1
- data/test/devise_test.rb +10 -0
- data/test/failure_app_test.rb +86 -22
- data/test/generators/active_record_generator_test.rb +24 -0
- data/test/generators/devise_generator_test.rb +33 -0
- data/test/generators/install_generator_test.rb +13 -0
- data/test/generators/mongoid_generator_test.rb +22 -0
- data/test/generators/views_generator_test.rb +35 -0
- data/test/indifferent_hash.rb +33 -0
- data/test/integration/authenticatable_test.rb +165 -62
- data/test/integration/database_authenticatable_test.rb +22 -0
- data/test/integration/http_authenticatable_test.rb +12 -2
- data/test/integration/omniauthable_test.rb +138 -0
- data/test/integration/recoverable_test.rb +39 -20
- data/test/integration/registerable_test.rb +60 -4
- data/test/integration/rememberable_test.rb +72 -29
- data/test/integration/timeoutable_test.rb +10 -1
- data/test/integration/token_authenticatable_test.rb +55 -6
- data/test/mailers/confirmation_instructions_test.rb +4 -0
- data/test/mailers/reset_password_instructions_test.rb +4 -0
- data/test/mailers/unlock_instructions_test.rb +4 -0
- data/test/mapping_test.rb +37 -3
- data/test/models/confirmable_test.rb +32 -15
- data/test/models/database_authenticatable_test.rb +14 -71
- data/test/models/encryptable_test.rb +65 -0
- data/test/models/lockable_test.rb +48 -11
- data/test/models/recoverable_test.rb +28 -2
- data/test/models/rememberable_test.rb +186 -125
- data/test/models/token_authenticatable_test.rb +19 -1
- data/test/models_test.rb +12 -5
- data/test/omniauth/url_helpers_test.rb +54 -0
- data/test/orm/mongoid.rb +3 -2
- data/test/rails_app/Rakefile +10 -0
- data/test/rails_app/app/active_record/admin.rb +4 -1
- data/test/rails_app/app/active_record/user.rb +5 -4
- data/test/rails_app/app/controllers/{sessions_controller.rb → admins/sessions_controller.rb} +1 -1
- data/test/rails_app/app/controllers/application_controller.rb +0 -1
- data/test/rails_app/app/controllers/home_controller.rb +9 -0
- data/test/rails_app/app/controllers/users/omniauth_callbacks_controller.rb +14 -0
- data/test/rails_app/app/mongoid/admin.rb +4 -1
- data/test/rails_app/app/mongoid/shim.rb +16 -3
- data/test/rails_app/app/mongoid/user.rb +5 -5
- data/test/rails_app/app/views/admins/index.html.erb +1 -0
- data/test/rails_app/app/views/admins/sessions/new.html.erb +2 -0
- data/test/rails_app/app/views/home/index.html.erb +1 -0
- data/test/rails_app/app/views/home/private.html.erb +1 -0
- data/test/rails_app/app/views/layouts/application.html.erb +24 -0
- data/test/rails_app/app/views/users/index.html.erb +1 -0
- data/test/rails_app/app/views/users/mailer/confirmation_instructions.erb +1 -0
- data/test/rails_app/app/views/users/sessions/new.html.erb +1 -0
- data/test/rails_app/config/application.rb +5 -0
- data/test/rails_app/config/boot.rb +2 -2
- data/test/rails_app/config/database.yml +18 -0
- data/test/rails_app/config/initializers/devise.rb +71 -31
- data/test/rails_app/config/routes.rb +14 -6
- data/test/rails_app/config.ru +4 -0
- data/test/rails_app/db/migrate/20100401102949_create_tables.rb +21 -17
- data/test/rails_app/db/schema.rb +17 -51
- data/test/rails_app/lib/shared_admin.rb +9 -0
- data/test/rails_app/lib/shared_user.rb +23 -0
- data/test/rails_app/public/404.html +26 -0
- data/test/rails_app/public/422.html +26 -0
- data/test/rails_app/public/500.html +26 -0
- data/test/rails_app/public/favicon.ico +0 -0
- data/test/rails_app/script/rails +10 -0
- data/test/routes_test.rb +42 -9
- data/test/schema_test.rb +33 -0
- data/test/support/integration.rb +4 -4
- data/test/support/locale/en.yml +4 -0
- data/test/support/webrat/integrations/rails.rb +11 -19
- data/test/test_helper.rb +8 -2
- data/test/test_helpers_test.rb +64 -2
- metadata +106 -30
- data/TODO +0 -3
- data/lib/devise/encryptors/bcrypt.rb +0 -19
- data/lib/generators/devise_install_generator.rb +0 -4
- data/lib/generators/devise_views_generator.rb +0 -4
- data/test/support/test_silencer.rb +0 -5
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
require 'tmpdir'
|
|
2
|
+
|
|
1
3
|
module Devise
|
|
2
4
|
module Generators
|
|
3
5
|
class ViewsGenerator < Rails::Generators::Base
|
|
@@ -8,56 +10,17 @@ module Devise
|
|
|
8
10
|
:desc => "The scope to copy views to"
|
|
9
11
|
|
|
10
12
|
class_option :template_engine, :type => :string, :aliases => "-t",
|
|
11
|
-
:desc => "Template engine for the views. Available options are 'erb' and '
|
|
13
|
+
:desc => "Template engine for the views. Available options are 'erb', 'haml' and 'slim'."
|
|
12
14
|
|
|
13
15
|
def copy_views
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
create_and_copy_haml_views
|
|
16
|
+
template = options[:template_engine].to_s
|
|
17
|
+
case template
|
|
18
|
+
when "haml", "slim"
|
|
19
|
+
warn "#{template} templates have been removed from Devise gem"
|
|
19
20
|
else
|
|
20
21
|
directory "devise", "app/views/#{scope || :devise}"
|
|
21
22
|
end
|
|
22
23
|
end
|
|
23
|
-
|
|
24
|
-
protected
|
|
25
|
-
|
|
26
|
-
def verify_haml_existence
|
|
27
|
-
begin
|
|
28
|
-
require 'haml'
|
|
29
|
-
rescue LoadError
|
|
30
|
-
say "HAML is not installed, or it is not specified in your Gemfile."
|
|
31
|
-
exit
|
|
32
|
-
end
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
def verify_haml_version
|
|
36
|
-
unless Haml.version[:major] == 2 and Haml.version[:minor] >= 3 or Haml.version[:major] >= 3
|
|
37
|
-
say "To generate HAML templates, you need to install HAML 2.3 or above."
|
|
38
|
-
exit
|
|
39
|
-
end
|
|
40
|
-
end
|
|
41
|
-
|
|
42
|
-
def create_and_copy_haml_views
|
|
43
|
-
require 'tmpdir'
|
|
44
|
-
html_root = "#{self.class.source_root}/devise"
|
|
45
|
-
|
|
46
|
-
Dir.mktmpdir("devise-haml.") do |haml_root|
|
|
47
|
-
Dir["#{html_root}/**/*"].each do |path|
|
|
48
|
-
relative_path = path.sub(html_root, "")
|
|
49
|
-
source_path = (haml_root + relative_path).sub(/erb$/, "haml")
|
|
50
|
-
|
|
51
|
-
if File.directory?(path)
|
|
52
|
-
FileUtils.mkdir_p(source_path)
|
|
53
|
-
else
|
|
54
|
-
`html2haml -r #{path} #{source_path}`
|
|
55
|
-
end
|
|
56
|
-
end
|
|
57
|
-
|
|
58
|
-
directory haml_root, "app/views/#{scope || :devise}"
|
|
59
|
-
end
|
|
60
|
-
end
|
|
61
24
|
end
|
|
62
25
|
end
|
|
63
|
-
end
|
|
26
|
+
end
|
|
@@ -6,11 +6,11 @@ module Mongoid
|
|
|
6
6
|
include Devise::Generators::OrmHelpers
|
|
7
7
|
|
|
8
8
|
def generate_model
|
|
9
|
-
invoke "mongoid:model", [name] unless model_exists?
|
|
9
|
+
invoke "mongoid:model", [name] unless model_exists? && behavior == :invoke
|
|
10
10
|
end
|
|
11
11
|
|
|
12
12
|
def inject_devise_content
|
|
13
|
-
inject_into_file model_path, model_contents, :after => "include Mongoid::Document\n"
|
|
13
|
+
inject_into_file model_path, model_contents, :after => "include Mongoid::Document\n" if model_exists?
|
|
14
14
|
end
|
|
15
15
|
end
|
|
16
16
|
end
|
|
@@ -15,23 +15,37 @@ Devise.setup do |config|
|
|
|
15
15
|
require 'devise/orm/<%= options[:orm] %>'
|
|
16
16
|
|
|
17
17
|
# ==> Configuration for any authentication mechanism
|
|
18
|
-
# Configure which keys are used when authenticating
|
|
18
|
+
# Configure which keys are used when authenticating a user. The default is
|
|
19
19
|
# just :email. You can configure it to use [:username, :subdomain], so for
|
|
20
|
-
# authenticating
|
|
20
|
+
# authenticating a user, both parameters are required. Remember that those
|
|
21
21
|
# parameters are used only when authenticating and not when retrieving from
|
|
22
22
|
# session. If you need permissions, you should implement that in a before filter.
|
|
23
|
+
# You can also supply a hash where the value is a boolean determining whether
|
|
24
|
+
# or not authentication should be aborted when the value is not present.
|
|
23
25
|
# config.authentication_keys = [ :email ]
|
|
24
26
|
|
|
27
|
+
# Configure parameters from the request object used for authentication. Each entry
|
|
28
|
+
# given should be a request method and it will automatically be passed to the
|
|
29
|
+
# find_for_authentication method and considered in your model lookup. For instance,
|
|
30
|
+
# if you set :request_keys to [:subdomain], :subdomain will be used on authentication.
|
|
31
|
+
# The same considerations mentioned for authentication_keys also apply to request_keys.
|
|
32
|
+
# config.request_keys = []
|
|
33
|
+
|
|
34
|
+
# Configure which authentication keys should be case-insensitive.
|
|
35
|
+
# These keys will be downcased upon creating or modifying a user and when used
|
|
36
|
+
# to authenticate or find a user. Default is :email.
|
|
37
|
+
config.case_insensitive_keys = [ :email ]
|
|
38
|
+
|
|
25
39
|
# Tell if authentication through request.params is enabled. True by default.
|
|
26
40
|
# config.params_authenticatable = true
|
|
27
41
|
|
|
28
|
-
# Tell if authentication through HTTP Basic Auth is enabled.
|
|
29
|
-
# config.http_authenticatable =
|
|
42
|
+
# Tell if authentication through HTTP Basic Auth is enabled. False by default.
|
|
43
|
+
# config.http_authenticatable = false
|
|
30
44
|
|
|
31
|
-
#
|
|
45
|
+
# If http headers should be returned for AJAX requests. True by default.
|
|
32
46
|
# config.http_authenticatable_on_xhr = true
|
|
33
47
|
|
|
34
|
-
# The realm used in Http Basic Authentication
|
|
48
|
+
# The realm used in Http Basic Authentication. "Application" by default.
|
|
35
49
|
# config.http_authentication_realm = "Application"
|
|
36
50
|
|
|
37
51
|
# ==> Configuration for :database_authenticatable
|
|
@@ -39,24 +53,21 @@ Devise.setup do |config|
|
|
|
39
53
|
# using other encryptors, it sets how many times you want the password re-encrypted.
|
|
40
54
|
config.stretches = 10
|
|
41
55
|
|
|
42
|
-
# Define which will be the encryption algorithm. Devise also supports encryptors
|
|
43
|
-
# from others authentication tools as :clearance_sha1, :authlogic_sha512 (then
|
|
44
|
-
# you should set stretches above to 20 for default behavior) and :restful_authentication_sha1
|
|
45
|
-
# (then you should set stretches to 10, and copy REST_AUTH_SITE_KEY to pepper)
|
|
46
|
-
config.encryptor = :bcrypt
|
|
47
|
-
|
|
48
56
|
# Setup a pepper to generate the encrypted password.
|
|
49
|
-
config.pepper = <%= ActiveSupport::SecureRandom.hex(64).inspect %>
|
|
57
|
+
# config.pepper = <%= ActiveSupport::SecureRandom.hex(64).inspect %>
|
|
50
58
|
|
|
51
59
|
# ==> Configuration for :confirmable
|
|
52
60
|
# The time you want to give your user to confirm his account. During this time
|
|
53
|
-
# he will be able to access your application without confirming. Default is
|
|
54
|
-
# When confirm_within is zero, the user won't be able to sign in without confirming.
|
|
55
|
-
# You can use this to let your user access some features of your application
|
|
56
|
-
# without confirming the account, but blocking it after a certain period
|
|
57
|
-
# (ie 2 days).
|
|
61
|
+
# he will be able to access your application without confirming. Default is 0.days
|
|
62
|
+
# When confirm_within is zero, the user won't be able to sign in without confirming.
|
|
63
|
+
# You can use this to let your user access some features of your application
|
|
64
|
+
# without confirming the account, but blocking it after a certain period
|
|
65
|
+
# (ie 2 days).
|
|
58
66
|
# config.confirm_within = 2.days
|
|
59
67
|
|
|
68
|
+
# Defines which key will be used when confirming an account
|
|
69
|
+
# config.confirmation_keys = [ :email ]
|
|
70
|
+
|
|
60
71
|
# ==> Configuration for :rememberable
|
|
61
72
|
# The time the user will be remembered without asking for credentials again.
|
|
62
73
|
# config.remember_for = 2.weeks
|
|
@@ -67,17 +78,21 @@ Devise.setup do |config|
|
|
|
67
78
|
# If true, extends the user's remember period when remembered via cookie.
|
|
68
79
|
# config.extend_remember_period = false
|
|
69
80
|
|
|
81
|
+
# If true, uses the password salt as remember token. This should be turned
|
|
82
|
+
# to false if you are not using database authenticatable.
|
|
83
|
+
config.use_salt_as_remember_token = true
|
|
84
|
+
|
|
70
85
|
# ==> Configuration for :validatable
|
|
71
|
-
# Range for password length
|
|
86
|
+
# Range for password length. Default is 6..20.
|
|
72
87
|
# config.password_length = 6..20
|
|
73
88
|
|
|
74
89
|
# Regex to use to validate the email address
|
|
75
|
-
# config.email_regexp =
|
|
90
|
+
# config.email_regexp = /\A([\w\.%\+\-]+)@([\w\-]+\.)+([\w]{2,})\z/i
|
|
76
91
|
|
|
77
92
|
# ==> Configuration for :timeoutable
|
|
78
93
|
# The time you want to timeout the user session without activity. After this
|
|
79
|
-
# time the user will be asked for credentials again.
|
|
80
|
-
# config.timeout_in =
|
|
94
|
+
# time the user will be asked for credentials again. Default is 30 minutes.
|
|
95
|
+
# config.timeout_in = 30.minutes
|
|
81
96
|
|
|
82
97
|
# ==> Configuration for :lockable
|
|
83
98
|
# Defines which strategy will be used to lock an account.
|
|
@@ -85,6 +100,9 @@ Devise.setup do |config|
|
|
|
85
100
|
# :none = No lock strategy. You should handle locking by yourself.
|
|
86
101
|
# config.lock_strategy = :failed_attempts
|
|
87
102
|
|
|
103
|
+
# Defines which key will be used when locking and unlocking an account
|
|
104
|
+
# config.unlock_keys = [ :email ]
|
|
105
|
+
|
|
88
106
|
# Defines which strategy will be used to unlock an account.
|
|
89
107
|
# :email = Sends an unlock link to the user email
|
|
90
108
|
# :time = Re-enables login after a certain amount of time (see :unlock_in below)
|
|
@@ -99,44 +117,69 @@ Devise.setup do |config|
|
|
|
99
117
|
# Time interval to unlock the account if :time is enabled as unlock_strategy.
|
|
100
118
|
# config.unlock_in = 1.hour
|
|
101
119
|
|
|
120
|
+
# ==> Configuration for :recoverable
|
|
121
|
+
#
|
|
122
|
+
# Defines which key will be used when recovering the password for an account
|
|
123
|
+
# config.reset_password_keys = [ :email ]
|
|
124
|
+
|
|
125
|
+
# ==> Configuration for :encryptable
|
|
126
|
+
# Allow you to use another encryption algorithm besides bcrypt (default). You can use
|
|
127
|
+
# :sha1, :sha512 or encryptors from others authentication tools as :clearance_sha1,
|
|
128
|
+
# :authlogic_sha512 (then you should set stretches above to 20 for default behavior)
|
|
129
|
+
# and :restful_authentication_sha1 (then you should set stretches to 10, and copy
|
|
130
|
+
# REST_AUTH_SITE_KEY to pepper)
|
|
131
|
+
# config.encryptor = :sha512
|
|
132
|
+
|
|
102
133
|
# ==> Configuration for :token_authenticatable
|
|
103
134
|
# Defines name of the authentication token params key
|
|
104
135
|
# config.token_authentication_key = :auth_token
|
|
105
136
|
|
|
137
|
+
# If true, authentication through token does not store user in session and needs
|
|
138
|
+
# to be supplied on each request. Useful if you are using the token as API token.
|
|
139
|
+
# config.stateless_token = false
|
|
140
|
+
|
|
106
141
|
# ==> Scopes configuration
|
|
107
142
|
# Turn scoped views on. Before rendering "sessions/new", it will first check for
|
|
108
143
|
# "users/sessions/new". It's turned off by default because it's slower if you
|
|
109
144
|
# are using only default views.
|
|
110
|
-
# config.scoped_views =
|
|
145
|
+
# config.scoped_views = false
|
|
111
146
|
|
|
112
147
|
# Configure the default scope given to Warden. By default it's the first
|
|
113
|
-
# devise role declared in your routes.
|
|
148
|
+
# devise role declared in your routes (usually :user).
|
|
114
149
|
# config.default_scope = :user
|
|
115
150
|
|
|
116
|
-
# Configure sign_out behavior.
|
|
117
|
-
#
|
|
118
|
-
#
|
|
119
|
-
# config.sign_out_all_scopes =
|
|
151
|
+
# Configure sign_out behavior.
|
|
152
|
+
# Sign_out action can be scoped (i.e. /users/sign_out affects only :user scope).
|
|
153
|
+
# The default is true, which means any logout action will sign out all active scopes.
|
|
154
|
+
# config.sign_out_all_scopes = true
|
|
120
155
|
|
|
121
156
|
# ==> Navigation configuration
|
|
122
157
|
# Lists the formats that should be treated as navigational. Formats like
|
|
123
158
|
# :html, should redirect to the sign in page when the user does not have
|
|
124
159
|
# access, but formats like :xml or :json, should return 401.
|
|
160
|
+
#
|
|
125
161
|
# If you have any extra navigational formats, like :iphone or :mobile, you
|
|
126
|
-
# should add them to the navigational formats lists.
|
|
127
|
-
#
|
|
162
|
+
# should add them to the navigational formats lists.
|
|
163
|
+
#
|
|
164
|
+
# The :"*/*" and "*/*" formats below is required to match Internet
|
|
165
|
+
# Explorer requests.
|
|
166
|
+
# config.navigational_formats = [:"*/*", "*/*", :html]
|
|
167
|
+
|
|
168
|
+
# The default HTTP method used to sign out a resource. Default is :get.
|
|
169
|
+
# config.sign_out_via = :get
|
|
170
|
+
|
|
171
|
+
# ==> OmniAuth
|
|
172
|
+
# Add a new OmniAuth provider. Check the wiki for more information on setting
|
|
173
|
+
# up on your models and hooks.
|
|
174
|
+
# config.omniauth :github, 'APP_ID', 'APP_SECRET', :scope => 'user,public_repo'
|
|
128
175
|
|
|
129
176
|
# ==> Warden configuration
|
|
130
|
-
# If you want to use other strategies, that are not
|
|
131
|
-
# you can configure them inside the config.warden block.
|
|
132
|
-
# allows you to setup OAuth, using http://github.com/roman/warden_oauth
|
|
177
|
+
# If you want to use other strategies, that are not supported by Devise, or
|
|
178
|
+
# change the failure app, you can configure them inside the config.warden block.
|
|
133
179
|
#
|
|
134
180
|
# config.warden do |manager|
|
|
135
|
-
# manager.
|
|
136
|
-
#
|
|
137
|
-
#
|
|
138
|
-
# twitter.options :site => 'http://twitter.com'
|
|
139
|
-
# end
|
|
140
|
-
# manager.default_strategies(:scope => :user).unshift :twitter_oauth
|
|
181
|
+
# manager.failure_app = AnotherApp
|
|
182
|
+
# manager.intercept_401 = false
|
|
183
|
+
# manager.default_strategies(:scope => :user).unshift :some_external_strategy
|
|
141
184
|
# end
|
|
142
185
|
end
|
|
@@ -1,63 +1,28 @@
|
|
|
1
1
|
require 'test_helper'
|
|
2
2
|
require 'ostruct'
|
|
3
3
|
|
|
4
|
-
class
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
def request
|
|
8
|
-
self
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
def path
|
|
12
|
-
''
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
def index
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
def host_with_port
|
|
19
|
-
"test.host:3000"
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
def protocol
|
|
23
|
-
"http"
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
def script_name
|
|
27
|
-
""
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
def symbolized_path_parameters
|
|
31
|
-
{}
|
|
32
|
-
end
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
class ControllerAuthenticableTest < ActionController::TestCase
|
|
36
|
-
tests MockController
|
|
4
|
+
class ControllerAuthenticatableTest < ActionController::TestCase
|
|
5
|
+
tests ApplicationController
|
|
37
6
|
|
|
38
7
|
def setup
|
|
39
8
|
@mock_warden = OpenStruct.new
|
|
40
|
-
@controller.env
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
test 'setup warden' do
|
|
44
|
-
assert_not_nil @controller.warden
|
|
9
|
+
@controller.request.env['warden'] = @mock_warden
|
|
45
10
|
end
|
|
46
11
|
|
|
47
12
|
test 'provide access to warden instance' do
|
|
48
|
-
assert_equal @
|
|
13
|
+
assert_equal @mock_warden, @controller.warden
|
|
49
14
|
end
|
|
50
15
|
|
|
51
|
-
test 'proxy signed_in? to
|
|
16
|
+
test 'proxy signed_in?(scope) to authenticate?' do
|
|
52
17
|
@mock_warden.expects(:authenticate?).with(:scope => :my_scope)
|
|
53
18
|
@controller.signed_in?(:my_scope)
|
|
54
19
|
end
|
|
55
20
|
|
|
56
|
-
test 'proxy
|
|
57
|
-
Devise.mappings.keys.each
|
|
58
|
-
@
|
|
59
|
-
|
|
60
|
-
@controller.
|
|
21
|
+
test 'proxy signed_in?(nil) to authenticate?' do
|
|
22
|
+
Devise.mappings.keys.each do |scope| # :user, :admin, :manager
|
|
23
|
+
@mock_warden.expects(:authenticate?).with(:scope => scope)
|
|
24
|
+
end
|
|
25
|
+
@controller.signed_in?
|
|
61
26
|
end
|
|
62
27
|
|
|
63
28
|
test 'proxy current_user to authenticate with user scope' do
|
|
@@ -90,18 +55,18 @@ class ControllerAuthenticableTest < ActionController::TestCase
|
|
|
90
55
|
@controller.authenticate_publisher_account!
|
|
91
56
|
end
|
|
92
57
|
|
|
93
|
-
test 'proxy user_signed_in? to authenticate
|
|
94
|
-
@mock_warden.expects(:authenticate
|
|
95
|
-
@controller.user_signed_in?
|
|
58
|
+
test 'proxy user_signed_in? to authenticate with user scope' do
|
|
59
|
+
@mock_warden.expects(:authenticate).with(:scope => :user).returns("user")
|
|
60
|
+
assert @controller.user_signed_in?
|
|
96
61
|
end
|
|
97
62
|
|
|
98
|
-
test 'proxy admin_signed_in? to
|
|
99
|
-
@mock_warden.expects(:authenticate
|
|
100
|
-
@controller.admin_signed_in?
|
|
63
|
+
test 'proxy admin_signed_in? to authenticatewith admin scope' do
|
|
64
|
+
@mock_warden.expects(:authenticate).with(:scope => :admin)
|
|
65
|
+
assert_not @controller.admin_signed_in?
|
|
101
66
|
end
|
|
102
67
|
|
|
103
|
-
test 'proxy publisher_account_signed_in? to authenticate
|
|
104
|
-
@mock_warden.expects(:authenticate
|
|
68
|
+
test 'proxy publisher_account_signed_in? to authenticate with namespaced publisher account scope' do
|
|
69
|
+
@mock_warden.expects(:authenticate).with(:scope => :publisher_account)
|
|
105
70
|
@controller.publisher_account_signed_in?
|
|
106
71
|
end
|
|
107
72
|
|
|
@@ -125,16 +90,39 @@ class ControllerAuthenticableTest < ActionController::TestCase
|
|
|
125
90
|
|
|
126
91
|
test 'sign in proxy to set_user on warden' do
|
|
127
92
|
user = User.new
|
|
93
|
+
@mock_warden.expects(:user).returns(nil)
|
|
128
94
|
@mock_warden.expects(:set_user).with(user, :scope => :user).returns(true)
|
|
129
95
|
@controller.sign_in(:user, user)
|
|
130
96
|
end
|
|
131
97
|
|
|
132
98
|
test 'sign in accepts a resource as argument' do
|
|
133
99
|
user = User.new
|
|
100
|
+
@mock_warden.expects(:user).returns(nil)
|
|
134
101
|
@mock_warden.expects(:set_user).with(user, :scope => :user).returns(true)
|
|
135
102
|
@controller.sign_in(user)
|
|
136
103
|
end
|
|
137
104
|
|
|
105
|
+
test 'does not sign in again if the user is already in' do
|
|
106
|
+
user = User.new
|
|
107
|
+
@mock_warden.expects(:user).returns(user)
|
|
108
|
+
@mock_warden.expects(:set_user).never
|
|
109
|
+
@controller.sign_in(user)
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
test 'sign in again when the user is already in only if force is given' do
|
|
113
|
+
user = User.new
|
|
114
|
+
@mock_warden.expects(:user).returns(user)
|
|
115
|
+
@mock_warden.expects(:set_user).with(user, :scope => :user).returns(true)
|
|
116
|
+
@controller.sign_in(user, :force => true)
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
test 'sign in accepts bypass as option' do
|
|
120
|
+
user = User.new
|
|
121
|
+
@mock_warden.expects(:session_serializer).returns(serializer = mock())
|
|
122
|
+
serializer.expects(:store).with(user, :user)
|
|
123
|
+
@controller.sign_in(user, :bypass => true)
|
|
124
|
+
end
|
|
125
|
+
|
|
138
126
|
test 'sign out proxy to logout on warden' do
|
|
139
127
|
@mock_warden.expects(:user).with(:user).returns(true)
|
|
140
128
|
@mock_warden.expects(:logout).with(:user).returns(true)
|
|
@@ -147,12 +135,15 @@ class ControllerAuthenticableTest < ActionController::TestCase
|
|
|
147
135
|
@controller.sign_out(User.new)
|
|
148
136
|
end
|
|
149
137
|
|
|
150
|
-
test 'sign out
|
|
151
|
-
Devise.mappings.
|
|
152
|
-
|
|
153
|
-
|
|
138
|
+
test 'sign out without args proxy to sign out all scopes' do
|
|
139
|
+
@mock_warden.expects(:user).times(Devise.mappings.size)
|
|
140
|
+
@mock_warden.expects(:logout).with().returns(true)
|
|
141
|
+
@controller.sign_out
|
|
142
|
+
end
|
|
154
143
|
|
|
155
|
-
|
|
144
|
+
test 'sign out everybody proxy to logout on warden' do
|
|
145
|
+
@mock_warden.expects(:user).times(Devise.mappings.size)
|
|
146
|
+
@mock_warden.expects(:logout).with().returns(true)
|
|
156
147
|
@controller.sign_out_all_scopes
|
|
157
148
|
end
|
|
158
149
|
|
|
@@ -182,14 +173,6 @@ class ControllerAuthenticableTest < ActionController::TestCase
|
|
|
182
173
|
assert_equal admin_root_path, @controller.after_sign_in_path_for(:admin)
|
|
183
174
|
end
|
|
184
175
|
|
|
185
|
-
test 'after update path defaults to root path if none by was specified for the given scope' do
|
|
186
|
-
assert_equal root_path, @controller.after_update_path_for(:user)
|
|
187
|
-
end
|
|
188
|
-
|
|
189
|
-
test 'after update path defaults to the scoped root path' do
|
|
190
|
-
assert_equal admin_root_path, @controller.after_update_path_for(:admin)
|
|
191
|
-
end
|
|
192
|
-
|
|
193
176
|
test 'after sign out path defaults to the root path' do
|
|
194
177
|
assert_equal root_path, @controller.after_sign_out_path_for(:admin)
|
|
195
178
|
assert_equal root_path, @controller.after_sign_out_path_for(:user)
|
|
@@ -220,12 +203,35 @@ class ControllerAuthenticableTest < ActionController::TestCase
|
|
|
220
203
|
@controller.sign_in_and_redirect(admin)
|
|
221
204
|
end
|
|
222
205
|
|
|
223
|
-
test '
|
|
224
|
-
|
|
225
|
-
@
|
|
226
|
-
@controller.
|
|
227
|
-
|
|
228
|
-
|
|
206
|
+
test 'redirect_location returns the stored location if set' do
|
|
207
|
+
user = User.new
|
|
208
|
+
@controller.session[:"user_return_to"] = "/foo.bar"
|
|
209
|
+
assert_equal '/foo.bar', @controller.redirect_location('user', user)
|
|
210
|
+
end
|
|
211
|
+
|
|
212
|
+
test 'redirect_location returns the after sign in path by default' do
|
|
213
|
+
user = User.new
|
|
214
|
+
assert_equal @controller.after_sign_in_path_for(:user), @controller.redirect_location('user', user)
|
|
215
|
+
end
|
|
216
|
+
|
|
217
|
+
test 'sign out and redirect uses the configured after sign out path when signing out only the current scope' do
|
|
218
|
+
swap Devise, :sign_out_all_scopes => false do
|
|
219
|
+
@mock_warden.expects(:user).with(:admin).returns(true)
|
|
220
|
+
@mock_warden.expects(:logout).with(:admin).returns(true)
|
|
221
|
+
@controller.expects(:redirect_to).with(admin_root_path)
|
|
222
|
+
@controller.instance_eval "def after_sign_out_path_for(resource); admin_root_path; end"
|
|
223
|
+
@controller.sign_out_and_redirect(:admin)
|
|
224
|
+
end
|
|
225
|
+
end
|
|
226
|
+
|
|
227
|
+
test 'sign out and redirect uses the configured after sign out path when signing out all scopes' do
|
|
228
|
+
swap Devise, :sign_out_all_scopes => true do
|
|
229
|
+
@mock_warden.expects(:user).times(Devise.mappings.size)
|
|
230
|
+
@mock_warden.expects(:logout).with().returns(true)
|
|
231
|
+
@controller.expects(:redirect_to).with(admin_root_path)
|
|
232
|
+
@controller.instance_eval "def after_sign_out_path_for(resource); admin_root_path; end"
|
|
233
|
+
@controller.sign_out_and_redirect(:admin)
|
|
234
|
+
end
|
|
229
235
|
end
|
|
230
236
|
|
|
231
237
|
test 'is not a devise controller' do
|
|
@@ -22,16 +22,16 @@ class HelpersTest < ActionController::TestCase
|
|
|
22
22
|
end
|
|
23
23
|
|
|
24
24
|
test 'get resource instance variable from env' do
|
|
25
|
-
@controller.instance_variable_set(:@user,
|
|
26
|
-
assert_equal
|
|
25
|
+
@controller.instance_variable_set(:@user, user = User.new)
|
|
26
|
+
assert_equal user, @controller.resource
|
|
27
27
|
end
|
|
28
28
|
|
|
29
29
|
test 'set resource instance variable from env' do
|
|
30
|
-
|
|
31
|
-
@controller.send(:resource=,
|
|
30
|
+
user = @controller.send(:resource_class).new
|
|
31
|
+
@controller.send(:resource=, user)
|
|
32
32
|
|
|
33
|
-
assert_equal
|
|
34
|
-
assert_equal
|
|
33
|
+
assert_equal user, @controller.send(:resource)
|
|
34
|
+
assert_equal user, @controller.instance_variable_get(:@user)
|
|
35
35
|
end
|
|
36
36
|
|
|
37
37
|
test 'resources methods are not controller actions' do
|
|
@@ -39,13 +39,34 @@ class HelpersTest < ActionController::TestCase
|
|
|
39
39
|
end
|
|
40
40
|
|
|
41
41
|
test 'require no authentication tests current mapping' do
|
|
42
|
-
@controller.expects(:resource_name).returns(:user).twice
|
|
43
42
|
@mock_warden.expects(:authenticated?).with(:user).returns(true)
|
|
43
|
+
@mock_warden.expects(:user).with(:user).returns(User.new)
|
|
44
44
|
@controller.expects(:redirect_to).with(root_path)
|
|
45
45
|
@controller.send :require_no_authentication
|
|
46
46
|
end
|
|
47
|
-
|
|
47
|
+
|
|
48
|
+
test 'signed in resource returns signed in resource for current scope' do
|
|
49
|
+
@mock_warden.expects(:authenticate).with(:scope => :user).returns(User.new)
|
|
50
|
+
assert_kind_of User, @controller.signed_in_resource
|
|
51
|
+
end
|
|
52
|
+
|
|
48
53
|
test 'is a devise controller' do
|
|
49
54
|
assert @controller.devise_controller?
|
|
50
55
|
end
|
|
56
|
+
|
|
57
|
+
test 'does not issue blank flash messages' do
|
|
58
|
+
MyController.send(:public, :set_flash_message)
|
|
59
|
+
I18n.stubs(:t).returns(' ')
|
|
60
|
+
@controller.set_flash_message :notice, :send_instructions
|
|
61
|
+
assert flash[:notice].nil?
|
|
62
|
+
MyController.send(:protected, :set_flash_message)
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
test 'issues non-blank flash messages normally' do
|
|
66
|
+
MyController.send(:public, :set_flash_message)
|
|
67
|
+
I18n.stubs(:t).returns('non-blank')
|
|
68
|
+
@controller.set_flash_message :notice, :send_instructions
|
|
69
|
+
assert flash[:notice] == 'non-blank'
|
|
70
|
+
MyController.send(:protected, :set_flash_message)
|
|
71
|
+
end
|
|
51
72
|
end
|
|
@@ -20,7 +20,7 @@ class RoutesTest < ActionController::TestCase
|
|
|
20
20
|
send(:"#{prepend_path}user_#{name}_url", :param => 123)
|
|
21
21
|
|
|
22
22
|
@request.path = nil
|
|
23
|
-
# With an
|
|
23
|
+
# With an object
|
|
24
24
|
assert_equal @controller.send(:"#{prepend_path}#{name}_path", User.new),
|
|
25
25
|
send(:"#{prepend_path}user_#{name}_path")
|
|
26
26
|
assert_equal @controller.send(:"#{prepend_path}#{name}_url", User.new),
|
|
@@ -54,5 +54,6 @@ class RoutesTest < ActionController::TestCase
|
|
|
54
54
|
assert_path_and_url :registration
|
|
55
55
|
assert_path_and_url :registration, :new
|
|
56
56
|
assert_path_and_url :registration, :edit
|
|
57
|
+
assert_path_and_url :registration, :cancel
|
|
57
58
|
end
|
|
58
59
|
end
|
data/test/devise_test.rb
CHANGED
|
@@ -62,4 +62,14 @@ class DeviseTest < ActiveSupport::TestCase
|
|
|
62
62
|
assert_nothing_raised(Exception) { Devise.add_module(:authenticatable_again, :model => 'devise/model/authenticatable') }
|
|
63
63
|
assert defined?(Devise::Models::AuthenticatableAgain)
|
|
64
64
|
end
|
|
65
|
+
|
|
66
|
+
test 'should complain when comparing empty or different sized passes' do
|
|
67
|
+
[nil, ""].each do |empty|
|
|
68
|
+
assert_not Devise.secure_compare(empty, "something")
|
|
69
|
+
assert_not Devise.secure_compare("something", empty)
|
|
70
|
+
assert_not Devise.secure_compare(empty, empty)
|
|
71
|
+
end
|
|
72
|
+
assert_not Devise.secure_compare("size_1", "size_four")
|
|
73
|
+
end
|
|
74
|
+
|
|
65
75
|
end
|