devise 1.5.4 → 2.0.0.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/.gitignore +0 -2
- data/CHANGELOG.rdoc +18 -7
- data/Gemfile.lock +168 -0
- data/README.rdoc +2 -0
- data/app/controllers/devise/registrations_controller.rb +6 -1
- data/app/controllers/devise/unlocks_controller.rb +1 -2
- data/app/views/devise/mailer/confirmation_instructions.html.erb +1 -1
- data/config/locales/en.yml +1 -0
- data/lib/devise.rb +41 -22
- data/lib/devise/controllers/internal_helpers.rb +9 -2
- data/lib/devise/models/authenticatable.rb +30 -12
- data/lib/devise/models/confirmable.rb +73 -18
- data/lib/devise/models/database_authenticatable.rb +0 -11
- data/lib/devise/models/recoverable.rb +5 -5
- data/lib/devise/models/rememberable.rb +5 -20
- data/lib/devise/models/timeoutable.rb +1 -3
- data/lib/devise/models/token_authenticatable.rb +1 -4
- data/lib/devise/models/validatable.rb +1 -1
- data/lib/devise/orm/active_record.rb +6 -0
- data/lib/devise/param_filter.rb +2 -1
- data/lib/devise/rails.rb +31 -0
- data/lib/devise/schema.rb +5 -0
- data/lib/devise/strategies/authenticatable.rb +12 -8
- data/lib/devise/strategies/token_authenticatable.rb +3 -3
- data/lib/devise/version.rb +1 -1
- data/lib/generators/active_record/devise_generator.rb +40 -2
- data/lib/generators/active_record/templates/migration.rb +1 -9
- data/lib/generators/active_record/templates/migration_existing.rb +1 -9
- data/lib/generators/mongoid/devise_generator.rb +43 -0
- data/lib/generators/templates/devise.rb +15 -9
- data/test/controllers/internal_helpers_test.rb +4 -2
- data/test/devise_test.rb +2 -2
- data/test/integration/confirmable_test.rb +55 -3
- data/test/integration/http_authenticatable_test.rb +16 -1
- data/test/integration/lockable_test.rb +3 -3
- data/test/integration/registerable_test.rb +32 -1
- data/test/integration/rememberable_test.rb +0 -50
- data/test/integration/token_authenticatable_test.rb +2 -2
- data/test/integration/trackable_test.rb +1 -1
- data/test/mapping_test.rb +2 -3
- data/test/models/confirmable_test.rb +86 -8
- data/test/models/database_authenticatable_test.rb +6 -6
- data/test/models/encryptable_test.rb +1 -1
- data/test/models/recoverable_test.rb +0 -27
- data/test/models/rememberable_test.rb +41 -160
- data/test/models/serializable_test.rb +1 -1
- data/test/models_test.rb +7 -7
- data/test/rails_app/app/mongoid/admin.rb +22 -1
- data/test/rails_app/app/mongoid/user.rb +35 -0
- data/test/rails_app/config/initializers/devise.rb +6 -7
- data/test/rails_app/db/migrate/20100401102949_create_tables.rb +58 -12
- data/test/rails_app/lib/shared_admin.rb +5 -2
- data/test/support/assertions.rb +4 -1
- data/test/support/integration.rb +3 -1
- data/test/test_helpers_test.rb +2 -2
- metadata +21 -39
- data/test/models/authenticatable_test.rb +0 -9
- data/test/schema_test.rb +0 -33
@@ -11,7 +11,7 @@ module Devise
|
|
11
11
|
# a password, you can pass "X" as password and it will simply be ignored.
|
12
12
|
class TokenAuthenticatable < Authenticatable
|
13
13
|
def store?
|
14
|
-
!mapping.to.
|
14
|
+
super && !mapping.to.skip_session_storage.include?(:token_auth)
|
15
15
|
end
|
16
16
|
|
17
17
|
def authenticate!
|
@@ -27,8 +27,8 @@ module Devise
|
|
27
27
|
|
28
28
|
private
|
29
29
|
|
30
|
-
#
|
31
|
-
def
|
30
|
+
# Token Authenticatable can be authenticated with params in any controller and any verb.
|
31
|
+
def valid_params_request?
|
32
32
|
true
|
33
33
|
end
|
34
34
|
|
data/lib/devise/version.rb
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
require 'rails/generators/active_record'
|
2
2
|
require 'generators/devise/orm_helpers'
|
3
3
|
|
4
|
-
|
5
4
|
module ActiveRecord
|
6
5
|
module Generators
|
7
6
|
class DeviseGenerator < ActiveRecord::Generators::Base
|
@@ -21,13 +20,52 @@ module ActiveRecord
|
|
21
20
|
def generate_model
|
22
21
|
invoke "active_record:model", [name], :migration => false unless model_exists? && behavior == :invoke
|
23
22
|
end
|
24
|
-
|
23
|
+
|
25
24
|
def inject_devise_content
|
26
25
|
inject_into_class(model_path, class_name, model_contents + <<CONTENT) if model_exists?
|
27
26
|
# Setup accessible (or protected) attributes for your model
|
28
27
|
attr_accessible :email, :password, :password_confirmation, :remember_me
|
29
28
|
CONTENT
|
30
29
|
end
|
30
|
+
|
31
|
+
def migration_data
|
32
|
+
<<RUBY
|
33
|
+
## Database authenticatable
|
34
|
+
t.string :email, :null => false, :default => ""
|
35
|
+
t.string :encrypted_password, :null => false, :default => ""
|
36
|
+
|
37
|
+
## Recoverable
|
38
|
+
t.string :reset_password_token
|
39
|
+
t.datetime :reset_password_sent_at
|
40
|
+
|
41
|
+
## Rememberable
|
42
|
+
t.datetime :remember_created_at
|
43
|
+
|
44
|
+
## Trackable
|
45
|
+
t.integer :sign_in_count, :default => 0
|
46
|
+
t.datetime :current_sign_in_at
|
47
|
+
t.datetime :last_sign_in_at
|
48
|
+
t.string :current_sign_in_ip
|
49
|
+
t.string :last_sign_in_ip
|
50
|
+
|
51
|
+
## Encryptable
|
52
|
+
# t.string :password_salt
|
53
|
+
|
54
|
+
## Confirmable
|
55
|
+
# t.string :confirmation_token
|
56
|
+
# t.datetime :confirmed_at
|
57
|
+
# t.datetime :confirmation_sent_at
|
58
|
+
# t.string :unconfirmed_email # Only if using reconfirmable
|
59
|
+
|
60
|
+
## Lockable
|
61
|
+
# t.integer :failed_attempts, :default => 0 # Only if lock strategy is :failed_attempts
|
62
|
+
# t.string :unlock_token # Only if unlock strategy is :email or :both
|
63
|
+
# t.datetime :locked_at
|
64
|
+
|
65
|
+
# Token authenticatable
|
66
|
+
# t.string :authentication_token
|
67
|
+
RUBY
|
68
|
+
end
|
31
69
|
end
|
32
70
|
end
|
33
71
|
end
|
@@ -5,15 +5,7 @@ class DeviseCreate<%= table_name.camelize %> < ActiveRecord::Migration
|
|
5
5
|
def self.up
|
6
6
|
<% end -%>
|
7
7
|
create_table(:<%= table_name %>) do |t|
|
8
|
-
|
9
|
-
t.recoverable
|
10
|
-
t.rememberable
|
11
|
-
t.trackable
|
12
|
-
|
13
|
-
# t.encryptable
|
14
|
-
# t.confirmable
|
15
|
-
# t.lockable :lock_strategy => :<%= Devise.lock_strategy %>, :unlock_strategy => :<%= Devise.unlock_strategy %>
|
16
|
-
# t.token_authenticatable
|
8
|
+
<%= migration_data -%>
|
17
9
|
|
18
10
|
<% attributes.each do |attribute| -%>
|
19
11
|
t.<%= attribute.type %> :<%= attribute.name %>
|
@@ -1,15 +1,7 @@
|
|
1
1
|
class AddDeviseTo<%= table_name.camelize %> < ActiveRecord::Migration
|
2
2
|
def self.up
|
3
3
|
change_table(:<%= table_name %>) do |t|
|
4
|
-
|
5
|
-
t.recoverable
|
6
|
-
t.rememberable
|
7
|
-
t.trackable
|
8
|
-
|
9
|
-
# t.encryptable
|
10
|
-
# t.confirmable
|
11
|
-
# t.lockable :lock_strategy => :<%= Devise.lock_strategy %>, :unlock_strategy => :<%= Devise.unlock_strategy %>
|
12
|
-
# t.token_authenticatable
|
4
|
+
<%= migration_data -%>
|
13
5
|
|
14
6
|
<% attributes.each do |attribute| -%>
|
15
7
|
t.<%= attribute.type %> :<%= attribute.name %>
|
@@ -9,9 +9,52 @@ module Mongoid
|
|
9
9
|
invoke "mongoid:model", [name] unless model_exists? && behavior == :invoke
|
10
10
|
end
|
11
11
|
|
12
|
+
def inject_field_types
|
13
|
+
inject_into_file model_path, migration_data, :after => "include Mongoid::Document\n" if model_exists?
|
14
|
+
end
|
15
|
+
|
12
16
|
def inject_devise_content
|
13
17
|
inject_into_file model_path, model_contents, :after => "include Mongoid::Document\n" if model_exists?
|
14
18
|
end
|
19
|
+
|
20
|
+
def migration_data
|
21
|
+
<<RUBY
|
22
|
+
## Database authenticatable
|
23
|
+
field :email, :type => String, :null => false, :default => ""
|
24
|
+
field :encrypted_password, :type => String, :null => false, :default => ""
|
25
|
+
|
26
|
+
## Recoverable
|
27
|
+
field :reset_password_token, :type => String
|
28
|
+
field :reset_password_sent_at, :type => Time
|
29
|
+
|
30
|
+
## Rememberable
|
31
|
+
field :remember_created_at, :type => Time
|
32
|
+
|
33
|
+
## Trackable
|
34
|
+
field :sign_in_count, :type => Integer, :default => 0
|
35
|
+
field :current_sign_in_at, :type => Time
|
36
|
+
field :last_sign_in_at, :type => Time
|
37
|
+
field :current_sign_in_ip, :type => String
|
38
|
+
field :last_sign_in_ip, :type => String
|
39
|
+
|
40
|
+
## Encryptable
|
41
|
+
# field :password_salt, :type => String
|
42
|
+
|
43
|
+
## Confirmable
|
44
|
+
# field :confirmation_token, :type => String
|
45
|
+
# field :confirmed_at, :type => Time
|
46
|
+
# field :confirmation_sent_at, :type => Time
|
47
|
+
# field :unconfirmed_email, :type => String # Only if using reconfirmable
|
48
|
+
|
49
|
+
## Lockable
|
50
|
+
# field :failed_attempts, :type => Integer, :default => 0 # Only if lock strategy is :failed_attempts
|
51
|
+
# field :unlock_token, :type => String # Only if unlock strategy is :email or :both
|
52
|
+
# field :locked_at, :type => Time
|
53
|
+
|
54
|
+
## Token authenticatable
|
55
|
+
# field :authentication_token, :type => String
|
56
|
+
RUBY
|
57
|
+
end
|
15
58
|
end
|
16
59
|
end
|
17
60
|
end
|
@@ -9,6 +9,9 @@ Devise.setup do |config|
|
|
9
9
|
# Configure the class responsible to send e-mails.
|
10
10
|
# config.mailer = "Devise::Mailer"
|
11
11
|
|
12
|
+
# Automatically apply schema changes in tableless databases
|
13
|
+
config.apply_schema = false
|
14
|
+
|
12
15
|
# ==> ORM configuration
|
13
16
|
# Load and configure the ORM. Supports :active_record (default) and
|
14
17
|
# :mongoid (bson_ext recommended) by default. Other ORMs may be
|
@@ -59,6 +62,10 @@ Devise.setup do |config|
|
|
59
62
|
# Does not affect registerable.
|
60
63
|
# config.paranoid = true
|
61
64
|
|
65
|
+
# By default Devise will store the user in session. You can skip storage for
|
66
|
+
# :http_auth and :token_auth by adding those symbols to the array below.
|
67
|
+
config.skip_session_storage = [:http_auth]
|
68
|
+
|
62
69
|
# ==> Configuration for :database_authenticatable
|
63
70
|
# For bcrypt, this is the cost for hashing the password and defaults to 10. If
|
64
71
|
# using other encryptors, it sets how many times you want the password re-encrypted.
|
@@ -77,7 +84,13 @@ Devise.setup do |config|
|
|
77
84
|
# able to access the website for two days without confirming his account,
|
78
85
|
# access will be blocked just in the third day. Default is 0.days, meaning
|
79
86
|
# the user cannot access the website without confirming his account.
|
80
|
-
# config.
|
87
|
+
# config.allow_unconfirmed_access_for = 2.days
|
88
|
+
|
89
|
+
# If true, requires any email changes to be confirmed (exctly the same way as
|
90
|
+
# initial account confirmation) to be applied. Requires additional unconfirmed_email
|
91
|
+
# db field (see migrations). Until confirmed new email is stored in
|
92
|
+
# unconfirmed email column, and copied to email column on successful confirmation.
|
93
|
+
config.reconfirmable = true
|
81
94
|
|
82
95
|
# Defines which key will be used when confirming an account
|
83
96
|
# config.confirmation_keys = [ :email ]
|
@@ -86,9 +99,6 @@ Devise.setup do |config|
|
|
86
99
|
# The time the user will be remembered without asking for credentials again.
|
87
100
|
# config.remember_for = 2.weeks
|
88
101
|
|
89
|
-
# If true, a valid remember token can be re-used between multiple browsers.
|
90
|
-
# config.remember_across_browsers = true
|
91
|
-
|
92
102
|
# If true, extends the user's remember period when remembered via cookie.
|
93
103
|
# config.extend_remember_period = false
|
94
104
|
|
@@ -145,7 +155,7 @@ Devise.setup do |config|
|
|
145
155
|
# Time interval you can reset your password with a reset password key.
|
146
156
|
# Don't put a too small interval or your users won't have the time to
|
147
157
|
# change their passwords.
|
148
|
-
config.reset_password_within =
|
158
|
+
config.reset_password_within = 6.hours
|
149
159
|
|
150
160
|
# ==> Configuration for :encryptable
|
151
161
|
# Allow you to use another encryption algorithm besides bcrypt (default). You can use
|
@@ -159,10 +169,6 @@ Devise.setup do |config|
|
|
159
169
|
# Defines name of the authentication token params key
|
160
170
|
# config.token_authentication_key = :auth_token
|
161
171
|
|
162
|
-
# If true, authentication through token does not store user in session and needs
|
163
|
-
# to be supplied on each request. Useful if you are using the token as API token.
|
164
|
-
# config.stateless_token = false
|
165
|
-
|
166
172
|
# ==> Scopes configuration
|
167
173
|
# Turn scoped views on. Before rendering "sessions/new", it will first check for
|
168
174
|
# "users/sessions/new". It's turned off by default because it's slower if you
|
@@ -45,10 +45,12 @@ class HelpersTest < ActionController::TestCase
|
|
45
45
|
@controller.send :require_no_authentication
|
46
46
|
end
|
47
47
|
|
48
|
-
test 'require no authentication
|
48
|
+
test 'require no authentication only checks if already authenticated if no inputs strategies are available' do
|
49
49
|
Devise.mappings[:user].expects(:no_input_strategies).returns([])
|
50
50
|
@mock_warden.expects(:authenticate?).never
|
51
|
-
@
|
51
|
+
@mock_warden.expects(:authenticated?).with(:user).once.returns(true)
|
52
|
+
@mock_warden.expects(:user).with(:user).returns(User.new)
|
53
|
+
@controller.expects(:redirect_to).with(root_path)
|
52
54
|
@controller.send :require_no_authentication
|
53
55
|
end
|
54
56
|
|
data/test/devise_test.rb
CHANGED
@@ -12,8 +12,8 @@ end
|
|
12
12
|
|
13
13
|
class DeviseTest < ActiveSupport::TestCase
|
14
14
|
test 'model options can be configured through Devise' do
|
15
|
-
swap Devise, :
|
16
|
-
assert_equal 113, Devise.
|
15
|
+
swap Devise, :allow_unconfirmed_access_for => 113, :pepper => "foo" do
|
16
|
+
assert_equal 113, Devise.allow_unconfirmed_access_for
|
17
17
|
assert_equal "foo", Devise.pepper
|
18
18
|
end
|
19
19
|
end
|
@@ -98,7 +98,7 @@ class ConfirmationTest < ActionController::IntegrationTest
|
|
98
98
|
end
|
99
99
|
|
100
100
|
test 'not confirmed user with setup to block without confirmation should not be able to sign in' do
|
101
|
-
swap Devise, :
|
101
|
+
swap Devise, :allow_unconfirmed_access_for => 0.days do
|
102
102
|
sign_in_as_user(:confirm => false)
|
103
103
|
|
104
104
|
assert_contain 'You have to confirm your account before continuing'
|
@@ -107,7 +107,7 @@ class ConfirmationTest < ActionController::IntegrationTest
|
|
107
107
|
end
|
108
108
|
|
109
109
|
test 'not confirmed user should not see confirmation message if invalid credentials are given' do
|
110
|
-
swap Devise, :
|
110
|
+
swap Devise, :allow_unconfirmed_access_for => 0.days do
|
111
111
|
sign_in_as_user(:confirm => false) do
|
112
112
|
fill_in 'password', :with => 'invalid'
|
113
113
|
end
|
@@ -118,7 +118,7 @@ class ConfirmationTest < ActionController::IntegrationTest
|
|
118
118
|
end
|
119
119
|
|
120
120
|
test 'not confirmed user but configured with some days to confirm should be able to sign in' do
|
121
|
-
swap Devise, :
|
121
|
+
swap Devise, :allow_unconfirmed_access_for => 1.day do
|
122
122
|
sign_in_as_user(:confirm => false)
|
123
123
|
|
124
124
|
assert_response :success
|
@@ -201,3 +201,55 @@ class ConfirmationTest < ActionController::IntegrationTest
|
|
201
201
|
end
|
202
202
|
end
|
203
203
|
end
|
204
|
+
|
205
|
+
class ConfirmationOnChangeTest < ActionController::IntegrationTest
|
206
|
+
def create_second_admin(options={})
|
207
|
+
@admin = nil
|
208
|
+
create_admin(options)
|
209
|
+
end
|
210
|
+
|
211
|
+
def visit_admin_confirmation_with_token(confirmation_token)
|
212
|
+
visit admin_confirmation_path(:confirmation_token => confirmation_token)
|
213
|
+
end
|
214
|
+
|
215
|
+
test 'admin should be able to request a new confirmation after email changed' do
|
216
|
+
admin = create_admin
|
217
|
+
admin.update_attributes(:email => 'new_test@example.com')
|
218
|
+
|
219
|
+
visit new_admin_session_path
|
220
|
+
click_link "Didn't receive confirmation instructions?"
|
221
|
+
|
222
|
+
fill_in 'email', :with => admin.unconfirmed_email
|
223
|
+
assert_difference "ActionMailer::Base.deliveries.size" do
|
224
|
+
click_button 'Resend confirmation instructions'
|
225
|
+
end
|
226
|
+
|
227
|
+
assert_current_url '/admin_area/sign_in'
|
228
|
+
assert_contain 'You will receive an email with instructions about how to confirm your account in a few minutes'
|
229
|
+
end
|
230
|
+
|
231
|
+
test 'admin with valid confirmation token should be able to confirm email after email changed' do
|
232
|
+
admin = create_admin
|
233
|
+
admin.update_attributes(:email => 'new_test@example.com')
|
234
|
+
assert_equal 'new_test@example.com', admin.unconfirmed_email
|
235
|
+
visit_admin_confirmation_with_token(admin.confirmation_token)
|
236
|
+
|
237
|
+
assert_contain 'Your account was successfully confirmed.'
|
238
|
+
assert_current_url '/admin_area/home'
|
239
|
+
assert admin.reload.confirmed?
|
240
|
+
assert_not admin.reload.pending_reconfirmation?
|
241
|
+
end
|
242
|
+
|
243
|
+
test 'admin email should be unique also within unconfirmed_email' do
|
244
|
+
admin = create_admin
|
245
|
+
admin.update_attributes(:email => 'new_admin_test@example.com')
|
246
|
+
assert_equal 'new_admin_test@example.com', admin.unconfirmed_email
|
247
|
+
|
248
|
+
create_second_admin(:email => "new_admin_test@example.com")
|
249
|
+
|
250
|
+
visit_admin_confirmation_with_token(admin.confirmation_token)
|
251
|
+
assert_have_selector '#error_explanation'
|
252
|
+
assert_contain /Email.*already.*taken/
|
253
|
+
assert admin.reload.pending_reconfirmation?
|
254
|
+
end
|
255
|
+
end
|
@@ -12,9 +12,24 @@ class HttpAuthenticationTest < ActionController::IntegrationTest
|
|
12
12
|
|
13
13
|
test 'sign in should authenticate with http' do
|
14
14
|
sign_in_as_new_user_with_http
|
15
|
-
assert_response
|
15
|
+
assert_response 200
|
16
16
|
assert_match '<email>user@test.com</email>', response.body
|
17
17
|
assert warden.authenticated?(:user)
|
18
|
+
|
19
|
+
get users_path(:format => :xml)
|
20
|
+
assert_response 200
|
21
|
+
end
|
22
|
+
|
23
|
+
test 'sign in should authenticate with http but not emit a cookie if skipping session storage' do
|
24
|
+
swap Devise, :skip_session_storage => [:http_auth] do
|
25
|
+
sign_in_as_new_user_with_http
|
26
|
+
assert_response 200
|
27
|
+
assert_match '<email>user@test.com</email>', response.body
|
28
|
+
assert warden.authenticated?(:user)
|
29
|
+
|
30
|
+
get users_path(:format => :xml)
|
31
|
+
assert_response 401
|
32
|
+
end
|
18
33
|
end
|
19
34
|
|
20
35
|
test 'returns a custom response with www-authenticate header on failures' do
|
@@ -80,16 +80,16 @@ class LockTest < ActionController::IntegrationTest
|
|
80
80
|
|
81
81
|
visit_user_unlock_with_token(user.unlock_token)
|
82
82
|
|
83
|
-
assert_current_url
|
83
|
+
assert_current_url "/users/sign_in"
|
84
84
|
assert_contain 'Your account was successfully unlocked.'
|
85
85
|
|
86
86
|
assert_not user.reload.access_locked?
|
87
87
|
end
|
88
88
|
|
89
|
-
test "sign in
|
89
|
+
test "redirect user to sign in page after unlocking its account" do
|
90
90
|
user = create_user(:locked => true)
|
91
91
|
visit_user_unlock_with_token(user.unlock_token)
|
92
|
-
|
92
|
+
assert_not warden.authenticated?(:user)
|
93
93
|
end
|
94
94
|
|
95
95
|
test "user should not be able to sign in when locked" do
|
@@ -13,7 +13,7 @@ class RegistrationTest < ActionController::IntegrationTest
|
|
13
13
|
fill_in 'password confirmation', :with => 'new_user123'
|
14
14
|
click_button 'Sign up'
|
15
15
|
|
16
|
-
assert_contain '
|
16
|
+
assert_contain 'You have signed up successfully'
|
17
17
|
assert warden.authenticated?(:admin)
|
18
18
|
assert_current_url "/admin_area/home"
|
19
19
|
|
@@ -291,3 +291,34 @@ class RegistrationTest < ActionController::IntegrationTest
|
|
291
291
|
assert_equal User.count, 0
|
292
292
|
end
|
293
293
|
end
|
294
|
+
|
295
|
+
class ReconfirmableRegistrationTest < ActionController::IntegrationTest
|
296
|
+
test 'a signed in admin should see a more appropriate flash message when editing his account if reconfirmable is enabled' do
|
297
|
+
sign_in_as_admin
|
298
|
+
get edit_admin_registration_path
|
299
|
+
|
300
|
+
fill_in 'email', :with => 'admin.new@example.com'
|
301
|
+
fill_in 'current password', :with => '123456'
|
302
|
+
click_button 'Update'
|
303
|
+
|
304
|
+
assert_current_url '/admin_area/home'
|
305
|
+
assert_contain 'but we need to verify your new email address'
|
306
|
+
|
307
|
+
assert_equal "admin.new@example.com", Admin.first.unconfirmed_email
|
308
|
+
end
|
309
|
+
|
310
|
+
test 'a signed in admin should not see a reconfirmation message if they did not change their password' do
|
311
|
+
sign_in_as_admin
|
312
|
+
get edit_admin_registration_path
|
313
|
+
|
314
|
+
fill_in 'password', :with => 'pas123'
|
315
|
+
fill_in 'password confirmation', :with => 'pas123'
|
316
|
+
fill_in 'current password', :with => '123456'
|
317
|
+
click_button 'Update'
|
318
|
+
|
319
|
+
assert_current_url '/admin_area/home'
|
320
|
+
assert_contain 'You updated your account successfully.'
|
321
|
+
|
322
|
+
assert Admin.first.valid_password?('pas123')
|
323
|
+
end
|
324
|
+
end
|
@@ -9,14 +9,6 @@ class RememberMeTest < ActionController::IntegrationTest
|
|
9
9
|
user
|
10
10
|
end
|
11
11
|
|
12
|
-
def create_admin_and_remember
|
13
|
-
admin = create_admin
|
14
|
-
admin.remember_me!
|
15
|
-
raw_cookie = Admin.serialize_into_cookie(admin)
|
16
|
-
cookies['remember_admin_token'] = generate_signed_cookie(raw_cookie)
|
17
|
-
admin
|
18
|
-
end
|
19
|
-
|
20
12
|
def generate_signed_cookie(raw_cookie)
|
21
13
|
request = ActionDispatch::TestRequest.new
|
22
14
|
request.cookie_jar.signed['raw_cookie'] = raw_cookie
|
@@ -117,34 +109,6 @@ class RememberMeTest < ActionController::IntegrationTest
|
|
117
109
|
end
|
118
110
|
end
|
119
111
|
|
120
|
-
test 'if both extend_remember_period and remember_across_browsers are true, sends the same token with a new expire date' do
|
121
|
-
swap Devise, :remember_across_browsers => true, :extend_remember_period => true, :remember_for => 1.year do
|
122
|
-
admin = create_admin_and_remember
|
123
|
-
token = admin.remember_token
|
124
|
-
|
125
|
-
admin.remember_created_at = old = 10.minutes.ago
|
126
|
-
admin.save!
|
127
|
-
|
128
|
-
get root_path
|
129
|
-
assert (cookie_expires("remember_admin_token") - 1.year) > (old + 5.minutes)
|
130
|
-
assert_equal token, signed_cookie("remember_admin_token").last
|
131
|
-
end
|
132
|
-
end
|
133
|
-
|
134
|
-
test 'if both extend_remember_period and remember_across_browsers are false, sends a new token with old expire date' do
|
135
|
-
swap Devise, :remember_across_browsers => false, :extend_remember_period => false, :remember_for => 1.year do
|
136
|
-
admin = create_admin_and_remember
|
137
|
-
token = admin.remember_token
|
138
|
-
|
139
|
-
admin.remember_created_at = old = 10.minutes.ago
|
140
|
-
admin.save!
|
141
|
-
|
142
|
-
get root_path
|
143
|
-
assert (cookie_expires("remember_admin_token") - 1.year) < (old + 5.minutes)
|
144
|
-
assert_not_equal token, signed_cookie("remember_admin_token").last
|
145
|
-
end
|
146
|
-
end
|
147
|
-
|
148
112
|
test 'do not remember other scopes' do
|
149
113
|
user = create_user_and_remember
|
150
114
|
get root_path
|
@@ -182,20 +146,6 @@ class RememberMeTest < ActionController::IntegrationTest
|
|
182
146
|
assert_not warden.authenticated?(:user)
|
183
147
|
end
|
184
148
|
|
185
|
-
test 'do not remember the admin anymore after forget' do
|
186
|
-
admin = create_admin_and_remember
|
187
|
-
get root_path
|
188
|
-
assert warden.authenticated?(:admin)
|
189
|
-
|
190
|
-
get destroy_admin_session_path
|
191
|
-
assert_not warden.authenticated?(:admin)
|
192
|
-
assert_nil admin.reload.remember_token
|
193
|
-
assert_nil warden.cookies['remember_admin_token']
|
194
|
-
|
195
|
-
get root_path
|
196
|
-
assert_not warden.authenticated?(:admin)
|
197
|
-
end
|
198
|
-
|
199
149
|
test 'changing user password expires remember me token' do
|
200
150
|
user = create_user_and_remember
|
201
151
|
user.password = "another_password"
|