devise 3.2.2 → 4.6.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of devise might be problematic. Click here for more details.
- checksums.yaml +7 -0
- data/CHANGELOG.md +242 -978
- data/MIT-LICENSE +1 -1
- data/README.md +371 -100
- data/app/controllers/devise/confirmations_controller.rb +11 -5
- data/app/controllers/devise/omniauth_callbacks_controller.rb +12 -6
- data/app/controllers/devise/passwords_controller.rb +21 -8
- data/app/controllers/devise/registrations_controller.rb +59 -26
- data/app/controllers/devise/sessions_controller.rb +47 -17
- data/app/controllers/devise/unlocks_controller.rb +9 -4
- data/app/controllers/devise_controller.rb +67 -31
- data/app/helpers/devise_helper.rb +12 -19
- data/app/mailers/devise/mailer.rb +10 -0
- data/app/views/devise/confirmations/new.html.erb +9 -5
- data/app/views/devise/mailer/confirmation_instructions.html.erb +1 -1
- data/app/views/devise/mailer/email_changed.html.erb +7 -0
- data/app/views/devise/mailer/password_change.html.erb +3 -0
- data/app/views/devise/mailer/reset_password_instructions.html.erb +1 -1
- data/app/views/devise/mailer/unlock_instructions.html.erb +1 -1
- data/app/views/devise/passwords/edit.html.erb +16 -7
- data/app/views/devise/passwords/new.html.erb +9 -5
- data/app/views/devise/registrations/edit.html.erb +29 -15
- data/app/views/devise/registrations/new.html.erb +20 -9
- data/app/views/devise/sessions/new.html.erb +19 -10
- data/app/views/devise/shared/_error_messages.html.erb +15 -0
- data/app/views/devise/shared/{_links.erb → _links.html.erb} +9 -9
- data/app/views/devise/unlocks/new.html.erb +9 -5
- data/config/locales/en.yml +23 -17
- data/lib/devise/controllers/helpers.rb +112 -32
- data/lib/devise/controllers/rememberable.rb +15 -6
- data/lib/devise/controllers/scoped_views.rb +3 -1
- data/lib/devise/controllers/sign_in_out.rb +42 -26
- data/lib/devise/controllers/store_location.rb +31 -5
- data/lib/devise/controllers/url_helpers.rb +9 -7
- data/lib/devise/delegator.rb +2 -0
- data/lib/devise/encryptor.rb +24 -0
- data/lib/devise/failure_app.rb +125 -39
- data/lib/devise/hooks/activatable.rb +7 -6
- data/lib/devise/hooks/csrf_cleaner.rb +5 -1
- data/lib/devise/hooks/forgetable.rb +2 -0
- data/lib/devise/hooks/lockable.rb +7 -2
- data/lib/devise/hooks/proxy.rb +4 -2
- data/lib/devise/hooks/rememberable.rb +4 -2
- data/lib/devise/hooks/timeoutable.rb +16 -9
- data/lib/devise/hooks/trackable.rb +3 -1
- data/lib/devise/mailers/helpers.rb +15 -12
- data/lib/devise/mapping.rb +8 -2
- data/lib/devise/models/authenticatable.rb +82 -56
- data/lib/devise/models/confirmable.rb +125 -42
- data/lib/devise/models/database_authenticatable.rb +110 -32
- data/lib/devise/models/lockable.rb +30 -17
- data/lib/devise/models/omniauthable.rb +3 -1
- data/lib/devise/models/recoverable.rb +62 -26
- data/lib/devise/models/registerable.rb +4 -0
- data/lib/devise/models/rememberable.rb +62 -33
- data/lib/devise/models/timeoutable.rb +4 -8
- data/lib/devise/models/trackable.rb +20 -4
- data/lib/devise/models/validatable.rb +16 -9
- data/lib/devise/models.rb +3 -1
- data/lib/devise/modules.rb +12 -10
- data/lib/devise/omniauth/config.rb +2 -0
- data/lib/devise/omniauth/url_helpers.rb +14 -5
- data/lib/devise/omniauth.rb +2 -0
- data/lib/devise/orm/active_record.rb +5 -1
- data/lib/devise/orm/mongoid.rb +6 -2
- data/lib/devise/parameter_filter.rb +4 -0
- data/lib/devise/parameter_sanitizer.rb +139 -65
- data/lib/devise/rails/routes.rb +147 -116
- data/lib/devise/rails/warden_compat.rb +3 -10
- data/lib/devise/rails.rb +10 -13
- data/lib/devise/secret_key_finder.rb +27 -0
- data/lib/devise/strategies/authenticatable.rb +20 -9
- data/lib/devise/strategies/base.rb +3 -1
- data/lib/devise/strategies/database_authenticatable.rb +14 -6
- data/lib/devise/strategies/rememberable.rb +15 -3
- data/lib/devise/test/controller_helpers.rb +165 -0
- data/lib/devise/test/integration_helpers.rb +63 -0
- data/lib/devise/test_helpers.rb +7 -124
- data/lib/devise/time_inflector.rb +4 -2
- data/lib/devise/token_generator.rb +3 -41
- data/lib/devise/version.rb +3 -1
- data/lib/devise.rb +111 -84
- data/lib/generators/active_record/devise_generator.rb +49 -12
- data/lib/generators/active_record/templates/migration.rb +9 -7
- data/lib/generators/active_record/templates/migration_existing.rb +9 -7
- data/lib/generators/devise/controllers_generator.rb +46 -0
- data/lib/generators/devise/devise_generator.rb +7 -5
- data/lib/generators/devise/install_generator.rb +21 -0
- data/lib/generators/devise/orm_helpers.rb +10 -21
- data/lib/generators/devise/views_generator.rb +49 -28
- data/lib/generators/mongoid/devise_generator.rb +21 -19
- data/lib/generators/templates/README +5 -12
- data/lib/generators/templates/controllers/README +14 -0
- data/lib/generators/templates/controllers/confirmations_controller.rb +30 -0
- data/lib/generators/templates/controllers/omniauth_callbacks_controller.rb +30 -0
- data/lib/generators/templates/controllers/passwords_controller.rb +34 -0
- data/lib/generators/templates/controllers/registrations_controller.rb +62 -0
- data/lib/generators/templates/controllers/sessions_controller.rb +27 -0
- data/lib/generators/templates/controllers/unlocks_controller.rb +30 -0
- data/lib/generators/templates/devise.rb +81 -36
- data/lib/generators/templates/markerb/confirmation_instructions.markerb +1 -1
- data/lib/generators/templates/markerb/email_changed.markerb +7 -0
- data/lib/generators/templates/markerb/password_change.markerb +3 -0
- data/lib/generators/templates/markerb/reset_password_instructions.markerb +1 -1
- data/lib/generators/templates/markerb/unlock_instructions.markerb +1 -1
- data/lib/generators/templates/simple_form_for/confirmations/new.html.erb +6 -2
- data/lib/generators/templates/simple_form_for/passwords/edit.html.erb +9 -4
- data/lib/generators/templates/simple_form_for/passwords/new.html.erb +5 -2
- data/lib/generators/templates/simple_form_for/registrations/edit.html.erb +14 -6
- data/lib/generators/templates/simple_form_for/registrations/new.html.erb +12 -4
- data/lib/generators/templates/simple_form_for/sessions/new.html.erb +11 -6
- data/lib/generators/templates/simple_form_for/unlocks/new.html.erb +5 -2
- metadata +52 -280
- data/.gitignore +0 -10
- data/.travis.yml +0 -20
- data/.yardopts +0 -9
- data/CONTRIBUTING.md +0 -14
- data/Gemfile +0 -31
- data/Gemfile.lock +0 -160
- data/Rakefile +0 -35
- data/devise.gemspec +0 -27
- data/devise.png +0 -0
- data/gemfiles/Gemfile.rails-3.2.x +0 -31
- data/gemfiles/Gemfile.rails-3.2.x.lock +0 -159
- data/test/controllers/custom_strategy_test.rb +0 -62
- data/test/controllers/helpers_test.rb +0 -276
- data/test/controllers/internal_helpers_test.rb +0 -120
- data/test/controllers/passwords_controller_test.rb +0 -31
- data/test/controllers/sessions_controller_test.rb +0 -99
- data/test/controllers/url_helpers_test.rb +0 -59
- data/test/delegator_test.rb +0 -19
- data/test/devise_test.rb +0 -94
- data/test/failure_app_test.rb +0 -232
- data/test/generators/active_record_generator_test.rb +0 -103
- data/test/generators/devise_generator_test.rb +0 -39
- data/test/generators/install_generator_test.rb +0 -13
- data/test/generators/mongoid_generator_test.rb +0 -23
- data/test/generators/views_generator_test.rb +0 -67
- data/test/helpers/devise_helper_test.rb +0 -51
- data/test/integration/authenticatable_test.rb +0 -713
- data/test/integration/confirmable_test.rb +0 -284
- data/test/integration/database_authenticatable_test.rb +0 -84
- data/test/integration/http_authenticatable_test.rb +0 -105
- data/test/integration/lockable_test.rb +0 -239
- data/test/integration/omniauthable_test.rb +0 -133
- data/test/integration/recoverable_test.rb +0 -334
- data/test/integration/registerable_test.rb +0 -349
- data/test/integration/rememberable_test.rb +0 -167
- data/test/integration/timeoutable_test.rb +0 -183
- data/test/integration/trackable_test.rb +0 -92
- data/test/mailers/confirmation_instructions_test.rb +0 -115
- data/test/mailers/reset_password_instructions_test.rb +0 -96
- data/test/mailers/unlock_instructions_test.rb +0 -91
- data/test/mapping_test.rb +0 -127
- data/test/models/authenticatable_test.rb +0 -13
- data/test/models/confirmable_test.rb +0 -454
- data/test/models/database_authenticatable_test.rb +0 -249
- data/test/models/lockable_test.rb +0 -298
- data/test/models/omniauthable_test.rb +0 -7
- data/test/models/recoverable_test.rb +0 -184
- data/test/models/registerable_test.rb +0 -7
- data/test/models/rememberable_test.rb +0 -183
- data/test/models/serializable_test.rb +0 -49
- data/test/models/timeoutable_test.rb +0 -51
- data/test/models/trackable_test.rb +0 -13
- data/test/models/validatable_test.rb +0 -127
- data/test/models_test.rb +0 -144
- data/test/omniauth/config_test.rb +0 -57
- data/test/omniauth/url_helpers_test.rb +0 -54
- data/test/orm/active_record.rb +0 -10
- data/test/orm/mongoid.rb +0 -13
- data/test/parameter_sanitizer_test.rb +0 -81
- data/test/rails_app/Rakefile +0 -6
- data/test/rails_app/app/active_record/admin.rb +0 -6
- data/test/rails_app/app/active_record/shim.rb +0 -2
- data/test/rails_app/app/active_record/user.rb +0 -6
- data/test/rails_app/app/controllers/admins/sessions_controller.rb +0 -6
- data/test/rails_app/app/controllers/admins_controller.rb +0 -11
- data/test/rails_app/app/controllers/application_controller.rb +0 -9
- data/test/rails_app/app/controllers/home_controller.rb +0 -25
- data/test/rails_app/app/controllers/publisher/registrations_controller.rb +0 -2
- data/test/rails_app/app/controllers/publisher/sessions_controller.rb +0 -2
- data/test/rails_app/app/controllers/users/omniauth_callbacks_controller.rb +0 -14
- data/test/rails_app/app/controllers/users_controller.rb +0 -31
- data/test/rails_app/app/helpers/application_helper.rb +0 -3
- data/test/rails_app/app/mailers/users/mailer.rb +0 -12
- data/test/rails_app/app/mongoid/admin.rb +0 -29
- data/test/rails_app/app/mongoid/shim.rb +0 -23
- data/test/rails_app/app/mongoid/user.rb +0 -39
- data/test/rails_app/app/views/admins/index.html.erb +0 -1
- data/test/rails_app/app/views/admins/sessions/new.html.erb +0 -2
- data/test/rails_app/app/views/home/admin_dashboard.html.erb +0 -1
- data/test/rails_app/app/views/home/index.html.erb +0 -1
- data/test/rails_app/app/views/home/join.html.erb +0 -1
- data/test/rails_app/app/views/home/private.html.erb +0 -1
- data/test/rails_app/app/views/home/user_dashboard.html.erb +0 -1
- data/test/rails_app/app/views/layouts/application.html.erb +0 -24
- data/test/rails_app/app/views/users/edit_form.html.erb +0 -1
- data/test/rails_app/app/views/users/index.html.erb +0 -1
- data/test/rails_app/app/views/users/mailer/confirmation_instructions.erb +0 -1
- data/test/rails_app/app/views/users/sessions/new.html.erb +0 -1
- data/test/rails_app/bin/bundle +0 -3
- data/test/rails_app/bin/rails +0 -4
- data/test/rails_app/bin/rake +0 -4
- data/test/rails_app/config/application.rb +0 -40
- data/test/rails_app/config/boot.rb +0 -14
- data/test/rails_app/config/database.yml +0 -18
- data/test/rails_app/config/environment.rb +0 -5
- data/test/rails_app/config/environments/development.rb +0 -30
- data/test/rails_app/config/environments/production.rb +0 -80
- data/test/rails_app/config/environments/test.rb +0 -36
- data/test/rails_app/config/initializers/backtrace_silencers.rb +0 -7
- data/test/rails_app/config/initializers/devise.rb +0 -181
- data/test/rails_app/config/initializers/inflections.rb +0 -2
- data/test/rails_app/config/initializers/secret_token.rb +0 -8
- data/test/rails_app/config/initializers/session_store.rb +0 -1
- data/test/rails_app/config/routes.rb +0 -104
- data/test/rails_app/config.ru +0 -4
- data/test/rails_app/db/migrate/20100401102949_create_tables.rb +0 -71
- data/test/rails_app/db/schema.rb +0 -55
- data/test/rails_app/lib/shared_admin.rb +0 -17
- data/test/rails_app/lib/shared_user.rb +0 -29
- data/test/rails_app/public/404.html +0 -26
- data/test/rails_app/public/422.html +0 -26
- data/test/rails_app/public/500.html +0 -26
- data/test/rails_app/public/favicon.ico +0 -0
- data/test/routes_test.rb +0 -250
- data/test/support/assertions.rb +0 -40
- data/test/support/helpers.rb +0 -70
- data/test/support/integration.rb +0 -92
- data/test/support/locale/en.yml +0 -8
- data/test/support/webrat/integrations/rails.rb +0 -24
- data/test/test_helper.rb +0 -27
- data/test/test_helpers_test.rb +0 -173
- data/test/test_models.rb +0 -33
@@ -1,249 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
require 'test_models'
|
3
|
-
require 'digest/sha1'
|
4
|
-
|
5
|
-
class DatabaseAuthenticatableTest < ActiveSupport::TestCase
|
6
|
-
test 'should downcase case insensitive keys when saving' do
|
7
|
-
# case_insensitive_keys is set to :email by default.
|
8
|
-
email = 'Foo@Bar.com'
|
9
|
-
user = new_user(:email => email)
|
10
|
-
|
11
|
-
assert_equal email, user.email
|
12
|
-
user.save!
|
13
|
-
assert_equal email.downcase, user.email
|
14
|
-
end
|
15
|
-
|
16
|
-
test 'should downcase case insensitive keys that refer to virtual attributes when saving' do
|
17
|
-
email = 'Foo@Bar1.com'
|
18
|
-
confirmation = 'Foo@Bar1.com'
|
19
|
-
attributes = valid_attributes(:email => email, :email_confirmation => confirmation)
|
20
|
-
user = UserWithVirtualAttributes.new(attributes)
|
21
|
-
|
22
|
-
assert_equal confirmation, user.email_confirmation
|
23
|
-
user.save!
|
24
|
-
assert_equal confirmation.downcase, user.email_confirmation
|
25
|
-
end
|
26
|
-
|
27
|
-
test 'should not mutate value assigned to case insensitive key' do
|
28
|
-
email = 'Foo@Bar.com'
|
29
|
-
original_email = email.dup
|
30
|
-
user = new_user(:email => email)
|
31
|
-
|
32
|
-
user.save!
|
33
|
-
assert_equal original_email, email
|
34
|
-
end
|
35
|
-
|
36
|
-
test 'should remove whitespace from strip whitespace keys when saving' do
|
37
|
-
# strip_whitespace_keys is set to :email by default.
|
38
|
-
email = ' foo@bar.com '
|
39
|
-
user = new_user(:email => email)
|
40
|
-
|
41
|
-
assert_equal email, user.email
|
42
|
-
user.save!
|
43
|
-
assert_equal email.strip, user.email
|
44
|
-
end
|
45
|
-
|
46
|
-
test 'should not mutate value assigned to string whitespace key' do
|
47
|
-
email = ' foo@bar.com '
|
48
|
-
original_email = email.dup
|
49
|
-
user = new_user(:email => email)
|
50
|
-
|
51
|
-
user.save!
|
52
|
-
assert_equal original_email, email
|
53
|
-
end
|
54
|
-
|
55
|
-
test "doesn't throw exception when globally configured strip_whitespace_keys are not present on a model" do
|
56
|
-
swap Devise, :strip_whitespace_keys => [:fake_key] do
|
57
|
-
assert_nothing_raised { create_user }
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
test "doesn't throw exception when globally configured case_insensitive_keys are not present on a model" do
|
62
|
-
swap Devise, :case_insensitive_keys => [:fake_key] do
|
63
|
-
assert_nothing_raised { create_user }
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
test "param filter should not convert booleans and integer to strings" do
|
68
|
-
conditions = { "login" => "foo@bar.com", "bool1" => true, "bool2" => false, "fixnum" => 123, "will_be_converted" => (1..10) }
|
69
|
-
conditions = Devise::ParameterFilter.new([], []).filter(conditions)
|
70
|
-
assert_equal( { "login" => "foo@bar.com", "bool1" => "true", "bool2" => "false", "fixnum" => "123", "will_be_converted" => "1..10" }, conditions)
|
71
|
-
end
|
72
|
-
|
73
|
-
test 'param filter should filter case_insensitive_keys as insensitive' do
|
74
|
-
conditions = {'insensitive' => 'insensitive_VAL', 'sensitive' => 'sensitive_VAL'}
|
75
|
-
conditions = Devise::ParameterFilter.new(['insensitive'], []).filter(conditions)
|
76
|
-
assert_equal( {'insensitive' => 'insensitive_val', 'sensitive' => 'sensitive_VAL'}, conditions )
|
77
|
-
end
|
78
|
-
|
79
|
-
test 'param filter should filter strip_whitespace_keys stripping whitespaces' do
|
80
|
-
conditions = {'strip_whitespace' => ' strip_whitespace_val ', 'do_not_strip_whitespace' => ' do_not_strip_whitespace_val '}
|
81
|
-
conditions = Devise::ParameterFilter.new([], ['strip_whitespace']).filter(conditions)
|
82
|
-
assert_equal( {'strip_whitespace' => 'strip_whitespace_val', 'do_not_strip_whitespace' => ' do_not_strip_whitespace_val '}, conditions )
|
83
|
-
end
|
84
|
-
|
85
|
-
test 'should respond to password and password confirmation' do
|
86
|
-
user = new_user
|
87
|
-
assert user.respond_to?(:password)
|
88
|
-
assert user.respond_to?(:password_confirmation)
|
89
|
-
end
|
90
|
-
|
91
|
-
test 'should generate encrypted password while setting password' do
|
92
|
-
user = new_user
|
93
|
-
assert_present user.encrypted_password
|
94
|
-
end
|
95
|
-
|
96
|
-
test 'should support custom encryption methods' do
|
97
|
-
user = UserWithCustomEncryption.new(:password => '654321')
|
98
|
-
assert_equal user.encrypted_password, '123456'
|
99
|
-
end
|
100
|
-
|
101
|
-
test 'allow authenticatable_salt to work even with nil encrypted password' do
|
102
|
-
user = User.new
|
103
|
-
user.encrypted_password = nil
|
104
|
-
assert_nil user.authenticatable_salt
|
105
|
-
end
|
106
|
-
|
107
|
-
test 'should not generate encrypted password if password is blank' do
|
108
|
-
assert_blank new_user(:password => nil).encrypted_password
|
109
|
-
assert_blank new_user(:password => '').encrypted_password
|
110
|
-
end
|
111
|
-
|
112
|
-
test 'should encrypt password again if password has changed' do
|
113
|
-
user = create_user
|
114
|
-
encrypted_password = user.encrypted_password
|
115
|
-
user.password = user.password_confirmation = 'new_password'
|
116
|
-
user.save!
|
117
|
-
assert_not_equal encrypted_password, user.encrypted_password
|
118
|
-
end
|
119
|
-
|
120
|
-
test 'should test for a valid password' do
|
121
|
-
user = create_user
|
122
|
-
assert user.valid_password?('12345678')
|
123
|
-
assert_not user.valid_password?('654321')
|
124
|
-
end
|
125
|
-
|
126
|
-
test 'should not raise error with an empty password' do
|
127
|
-
user = create_user
|
128
|
-
user.encrypted_password = ''
|
129
|
-
assert_nothing_raised { user.valid_password?('12345678') }
|
130
|
-
end
|
131
|
-
|
132
|
-
test 'should be an invalid password if the user has an empty password' do
|
133
|
-
user = create_user
|
134
|
-
user.encrypted_password = ''
|
135
|
-
assert_not user.valid_password?('654321')
|
136
|
-
end
|
137
|
-
|
138
|
-
test 'should respond to current password' do
|
139
|
-
assert new_user.respond_to?(:current_password)
|
140
|
-
end
|
141
|
-
|
142
|
-
test 'should update password with valid current password' do
|
143
|
-
user = create_user
|
144
|
-
assert user.update_with_password(:current_password => '12345678',
|
145
|
-
:password => 'pass4321', :password_confirmation => 'pass4321')
|
146
|
-
assert user.reload.valid_password?('pass4321')
|
147
|
-
end
|
148
|
-
|
149
|
-
test 'should add an error to current password when it is invalid' do
|
150
|
-
user = create_user
|
151
|
-
assert_not user.update_with_password(:current_password => 'other',
|
152
|
-
:password => 'pass4321', :password_confirmation => 'pass4321')
|
153
|
-
assert user.reload.valid_password?('12345678')
|
154
|
-
assert_match "is invalid", user.errors[:current_password].join
|
155
|
-
end
|
156
|
-
|
157
|
-
test 'should add an error to current password when it is blank' do
|
158
|
-
user = create_user
|
159
|
-
assert_not user.update_with_password(:password => 'pass4321',
|
160
|
-
:password_confirmation => 'pass4321')
|
161
|
-
assert user.reload.valid_password?('12345678')
|
162
|
-
assert_match "can't be blank", user.errors[:current_password].join
|
163
|
-
end
|
164
|
-
|
165
|
-
test 'should run validations even when current password is invalid or blank' do
|
166
|
-
user = UserWithValidation.create!(valid_attributes)
|
167
|
-
user.save
|
168
|
-
assert user.persisted?
|
169
|
-
assert_not user.update_with_password(:username => "")
|
170
|
-
assert_match "usertest", user.reload.username
|
171
|
-
assert_match "can't be blank", user.errors[:username].join
|
172
|
-
end
|
173
|
-
|
174
|
-
test 'should ignore password and its confirmation if they are blank' do
|
175
|
-
user = create_user
|
176
|
-
assert user.update_with_password(:current_password => '12345678', :email => "new@example.com")
|
177
|
-
assert_equal "new@example.com", user.email
|
178
|
-
end
|
179
|
-
|
180
|
-
test 'should not update password with invalid confirmation' do
|
181
|
-
user = create_user
|
182
|
-
assert_not user.update_with_password(:current_password => '12345678',
|
183
|
-
:password => 'pass4321', :password_confirmation => 'other')
|
184
|
-
assert user.reload.valid_password?('12345678')
|
185
|
-
end
|
186
|
-
|
187
|
-
test 'should clean up password fields on failure' do
|
188
|
-
user = create_user
|
189
|
-
assert_not user.update_with_password(:current_password => '12345678',
|
190
|
-
:password => 'pass4321', :password_confirmation => 'other')
|
191
|
-
assert user.password.blank?
|
192
|
-
assert user.password_confirmation.blank?
|
193
|
-
end
|
194
|
-
|
195
|
-
test 'should update the user without password' do
|
196
|
-
user = create_user
|
197
|
-
user.update_without_password(:email => 'new@example.com')
|
198
|
-
assert_equal 'new@example.com', user.email
|
199
|
-
end
|
200
|
-
|
201
|
-
test 'should not update password without password' do
|
202
|
-
user = create_user
|
203
|
-
user.update_without_password(:password => 'pass4321', :password_confirmation => 'pass4321')
|
204
|
-
assert !user.reload.valid_password?('pass4321')
|
205
|
-
assert user.valid_password?('12345678')
|
206
|
-
end
|
207
|
-
|
208
|
-
test 'should destroy user if current password is valid' do
|
209
|
-
user = create_user
|
210
|
-
assert user.destroy_with_password('12345678')
|
211
|
-
assert !user.persisted?
|
212
|
-
end
|
213
|
-
|
214
|
-
test 'should not destroy user with invalid password' do
|
215
|
-
user = create_user
|
216
|
-
assert_not user.destroy_with_password('other')
|
217
|
-
assert user.persisted?
|
218
|
-
assert_match "is invalid", user.errors[:current_password].join
|
219
|
-
end
|
220
|
-
|
221
|
-
test 'should not destroy user with blank password' do
|
222
|
-
user = create_user
|
223
|
-
assert_not user.destroy_with_password(nil)
|
224
|
-
assert user.persisted?
|
225
|
-
assert_match "can't be blank", user.errors[:current_password].join
|
226
|
-
end
|
227
|
-
|
228
|
-
test 'downcase_keys with validation' do
|
229
|
-
User.create(:email => "HEllO@example.com", :password => "123456")
|
230
|
-
user = User.create(:email => "HEllO@example.com", :password => "123456")
|
231
|
-
assert !user.valid?
|
232
|
-
end
|
233
|
-
|
234
|
-
test 'required_fiels should be encryptable_password and the email field by default' do
|
235
|
-
assert_same_content Devise::Models::DatabaseAuthenticatable.required_fields(User), [
|
236
|
-
:email,
|
237
|
-
:encrypted_password
|
238
|
-
]
|
239
|
-
end
|
240
|
-
|
241
|
-
test 'required_fields should be encryptable_password and the login when the login is on authentication_keys' do
|
242
|
-
swap Devise, :authentication_keys => [:login] do
|
243
|
-
assert_same_content Devise::Models::DatabaseAuthenticatable.required_fields(User), [
|
244
|
-
:encrypted_password,
|
245
|
-
:login
|
246
|
-
]
|
247
|
-
end
|
248
|
-
end
|
249
|
-
end
|
@@ -1,298 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
class LockableTest < ActiveSupport::TestCase
|
4
|
-
def setup
|
5
|
-
setup_mailer
|
6
|
-
end
|
7
|
-
|
8
|
-
test "should respect maximum attempts configuration" do
|
9
|
-
user = create_user
|
10
|
-
user.confirm!
|
11
|
-
swap Devise, :maximum_attempts => 2 do
|
12
|
-
3.times { user.valid_for_authentication?{ false } }
|
13
|
-
assert user.reload.access_locked?
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
test "should increment failed_attempts on successfull validation if the user is already locked" do
|
18
|
-
user = create_user
|
19
|
-
user.confirm!
|
20
|
-
|
21
|
-
swap Devise, :maximum_attempts => 2 do
|
22
|
-
3.times { user.valid_for_authentication?{ false } }
|
23
|
-
assert user.reload.access_locked?
|
24
|
-
end
|
25
|
-
|
26
|
-
user.valid_for_authentication?{ true }
|
27
|
-
assert_equal 4, user.reload.failed_attempts
|
28
|
-
end
|
29
|
-
|
30
|
-
test "should not touch failed_attempts if lock_strategy is none" do
|
31
|
-
user = create_user
|
32
|
-
user.confirm!
|
33
|
-
swap Devise, :lock_strategy => :none, :maximum_attempts => 2 do
|
34
|
-
3.times { user.valid_for_authentication?{ false } }
|
35
|
-
assert !user.access_locked?
|
36
|
-
assert_equal 0, user.failed_attempts
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
test 'should be valid for authentication with a unlocked user' do
|
41
|
-
user = create_user
|
42
|
-
user.lock_access!
|
43
|
-
user.unlock_access!
|
44
|
-
assert user.valid_for_authentication?{ true }
|
45
|
-
end
|
46
|
-
|
47
|
-
test "should verify whether a user is locked or not" do
|
48
|
-
user = create_user
|
49
|
-
assert_not user.access_locked?
|
50
|
-
user.lock_access!
|
51
|
-
assert user.access_locked?
|
52
|
-
end
|
53
|
-
|
54
|
-
test "active_for_authentication? should be the opposite of locked?" do
|
55
|
-
user = create_user
|
56
|
-
user.confirm!
|
57
|
-
assert user.active_for_authentication?
|
58
|
-
user.lock_access!
|
59
|
-
assert_not user.active_for_authentication?
|
60
|
-
end
|
61
|
-
|
62
|
-
test "should unlock a user by cleaning locked_at, failed_attempts and unlock_token" do
|
63
|
-
user = create_user
|
64
|
-
user.lock_access!
|
65
|
-
assert_not_nil user.reload.locked_at
|
66
|
-
assert_not_nil user.reload.unlock_token
|
67
|
-
|
68
|
-
user.unlock_access!
|
69
|
-
assert_nil user.reload.locked_at
|
70
|
-
assert_nil user.reload.unlock_token
|
71
|
-
assert_equal 0, user.reload.failed_attempts
|
72
|
-
end
|
73
|
-
|
74
|
-
test "new user should not be locked and should have zero failed_attempts" do
|
75
|
-
assert_not new_user.access_locked?
|
76
|
-
assert_equal 0, create_user.failed_attempts
|
77
|
-
end
|
78
|
-
|
79
|
-
test "should unlock user after unlock_in period" do
|
80
|
-
swap Devise, :unlock_in => 3.hours do
|
81
|
-
user = new_user
|
82
|
-
user.locked_at = 2.hours.ago
|
83
|
-
assert user.access_locked?
|
84
|
-
|
85
|
-
Devise.unlock_in = 1.hour
|
86
|
-
assert_not user.access_locked?
|
87
|
-
end
|
88
|
-
end
|
89
|
-
|
90
|
-
test "should not unlock in 'unlock_in' if :time unlock strategy is not set" do
|
91
|
-
swap Devise, :unlock_strategy => :email do
|
92
|
-
user = new_user
|
93
|
-
user.locked_at = 2.hours.ago
|
94
|
-
assert user.access_locked?
|
95
|
-
end
|
96
|
-
end
|
97
|
-
|
98
|
-
test "should set unlock_token when locking" do
|
99
|
-
user = create_user
|
100
|
-
assert_nil user.unlock_token
|
101
|
-
user.lock_access!
|
102
|
-
assert_not_nil user.unlock_token
|
103
|
-
end
|
104
|
-
|
105
|
-
test "should never generate the same unlock token for different users" do
|
106
|
-
unlock_tokens = []
|
107
|
-
3.times do
|
108
|
-
user = create_user
|
109
|
-
user.lock_access!
|
110
|
-
token = user.unlock_token
|
111
|
-
assert !unlock_tokens.include?(token)
|
112
|
-
unlock_tokens << token
|
113
|
-
end
|
114
|
-
end
|
115
|
-
|
116
|
-
test "should not generate unlock_token when :email is not an unlock strategy" do
|
117
|
-
swap Devise, :unlock_strategy => :time do
|
118
|
-
user = create_user
|
119
|
-
user.lock_access!
|
120
|
-
assert_nil user.unlock_token
|
121
|
-
end
|
122
|
-
end
|
123
|
-
|
124
|
-
test "should send email with unlock instructions when :email is an unlock strategy" do
|
125
|
-
swap Devise, :unlock_strategy => :email do
|
126
|
-
user = create_user
|
127
|
-
assert_email_sent do
|
128
|
-
user.lock_access!
|
129
|
-
end
|
130
|
-
end
|
131
|
-
end
|
132
|
-
|
133
|
-
test "should not send email with unlock instructions when :email is not an unlock strategy" do
|
134
|
-
swap Devise, :unlock_strategy => :time do
|
135
|
-
user = create_user
|
136
|
-
assert_email_not_sent do
|
137
|
-
user.lock_access!
|
138
|
-
end
|
139
|
-
end
|
140
|
-
end
|
141
|
-
|
142
|
-
test 'should find and unlock a user automatically based on raw token' do
|
143
|
-
user = create_user
|
144
|
-
raw = user.send_unlock_instructions
|
145
|
-
locked_user = User.unlock_access_by_token(raw)
|
146
|
-
assert_equal locked_user, user
|
147
|
-
assert_not user.reload.access_locked?
|
148
|
-
end
|
149
|
-
|
150
|
-
test 'should return a new record with errors when a invalid token is given' do
|
151
|
-
locked_user = User.unlock_access_by_token('invalid_token')
|
152
|
-
assert_not locked_user.persisted?
|
153
|
-
assert_equal "is invalid", locked_user.errors[:unlock_token].join
|
154
|
-
end
|
155
|
-
|
156
|
-
test 'should return a new record with errors when a blank token is given' do
|
157
|
-
locked_user = User.unlock_access_by_token('')
|
158
|
-
assert_not locked_user.persisted?
|
159
|
-
assert_equal "can't be blank", locked_user.errors[:unlock_token].join
|
160
|
-
end
|
161
|
-
|
162
|
-
test 'should find a user to send unlock instructions' do
|
163
|
-
user = create_user
|
164
|
-
user.lock_access!
|
165
|
-
unlock_user = User.send_unlock_instructions(:email => user.email)
|
166
|
-
assert_equal unlock_user, user
|
167
|
-
end
|
168
|
-
|
169
|
-
test 'should return a new user if no email was found' do
|
170
|
-
unlock_user = User.send_unlock_instructions(:email => "invalid@example.com")
|
171
|
-
assert_not unlock_user.persisted?
|
172
|
-
end
|
173
|
-
|
174
|
-
test 'should add error to new user email if no email was found' do
|
175
|
-
unlock_user = User.send_unlock_instructions(:email => "invalid@example.com")
|
176
|
-
assert_equal 'not found', unlock_user.errors[:email].join
|
177
|
-
end
|
178
|
-
|
179
|
-
test 'should find a user to send unlock instructions by authentication_keys' do
|
180
|
-
swap Devise, :authentication_keys => [:username, :email] do
|
181
|
-
user = create_user
|
182
|
-
unlock_user = User.send_unlock_instructions(:email => user.email, :username => user.username)
|
183
|
-
assert_equal unlock_user, user
|
184
|
-
end
|
185
|
-
end
|
186
|
-
|
187
|
-
test 'should require all unlock_keys' do
|
188
|
-
swap Devise, :unlock_keys => [:username, :email] do
|
189
|
-
user = create_user
|
190
|
-
unlock_user = User.send_unlock_instructions(:email => user.email)
|
191
|
-
assert_not unlock_user.persisted?
|
192
|
-
assert_equal "can't be blank", unlock_user.errors[:username].join
|
193
|
-
end
|
194
|
-
end
|
195
|
-
|
196
|
-
test 'should not be able to send instructions if the user is not locked' do
|
197
|
-
user = create_user
|
198
|
-
assert_not user.resend_unlock_instructions
|
199
|
-
assert_not user.access_locked?
|
200
|
-
assert_equal 'was not locked', user.errors[:email].join
|
201
|
-
end
|
202
|
-
|
203
|
-
test 'should not be able to send instructions if the user if not locked and have username as unlock key' do
|
204
|
-
swap Devise, :unlock_keys => [:username] do
|
205
|
-
user = create_user
|
206
|
-
assert_not user.resend_unlock_instructions
|
207
|
-
assert_not user.access_locked?
|
208
|
-
assert_equal 'was not locked', user.errors[:username].join
|
209
|
-
end
|
210
|
-
end
|
211
|
-
|
212
|
-
test 'should unlock account if lock has expired and increase attempts on failure' do
|
213
|
-
swap Devise, :unlock_in => 1.minute do
|
214
|
-
user = create_user
|
215
|
-
user.confirm!
|
216
|
-
|
217
|
-
user.failed_attempts = 2
|
218
|
-
user.locked_at = 2.minutes.ago
|
219
|
-
|
220
|
-
user.valid_for_authentication? { false }
|
221
|
-
assert_equal 1, user.failed_attempts
|
222
|
-
end
|
223
|
-
end
|
224
|
-
|
225
|
-
test 'should unlock account if lock has expired on success' do
|
226
|
-
swap Devise, :unlock_in => 1.minute do
|
227
|
-
user = create_user
|
228
|
-
user.confirm!
|
229
|
-
|
230
|
-
user.failed_attempts = 2
|
231
|
-
user.locked_at = 2.minutes.ago
|
232
|
-
|
233
|
-
user.valid_for_authentication? { true }
|
234
|
-
assert_equal 0, user.failed_attempts
|
235
|
-
assert_nil user.locked_at
|
236
|
-
end
|
237
|
-
end
|
238
|
-
|
239
|
-
test 'required_fields should contain the all the fields when all the strategies are enabled' do
|
240
|
-
swap Devise, :unlock_strategy => :both do
|
241
|
-
swap Devise, :lock_strategy => :failed_attempts do
|
242
|
-
assert_same_content Devise::Models::Lockable.required_fields(User), [
|
243
|
-
:failed_attempts,
|
244
|
-
:locked_at,
|
245
|
-
:unlock_token
|
246
|
-
]
|
247
|
-
end
|
248
|
-
end
|
249
|
-
end
|
250
|
-
|
251
|
-
test 'required_fields should contain only failed_attempts and locked_at when the strategies are time and failed_attempts are enabled' do
|
252
|
-
swap Devise, :unlock_strategy => :time do
|
253
|
-
swap Devise, :lock_strategy => :failed_attempts do
|
254
|
-
assert_same_content Devise::Models::Lockable.required_fields(User), [
|
255
|
-
:failed_attempts,
|
256
|
-
:locked_at
|
257
|
-
]
|
258
|
-
end
|
259
|
-
end
|
260
|
-
end
|
261
|
-
|
262
|
-
test 'required_fields should contain only failed_attempts and unlock_token when the strategies are token and failed_attempts are enabled' do
|
263
|
-
swap Devise, :unlock_strategy => :email do
|
264
|
-
swap Devise, :lock_strategy => :failed_attempts do
|
265
|
-
assert_same_content Devise::Models::Lockable.required_fields(User), [
|
266
|
-
:failed_attempts,
|
267
|
-
:unlock_token
|
268
|
-
]
|
269
|
-
end
|
270
|
-
end
|
271
|
-
end
|
272
|
-
|
273
|
-
test 'should not return a locked unauthenticated message if in paranoid mode' do
|
274
|
-
swap Devise, :paranoid => :true do
|
275
|
-
user = create_user
|
276
|
-
user.failed_attempts = Devise.maximum_attempts + 1
|
277
|
-
user.lock_access!
|
278
|
-
|
279
|
-
assert_equal :invalid, user.unauthenticated_message
|
280
|
-
end
|
281
|
-
end
|
282
|
-
|
283
|
-
test 'should return last attempt message if user made next-to-last attempt of password entering' do
|
284
|
-
swap Devise, :last_attempt_warning => :true do
|
285
|
-
swap Devise, :lock_strategy => :failed_attempts do
|
286
|
-
user = create_user
|
287
|
-
user.failed_attempts = Devise.maximum_attempts - 1
|
288
|
-
assert_equal :invalid, user.unauthenticated_message
|
289
|
-
|
290
|
-
user.failed_attempts = Devise.maximum_attempts
|
291
|
-
assert_equal :last_attempt, user.unauthenticated_message
|
292
|
-
|
293
|
-
user.failed_attempts = Devise.maximum_attempts + 1
|
294
|
-
assert_equal :locked, user.unauthenticated_message
|
295
|
-
end
|
296
|
-
end
|
297
|
-
end
|
298
|
-
end
|