devise-jdguyot 1.2.rc
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +10 -0
- data/CHANGELOG.rdoc +532 -0
- data/Gemfile +29 -0
- data/Gemfile.lock +152 -0
- data/MIT-LICENSE +20 -0
- data/README.rdoc +353 -0
- data/Rakefile +36 -0
- data/TODO +4 -0
- data/app/controllers/devise/confirmations_controller.rb +33 -0
- data/app/controllers/devise/omniauth_callbacks_controller.rb +26 -0
- data/app/controllers/devise/passwords_controller.rb +41 -0
- data/app/controllers/devise/registrations_controller.rb +110 -0
- data/app/controllers/devise/sessions_controller.rb +25 -0
- data/app/controllers/devise/unlocks_controller.rb +34 -0
- data/app/helpers/devise_helper.rb +19 -0
- data/app/mailers/devise/mailer.rb +88 -0
- data/app/views/devise/confirmations/new.html.erb +12 -0
- data/app/views/devise/mailer/confirmation_instructions.html.erb +5 -0
- data/app/views/devise/mailer/reset_password_instructions.html.erb +8 -0
- data/app/views/devise/mailer/unlock_instructions.html.erb +7 -0
- data/app/views/devise/passwords/edit.html.erb +16 -0
- data/app/views/devise/passwords/new.html.erb +12 -0
- data/app/views/devise/registrations/edit.html.erb +25 -0
- data/app/views/devise/registrations/new.html.erb +18 -0
- data/app/views/devise/sessions/new.html.erb +17 -0
- data/app/views/devise/shared/_links.erb +25 -0
- data/app/views/devise/unlocks/new.html.erb +12 -0
- data/config/locales/en.yml +46 -0
- data/devise.gemspec +25 -0
- data/lib/devise/controllers/helpers.rb +227 -0
- data/lib/devise/controllers/internal_helpers.rb +119 -0
- data/lib/devise/controllers/scoped_views.rb +33 -0
- data/lib/devise/controllers/url_helpers.rb +39 -0
- data/lib/devise/encryptors/authlogic_sha512.rb +19 -0
- data/lib/devise/encryptors/base.rb +20 -0
- data/lib/devise/encryptors/clearance_sha1.rb +17 -0
- data/lib/devise/encryptors/restful_authentication_sha1.rb +22 -0
- data/lib/devise/encryptors/sha1.rb +25 -0
- data/lib/devise/encryptors/sha512.rb +25 -0
- data/lib/devise/failure_app.rb +132 -0
- data/lib/devise/hooks/activatable.rb +11 -0
- data/lib/devise/hooks/forgetable.rb +12 -0
- data/lib/devise/hooks/rememberable.rb +48 -0
- data/lib/devise/hooks/timeoutable.rb +22 -0
- data/lib/devise/hooks/trackable.rb +9 -0
- data/lib/devise/mapping.rb +110 -0
- data/lib/devise/models/authenticatable.rb +146 -0
- data/lib/devise/models/confirmable.rb +160 -0
- data/lib/devise/models/database_authenticatable.rb +100 -0
- data/lib/devise/models/encryptable.rb +72 -0
- data/lib/devise/models/lockable.rb +169 -0
- data/lib/devise/models/omniauthable.rb +23 -0
- data/lib/devise/models/recoverable.rb +123 -0
- data/lib/devise/models/registerable.rb +21 -0
- data/lib/devise/models/rememberable.rb +130 -0
- data/lib/devise/models/timeoutable.rb +43 -0
- data/lib/devise/models/token_authenticatable.rb +72 -0
- data/lib/devise/models/trackable.rb +30 -0
- data/lib/devise/models/validatable.rb +65 -0
- data/lib/devise/models.rb +68 -0
- data/lib/devise/modules.rb +30 -0
- data/lib/devise/omniauth/config.rb +30 -0
- data/lib/devise/omniauth/test_helpers.rb +57 -0
- data/lib/devise/omniauth/url_helpers.rb +29 -0
- data/lib/devise/omniauth.rb +47 -0
- data/lib/devise/orm/active_record.rb +38 -0
- data/lib/devise/orm/mongoid.rb +31 -0
- data/lib/devise/path_checker.rb +18 -0
- data/lib/devise/rails/routes.rb +292 -0
- data/lib/devise/rails/warden_compat.rb +125 -0
- data/lib/devise/rails.rb +50 -0
- data/lib/devise/schema.rb +97 -0
- data/lib/devise/strategies/authenticatable.rb +150 -0
- data/lib/devise/strategies/base.rb +15 -0
- data/lib/devise/strategies/database_authenticatable.rb +21 -0
- data/lib/devise/strategies/rememberable.rb +51 -0
- data/lib/devise/strategies/token_authenticatable.rb +53 -0
- data/lib/devise/test_helpers.rb +100 -0
- data/lib/devise/version.rb +3 -0
- data/lib/devise.rb +381 -0
- data/lib/generators/active_record/devise_generator.rb +28 -0
- data/lib/generators/active_record/templates/migration.rb +31 -0
- data/lib/generators/devise/devise_generator.rb +17 -0
- data/lib/generators/devise/install_generator.rb +24 -0
- data/lib/generators/devise/orm_helpers.rb +23 -0
- data/lib/generators/devise/views_generator.rb +106 -0
- data/lib/generators/mongoid/devise_generator.rb +17 -0
- data/lib/generators/templates/README +25 -0
- data/lib/generators/templates/devise.rb +186 -0
- data/test/controllers/helpers_test.rb +237 -0
- data/test/controllers/internal_helpers_test.rb +72 -0
- data/test/controllers/url_helpers_test.rb +59 -0
- data/test/devise_test.rb +65 -0
- data/test/encryptors_test.rb +30 -0
- data/test/failure_app_test.rb +187 -0
- data/test/generators/active_record_generator_test.rb +24 -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 +447 -0
- data/test/integration/confirmable_test.rb +104 -0
- data/test/integration/database_authenticatable_test.rb +60 -0
- data/test/integration/http_authenticatable_test.rb +74 -0
- data/test/integration/lockable_test.rb +109 -0
- data/test/integration/omniauthable_test.rb +107 -0
- data/test/integration/recoverable_test.rb +160 -0
- data/test/integration/registerable_test.rb +179 -0
- data/test/integration/rememberable_test.rb +180 -0
- data/test/integration/timeoutable_test.rb +89 -0
- data/test/integration/token_authenticatable_test.rb +99 -0
- data/test/integration/trackable_test.rb +64 -0
- data/test/mailers/confirmation_instructions_test.rb +84 -0
- data/test/mailers/reset_password_instructions_test.rb +72 -0
- data/test/mailers/unlock_instructions_test.rb +66 -0
- data/test/mapping_test.rb +119 -0
- data/test/models/confirmable_test.rb +221 -0
- data/test/models/database_authenticatable_test.rb +98 -0
- data/test/models/encryptable_test.rb +65 -0
- data/test/models/lockable_test.rb +204 -0
- data/test/models/recoverable_test.rb +190 -0
- data/test/models/rememberable_test.rb +279 -0
- data/test/models/timeoutable_test.rb +28 -0
- data/test/models/token_authenticatable_test.rb +37 -0
- data/test/models/trackable_test.rb +5 -0
- data/test/models/validatable_test.rb +99 -0
- data/test/models_test.rb +84 -0
- data/test/omniauth/url_helpers_test.rb +47 -0
- data/test/orm/active_record.rb +9 -0
- data/test/orm/mongoid.rb +11 -0
- data/test/rails_app/Rakefile +10 -0
- data/test/rails_app/app/active_record/admin.rb +6 -0
- data/test/rails_app/app/active_record/shim.rb +2 -0
- data/test/rails_app/app/active_record/user.rb +8 -0
- data/test/rails_app/app/controllers/admins/sessions_controller.rb +6 -0
- data/test/rails_app/app/controllers/admins_controller.rb +6 -0
- data/test/rails_app/app/controllers/application_controller.rb +8 -0
- data/test/rails_app/app/controllers/home_controller.rb +16 -0
- data/test/rails_app/app/controllers/publisher/registrations_controller.rb +2 -0
- data/test/rails_app/app/controllers/publisher/sessions_controller.rb +2 -0
- data/test/rails_app/app/controllers/users/omniauth_callbacks_controller.rb +7 -0
- data/test/rails_app/app/controllers/users_controller.rb +18 -0
- data/test/rails_app/app/helpers/application_helper.rb +3 -0
- data/test/rails_app/app/mongoid/admin.rb +9 -0
- data/test/rails_app/app/mongoid/shim.rb +29 -0
- data/test/rails_app/app/mongoid/user.rb +10 -0
- 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 +40 -0
- data/test/rails_app/config/boot.rb +13 -0
- data/test/rails_app/config/database.yml +18 -0
- data/test/rails_app/config/environment.rb +5 -0
- data/test/rails_app/config/environments/development.rb +19 -0
- data/test/rails_app/config/environments/production.rb +33 -0
- data/test/rails_app/config/environments/test.rb +33 -0
- data/test/rails_app/config/initializers/backtrace_silencers.rb +7 -0
- data/test/rails_app/config/initializers/devise.rb +176 -0
- data/test/rails_app/config/initializers/inflections.rb +2 -0
- data/test/rails_app/config/initializers/secret_token.rb +2 -0
- data/test/rails_app/config/routes.rb +55 -0
- data/test/rails_app/config.ru +4 -0
- data/test/rails_app/db/migrate/20100401102949_create_tables.rb +31 -0
- data/test/rails_app/db/schema.rb +52 -0
- 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 +179 -0
- data/test/support/assertions.rb +24 -0
- data/test/support/helpers.rb +60 -0
- data/test/support/integration.rb +88 -0
- data/test/support/locale/en.yml +4 -0
- data/test/support/webrat/integrations/rails.rb +24 -0
- data/test/test_helper.rb +29 -0
- data/test/test_helpers_test.rb +118 -0
- metadata +388 -0
@@ -0,0 +1,186 @@
|
|
1
|
+
# Use this hook to configure devise mailer, warden hooks and so forth. The first
|
2
|
+
# four configuration values can also be set straight in your models.
|
3
|
+
Devise.setup do |config|
|
4
|
+
# ==> Mailer Configuration
|
5
|
+
# Configure the e-mail address which will be shown in DeviseMailer.
|
6
|
+
config.mailer_sender = "please-change-me@config-initializers-devise.com"
|
7
|
+
|
8
|
+
# Configure the class responsible to send e-mails.
|
9
|
+
# config.mailer = "Devise::Mailer"
|
10
|
+
|
11
|
+
# ==> ORM configuration
|
12
|
+
# Load and configure the ORM. Supports :active_record (default) and
|
13
|
+
# :mongoid (bson_ext recommended) by default. Other ORMs may be
|
14
|
+
# available as additional gems.
|
15
|
+
require 'devise/orm/<%= options[:orm] %>'
|
16
|
+
|
17
|
+
# ==> Configuration for any authentication mechanism
|
18
|
+
# Configure which keys are used when authenticating a user. The default is
|
19
|
+
# just :email. You can configure it to use [:username, :subdomain], so for
|
20
|
+
# authenticating a user, both parameters are required. Remember that those
|
21
|
+
# parameters are used only when authenticating and not when retrieving from
|
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.
|
25
|
+
# config.authentication_keys = [ :email ]
|
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
|
+
|
39
|
+
# Tell if authentication through request.params is enabled. True by default.
|
40
|
+
# config.params_authenticatable = true
|
41
|
+
|
42
|
+
# Tell if authentication through HTTP Basic Auth is enabled. False by default.
|
43
|
+
# config.http_authenticatable = false
|
44
|
+
|
45
|
+
# If http headers should be returned for AJAX requests. True by default.
|
46
|
+
# config.http_authenticatable_on_xhr = true
|
47
|
+
|
48
|
+
# The realm used in Http Basic Authentication. "Application" by default.
|
49
|
+
# config.http_authentication_realm = "Application"
|
50
|
+
|
51
|
+
# ==> Configuration for :database_authenticatable
|
52
|
+
# For bcrypt, this is the cost for hashing the password and defaults to 10. If
|
53
|
+
# using other encryptors, it sets how many times you want the password re-encrypted.
|
54
|
+
config.stretches = 10
|
55
|
+
|
56
|
+
# Setup a pepper to generate the encrypted password.
|
57
|
+
# config.pepper = <%= ActiveSupport::SecureRandom.hex(64).inspect %>
|
58
|
+
|
59
|
+
# ==> Configuration for :confirmable
|
60
|
+
# The time you want to give your user to confirm his account. During this time
|
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).
|
66
|
+
# config.confirm_within = 2.days
|
67
|
+
|
68
|
+
# ==> Configuration for :rememberable
|
69
|
+
# The time the user will be remembered without asking for credentials again.
|
70
|
+
# config.remember_for = 2.weeks
|
71
|
+
|
72
|
+
# If true, a valid remember token can be re-used between multiple browsers.
|
73
|
+
# config.remember_across_browsers = true
|
74
|
+
|
75
|
+
# If true, extends the user's remember period when remembered via cookie.
|
76
|
+
# config.extend_remember_period = false
|
77
|
+
|
78
|
+
# If true, uses the password salt as remember token. This should be turned
|
79
|
+
# to false if you are not using database authenticatable.
|
80
|
+
config.use_salt_as_remember_token = true
|
81
|
+
|
82
|
+
# ==> Configuration for :validatable
|
83
|
+
# Range for password length. Default is 6..20.
|
84
|
+
# config.password_length = 6..20
|
85
|
+
|
86
|
+
# Regex to use to validate the email address
|
87
|
+
# config.email_regexp = /\A([\w\.%\+\-]+)@([\w\-]+\.)+([\w]{2,})\z/i
|
88
|
+
|
89
|
+
# ==> Configuration for :timeoutable
|
90
|
+
# The time you want to timeout the user session without activity. After this
|
91
|
+
# time the user will be asked for credentials again. Default is 30 minutes.
|
92
|
+
# config.timeout_in = 30.minutes
|
93
|
+
|
94
|
+
# ==> Configuration for :lockable
|
95
|
+
# Defines which strategy will be used to lock an account.
|
96
|
+
# :failed_attempts = Locks an account after a number of failed attempts to sign in.
|
97
|
+
# :none = No lock strategy. You should handle locking by yourself.
|
98
|
+
# config.lock_strategy = :failed_attempts
|
99
|
+
|
100
|
+
# Defines which key will be used when locking and unlocking an account
|
101
|
+
# config.unlock_keys = [ :email ]
|
102
|
+
|
103
|
+
# Defines which strategy will be used to unlock an account.
|
104
|
+
# :email = Sends an unlock link to the user email
|
105
|
+
# :time = Re-enables login after a certain amount of time (see :unlock_in below)
|
106
|
+
# :both = Enables both strategies
|
107
|
+
# :none = No unlock strategy. You should handle unlocking by yourself.
|
108
|
+
# config.unlock_strategy = :both
|
109
|
+
|
110
|
+
# Number of authentication tries before locking an account if lock_strategy
|
111
|
+
# is failed attempts.
|
112
|
+
# config.maximum_attempts = 20
|
113
|
+
|
114
|
+
# Time interval to unlock the account if :time is enabled as unlock_strategy.
|
115
|
+
# config.unlock_in = 1.hour
|
116
|
+
|
117
|
+
# ==> Configuration for :recoverable
|
118
|
+
#
|
119
|
+
# Defines which key will be used when recovering the password for an account
|
120
|
+
# config.reset_password_keys = [ :email ]
|
121
|
+
#
|
122
|
+
# Time interval you can reset your password with a reset password key
|
123
|
+
# Don't put a too small interval or your users won't have the time to change their passwords
|
124
|
+
# Default to 1 hour
|
125
|
+
config.reset_password_within = 1.hour
|
126
|
+
|
127
|
+
# ==> Configuration for :encryptable
|
128
|
+
# Allow you to use another encryption algorithm besides bcrypt (default). You can use
|
129
|
+
# :sha1, :sha512 or encryptors from others authentication tools as :clearance_sha1,
|
130
|
+
# :authlogic_sha512 (then you should set stretches above to 20 for default behavior)
|
131
|
+
# and :restful_authentication_sha1 (then you should set stretches to 10, and copy
|
132
|
+
# REST_AUTH_SITE_KEY to pepper)
|
133
|
+
# config.encryptor = :sha512
|
134
|
+
|
135
|
+
# ==> Configuration for :token_authenticatable
|
136
|
+
# Defines name of the authentication token params key
|
137
|
+
# config.token_authentication_key = :auth_token
|
138
|
+
|
139
|
+
# If true, authentication through token does not store user in session and needs
|
140
|
+
# to be supplied on each request. Useful if you are using the token as API token.
|
141
|
+
# config.stateless_token = false
|
142
|
+
|
143
|
+
# ==> Scopes configuration
|
144
|
+
# Turn scoped views on. Before rendering "sessions/new", it will first check for
|
145
|
+
# "users/sessions/new". It's turned off by default because it's slower if you
|
146
|
+
# are using only default views.
|
147
|
+
# config.scoped_views = false
|
148
|
+
|
149
|
+
# Configure the default scope given to Warden. By default it's the first
|
150
|
+
# devise role declared in your routes (usually :user).
|
151
|
+
# config.default_scope = :user
|
152
|
+
|
153
|
+
# Configure sign_out behavior.
|
154
|
+
# Sign_out action can be scoped (i.e. /users/sign_out affects only :user scope).
|
155
|
+
# The default is true, which means any logout action will sign out all active scopes.
|
156
|
+
# config.sign_out_all_scopes = true
|
157
|
+
|
158
|
+
# ==> Navigation configuration
|
159
|
+
# Lists the formats that should be treated as navigational. Formats like
|
160
|
+
# :html, should redirect to the sign in page when the user does not have
|
161
|
+
# access, but formats like :xml or :json, should return 401.
|
162
|
+
#
|
163
|
+
# If you have any extra navigational formats, like :iphone or :mobile, you
|
164
|
+
# should add them to the navigational formats lists.
|
165
|
+
#
|
166
|
+
# The :"*/*" format below is required to match Internet Explorer requests.
|
167
|
+
# config.navigational_formats = [:"*/*", :html]
|
168
|
+
|
169
|
+
# The default HTTP method used to sign out a resource. Default is :get.
|
170
|
+
# config.sign_out_via = :get
|
171
|
+
|
172
|
+
# ==> OmniAuth
|
173
|
+
# Add a new OmniAuth provider. Check the wiki for more information on setting
|
174
|
+
# up on your models and hooks.
|
175
|
+
# config.omniauth :github, 'APP_ID', 'APP_SECRET', :scope => 'user,public_repo'
|
176
|
+
|
177
|
+
# ==> Warden configuration
|
178
|
+
# If you want to use other strategies, that are not supported by Devise, or
|
179
|
+
# change the failure app, you can configure them inside the config.warden block.
|
180
|
+
#
|
181
|
+
# config.warden do |manager|
|
182
|
+
# manager.failure_app = AnotherApp
|
183
|
+
# manager.intercept_401 = false
|
184
|
+
# manager.default_strategies(:scope => :user).unshift :some_external_strategy
|
185
|
+
# end
|
186
|
+
end
|
@@ -0,0 +1,237 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require 'ostruct'
|
3
|
+
|
4
|
+
class ControllerAuthenticatableTest < ActionController::TestCase
|
5
|
+
tests ApplicationController
|
6
|
+
|
7
|
+
def setup
|
8
|
+
@mock_warden = OpenStruct.new
|
9
|
+
@controller.request.env['warden'] = @mock_warden
|
10
|
+
end
|
11
|
+
|
12
|
+
test 'provide access to warden instance' do
|
13
|
+
assert_equal @mock_warden, @controller.warden
|
14
|
+
end
|
15
|
+
|
16
|
+
test 'proxy signed_in?(scope) to authenticate?' do
|
17
|
+
@mock_warden.expects(:authenticate?).with(:scope => :my_scope)
|
18
|
+
@controller.signed_in?(:my_scope)
|
19
|
+
end
|
20
|
+
|
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?
|
26
|
+
end
|
27
|
+
|
28
|
+
test 'proxy current_user to authenticate with user scope' do
|
29
|
+
@mock_warden.expects(:authenticate).with(:scope => :user)
|
30
|
+
@controller.current_user
|
31
|
+
end
|
32
|
+
|
33
|
+
test 'proxy current_admin to authenticate with admin scope' do
|
34
|
+
@mock_warden.expects(:authenticate).with(:scope => :admin)
|
35
|
+
@controller.current_admin
|
36
|
+
end
|
37
|
+
|
38
|
+
test 'proxy current_publisher_account to authenticate with namespaced publisher account scope' do
|
39
|
+
@mock_warden.expects(:authenticate).with(:scope => :publisher_account)
|
40
|
+
@controller.current_publisher_account
|
41
|
+
end
|
42
|
+
|
43
|
+
test 'proxy authenticate_user! to authenticate with user scope' do
|
44
|
+
@mock_warden.expects(:authenticate!).with(:scope => :user)
|
45
|
+
@controller.authenticate_user!
|
46
|
+
end
|
47
|
+
|
48
|
+
test 'proxy authenticate_admin! to authenticate with admin scope' do
|
49
|
+
@mock_warden.expects(:authenticate!).with(:scope => :admin)
|
50
|
+
@controller.authenticate_admin!
|
51
|
+
end
|
52
|
+
|
53
|
+
test 'proxy authenticate_publisher_account! to authenticate with namespaced publisher account scope' do
|
54
|
+
@mock_warden.expects(:authenticate!).with(:scope => :publisher_account)
|
55
|
+
@controller.authenticate_publisher_account!
|
56
|
+
end
|
57
|
+
|
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?
|
61
|
+
end
|
62
|
+
|
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?
|
66
|
+
end
|
67
|
+
|
68
|
+
test 'proxy publisher_account_signed_in? to authenticate with namespaced publisher account scope' do
|
69
|
+
@mock_warden.expects(:authenticate).with(:scope => :publisher_account)
|
70
|
+
@controller.publisher_account_signed_in?
|
71
|
+
end
|
72
|
+
|
73
|
+
test 'proxy user_session to session scope in warden' do
|
74
|
+
@mock_warden.expects(:authenticate).with(:scope => :user).returns(true)
|
75
|
+
@mock_warden.expects(:session).with(:user).returns({})
|
76
|
+
@controller.user_session
|
77
|
+
end
|
78
|
+
|
79
|
+
test 'proxy admin_session to session scope in warden' do
|
80
|
+
@mock_warden.expects(:authenticate).with(:scope => :admin).returns(true)
|
81
|
+
@mock_warden.expects(:session).with(:admin).returns({})
|
82
|
+
@controller.admin_session
|
83
|
+
end
|
84
|
+
|
85
|
+
test 'proxy publisher_account_session from namespaced scope to session scope in warden' do
|
86
|
+
@mock_warden.expects(:authenticate).with(:scope => :publisher_account).returns(true)
|
87
|
+
@mock_warden.expects(:session).with(:publisher_account).returns({})
|
88
|
+
@controller.publisher_account_session
|
89
|
+
end
|
90
|
+
|
91
|
+
test 'sign in proxy to set_user on warden' do
|
92
|
+
user = User.new
|
93
|
+
@mock_warden.expects(:user).returns(nil)
|
94
|
+
@mock_warden.expects(:set_user).with(user, :scope => :user).returns(true)
|
95
|
+
@controller.sign_in(:user, user)
|
96
|
+
end
|
97
|
+
|
98
|
+
test 'sign in accepts a resource as argument' do
|
99
|
+
user = User.new
|
100
|
+
@mock_warden.expects(:user).returns(nil)
|
101
|
+
@mock_warden.expects(:set_user).with(user, :scope => :user).returns(true)
|
102
|
+
@controller.sign_in(user)
|
103
|
+
end
|
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
|
+
|
126
|
+
test 'sign out proxy to logout on warden' do
|
127
|
+
@mock_warden.expects(:user).with(:user).returns(true)
|
128
|
+
@mock_warden.expects(:logout).with(:user).returns(true)
|
129
|
+
@controller.sign_out(:user)
|
130
|
+
end
|
131
|
+
|
132
|
+
test 'sign out accepts a resource as argument' do
|
133
|
+
@mock_warden.expects(:user).with(:user).returns(true)
|
134
|
+
@mock_warden.expects(:logout).with(:user).returns(true)
|
135
|
+
@controller.sign_out(User.new)
|
136
|
+
end
|
137
|
+
|
138
|
+
test 'sign out without args proxy to sign out all scopes' do
|
139
|
+
@mock_warden.expects(:logout).with().returns(true)
|
140
|
+
@controller.sign_out
|
141
|
+
end
|
142
|
+
|
143
|
+
test 'sign out everybody proxy to logout on warden' do
|
144
|
+
@mock_warden.expects(:logout).with().returns(true)
|
145
|
+
@controller.sign_out_all_scopes
|
146
|
+
end
|
147
|
+
|
148
|
+
test 'stored location for returns the location for a given scope' do
|
149
|
+
assert_nil @controller.stored_location_for(:user)
|
150
|
+
@controller.session[:"user_return_to"] = "/foo.bar"
|
151
|
+
assert_equal "/foo.bar", @controller.stored_location_for(:user)
|
152
|
+
end
|
153
|
+
|
154
|
+
test 'stored location for accepts a resource as argument' do
|
155
|
+
assert_nil @controller.stored_location_for(:user)
|
156
|
+
@controller.session[:"user_return_to"] = "/foo.bar"
|
157
|
+
assert_equal "/foo.bar", @controller.stored_location_for(User.new)
|
158
|
+
end
|
159
|
+
|
160
|
+
test 'stored location cleans information after reading' do
|
161
|
+
@controller.session[:"user_return_to"] = "/foo.bar"
|
162
|
+
assert_equal "/foo.bar", @controller.stored_location_for(:user)
|
163
|
+
assert_nil @controller.session[:"user_return_to"]
|
164
|
+
end
|
165
|
+
|
166
|
+
test 'after sign in path defaults to root path if none by was specified for the given scope' do
|
167
|
+
assert_equal root_path, @controller.after_sign_in_path_for(:user)
|
168
|
+
end
|
169
|
+
|
170
|
+
test 'after sign in path defaults to the scoped root path' do
|
171
|
+
assert_equal admin_root_path, @controller.after_sign_in_path_for(:admin)
|
172
|
+
end
|
173
|
+
|
174
|
+
test 'after sign out path defaults to the root path' do
|
175
|
+
assert_equal root_path, @controller.after_sign_out_path_for(:admin)
|
176
|
+
assert_equal root_path, @controller.after_sign_out_path_for(:user)
|
177
|
+
end
|
178
|
+
|
179
|
+
test 'sign in and redirect uses the stored location' do
|
180
|
+
user = User.new
|
181
|
+
@controller.session[:"user_return_to"] = "/foo.bar"
|
182
|
+
@mock_warden.expects(:user).with(:user).returns(nil)
|
183
|
+
@mock_warden.expects(:set_user).with(user, :scope => :user).returns(true)
|
184
|
+
@controller.expects(:redirect_to).with("/foo.bar")
|
185
|
+
@controller.sign_in_and_redirect(user)
|
186
|
+
end
|
187
|
+
|
188
|
+
test 'sign in and redirect uses the configured after sign in path' do
|
189
|
+
admin = Admin.new
|
190
|
+
@mock_warden.expects(:user).with(:admin).returns(nil)
|
191
|
+
@mock_warden.expects(:set_user).with(admin, :scope => :admin).returns(true)
|
192
|
+
@controller.expects(:redirect_to).with(admin_root_path)
|
193
|
+
@controller.sign_in_and_redirect(admin)
|
194
|
+
end
|
195
|
+
|
196
|
+
test 'sign in and redirect does not sign in again if user is already signed' do
|
197
|
+
admin = Admin.new
|
198
|
+
@mock_warden.expects(:user).with(:admin).returns(admin)
|
199
|
+
@mock_warden.expects(:set_user).never
|
200
|
+
@controller.expects(:redirect_to).with(admin_root_path)
|
201
|
+
@controller.sign_in_and_redirect(admin)
|
202
|
+
end
|
203
|
+
|
204
|
+
test 'redirect_location returns the stored location if set' do
|
205
|
+
user = User.new
|
206
|
+
@controller.session[:"user_return_to"] = "/foo.bar"
|
207
|
+
assert_equal '/foo.bar', @controller.redirect_location('user', user)
|
208
|
+
end
|
209
|
+
|
210
|
+
test 'redirect_location returns the after sign in path by default' do
|
211
|
+
user = User.new
|
212
|
+
assert_equal @controller.after_sign_in_path_for(:user), @controller.redirect_location('user', user)
|
213
|
+
end
|
214
|
+
|
215
|
+
test 'sign out and redirect uses the configured after sign out path when signing out only the current scope' do
|
216
|
+
swap Devise, :sign_out_all_scopes => false do
|
217
|
+
@mock_warden.expects(:user).with(:admin).returns(true)
|
218
|
+
@mock_warden.expects(:logout).with(:admin).returns(true)
|
219
|
+
@controller.expects(:redirect_to).with(admin_root_path)
|
220
|
+
@controller.instance_eval "def after_sign_out_path_for(resource); admin_root_path; end"
|
221
|
+
@controller.sign_out_and_redirect(:admin)
|
222
|
+
end
|
223
|
+
end
|
224
|
+
|
225
|
+
test 'sign out and redirect uses the configured after sign out path when signing out all scopes' do
|
226
|
+
swap Devise, :sign_out_all_scopes => true do
|
227
|
+
@mock_warden.expects(:logout).with().returns(true)
|
228
|
+
@controller.expects(:redirect_to).with(admin_root_path)
|
229
|
+
@controller.instance_eval "def after_sign_out_path_for(resource); admin_root_path; end"
|
230
|
+
@controller.sign_out_and_redirect(:admin)
|
231
|
+
end
|
232
|
+
end
|
233
|
+
|
234
|
+
test 'is not a devise controller' do
|
235
|
+
assert_not @controller.devise_controller?
|
236
|
+
end
|
237
|
+
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class MyController < ApplicationController
|
4
|
+
include Devise::Controllers::InternalHelpers
|
5
|
+
end
|
6
|
+
|
7
|
+
class HelpersTest < ActionController::TestCase
|
8
|
+
tests MyController
|
9
|
+
|
10
|
+
def setup
|
11
|
+
@mock_warden = OpenStruct.new
|
12
|
+
@controller.request.env['warden'] = @mock_warden
|
13
|
+
@controller.request.env['devise.mapping'] = Devise.mappings[:user]
|
14
|
+
end
|
15
|
+
|
16
|
+
test 'get resource name from env' do
|
17
|
+
assert_equal :user, @controller.resource_name
|
18
|
+
end
|
19
|
+
|
20
|
+
test 'get resource class from env' do
|
21
|
+
assert_equal User, @controller.resource_class
|
22
|
+
end
|
23
|
+
|
24
|
+
test 'get resource instance variable from env' do
|
25
|
+
@controller.instance_variable_set(:@user, user = User.new)
|
26
|
+
assert_equal user, @controller.resource
|
27
|
+
end
|
28
|
+
|
29
|
+
test 'set resource instance variable from env' do
|
30
|
+
user = @controller.send(:resource_class).new
|
31
|
+
@controller.send(:resource=, user)
|
32
|
+
|
33
|
+
assert_equal user, @controller.send(:resource)
|
34
|
+
assert_equal user, @controller.instance_variable_get(:@user)
|
35
|
+
end
|
36
|
+
|
37
|
+
test 'resources methods are not controller actions' do
|
38
|
+
assert @controller.class.action_methods.empty?
|
39
|
+
end
|
40
|
+
|
41
|
+
test 'require no authentication tests current mapping' do
|
42
|
+
@mock_warden.expects(:authenticated?).with(:user).returns(true)
|
43
|
+
@mock_warden.expects(:user).with(:user).returns(User.new)
|
44
|
+
@controller.expects(:redirect_to).with(root_path)
|
45
|
+
@controller.send :require_no_authentication
|
46
|
+
end
|
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
|
+
|
53
|
+
test 'is a devise controller' do
|
54
|
+
assert @controller.devise_controller?
|
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
|
72
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class RoutesTest < ActionController::TestCase
|
4
|
+
tests ApplicationController
|
5
|
+
|
6
|
+
def assert_path_and_url(name, prepend_path=nil)
|
7
|
+
@request.path = '/users/session'
|
8
|
+
prepend_path = "#{prepend_path}_" if prepend_path
|
9
|
+
|
10
|
+
# Resource param
|
11
|
+
assert_equal @controller.send(:"#{prepend_path}#{name}_path", :user),
|
12
|
+
send(:"#{prepend_path}user_#{name}_path")
|
13
|
+
assert_equal @controller.send(:"#{prepend_path}#{name}_url", :user),
|
14
|
+
send(:"#{prepend_path}user_#{name}_url")
|
15
|
+
|
16
|
+
# Default url params
|
17
|
+
assert_equal @controller.send(:"#{prepend_path}#{name}_path", :user, :param => 123),
|
18
|
+
send(:"#{prepend_path}user_#{name}_path", :param => 123)
|
19
|
+
assert_equal @controller.send(:"#{prepend_path}#{name}_url", :user, :param => 123),
|
20
|
+
send(:"#{prepend_path}user_#{name}_url", :param => 123)
|
21
|
+
|
22
|
+
@request.path = nil
|
23
|
+
# With an object
|
24
|
+
assert_equal @controller.send(:"#{prepend_path}#{name}_path", User.new),
|
25
|
+
send(:"#{prepend_path}user_#{name}_path")
|
26
|
+
assert_equal @controller.send(:"#{prepend_path}#{name}_url", User.new),
|
27
|
+
send(:"#{prepend_path}user_#{name}_url")
|
28
|
+
end
|
29
|
+
|
30
|
+
|
31
|
+
test 'should alias session to mapped user session' do
|
32
|
+
assert_path_and_url :session
|
33
|
+
assert_path_and_url :session, :new
|
34
|
+
assert_path_and_url :session, :destroy
|
35
|
+
end
|
36
|
+
|
37
|
+
test 'should alias password to mapped user password' do
|
38
|
+
assert_path_and_url :password
|
39
|
+
assert_path_and_url :password, :new
|
40
|
+
assert_path_and_url :password, :edit
|
41
|
+
end
|
42
|
+
|
43
|
+
test 'should alias confirmation to mapped user confirmation' do
|
44
|
+
assert_path_and_url :confirmation
|
45
|
+
assert_path_and_url :confirmation, :new
|
46
|
+
end
|
47
|
+
|
48
|
+
test 'should alias unlock to mapped user unlock' do
|
49
|
+
assert_path_and_url :unlock
|
50
|
+
assert_path_and_url :unlock, :new
|
51
|
+
end
|
52
|
+
|
53
|
+
test 'should alias registration to mapped user registration' do
|
54
|
+
assert_path_and_url :registration
|
55
|
+
assert_path_and_url :registration, :new
|
56
|
+
assert_path_and_url :registration, :edit
|
57
|
+
assert_path_and_url :registration, :cancel
|
58
|
+
end
|
59
|
+
end
|
data/test/devise_test.rb
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
module Devise
|
4
|
+
def self.yield_and_restore
|
5
|
+
@@warden_configured = nil
|
6
|
+
c, b = @@warden_config, @@warden_config_block
|
7
|
+
yield
|
8
|
+
ensure
|
9
|
+
@@warden_config, @@warden_config_block = c, b
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
class DeviseTest < ActiveSupport::TestCase
|
14
|
+
test 'model options can be configured through Devise' do
|
15
|
+
swap Devise, :confirm_within => 113, :pepper => "foo" do
|
16
|
+
assert_equal 113, Devise.confirm_within
|
17
|
+
assert_equal "foo", Devise.pepper
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
test 'setup block yields self' do
|
22
|
+
Devise.setup do |config|
|
23
|
+
assert_equal Devise, config
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
test 'stores warden configuration' do
|
28
|
+
assert_equal Devise::FailureApp, Devise.warden_config.failure_app
|
29
|
+
assert_equal :user, Devise.warden_config.default_scope
|
30
|
+
end
|
31
|
+
|
32
|
+
test 'warden manager user configuration through a block' do
|
33
|
+
Devise.yield_and_restore do
|
34
|
+
@executed = false
|
35
|
+
Devise.warden do |config|
|
36
|
+
@executed = true
|
37
|
+
assert_kind_of Warden::Config, config
|
38
|
+
end
|
39
|
+
|
40
|
+
Devise.configure_warden!
|
41
|
+
assert @executed
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
test 'add new module using the helper method' do
|
46
|
+
assert_nothing_raised(Exception) { Devise.add_module(:coconut) }
|
47
|
+
assert_equal 1, Devise::ALL.select { |v| v == :coconut }.size
|
48
|
+
assert_not Devise::STRATEGIES.include?(:coconut)
|
49
|
+
assert_not defined?(Devise::Models::Coconut)
|
50
|
+
Devise::ALL.delete(:coconut)
|
51
|
+
|
52
|
+
assert_nothing_raised(Exception) { Devise.add_module(:banana, :strategy => :fruits) }
|
53
|
+
assert_equal :fruits, Devise::STRATEGIES[:banana]
|
54
|
+
Devise::ALL.delete(:banana)
|
55
|
+
Devise::STRATEGIES.delete(:banana)
|
56
|
+
|
57
|
+
assert_nothing_raised(Exception) { Devise.add_module(:kivi, :controller => :fruits) }
|
58
|
+
assert_equal :fruits, Devise::CONTROLLERS[:kivi]
|
59
|
+
Devise::ALL.delete(:kivi)
|
60
|
+
Devise::CONTROLLERS.delete(:kivi)
|
61
|
+
|
62
|
+
assert_nothing_raised(Exception) { Devise.add_module(:authenticatable_again, :model => 'devise/model/authenticatable') }
|
63
|
+
assert defined?(Devise::Models::AuthenticatableAgain)
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class Encryptors < ActiveSupport::TestCase
|
4
|
+
test 'should match a password created by authlogic' do
|
5
|
+
authlogic = "b623c3bc9c775b0eb8edb218a382453396fec4146422853e66ecc4b6bc32d7162ee42074dcb5f180a770dc38b5df15812f09bbf497a4a1b95fe5e7d2b8eb7eb4"
|
6
|
+
encryptor = Devise::Encryptors::AuthlogicSha512.digest('123mudar', 20, 'usZK_z_EAaF61Gwkw-ed', '')
|
7
|
+
assert_equal authlogic, encryptor
|
8
|
+
end
|
9
|
+
|
10
|
+
test 'should match a password created by restful_authentication' do
|
11
|
+
restful_authentication = "93110f71309ce91366375ea44e2a6f5cc73fa8d4"
|
12
|
+
encryptor = Devise::Encryptors::RestfulAuthenticationSha1.digest('123mudar', 10, '48901d2b247a54088acb7f8ea3e695e50fe6791b', 'fee9a51ec0a28d11be380ca6dee6b4b760c1a3bf')
|
13
|
+
assert_equal restful_authentication, encryptor
|
14
|
+
end
|
15
|
+
|
16
|
+
test 'should match a password created by clearance' do
|
17
|
+
clearance = "0f40bbae18ddefd7066276c3ef209d40729b0378"
|
18
|
+
encryptor = Devise::Encryptors::ClearanceSha1.digest('123mudar', nil, '65c58472c207c829f28c68619d3e3aefed18ab3f', nil)
|
19
|
+
assert_equal clearance, encryptor
|
20
|
+
end
|
21
|
+
|
22
|
+
Devise::ENCRYPTORS_LENGTH.each do |key, value|
|
23
|
+
test "should have length #{value} for #{key.inspect}" do
|
24
|
+
swap Devise, :encryptor => key do
|
25
|
+
encryptor = Devise::Encryptors.const_get(key.to_s.classify)
|
26
|
+
assert_equal value, encryptor.digest('a', 4, encryptor.salt(4), nil).size
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|