devise 4.5.0 → 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 +5 -5
- data/CHANGELOG.md +30 -1
- data/MIT-LICENSE +1 -1
- data/README.md +18 -0
- data/app/controllers/devise/passwords_controller.rb +1 -0
- data/app/controllers/devise/registrations_controller.rb +25 -7
- data/app/helpers/devise_helper.rb +10 -19
- data/app/views/devise/confirmations/new.html.erb +1 -1
- data/app/views/devise/passwords/edit.html.erb +1 -1
- 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 +2 -2
- data/app/views/devise/shared/_error_messages.html.erb +15 -0
- data/app/views/devise/shared/_links.html.erb +7 -7
- data/app/views/devise/unlocks/new.html.erb +1 -1
- data/config/locales/en.yml +1 -0
- data/lib/devise.rb +4 -0
- data/lib/devise/controllers/helpers.rb +1 -1
- data/lib/devise/failure_app.rb +28 -3
- data/lib/devise/models/authenticatable.rb +7 -15
- data/lib/devise/models/confirmable.rb +4 -1
- data/lib/devise/models/database_authenticatable.rb +41 -6
- data/lib/devise/models/lockable.rb +2 -2
- data/lib/devise/models/registerable.rb +2 -0
- data/lib/devise/strategies/database_authenticatable.rb +3 -0
- data/lib/devise/test/controller_helpers.rb +1 -1
- data/lib/devise/version.rb +1 -1
- data/lib/generators/active_record/devise_generator.rb +4 -4
- data/lib/generators/devise/controllers_generator.rb +1 -1
- data/lib/generators/templates/devise.rb +12 -3
- data/lib/generators/templates/simple_form_for/registrations/edit.html.erb +1 -1
- data/lib/generators/templates/simple_form_for/registrations/new.html.erb +1 -1
- metadata +5 -305
- data/.gitignore +0 -10
- data/.travis.yml +0 -69
- data/.yardopts +0 -9
- data/CODE_OF_CONDUCT.md +0 -22
- data/CONTRIBUTING.md +0 -79
- data/Gemfile +0 -39
- data/Gemfile.lock +0 -202
- data/ISSUE_TEMPLATE.md +0 -19
- data/Rakefile +0 -37
- data/bin/test +0 -13
- data/devise.gemspec +0 -28
- data/devise.png +0 -0
- data/gemfiles/Gemfile.rails-4.1-stable +0 -32
- data/gemfiles/Gemfile.rails-4.1-stable.lock +0 -171
- data/gemfiles/Gemfile.rails-4.2-stable +0 -32
- data/gemfiles/Gemfile.rails-4.2-stable.lock +0 -192
- data/gemfiles/Gemfile.rails-5.0-stable +0 -33
- data/gemfiles/Gemfile.rails-5.0-stable.lock +0 -192
- data/gemfiles/Gemfile.rails-5.2-rc1 +0 -26
- data/gemfiles/Gemfile.rails-5.2-rc1.lock +0 -201
- data/guides/bug_report_templates/integration_test.rb +0 -106
- data/test/controllers/custom_registrations_controller_test.rb +0 -42
- data/test/controllers/custom_strategy_test.rb +0 -66
- data/test/controllers/helper_methods_test.rb +0 -24
- data/test/controllers/helpers_test.rb +0 -318
- data/test/controllers/inherited_controller_i18n_messages_test.rb +0 -53
- data/test/controllers/internal_helpers_test.rb +0 -129
- data/test/controllers/load_hooks_controller_test.rb +0 -21
- data/test/controllers/passwords_controller_test.rb +0 -34
- data/test/controllers/sessions_controller_test.rb +0 -108
- data/test/controllers/url_helpers_test.rb +0 -67
- data/test/delegator_test.rb +0 -21
- data/test/devise_test.rb +0 -109
- data/test/failure_app_test.rb +0 -346
- data/test/generators/active_record_generator_test.rb +0 -130
- data/test/generators/controllers_generator_test.rb +0 -50
- data/test/generators/devise_generator_test.rb +0 -41
- data/test/generators/install_generator_test.rb +0 -26
- data/test/generators/mongoid_generator_test.rb +0 -25
- data/test/generators/views_generator_test.rb +0 -105
- data/test/helpers/devise_helper_test.rb +0 -51
- data/test/integration/authenticatable_test.rb +0 -706
- data/test/integration/confirmable_test.rb +0 -326
- data/test/integration/database_authenticatable_test.rb +0 -110
- data/test/integration/http_authenticatable_test.rb +0 -114
- data/test/integration/lockable_test.rb +0 -242
- data/test/integration/mounted_engine_test.rb +0 -38
- data/test/integration/omniauthable_test.rb +0 -148
- data/test/integration/recoverable_test.rb +0 -349
- data/test/integration/registerable_test.rb +0 -365
- data/test/integration/rememberable_test.rb +0 -219
- data/test/integration/timeoutable_test.rb +0 -186
- data/test/integration/trackable_test.rb +0 -99
- data/test/mailers/confirmation_instructions_test.rb +0 -117
- data/test/mailers/email_changed_test.rb +0 -132
- data/test/mailers/mailer_test.rb +0 -20
- data/test/mailers/reset_password_instructions_test.rb +0 -98
- data/test/mailers/unlock_instructions_test.rb +0 -93
- data/test/mapping_test.rb +0 -136
- data/test/models/authenticatable_test.rb +0 -25
- data/test/models/confirmable_test.rb +0 -549
- data/test/models/database_authenticatable_test.rb +0 -290
- data/test/models/lockable_test.rb +0 -352
- data/test/models/omniauthable_test.rb +0 -9
- data/test/models/recoverable_test.rb +0 -263
- data/test/models/registerable_test.rb +0 -9
- data/test/models/rememberable_test.rb +0 -184
- data/test/models/serializable_test.rb +0 -60
- data/test/models/timeoutable_test.rb +0 -53
- data/test/models/trackable_test.rb +0 -80
- data/test/models/validatable_test.rb +0 -121
- data/test/models_test.rb +0 -155
- data/test/omniauth/config_test.rb +0 -61
- data/test/omniauth/url_helpers_test.rb +0 -53
- data/test/orm/active_record.rb +0 -24
- data/test/orm/mongoid.rb +0 -15
- data/test/parameter_sanitizer_test.rb +0 -105
- data/test/rails_app/Rakefile +0 -6
- data/test/rails_app/app/active_record/admin.rb +0 -8
- data/test/rails_app/app/active_record/shim.rb +0 -4
- data/test/rails_app/app/active_record/user.rb +0 -20
- data/test/rails_app/app/active_record/user_on_engine.rb +0 -9
- data/test/rails_app/app/active_record/user_on_main_app.rb +0 -9
- data/test/rails_app/app/active_record/user_with_validations.rb +0 -12
- data/test/rails_app/app/active_record/user_without_email.rb +0 -10
- data/test/rails_app/app/controllers/admins/sessions_controller.rb +0 -8
- data/test/rails_app/app/controllers/admins_controller.rb +0 -8
- data/test/rails_app/app/controllers/application_controller.rb +0 -13
- data/test/rails_app/app/controllers/application_with_fake_engine.rb +0 -32
- data/test/rails_app/app/controllers/custom/registrations_controller.rb +0 -33
- data/test/rails_app/app/controllers/home_controller.rb +0 -31
- data/test/rails_app/app/controllers/publisher/registrations_controller.rb +0 -4
- data/test/rails_app/app/controllers/publisher/sessions_controller.rb +0 -4
- data/test/rails_app/app/controllers/users/omniauth_callbacks_controller.rb +0 -16
- data/test/rails_app/app/controllers/users_controller.rb +0 -33
- data/test/rails_app/app/helpers/application_helper.rb +0 -5
- data/test/rails_app/app/mailers/users/from_proc_mailer.rb +0 -5
- data/test/rails_app/app/mailers/users/mailer.rb +0 -5
- data/test/rails_app/app/mailers/users/reply_to_mailer.rb +0 -6
- data/test/rails_app/app/mongoid/admin.rb +0 -31
- data/test/rails_app/app/mongoid/shim.rb +0 -25
- data/test/rails_app/app/mongoid/user.rb +0 -50
- data/test/rails_app/app/mongoid/user_on_engine.rb +0 -41
- data/test/rails_app/app/mongoid/user_on_main_app.rb +0 -41
- data/test/rails_app/app/mongoid/user_with_validations.rb +0 -37
- data/test/rails_app/app/mongoid/user_without_email.rb +0 -35
- 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.ru +0 -4
- data/test/rails_app/config/application.rb +0 -48
- data/test/rails_app/config/boot.rb +0 -27
- data/test/rails_app/config/database.yml +0 -18
- data/test/rails_app/config/environment.rb +0 -7
- data/test/rails_app/config/environments/development.rb +0 -32
- data/test/rails_app/config/environments/production.rb +0 -88
- data/test/rails_app/config/environments/test.rb +0 -47
- data/test/rails_app/config/initializers/backtrace_silencers.rb +0 -9
- data/test/rails_app/config/initializers/devise.rb +0 -187
- data/test/rails_app/config/initializers/inflections.rb +0 -4
- data/test/rails_app/config/initializers/secret_token.rb +0 -5
- data/test/rails_app/config/initializers/session_store.rb +0 -3
- data/test/rails_app/config/routes.rb +0 -128
- data/test/rails_app/db/migrate/20100401102949_create_tables.rb +0 -77
- data/test/rails_app/db/schema.rb +0 -57
- data/test/rails_app/lib/lazy_load_test_module.rb +0 -5
- data/test/rails_app/lib/shared_admin.rb +0 -23
- data/test/rails_app/lib/shared_user.rb +0 -32
- data/test/rails_app/lib/shared_user_without_email.rb +0 -28
- data/test/rails_app/lib/shared_user_without_omniauth.rb +0 -15
- 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/rails_test.rb +0 -11
- data/test/routes_test.rb +0 -281
- data/test/secret_key_finder_test.rb +0 -121
- data/test/support/action_controller/record_identifier.rb +0 -12
- data/test/support/assertions.rb +0 -30
- data/test/support/helpers.rb +0 -83
- data/test/support/http_method_compatibility.rb +0 -53
- data/test/support/integration.rb +0 -95
- data/test/support/locale/en.yml +0 -8
- data/test/support/mongoid.yml +0 -6
- data/test/support/webrat/integrations/rails.rb +0 -35
- data/test/test/controller_helpers_test.rb +0 -193
- data/test/test/integration_helpers_test.rb +0 -34
- data/test/test_helper.rb +0 -36
- data/test/test_models.rb +0 -35
@@ -1,263 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'test_helper'
|
4
|
-
|
5
|
-
class RecoverableTest < ActiveSupport::TestCase
|
6
|
-
|
7
|
-
def setup
|
8
|
-
setup_mailer
|
9
|
-
end
|
10
|
-
|
11
|
-
test 'should not generate reset password token after creating a record' do
|
12
|
-
assert_nil new_user.reset_password_token
|
13
|
-
end
|
14
|
-
|
15
|
-
test 'should never generate the same reset password token for different users' do
|
16
|
-
reset_password_tokens = []
|
17
|
-
3.times do
|
18
|
-
user = create_user
|
19
|
-
user.send_reset_password_instructions
|
20
|
-
token = user.reset_password_token
|
21
|
-
assert !reset_password_tokens.include?(token)
|
22
|
-
reset_password_tokens << token
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
test 'should reset password and password confirmation from params' do
|
27
|
-
user = create_user
|
28
|
-
user.reset_password('123456789', '987654321')
|
29
|
-
assert_equal '123456789', user.password
|
30
|
-
assert_equal '987654321', user.password_confirmation
|
31
|
-
end
|
32
|
-
|
33
|
-
test 'should reset password and save the record' do
|
34
|
-
assert create_user.reset_password('123456789', '123456789')
|
35
|
-
end
|
36
|
-
|
37
|
-
test 'should clear reset password token while reseting the password' do
|
38
|
-
user = create_user
|
39
|
-
assert_nil user.reset_password_token
|
40
|
-
|
41
|
-
user.send_reset_password_instructions
|
42
|
-
assert_present user.reset_password_token
|
43
|
-
assert user.reset_password('123456789', '123456789')
|
44
|
-
assert_nil user.reset_password_token
|
45
|
-
end
|
46
|
-
|
47
|
-
test 'should not clear reset password token for new user' do
|
48
|
-
user = new_user
|
49
|
-
assert_nil user.reset_password_token
|
50
|
-
|
51
|
-
user.send_reset_password_instructions
|
52
|
-
assert_present user.reset_password_token
|
53
|
-
|
54
|
-
user.save
|
55
|
-
assert_present user.reset_password_token
|
56
|
-
end
|
57
|
-
|
58
|
-
test 'should clear reset password token if changing password' do
|
59
|
-
user = create_user
|
60
|
-
assert_nil user.reset_password_token
|
61
|
-
|
62
|
-
user.send_reset_password_instructions
|
63
|
-
assert_present user.reset_password_token
|
64
|
-
user.password = "123456678"
|
65
|
-
user.password_confirmation = "123456678"
|
66
|
-
user.save!
|
67
|
-
assert_nil user.reset_password_token
|
68
|
-
end
|
69
|
-
|
70
|
-
test 'should clear reset password token if changing email' do
|
71
|
-
user = create_user
|
72
|
-
assert_nil user.reset_password_token
|
73
|
-
|
74
|
-
user.send_reset_password_instructions
|
75
|
-
assert_present user.reset_password_token
|
76
|
-
user.email = "another@example.com"
|
77
|
-
user.save!
|
78
|
-
assert_nil user.reset_password_token
|
79
|
-
end
|
80
|
-
|
81
|
-
test 'should clear reset password successfully even if there is no email' do
|
82
|
-
user = create_user_without_email
|
83
|
-
assert_nil user.reset_password_token
|
84
|
-
|
85
|
-
user.send_reset_password_instructions
|
86
|
-
assert_present user.reset_password_token
|
87
|
-
user.password = "123456678"
|
88
|
-
user.password_confirmation = "123456678"
|
89
|
-
user.save!
|
90
|
-
assert_nil user.reset_password_token
|
91
|
-
end
|
92
|
-
|
93
|
-
test 'should not clear reset password token if record is invalid' do
|
94
|
-
user = create_user
|
95
|
-
user.send_reset_password_instructions
|
96
|
-
assert_present user.reset_password_token
|
97
|
-
refute user.reset_password('123456789', '987654321')
|
98
|
-
assert_present user.reset_password_token
|
99
|
-
end
|
100
|
-
|
101
|
-
test 'should not reset password with invalid data' do
|
102
|
-
user = create_user
|
103
|
-
user.stubs(:valid?).returns(false)
|
104
|
-
refute user.reset_password('123456789', '987654321')
|
105
|
-
end
|
106
|
-
|
107
|
-
test 'should reset reset password token and send instructions by email' do
|
108
|
-
user = create_user
|
109
|
-
assert_email_sent do
|
110
|
-
token = user.reset_password_token
|
111
|
-
user.send_reset_password_instructions
|
112
|
-
assert_not_equal token, user.reset_password_token
|
113
|
-
end
|
114
|
-
end
|
115
|
-
|
116
|
-
test 'should find a user to send instructions by email' do
|
117
|
-
user = create_user
|
118
|
-
reset_password_user = User.send_reset_password_instructions(email: user.email)
|
119
|
-
assert_equal reset_password_user, user
|
120
|
-
end
|
121
|
-
|
122
|
-
test 'should return a new record with errors if user was not found by e-mail' do
|
123
|
-
reset_password_user = User.send_reset_password_instructions(email: "invalid@example.com")
|
124
|
-
refute reset_password_user.persisted?
|
125
|
-
assert_equal "not found", reset_password_user.errors[:email].join
|
126
|
-
end
|
127
|
-
|
128
|
-
test 'should find a user to send instructions by authentication_keys' do
|
129
|
-
swap Devise, authentication_keys: [:username, :email] do
|
130
|
-
user = create_user
|
131
|
-
reset_password_user = User.send_reset_password_instructions(email: user.email, username: user.username)
|
132
|
-
assert_equal reset_password_user, user
|
133
|
-
end
|
134
|
-
end
|
135
|
-
|
136
|
-
test 'should require all reset_password_keys' do
|
137
|
-
swap Devise, reset_password_keys: [:username, :email] do
|
138
|
-
user = create_user
|
139
|
-
reset_password_user = User.send_reset_password_instructions(email: user.email)
|
140
|
-
refute reset_password_user.persisted?
|
141
|
-
assert_equal "can't be blank", reset_password_user.errors[:username].join
|
142
|
-
end
|
143
|
-
end
|
144
|
-
|
145
|
-
test 'should reset reset_password_token before send the reset instructions email' do
|
146
|
-
user = create_user
|
147
|
-
token = user.reset_password_token
|
148
|
-
User.send_reset_password_instructions(email: user.email)
|
149
|
-
assert_not_equal token, user.reload.reset_password_token
|
150
|
-
end
|
151
|
-
|
152
|
-
test 'should send email instructions to the user reset their password' do
|
153
|
-
user = create_user
|
154
|
-
assert_email_sent do
|
155
|
-
User.send_reset_password_instructions(email: user.email)
|
156
|
-
end
|
157
|
-
end
|
158
|
-
|
159
|
-
test 'should find a user to reset their password based on the raw token' do
|
160
|
-
user = create_user
|
161
|
-
raw = user.send_reset_password_instructions
|
162
|
-
|
163
|
-
reset_password_user = User.reset_password_by_token(reset_password_token: raw)
|
164
|
-
assert_equal reset_password_user, user
|
165
|
-
end
|
166
|
-
|
167
|
-
test 'should return a new record with errors if no reset_password_token is found' do
|
168
|
-
reset_password_user = User.reset_password_by_token(reset_password_token: 'invalid_token')
|
169
|
-
refute reset_password_user.persisted?
|
170
|
-
assert_equal "is invalid", reset_password_user.errors[:reset_password_token].join
|
171
|
-
end
|
172
|
-
|
173
|
-
test 'should return a new record with errors if reset_password_token is blank' do
|
174
|
-
reset_password_user = User.reset_password_by_token(reset_password_token: '')
|
175
|
-
refute reset_password_user.persisted?
|
176
|
-
assert_match "can't be blank", reset_password_user.errors[:reset_password_token].join
|
177
|
-
end
|
178
|
-
|
179
|
-
test 'should return a new record with errors if password is blank' do
|
180
|
-
user = create_user
|
181
|
-
raw = user.send_reset_password_instructions
|
182
|
-
|
183
|
-
reset_password_user = User.reset_password_by_token(reset_password_token: raw, password: '')
|
184
|
-
refute reset_password_user.errors.empty?
|
185
|
-
assert_match "can't be blank", reset_password_user.errors[:password].join
|
186
|
-
assert_equal raw, reset_password_user.reset_password_token
|
187
|
-
end
|
188
|
-
|
189
|
-
test 'should return a new record with errors if password is not provided' do
|
190
|
-
user = create_user
|
191
|
-
raw = user.send_reset_password_instructions
|
192
|
-
|
193
|
-
reset_password_user = User.reset_password_by_token(reset_password_token: raw)
|
194
|
-
refute reset_password_user.errors.empty?
|
195
|
-
assert_match "can't be blank", reset_password_user.errors[:password].join
|
196
|
-
assert_equal raw, reset_password_user.reset_password_token
|
197
|
-
end
|
198
|
-
|
199
|
-
test 'should reset successfully user password given the new password and confirmation' do
|
200
|
-
user = create_user
|
201
|
-
old_password = user.password
|
202
|
-
raw = user.send_reset_password_instructions
|
203
|
-
|
204
|
-
reset_password_user = User.reset_password_by_token(
|
205
|
-
reset_password_token: raw,
|
206
|
-
password: 'new_password',
|
207
|
-
password_confirmation: 'new_password'
|
208
|
-
)
|
209
|
-
assert_nil reset_password_user.reset_password_token
|
210
|
-
|
211
|
-
user.reload
|
212
|
-
refute user.valid_password?(old_password)
|
213
|
-
assert user.valid_password?('new_password')
|
214
|
-
assert_nil user.reset_password_token
|
215
|
-
end
|
216
|
-
|
217
|
-
test 'should not reset password after reset_password_within time' do
|
218
|
-
swap Devise, reset_password_within: 1.hour do
|
219
|
-
user = create_user
|
220
|
-
raw = user.send_reset_password_instructions
|
221
|
-
|
222
|
-
old_password = user.password
|
223
|
-
user.reset_password_sent_at = 2.days.ago
|
224
|
-
user.save!
|
225
|
-
|
226
|
-
reset_password_user = User.reset_password_by_token(
|
227
|
-
reset_password_token: raw,
|
228
|
-
password: 'new_password',
|
229
|
-
password_confirmation: 'new_password'
|
230
|
-
)
|
231
|
-
user.reload
|
232
|
-
|
233
|
-
assert user.valid_password?(old_password)
|
234
|
-
refute user.valid_password?('new_password')
|
235
|
-
assert_equal "has expired, please request a new one", reset_password_user.errors[:reset_password_token].join
|
236
|
-
end
|
237
|
-
end
|
238
|
-
|
239
|
-
test 'required_fields should contain the fields that Devise uses' do
|
240
|
-
assert_equal Devise::Models::Recoverable.required_fields(User), [
|
241
|
-
:reset_password_sent_at,
|
242
|
-
:reset_password_token
|
243
|
-
]
|
244
|
-
end
|
245
|
-
|
246
|
-
test 'should return a user based on the raw token' do
|
247
|
-
user = create_user
|
248
|
-
raw = user.send_reset_password_instructions
|
249
|
-
|
250
|
-
assert_equal User.with_reset_password_token(raw), user
|
251
|
-
end
|
252
|
-
|
253
|
-
test 'should return the same reset password token as generated' do
|
254
|
-
user = create_user
|
255
|
-
raw = user.send_reset_password_instructions
|
256
|
-
assert_equal Devise.token_generator.digest(self.class, :reset_password_token, raw), user.reset_password_token
|
257
|
-
end
|
258
|
-
|
259
|
-
test 'should return nil if a user based on the raw token is not found' do
|
260
|
-
assert_nil User.with_reset_password_token('random-token')
|
261
|
-
end
|
262
|
-
|
263
|
-
end
|
@@ -1,184 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'test_helper'
|
4
|
-
|
5
|
-
class RememberableTest < ActiveSupport::TestCase
|
6
|
-
def resource_class
|
7
|
-
User
|
8
|
-
end
|
9
|
-
|
10
|
-
def create_resource
|
11
|
-
create_user
|
12
|
-
end
|
13
|
-
|
14
|
-
test 'remember_me should not generate a new token if using salt' do
|
15
|
-
user = create_user
|
16
|
-
user.expects(:valid?).never
|
17
|
-
user.remember_me!
|
18
|
-
assert user.remember_created_at
|
19
|
-
end
|
20
|
-
|
21
|
-
test 'remember_me should not generate a new token if valid token exists' do
|
22
|
-
user = create_user
|
23
|
-
user.singleton_class.send(:attr_accessor, :remember_token)
|
24
|
-
User.to_adapter.expects(:find_first).returns(nil)
|
25
|
-
|
26
|
-
user.remember_me!
|
27
|
-
existing_token = user.remember_token
|
28
|
-
|
29
|
-
user.remember_me!
|
30
|
-
assert_equal existing_token, user.remember_token
|
31
|
-
end
|
32
|
-
|
33
|
-
test 'forget_me should not clear remember token if using salt' do
|
34
|
-
user = create_user
|
35
|
-
user.remember_me!
|
36
|
-
user.expects(:valid?).never
|
37
|
-
user.forget_me!
|
38
|
-
end
|
39
|
-
|
40
|
-
test 'can generate remember token' do
|
41
|
-
user = create_user
|
42
|
-
user.singleton_class.send(:attr_accessor, :remember_token)
|
43
|
-
User.to_adapter.expects(:find_first).returns(nil)
|
44
|
-
user.remember_me!
|
45
|
-
assert user.remember_token
|
46
|
-
end
|
47
|
-
|
48
|
-
test 'serialize into cookie' do
|
49
|
-
user = create_user
|
50
|
-
user.remember_me!
|
51
|
-
id, token, date = User.serialize_into_cookie(user)
|
52
|
-
assert_equal id, user.to_key
|
53
|
-
assert_equal token, user.authenticatable_salt
|
54
|
-
assert date.is_a?(String)
|
55
|
-
end
|
56
|
-
|
57
|
-
test 'serialize from cookie' do
|
58
|
-
user = create_user
|
59
|
-
user.remember_me!
|
60
|
-
assert_equal user, User.serialize_from_cookie(user.to_key, user.authenticatable_salt, Time.now.utc)
|
61
|
-
end
|
62
|
-
|
63
|
-
test 'serialize from cookie should accept a String with the datetime seconds and microseconds' do
|
64
|
-
user = create_user
|
65
|
-
user.remember_me!
|
66
|
-
assert_equal user, User.serialize_from_cookie(user.to_key, user.authenticatable_salt, Time.now.utc.to_f.to_json)
|
67
|
-
end
|
68
|
-
|
69
|
-
test 'serialize from cookie should return nil with invalid datetime' do
|
70
|
-
user = create_user
|
71
|
-
user.remember_me!
|
72
|
-
assert_nil User.serialize_from_cookie(user.to_key, user.authenticatable_salt, "2013")
|
73
|
-
end
|
74
|
-
|
75
|
-
test 'serialize from cookie should return nil if no resource is found' do
|
76
|
-
assert_nil resource_class.serialize_from_cookie([0], "123", Time.now.utc)
|
77
|
-
end
|
78
|
-
|
79
|
-
test 'serialize from cookie should return nil if no timestamp' do
|
80
|
-
user = create_user
|
81
|
-
user.remember_me!
|
82
|
-
assert_nil User.serialize_from_cookie(user.to_key, user.authenticatable_salt)
|
83
|
-
end
|
84
|
-
|
85
|
-
test 'serialize from cookie should return nil if timestamp is earlier than token creation' do
|
86
|
-
user = create_user
|
87
|
-
user.remember_me!
|
88
|
-
assert_nil User.serialize_from_cookie(user.to_key, user.authenticatable_salt, 1.day.ago)
|
89
|
-
end
|
90
|
-
|
91
|
-
test 'serialize from cookie should return nil if timestamp is older than remember_for' do
|
92
|
-
user = create_user
|
93
|
-
user.remember_created_at = 1.month.ago
|
94
|
-
user.remember_me!
|
95
|
-
assert_nil User.serialize_from_cookie(user.to_key, user.authenticatable_salt, 3.weeks.ago)
|
96
|
-
end
|
97
|
-
|
98
|
-
test 'serialize from cookie me return nil if is a valid resource with invalid token' do
|
99
|
-
user = create_user
|
100
|
-
user.remember_me!
|
101
|
-
assert_nil User.serialize_from_cookie(user.to_key, "123", Time.now.utc)
|
102
|
-
end
|
103
|
-
|
104
|
-
test 'raises a RuntimeError if the user does not implements a rememberable value' do
|
105
|
-
user = User.new
|
106
|
-
assert_raise(RuntimeError) { user.rememberable_value }
|
107
|
-
|
108
|
-
user_with_remember_token = User.new
|
109
|
-
def user_with_remember_token.remember_token; '123-token'; end
|
110
|
-
assert_equal '123-token', user_with_remember_token.rememberable_value
|
111
|
-
|
112
|
-
user_with_salt = User.new
|
113
|
-
def user_with_salt.authenticatable_salt; '123-salt'; end
|
114
|
-
assert_equal '123-salt', user_with_salt.rememberable_value
|
115
|
-
end
|
116
|
-
|
117
|
-
test 'raises a RuntimeError if authenticatable_salt is nil or empty' do
|
118
|
-
user = User.new
|
119
|
-
def user.authenticatable_salt; nil; end
|
120
|
-
assert_raise RuntimeError do
|
121
|
-
user.rememberable_value
|
122
|
-
end
|
123
|
-
|
124
|
-
user = User.new
|
125
|
-
def user.authenticatable_salt; ""; end
|
126
|
-
assert_raise RuntimeError do
|
127
|
-
user.rememberable_value
|
128
|
-
end
|
129
|
-
end
|
130
|
-
|
131
|
-
test 'should respond to remember_me attribute' do
|
132
|
-
assert resource_class.new.respond_to?(:remember_me)
|
133
|
-
assert resource_class.new.respond_to?(:remember_me=)
|
134
|
-
end
|
135
|
-
|
136
|
-
test 'forget_me should clear remember_created_at if expire_all_remember_me_on_sign_out is true' do
|
137
|
-
swap Devise, expire_all_remember_me_on_sign_out: true do
|
138
|
-
resource = create_resource
|
139
|
-
resource.remember_me!
|
140
|
-
assert_not_nil resource.remember_created_at
|
141
|
-
|
142
|
-
resource.forget_me!
|
143
|
-
assert_nil resource.remember_created_at
|
144
|
-
end
|
145
|
-
end
|
146
|
-
|
147
|
-
test 'forget_me should not clear remember_created_at if expire_all_remember_me_on_sign_out is false' do
|
148
|
-
swap Devise, expire_all_remember_me_on_sign_out: false do
|
149
|
-
resource = create_resource
|
150
|
-
resource.remember_me!
|
151
|
-
|
152
|
-
assert_not_nil resource.remember_created_at
|
153
|
-
|
154
|
-
resource.forget_me!
|
155
|
-
assert_not_nil resource.remember_created_at
|
156
|
-
end
|
157
|
-
end
|
158
|
-
|
159
|
-
test 'forget_me should not try to update resource if it has been destroyed' do
|
160
|
-
resource = create_resource
|
161
|
-
resource.expects(:remember_created_at).never
|
162
|
-
resource.expects(:save).never
|
163
|
-
|
164
|
-
resource.destroy
|
165
|
-
resource.forget_me!
|
166
|
-
end
|
167
|
-
|
168
|
-
test 'remember expires at uses remember for configuration' do
|
169
|
-
swap Devise, remember_for: 3.days do
|
170
|
-
resource = create_resource
|
171
|
-
resource.remember_me!
|
172
|
-
assert_equal 3.days.from_now.to_date, resource.remember_expires_at.to_date
|
173
|
-
|
174
|
-
Devise.remember_for = 5.days
|
175
|
-
assert_equal 5.days.from_now.to_date, resource.remember_expires_at.to_date
|
176
|
-
end
|
177
|
-
end
|
178
|
-
|
179
|
-
test 'should have the required_fields array' do
|
180
|
-
assert_equal Devise::Models::Rememberable.required_fields(User), [
|
181
|
-
:remember_created_at
|
182
|
-
]
|
183
|
-
end
|
184
|
-
end
|