devise 1.1.9 → 1.2.rc
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.
- data/CHANGELOG.rdoc +34 -26
- data/README.rdoc +134 -100
- 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 +59 -6
- data/app/controllers/devise/sessions_controller.rb +3 -2
- data/app/controllers/devise/unlocks_controller.rb +1 -1
- data/app/helpers/devise_helper.rb +4 -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 +9 -2
- data/lib/devise.rb +116 -58
- data/lib/devise/controllers/helpers.rb +103 -107
- data/lib/devise/controllers/internal_helpers.rb +23 -7
- data/lib/devise/controllers/scoped_views.rb +4 -6
- data/lib/devise/controllers/url_helpers.rb +3 -5
- data/lib/devise/encryptors/base.rb +1 -1
- data/lib/devise/encryptors/restful_authentication_sha1.rb +4 -4
- data/lib/devise/failure_app.rb +29 -21
- data/lib/devise/hooks/forgetable.rb +2 -1
- data/lib/devise/hooks/rememberable.rb +11 -9
- data/lib/devise/mapping.rb +12 -5
- data/lib/devise/models.rb +0 -14
- data/lib/devise/models/authenticatable.rb +40 -30
- data/lib/devise/models/confirmable.rb +11 -15
- data/lib/devise/models/database_authenticatable.rb +23 -35
- data/lib/devise/models/encryptable.rb +65 -0
- data/lib/devise/models/lockable.rb +8 -7
- data/lib/devise/models/omniauthable.rb +23 -0
- data/lib/devise/models/recoverable.rb +5 -3
- data/lib/devise/models/registerable.rb +13 -0
- data/lib/devise/models/rememberable.rb +38 -30
- data/lib/devise/models/timeoutable.rb +20 -3
- data/lib/devise/models/token_authenticatable.rb +19 -7
- data/lib/devise/models/validatable.rb +16 -4
- data/lib/devise/modules.rb +15 -8
- data/lib/devise/omniauth.rb +47 -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/orm/active_record.rb +2 -0
- data/lib/devise/orm/mongoid.rb +4 -2
- data/lib/devise/rails.rb +26 -46
- data/lib/devise/rails/routes.rb +64 -20
- data/lib/devise/rails/warden_compat.rb +18 -20
- data/lib/devise/schema.rb +13 -14
- data/lib/devise/strategies/authenticatable.rb +33 -7
- data/lib/devise/strategies/database_authenticatable.rb +1 -1
- data/lib/devise/strategies/rememberable.rb +1 -1
- data/lib/devise/strategies/token_authenticatable.rb +6 -2
- data/lib/devise/test_helpers.rb +11 -1
- data/lib/devise/version.rb +1 -1
- data/lib/generators/active_record/templates/migration.rb +1 -0
- data/lib/generators/devise/orm_helpers.rb +3 -2
- data/lib/generators/templates/devise.rb +70 -39
- data/test/controllers/helpers_test.rb +43 -67
- data/test/controllers/internal_helpers_test.rb +29 -8
- data/test/controllers/url_helpers_test.rb +2 -1
- data/test/failure_app_test.rb +56 -21
- data/test/generators/generators_test_helper.rb +4 -0
- data/test/generators/install_generator_test.rb +14 -0
- data/test/generators/views_generator_test.rb +37 -0
- data/test/integration/authenticatable_test.rb +147 -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 +107 -0
- data/test/integration/recoverable_test.rb +39 -20
- data/test/integration/registerable_test.rb +30 -4
- data/test/integration/rememberable_test.rb +57 -34
- data/test/integration/timeoutable_test.rb +10 -1
- data/test/integration/token_authenticatable_test.rb +12 -17
- 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 +3 -3
- data/test/models/database_authenticatable_test.rb +14 -71
- data/test/models/encryptable_test.rb +65 -0
- data/test/models/lockable_test.rb +17 -1
- data/test/models/recoverable_test.rb +17 -0
- data/test/models/rememberable_test.rb +186 -125
- data/test/models/token_authenticatable_test.rb +1 -13
- data/test/models_test.rb +5 -5
- data/test/omniauth/url_helpers_test.rb +47 -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/home_controller.rb +9 -0
- data/test/rails_app/app/controllers/users/omniauth_callbacks_controller.rb +7 -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/config/initializers/devise.rb +52 -28
- data/test/rails_app/config/routes.rb +14 -6
- 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/routes_test.rb +42 -9
- data/test/support/integration.rb +3 -3
- data/test/support/webrat/integrations/rails.rb +7 -0
- data/test/test_helper.rb +2 -0
- data/test/test_helpers_test.rb +29 -0
- metadata +60 -30
- data/Gemfile +0 -27
- data/Gemfile.lock +0 -115
- data/Rakefile +0 -55
- 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/indifferent_hash.rb +0 -33
- data/test/support/test_silencer.rb +0 -5
@@ -10,13 +10,17 @@ module Devise
|
|
10
10
|
# For HTTP, you can pass the token as username and blank password. Since some clients may require
|
11
11
|
# a password, you can pass "X" as password and it will simply be ignored.
|
12
12
|
class TokenAuthenticatable < Authenticatable
|
13
|
+
def store?
|
14
|
+
!mapping.to.stateless_token
|
15
|
+
end
|
16
|
+
|
13
17
|
def authenticate!
|
14
18
|
resource = mapping.to.find_for_token_authentication(authentication_hash)
|
15
19
|
|
16
20
|
if validate(resource)
|
17
21
|
resource.after_token_authentication
|
18
22
|
success!(resource)
|
19
|
-
|
23
|
+
else
|
20
24
|
fail(:invalid_token)
|
21
25
|
end
|
22
26
|
end
|
@@ -28,7 +32,7 @@ module Devise
|
|
28
32
|
true
|
29
33
|
end
|
30
34
|
|
31
|
-
# Do not use remember_me
|
35
|
+
# Do not use remember_me behavior with token.
|
32
36
|
def remember_me?
|
33
37
|
false
|
34
38
|
end
|
data/lib/devise/test_helpers.rb
CHANGED
@@ -1,4 +1,11 @@
|
|
1
1
|
module Devise
|
2
|
+
# Devise::TestHelpers provides a facility to test controllers in isolation
|
3
|
+
# when using ActionController::TestCase allowing you to quickly sign_in or
|
4
|
+
# sign_out an user. Do not use Devise::TestHelpers in integration tests.
|
5
|
+
#
|
6
|
+
# Notice you should not test Warden specific behavior (like Warden callbacks)
|
7
|
+
# using Devise::TestHelpers since it is a stub of the actual behavior. Such
|
8
|
+
# callbacks should be tested in your integration suite instead.
|
2
9
|
module TestHelpers
|
3
10
|
def self.included(base)
|
4
11
|
base.class_eval do
|
@@ -61,6 +68,7 @@ module Devise
|
|
61
68
|
end
|
62
69
|
|
63
70
|
# sign_in a given resource by storing its keys in the session.
|
71
|
+
# This method bypass any warden authentication callback.
|
64
72
|
#
|
65
73
|
# Examples:
|
66
74
|
#
|
@@ -74,6 +82,7 @@ module Devise
|
|
74
82
|
end
|
75
83
|
|
76
84
|
# Sign out a given resource or scope by calling logout on Warden.
|
85
|
+
# This method bypass any warden logout callback.
|
77
86
|
#
|
78
87
|
# Examples:
|
79
88
|
#
|
@@ -83,7 +92,8 @@ module Devise
|
|
83
92
|
def sign_out(resource_or_scope)
|
84
93
|
scope = Devise::Mapping.find_scope!(resource_or_scope)
|
85
94
|
@controller.instance_variable_set(:"@current_#{scope}", nil)
|
86
|
-
warden.
|
95
|
+
user = warden.instance_variable_get(:@users).delete(scope)
|
96
|
+
warden.session_serializer.delete(scope, user)
|
87
97
|
end
|
88
98
|
|
89
99
|
end
|
data/lib/devise/version.rb
CHANGED
@@ -6,6 +6,7 @@ class DeviseCreate<%= table_name.camelize %> < ActiveRecord::Migration
|
|
6
6
|
t.rememberable
|
7
7
|
t.trackable
|
8
8
|
|
9
|
+
# t.encryptable
|
9
10
|
# t.confirmable
|
10
11
|
# t.lockable :lock_strategy => :<%= Devise.lock_strategy %>, :unlock_strategy => :<%= Devise.unlock_strategy %>
|
11
12
|
# t.token_authenticatable
|
@@ -4,7 +4,7 @@ module Devise
|
|
4
4
|
def model_contents
|
5
5
|
<<-CONTENT
|
6
6
|
# Include default devise modules. Others available are:
|
7
|
-
# :token_authenticatable, :confirmable, :lockable and :
|
7
|
+
# :token_authenticatable, :encryptable, :confirmable, :lockable, :timeoutable and :omniauthable
|
8
8
|
devise :database_authenticatable, :registerable,
|
9
9
|
:recoverable, :rememberable, :trackable, :validatable
|
10
10
|
|
@@ -12,7 +12,8 @@ CONTENT
|
|
12
12
|
end
|
13
13
|
|
14
14
|
def model_exists?
|
15
|
-
|
15
|
+
return @model_exists if instance_variable_defined?(:@model_exists)
|
16
|
+
@model_exists = File.exists?(File.join(destination_root, model_path))
|
16
17
|
end
|
17
18
|
|
18
19
|
def model_path
|
@@ -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
42
|
# Tell if authentication through HTTP Basic Auth is enabled. False by default.
|
29
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,22 +53,13 @@ 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
|
-
# Setup a pepper to generate the encrypted password.
|
49
|
-
config.pepper = <%= ActiveSupport::SecureRandom.hex(64).inspect %>
|
50
|
-
|
51
56
|
# ==> Configuration for :confirmable
|
52
57
|
# 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).
|
58
|
+
# he will be able to access your application without confirming. Default is 0.days
|
59
|
+
# When confirm_within is zero, the user won't be able to sign in without confirming.
|
60
|
+
# You can use this to let your user access some features of your application
|
61
|
+
# without confirming the account, but blocking it after a certain period
|
62
|
+
# (ie 2 days).
|
58
63
|
# config.confirm_within = 2.days
|
59
64
|
|
60
65
|
# ==> Configuration for :rememberable
|
@@ -67,17 +72,21 @@ Devise.setup do |config|
|
|
67
72
|
# If true, extends the user's remember period when remembered via cookie.
|
68
73
|
# config.extend_remember_period = false
|
69
74
|
|
75
|
+
# If true, uses the password salt as remember token. This should be turned
|
76
|
+
# to false if you are not using database authenticatable.
|
77
|
+
config.use_salt_as_remember_token = true
|
78
|
+
|
70
79
|
# ==> Configuration for :validatable
|
71
|
-
# Range for password length
|
80
|
+
# Range for password length. Default is 6..20.
|
72
81
|
# config.password_length = 6..20
|
73
82
|
|
74
83
|
# Regex to use to validate the email address
|
75
|
-
# config.email_regexp =
|
84
|
+
# config.email_regexp = /^([\w\.%\+\-]+)@([\w\-]+\.)+([\w]{2,})$/i
|
76
85
|
|
77
86
|
# ==> Configuration for :timeoutable
|
78
87
|
# 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 =
|
88
|
+
# time the user will be asked for credentials again. Default is 30 minutes.
|
89
|
+
# config.timeout_in = 30.minutes
|
81
90
|
|
82
91
|
# ==> Configuration for :lockable
|
83
92
|
# Defines which strategy will be used to lock an account.
|
@@ -99,44 +108,66 @@ Devise.setup do |config|
|
|
99
108
|
# Time interval to unlock the account if :time is enabled as unlock_strategy.
|
100
109
|
# config.unlock_in = 1.hour
|
101
110
|
|
111
|
+
# ==> Configuration for :encryptable
|
112
|
+
# Allow you to use another encryption algorithm besides bcrypt (default). You can use
|
113
|
+
# :sha1, :sha512 or encryptors from others authentication tools as :clearance_sha1,
|
114
|
+
# :authlogic_sha512 (then you should set stretches above to 20 for default behavior)
|
115
|
+
# and :restful_authentication_sha1 (then you should set stretches to 10, and copy
|
116
|
+
# REST_AUTH_SITE_KEY to pepper)
|
117
|
+
# config.encryptor = :sha512
|
118
|
+
|
119
|
+
# Setup a pepper to generate the encrypted password.
|
120
|
+
# config.pepper = <%= ActiveSupport::SecureRandom.hex(64).inspect %>
|
121
|
+
|
102
122
|
# ==> Configuration for :token_authenticatable
|
103
123
|
# Defines name of the authentication token params key
|
104
124
|
# config.token_authentication_key = :auth_token
|
105
125
|
|
126
|
+
# If true, authentication through token does not store user in session and needs
|
127
|
+
# to be supplied on each request. Useful if you are using the token as API token.
|
128
|
+
# config.stateless_token = false
|
129
|
+
|
106
130
|
# ==> Scopes configuration
|
107
131
|
# Turn scoped views on. Before rendering "sessions/new", it will first check for
|
108
132
|
# "users/sessions/new". It's turned off by default because it's slower if you
|
109
133
|
# are using only default views.
|
110
|
-
# config.scoped_views =
|
134
|
+
# config.scoped_views = false
|
111
135
|
|
112
136
|
# Configure the default scope given to Warden. By default it's the first
|
113
|
-
# devise role declared in your routes.
|
137
|
+
# devise role declared in your routes (usually :user).
|
114
138
|
# config.default_scope = :user
|
115
139
|
|
116
|
-
# Configure sign_out behavior.
|
117
|
-
#
|
118
|
-
#
|
119
|
-
# config.sign_out_all_scopes =
|
140
|
+
# Configure sign_out behavior.
|
141
|
+
# Sign_out action can be scoped (i.e. /users/sign_out affects only :user scope).
|
142
|
+
# The default is true, which means any logout action will sign out all active scopes.
|
143
|
+
# config.sign_out_all_scopes = true
|
120
144
|
|
121
145
|
# ==> Navigation configuration
|
122
146
|
# Lists the formats that should be treated as navigational. Formats like
|
123
147
|
# :html, should redirect to the sign in page when the user does not have
|
124
148
|
# access, but formats like :xml or :json, should return 401.
|
149
|
+
#
|
125
150
|
# If you have any extra navigational formats, like :iphone or :mobile, you
|
126
|
-
# should add them to the navigational formats lists.
|
127
|
-
#
|
151
|
+
# should add them to the navigational formats lists.
|
152
|
+
#
|
153
|
+
# The :"*/*" format below is required to match Internet Explorer requests.
|
154
|
+
# config.navigational_formats = [:"*/*", :html]
|
155
|
+
|
156
|
+
# The default HTTP method used to sign out a resource. Default is :get.
|
157
|
+
# config.sign_out_via = :get
|
158
|
+
|
159
|
+
# ==> OmniAuth
|
160
|
+
# Add a new OmniAuth provider. Check the wiki for more information on setting
|
161
|
+
# up on your models and hooks.
|
162
|
+
# config.omniauth :github, 'APP_ID', 'APP_SECRET', :scope => 'user,public_repo'
|
128
163
|
|
129
164
|
# ==> 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
|
165
|
+
# If you want to use other strategies, that are not supported by Devise, or
|
166
|
+
# change the failure app, you can configure them inside the config.warden block.
|
133
167
|
#
|
134
168
|
# 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
|
169
|
+
# manager.failure_app = AnotherApp
|
170
|
+
# manager.intercept_401 = false
|
171
|
+
# manager.default_strategies(:scope => :user).unshift :some_external_strategy
|
141
172
|
# end
|
142
173
|
end
|
@@ -1,51 +1,16 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
require 'ostruct'
|
3
3
|
|
4
|
-
class MockController < ApplicationController
|
5
|
-
attr_accessor :env
|
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
4
|
class ControllerAuthenticableTest < ActionController::TestCase
|
36
|
-
tests
|
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
16
|
test 'proxy signed_in? to authenticated' do
|
@@ -54,9 +19,9 @@ class ControllerAuthenticableTest < ActionController::TestCase
|
|
54
19
|
end
|
55
20
|
|
56
21
|
test 'proxy anybody_signed_in? to signed_in?' do
|
57
|
-
Devise.mappings.keys.each
|
22
|
+
Devise.mappings.keys.each do |scope| # :user, :admin, :manager
|
58
23
|
@controller.expects(:signed_in?).with(scope)
|
59
|
-
|
24
|
+
end
|
60
25
|
@controller.anybody_signed_in?
|
61
26
|
end
|
62
27
|
|
@@ -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
|
|
@@ -135,6 +100,13 @@ class ControllerAuthenticableTest < ActionController::TestCase
|
|
135
100
|
@controller.sign_in(user)
|
136
101
|
end
|
137
102
|
|
103
|
+
test 'sign in accepts bypass as option' do
|
104
|
+
user = User.new
|
105
|
+
@mock_warden.expects(:session_serializer).returns(serializer = mock())
|
106
|
+
serializer.expects(:store).with(user, :user)
|
107
|
+
@controller.sign_in(user, :bypass => true)
|
108
|
+
end
|
109
|
+
|
138
110
|
test 'sign out proxy to logout on warden' do
|
139
111
|
@mock_warden.expects(:user).with(:user).returns(true)
|
140
112
|
@mock_warden.expects(:logout).with(:user).returns(true)
|
@@ -147,12 +119,13 @@ class ControllerAuthenticableTest < ActionController::TestCase
|
|
147
119
|
@controller.sign_out(User.new)
|
148
120
|
end
|
149
121
|
|
150
|
-
test 'sign out
|
151
|
-
|
152
|
-
|
153
|
-
|
122
|
+
test 'sign out without args proxy to sign out all scopes' do
|
123
|
+
@mock_warden.expects(:logout).with().returns(true)
|
124
|
+
@controller.sign_out
|
125
|
+
end
|
154
126
|
|
155
|
-
|
127
|
+
test 'sign out everybody proxy to logout on warden' do
|
128
|
+
@mock_warden.expects(:logout).with().returns(true)
|
156
129
|
@controller.sign_out_all_scopes
|
157
130
|
end
|
158
131
|
|
@@ -182,14 +155,6 @@ class ControllerAuthenticableTest < ActionController::TestCase
|
|
182
155
|
assert_equal admin_root_path, @controller.after_sign_in_path_for(:admin)
|
183
156
|
end
|
184
157
|
|
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
158
|
test 'after sign out path defaults to the root path' do
|
194
159
|
assert_equal root_path, @controller.after_sign_out_path_for(:admin)
|
195
160
|
assert_equal root_path, @controller.after_sign_out_path_for(:user)
|
@@ -220,12 +185,23 @@ class ControllerAuthenticableTest < ActionController::TestCase
|
|
220
185
|
@controller.sign_in_and_redirect(admin)
|
221
186
|
end
|
222
187
|
|
223
|
-
test 'sign out and redirect uses the configured after sign out path' do
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
188
|
+
test 'sign out and redirect uses the configured after sign out path when signing out only the current scope' do
|
189
|
+
swap Devise, :sign_out_all_scopes => false do
|
190
|
+
@mock_warden.expects(:user).with(:admin).returns(true)
|
191
|
+
@mock_warden.expects(:logout).with(:admin).returns(true)
|
192
|
+
@controller.expects(:redirect_to).with(admin_root_path)
|
193
|
+
@controller.instance_eval "def after_sign_out_path_for(resource); admin_root_path; end"
|
194
|
+
@controller.sign_out_and_redirect(:admin)
|
195
|
+
end
|
196
|
+
end
|
197
|
+
|
198
|
+
test 'sign out and redirect uses the configured after sign out path when signing out all scopes' do
|
199
|
+
swap Devise, :sign_out_all_scopes => true do
|
200
|
+
@mock_warden.expects(:logout).with().returns(true)
|
201
|
+
@controller.expects(:redirect_to).with(admin_root_path)
|
202
|
+
@controller.instance_eval "def after_sign_out_path_for(resource); admin_root_path; end"
|
203
|
+
@controller.sign_out_and_redirect(:admin)
|
204
|
+
end
|
229
205
|
end
|
230
206
|
|
231
207
|
test 'is not a devise controller' do
|