devise 2.1.2 → 3.5.10
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/.travis.yml +39 -10
- data/.yardopts +9 -0
- data/{CHANGELOG.rdoc → CHANGELOG.md} +445 -112
- data/CODE_OF_CONDUCT.md +22 -0
- data/CONTRIBUTING.md +16 -0
- data/Gemfile +10 -15
- data/Gemfile.lock +151 -129
- data/MIT-LICENSE +1 -1
- data/README.md +256 -96
- data/Rakefile +4 -2
- data/app/controllers/devise/confirmations_controller.rb +15 -7
- data/app/controllers/devise/omniauth_callbacks_controller.rb +6 -2
- data/app/controllers/devise/passwords_controller.rb +33 -9
- data/app/controllers/devise/registrations_controller.rb +66 -26
- data/app/controllers/devise/sessions_controller.rb +52 -21
- data/app/controllers/devise/unlocks_controller.rb +11 -6
- data/app/controllers/devise_controller.rb +65 -58
- data/app/helpers/devise_helper.rb +2 -2
- data/app/mailers/devise/mailer.rb +19 -10
- data/app/views/devise/confirmations/new.html.erb +8 -4
- data/app/views/devise/mailer/confirmation_instructions.html.erb +2 -2
- data/app/views/devise/mailer/password_change.html.erb +3 -0
- data/app/views/devise/mailer/reset_password_instructions.html.erb +2 -2
- data/app/views/devise/mailer/unlock_instructions.html.erb +2 -2
- data/app/views/devise/passwords/edit.html.erb +15 -6
- data/app/views/devise/passwords/new.html.erb +8 -4
- data/app/views/devise/registrations/edit.html.erb +29 -15
- data/app/views/devise/registrations/new.html.erb +19 -8
- data/app/views/devise/sessions/new.html.erb +17 -8
- data/app/views/devise/shared/{_links.erb → _links.html.erb} +4 -4
- data/app/views/devise/unlocks/new.html.erb +8 -4
- data/config/locales/en.yml +51 -47
- data/devise.gemspec +8 -6
- data/devise.png +0 -0
- data/gemfiles/Gemfile.rails-3.2-stable +29 -0
- data/gemfiles/Gemfile.rails-3.2-stable.lock +172 -0
- data/gemfiles/Gemfile.rails-4.0-stable +30 -0
- data/gemfiles/Gemfile.rails-4.0-stable.lock +166 -0
- data/gemfiles/Gemfile.rails-4.1-stable +30 -0
- data/gemfiles/Gemfile.rails-4.1-stable.lock +171 -0
- data/gemfiles/Gemfile.rails-4.2-stable +30 -0
- data/gemfiles/Gemfile.rails-4.2-stable.lock +193 -0
- data/lib/devise/controllers/helpers.rb +126 -108
- data/lib/devise/controllers/rememberable.rb +19 -17
- data/lib/devise/controllers/scoped_views.rb +1 -1
- data/lib/devise/controllers/sign_in_out.rb +96 -0
- data/lib/devise/controllers/store_location.rb +58 -0
- data/lib/devise/controllers/url_helpers.rb +7 -7
- data/lib/devise/encryptor.rb +22 -0
- data/lib/devise/failure_app.rb +85 -25
- data/lib/devise/hooks/activatable.rb +5 -6
- data/lib/devise/hooks/csrf_cleaner.rb +7 -0
- data/lib/devise/hooks/forgetable.rb +1 -1
- data/lib/devise/hooks/lockable.rb +2 -2
- data/lib/devise/hooks/proxy.rb +21 -0
- data/lib/devise/hooks/rememberable.rb +5 -4
- data/lib/devise/hooks/timeoutable.rb +16 -8
- data/lib/devise/hooks/trackable.rb +1 -1
- data/lib/devise/mailers/helpers.rb +27 -23
- data/lib/devise/mapping.rb +11 -7
- data/lib/devise/models/authenticatable.rb +82 -66
- data/lib/devise/models/confirmable.rb +142 -55
- data/lib/devise/models/database_authenticatable.rb +59 -15
- data/lib/devise/models/lockable.rb +41 -30
- data/lib/devise/models/omniauthable.rb +3 -3
- data/lib/devise/models/recoverable.rb +56 -41
- data/lib/devise/models/rememberable.rb +65 -27
- data/lib/devise/models/timeoutable.rb +2 -8
- data/lib/devise/models/trackable.rb +6 -4
- data/lib/devise/models/validatable.rb +9 -9
- data/lib/devise/models.rb +4 -13
- data/lib/devise/modules.rb +10 -11
- data/lib/devise/omniauth/url_helpers.rb +2 -2
- data/lib/devise/orm/active_record.rb +1 -1
- data/lib/devise/orm/mongoid.rb +1 -1
- data/lib/devise/{param_filter.rb → parameter_filter.rb} +10 -11
- data/lib/devise/parameter_sanitizer.rb +99 -0
- data/lib/devise/rails/routes.rb +173 -115
- data/lib/devise/rails/warden_compat.rb +10 -31
- data/lib/devise/rails.rb +14 -12
- data/lib/devise/strategies/authenticatable.rb +26 -26
- data/lib/devise/strategies/base.rb +1 -1
- data/lib/devise/strategies/database_authenticatable.rb +8 -4
- data/lib/devise/strategies/rememberable.rb +15 -5
- data/lib/devise/test_helpers.rb +7 -5
- data/lib/devise/time_inflector.rb +14 -0
- data/lib/devise/token_generator.rb +70 -0
- data/lib/devise/version.rb +1 -1
- data/lib/devise.rb +110 -52
- data/lib/generators/active_record/devise_generator.rb +34 -18
- data/lib/generators/active_record/templates/migration.rb +5 -6
- data/lib/generators/active_record/templates/migration_existing.rb +5 -6
- data/lib/generators/devise/controllers_generator.rb +44 -0
- data/lib/generators/devise/devise_generator.rb +5 -3
- data/lib/generators/devise/install_generator.rb +5 -0
- data/lib/generators/devise/orm_helpers.rb +25 -6
- data/lib/generators/devise/views_generator.rb +52 -22
- data/lib/generators/mongoid/devise_generator.rb +21 -26
- data/lib/generators/templates/README +9 -5
- data/lib/generators/templates/controllers/README +14 -0
- data/lib/generators/templates/controllers/confirmations_controller.rb +28 -0
- data/lib/generators/templates/controllers/omniauth_callbacks_controller.rb +28 -0
- data/lib/generators/templates/controllers/passwords_controller.rb +32 -0
- data/lib/generators/templates/controllers/registrations_controller.rb +60 -0
- data/lib/generators/templates/controllers/sessions_controller.rb +25 -0
- data/lib/generators/templates/controllers/unlocks_controller.rb +28 -0
- data/lib/generators/templates/devise.rb +80 -43
- data/lib/generators/templates/markerb/confirmation_instructions.markerb +2 -2
- 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 +2 -2
- data/lib/generators/templates/simple_form_for/confirmations/new.html.erb +3 -2
- data/lib/generators/templates/simple_form_for/passwords/edit.html.erb +4 -4
- data/lib/generators/templates/simple_form_for/passwords/new.html.erb +2 -2
- data/lib/generators/templates/simple_form_for/registrations/edit.html.erb +11 -6
- data/lib/generators/templates/simple_form_for/registrations/new.html.erb +4 -4
- data/lib/generators/templates/simple_form_for/sessions/new.html.erb +6 -6
- data/lib/generators/templates/simple_form_for/unlocks/new.html.erb +3 -2
- data/script/cached-bundle +49 -0
- data/script/s3-put +71 -0
- data/test/controllers/custom_registrations_controller_test.rb +40 -0
- data/test/controllers/helper_methods_test.rb +21 -0
- data/test/controllers/helpers_test.rb +95 -32
- data/test/controllers/inherited_controller_i18n_messages_test.rb +51 -0
- data/test/controllers/internal_helpers_test.rb +39 -14
- data/test/controllers/load_hooks_controller_test.rb +19 -0
- data/test/controllers/passwords_controller_test.rb +31 -0
- data/test/controllers/sessions_controller_test.rb +66 -6
- data/test/controllers/url_helpers_test.rb +10 -4
- data/test/delegator_test.rb +1 -1
- data/test/devise_test.rb +45 -10
- data/test/failure_app_test.rb +121 -27
- data/test/generators/active_record_generator_test.rb +48 -8
- data/test/generators/controllers_generator_test.rb +48 -0
- data/test/generators/devise_generator_test.rb +2 -2
- data/test/generators/mongoid_generator_test.rb +3 -3
- data/test/generators/views_generator_test.rb +54 -3
- data/test/helpers/devise_helper_test.rb +18 -20
- data/test/integration/authenticatable_test.rb +161 -65
- data/test/integration/confirmable_test.rb +146 -77
- data/test/integration/database_authenticatable_test.rb +43 -30
- data/test/integration/http_authenticatable_test.rb +30 -22
- data/test/integration/lockable_test.rb +64 -49
- data/test/integration/omniauthable_test.rb +17 -15
- data/test/integration/recoverable_test.rb +111 -70
- data/test/integration/registerable_test.rb +114 -79
- data/test/integration/rememberable_test.rb +87 -31
- data/test/integration/timeoutable_test.rb +77 -33
- data/test/integration/trackable_test.rb +5 -5
- data/test/mailers/confirmation_instructions_test.rb +28 -8
- data/test/mailers/reset_password_instructions_test.rb +21 -8
- data/test/mailers/unlock_instructions_test.rb +20 -6
- data/test/mapping_test.rb +12 -5
- data/test/models/authenticatable_test.rb +17 -1
- data/test/models/confirmable_test.rb +216 -62
- data/test/models/database_authenticatable_test.rb +129 -49
- data/test/models/lockable_test.rb +132 -45
- data/test/models/recoverable_test.rb +100 -54
- data/test/models/rememberable_test.rb +89 -94
- data/test/models/serializable_test.rb +12 -11
- data/test/models/timeoutable_test.rb +6 -1
- data/test/models/trackable_test.rb +28 -0
- data/test/models/validatable_test.rb +31 -21
- data/test/models_test.rb +22 -48
- data/test/omniauth/config_test.rb +4 -4
- data/test/omniauth/url_helpers_test.rb +7 -4
- data/test/orm/active_record.rb +1 -0
- data/test/orm/mongoid.rb +2 -3
- data/test/parameter_sanitizer_test.rb +81 -0
- data/test/rails_app/Rakefile +0 -4
- data/test/rails_app/app/active_record/shim.rb +1 -1
- data/test/rails_app/app/active_record/user_on_engine.rb +7 -0
- data/test/rails_app/app/active_record/user_on_main_app.rb +7 -0
- data/test/rails_app/app/active_record/user_without_email.rb +8 -0
- data/test/rails_app/app/controllers/admins/sessions_controller.rb +1 -1
- data/test/rails_app/app/controllers/admins_controller.rb +0 -5
- data/test/rails_app/app/controllers/application_controller.rb +6 -2
- data/test/rails_app/app/controllers/application_with_fake_engine.rb +30 -0
- data/test/rails_app/app/controllers/custom/registrations_controller.rb +31 -0
- data/test/rails_app/app/controllers/home_controller.rb +1 -1
- data/test/rails_app/app/controllers/publisher/registrations_controller.rb +1 -1
- data/test/rails_app/app/controllers/publisher/sessions_controller.rb +1 -1
- data/test/rails_app/app/controllers/users/omniauth_callbacks_controller.rb +4 -4
- data/test/rails_app/app/controllers/users_controller.rb +12 -4
- data/test/rails_app/app/mailers/users/from_proc_mailer.rb +3 -0
- data/test/rails_app/app/mailers/users/mailer.rb +1 -1
- data/test/rails_app/app/mailers/users/reply_to_mailer.rb +4 -0
- data/test/rails_app/app/mongoid/admin.rb +12 -10
- data/test/rails_app/app/mongoid/shim.rb +4 -5
- data/test/rails_app/app/mongoid/user.rb +19 -22
- data/test/rails_app/app/mongoid/user_on_engine.rb +39 -0
- data/test/rails_app/app/mongoid/user_on_main_app.rb +39 -0
- data/test/rails_app/app/mongoid/user_without_email.rb +33 -0
- data/test/rails_app/app/views/admins/sessions/new.html.erb +1 -1
- data/test/rails_app/app/views/home/admin_dashboard.html.erb +1 -1
- data/test/rails_app/app/views/home/index.html.erb +1 -1
- data/test/rails_app/app/views/home/join.html.erb +1 -1
- data/test/rails_app/app/views/home/user_dashboard.html.erb +1 -1
- data/test/rails_app/app/views/layouts/application.html.erb +1 -1
- data/test/rails_app/app/views/users/edit_form.html.erb +1 -0
- data/test/rails_app/bin/bundle +3 -0
- data/test/rails_app/bin/rails +4 -0
- data/test/rails_app/bin/rake +4 -0
- data/test/rails_app/config/application.rb +4 -5
- data/test/rails_app/config/boot.rb +9 -3
- data/test/rails_app/config/environment.rb +2 -2
- data/test/rails_app/config/environments/development.rb +19 -7
- data/test/rails_app/config/environments/production.rb +68 -17
- data/test/rails_app/config/environments/test.rb +24 -16
- data/test/rails_app/config/initializers/devise.rb +22 -20
- data/test/rails_app/config/initializers/secret_token.rb +8 -2
- data/test/rails_app/config/initializers/session_store.rb +1 -0
- data/test/rails_app/config/routes.rb +71 -46
- data/test/rails_app/db/migrate/20100401102949_create_tables.rb +9 -12
- data/test/rails_app/db/schema.rb +21 -18
- data/test/rails_app/lib/shared_admin.rb +7 -4
- data/test/rails_app/lib/shared_user.rb +6 -3
- data/test/rails_app/lib/shared_user_without_email.rb +26 -0
- data/test/rails_app/lib/shared_user_without_omniauth.rb +13 -0
- data/test/rails_test.rb +9 -0
- data/test/routes_test.rb +94 -78
- data/test/support/action_controller/record_identifier.rb +10 -0
- data/test/support/assertions.rb +2 -3
- data/test/support/helpers.rb +18 -32
- data/test/support/integration.rb +17 -16
- data/test/support/locale/en.yml +4 -0
- data/test/support/mongoid.yml +6 -0
- data/test/test_helper.rb +8 -1
- data/test/test_helpers_test.rb +64 -20
- data/test/test_models.rb +33 -0
- data/test/time_helpers.rb +137 -0
- metadata +172 -51
- data/app/views/devise/_links.erb +0 -3
- data/gemfiles/Gemfile.rails-3.1.x +0 -35
- data/gemfiles/Gemfile.rails-3.1.x.lock +0 -167
- data/lib/devise/models/token_authenticatable.rb +0 -77
- data/lib/devise/strategies/token_authenticatable.rb +0 -56
- data/test/indifferent_hash.rb +0 -33
- data/test/integration/token_authenticatable_test.rb +0 -161
- data/test/models/token_authenticatable_test.rb +0 -55
- data/test/rails_app/script/rails +0 -10
@@ -23,13 +23,13 @@ class RecoverableTest < ActiveSupport::TestCase
|
|
23
23
|
|
24
24
|
test 'should reset password and password confirmation from params' do
|
25
25
|
user = create_user
|
26
|
-
user.reset_password
|
26
|
+
user.reset_password('123456789', '987654321')
|
27
27
|
assert_equal '123456789', user.password
|
28
28
|
assert_equal '987654321', user.password_confirmation
|
29
29
|
end
|
30
30
|
|
31
31
|
test 'should reset password and save the record' do
|
32
|
-
assert create_user.reset_password
|
32
|
+
assert create_user.reset_password('123456789', '123456789')
|
33
33
|
end
|
34
34
|
|
35
35
|
test 'should clear reset password token while reseting the password' do
|
@@ -38,7 +38,53 @@ class RecoverableTest < ActiveSupport::TestCase
|
|
38
38
|
|
39
39
|
user.send_reset_password_instructions
|
40
40
|
assert_present user.reset_password_token
|
41
|
-
assert user.reset_password
|
41
|
+
assert user.reset_password('123456789', '123456789')
|
42
|
+
assert_nil user.reset_password_token
|
43
|
+
end
|
44
|
+
|
45
|
+
test 'should not clear reset password token for new user' do
|
46
|
+
user = new_user
|
47
|
+
assert_nil user.reset_password_token
|
48
|
+
|
49
|
+
user.send_reset_password_instructions
|
50
|
+
assert_present user.reset_password_token
|
51
|
+
|
52
|
+
user.save
|
53
|
+
assert_present user.reset_password_token
|
54
|
+
end
|
55
|
+
|
56
|
+
test 'should clear reset password token if changing password' do
|
57
|
+
user = create_user
|
58
|
+
assert_nil user.reset_password_token
|
59
|
+
|
60
|
+
user.send_reset_password_instructions
|
61
|
+
assert_present user.reset_password_token
|
62
|
+
user.password = "123456678"
|
63
|
+
user.password_confirmation = "123456678"
|
64
|
+
user.save!
|
65
|
+
assert_nil user.reset_password_token
|
66
|
+
end
|
67
|
+
|
68
|
+
test 'should clear reset password token if changing email' do
|
69
|
+
user = create_user
|
70
|
+
assert_nil user.reset_password_token
|
71
|
+
|
72
|
+
user.send_reset_password_instructions
|
73
|
+
assert_present user.reset_password_token
|
74
|
+
user.email = "another@example.com"
|
75
|
+
user.save!
|
76
|
+
assert_nil user.reset_password_token
|
77
|
+
end
|
78
|
+
|
79
|
+
test 'should clear reset password successfully even if there is no email' do
|
80
|
+
user = create_user_without_email
|
81
|
+
assert_nil user.reset_password_token
|
82
|
+
|
83
|
+
user.send_reset_password_instructions
|
84
|
+
assert_present user.reset_password_token
|
85
|
+
user.password = "123456678"
|
86
|
+
user.password_confirmation = "123456678"
|
87
|
+
user.save!
|
42
88
|
assert_nil user.reset_password_token
|
43
89
|
end
|
44
90
|
|
@@ -46,14 +92,14 @@ class RecoverableTest < ActiveSupport::TestCase
|
|
46
92
|
user = create_user
|
47
93
|
user.send_reset_password_instructions
|
48
94
|
assert_present user.reset_password_token
|
49
|
-
assert_not user.reset_password
|
95
|
+
assert_not user.reset_password('123456789', '987654321')
|
50
96
|
assert_present user.reset_password_token
|
51
97
|
end
|
52
98
|
|
53
99
|
test 'should not reset password with invalid data' do
|
54
100
|
user = create_user
|
55
101
|
user.stubs(:valid?).returns(false)
|
56
|
-
assert_not user.reset_password
|
102
|
+
assert_not user.reset_password('123456789', '987654321')
|
57
103
|
end
|
58
104
|
|
59
105
|
test 'should reset reset password token and send instructions by email' do
|
@@ -67,28 +113,28 @@ class RecoverableTest < ActiveSupport::TestCase
|
|
67
113
|
|
68
114
|
test 'should find a user to send instructions by email' do
|
69
115
|
user = create_user
|
70
|
-
reset_password_user = User.send_reset_password_instructions(:
|
116
|
+
reset_password_user = User.send_reset_password_instructions(email: user.email)
|
71
117
|
assert_equal reset_password_user, user
|
72
118
|
end
|
73
119
|
|
74
120
|
test 'should return a new record with errors if user was not found by e-mail' do
|
75
|
-
reset_password_user = User.send_reset_password_instructions(:
|
121
|
+
reset_password_user = User.send_reset_password_instructions(email: "invalid@example.com")
|
76
122
|
assert_not reset_password_user.persisted?
|
77
123
|
assert_equal "not found", reset_password_user.errors[:email].join
|
78
124
|
end
|
79
125
|
|
80
126
|
test 'should find a user to send instructions by authentication_keys' do
|
81
|
-
swap Devise, :
|
127
|
+
swap Devise, authentication_keys: [:username, :email] do
|
82
128
|
user = create_user
|
83
|
-
reset_password_user = User.send_reset_password_instructions(:
|
129
|
+
reset_password_user = User.send_reset_password_instructions(email: user.email, username: user.username)
|
84
130
|
assert_equal reset_password_user, user
|
85
131
|
end
|
86
132
|
end
|
87
133
|
|
88
134
|
test 'should require all reset_password_keys' do
|
89
|
-
swap Devise, :
|
135
|
+
swap Devise, reset_password_keys: [:username, :email] do
|
90
136
|
user = create_user
|
91
|
-
reset_password_user = User.send_reset_password_instructions(:
|
137
|
+
reset_password_user = User.send_reset_password_instructions(email: user.email)
|
92
138
|
assert_not reset_password_user.persisted?
|
93
139
|
assert_equal "can't be blank", reset_password_user.errors[:username].join
|
94
140
|
end
|
@@ -97,96 +143,78 @@ class RecoverableTest < ActiveSupport::TestCase
|
|
97
143
|
test 'should reset reset_password_token before send the reset instructions email' do
|
98
144
|
user = create_user
|
99
145
|
token = user.reset_password_token
|
100
|
-
User.send_reset_password_instructions(:
|
146
|
+
User.send_reset_password_instructions(email: user.email)
|
101
147
|
assert_not_equal token, user.reload.reset_password_token
|
102
148
|
end
|
103
149
|
|
104
|
-
test 'should send email instructions to the user reset
|
150
|
+
test 'should send email instructions to the user reset their password' do
|
105
151
|
user = create_user
|
106
152
|
assert_email_sent do
|
107
|
-
User.send_reset_password_instructions(:
|
153
|
+
User.send_reset_password_instructions(email: user.email)
|
108
154
|
end
|
109
155
|
end
|
110
156
|
|
111
|
-
test 'should find a user to reset
|
157
|
+
test 'should find a user to reset their password based on the raw token' do
|
112
158
|
user = create_user
|
113
|
-
user.
|
159
|
+
raw = user.send_reset_password_instructions
|
114
160
|
|
115
|
-
reset_password_user = User.reset_password_by_token(:
|
161
|
+
reset_password_user = User.reset_password_by_token(reset_password_token: raw)
|
116
162
|
assert_equal reset_password_user, user
|
117
163
|
end
|
118
164
|
|
119
165
|
test 'should return a new record with errors if no reset_password_token is found' do
|
120
|
-
reset_password_user = User.reset_password_by_token(:
|
166
|
+
reset_password_user = User.reset_password_by_token(reset_password_token: 'invalid_token')
|
121
167
|
assert_not reset_password_user.persisted?
|
122
168
|
assert_equal "is invalid", reset_password_user.errors[:reset_password_token].join
|
123
169
|
end
|
124
170
|
|
125
171
|
test 'should return a new record with errors if reset_password_token is blank' do
|
126
|
-
reset_password_user = User.reset_password_by_token(:
|
172
|
+
reset_password_user = User.reset_password_by_token(reset_password_token: '')
|
127
173
|
assert_not reset_password_user.persisted?
|
128
174
|
assert_match "can't be blank", reset_password_user.errors[:reset_password_token].join
|
129
175
|
end
|
130
176
|
|
131
177
|
test 'should return a new record with errors if password is blank' do
|
132
178
|
user = create_user
|
133
|
-
user.
|
179
|
+
raw = user.send_reset_password_instructions
|
134
180
|
|
135
|
-
reset_password_user = User.reset_password_by_token(:
|
181
|
+
reset_password_user = User.reset_password_by_token(reset_password_token: raw, password: '')
|
136
182
|
assert_not reset_password_user.errors.empty?
|
137
183
|
assert_match "can't be blank", reset_password_user.errors[:password].join
|
184
|
+
assert_equal raw, reset_password_user.reset_password_token
|
138
185
|
end
|
139
186
|
|
140
187
|
test 'should reset successfully user password given the new password and confirmation' do
|
141
188
|
user = create_user
|
142
189
|
old_password = user.password
|
143
|
-
user.
|
190
|
+
raw = user.send_reset_password_instructions
|
144
191
|
|
145
|
-
User.reset_password_by_token(
|
146
|
-
:
|
147
|
-
:
|
148
|
-
:
|
192
|
+
reset_password_user = User.reset_password_by_token(
|
193
|
+
reset_password_token: raw,
|
194
|
+
password: 'new_password',
|
195
|
+
password_confirmation: 'new_password'
|
149
196
|
)
|
150
|
-
|
197
|
+
assert_nil reset_password_user.reset_password_token
|
151
198
|
|
199
|
+
user.reload
|
152
200
|
assert_not user.valid_password?(old_password)
|
153
201
|
assert user.valid_password?('new_password')
|
154
|
-
|
155
|
-
|
156
|
-
test 'should not reset reset password token during reset_password_within time' do
|
157
|
-
swap Devise, :reset_password_within => 1.hour do
|
158
|
-
user = create_user
|
159
|
-
user.send_reset_password_instructions
|
160
|
-
3.times do
|
161
|
-
token = user.reset_password_token
|
162
|
-
user.send_reset_password_instructions
|
163
|
-
assert_equal token, user.reset_password_token
|
164
|
-
end
|
165
|
-
end
|
166
|
-
end
|
167
|
-
|
168
|
-
test 'should reset reset password token after reset_password_within time' do
|
169
|
-
swap Devise, :reset_password_within => 1.hour do
|
170
|
-
user = create_user
|
171
|
-
user.reset_password_sent_at = 2.days.ago
|
172
|
-
token = user.reset_password_token
|
173
|
-
user.send_reset_password_instructions
|
174
|
-
assert_not_equal token, user.reset_password_token
|
175
|
-
end
|
202
|
+
assert_nil user.reset_password_token
|
176
203
|
end
|
177
204
|
|
178
205
|
test 'should not reset password after reset_password_within time' do
|
179
|
-
swap Devise, :
|
206
|
+
swap Devise, reset_password_within: 1.hour do
|
180
207
|
user = create_user
|
208
|
+
raw = user.send_reset_password_instructions
|
209
|
+
|
181
210
|
old_password = user.password
|
182
|
-
user.send :generate_reset_password_token!
|
183
211
|
user.reset_password_sent_at = 2.days.ago
|
184
212
|
user.save!
|
185
213
|
|
186
214
|
reset_password_user = User.reset_password_by_token(
|
187
|
-
:
|
188
|
-
:
|
189
|
-
:
|
215
|
+
reset_password_token: raw,
|
216
|
+
password: 'new_password',
|
217
|
+
password_confirmation: 'new_password'
|
190
218
|
)
|
191
219
|
user.reload
|
192
220
|
|
@@ -202,4 +230,22 @@ class RecoverableTest < ActiveSupport::TestCase
|
|
202
230
|
:reset_password_token
|
203
231
|
]
|
204
232
|
end
|
233
|
+
|
234
|
+
test 'should return a user based on the raw token' do
|
235
|
+
user = create_user
|
236
|
+
raw = user.send_reset_password_instructions
|
237
|
+
|
238
|
+
assert_equal User.with_reset_password_token(raw), user
|
239
|
+
end
|
240
|
+
|
241
|
+
test 'should return the same reset password token as generated' do
|
242
|
+
user = create_user
|
243
|
+
raw = user.send_reset_password_instructions
|
244
|
+
assert_equal Devise.token_generator.digest(self.class, :reset_password_token, raw), user.reset_password_token
|
245
|
+
end
|
246
|
+
|
247
|
+
test 'should return nil if a user based on the raw token is not found' do
|
248
|
+
assert_equal User.with_reset_password_token('random-token'), nil
|
249
|
+
end
|
250
|
+
|
205
251
|
end
|
@@ -13,6 +13,19 @@ class RememberableTest < ActiveSupport::TestCase
|
|
13
13
|
user = create_user
|
14
14
|
user.expects(:valid?).never
|
15
15
|
user.remember_me!
|
16
|
+
assert user.remember_created_at
|
17
|
+
end
|
18
|
+
|
19
|
+
test 'remember_me should not generate a new token if valid token exists' do
|
20
|
+
user = create_user
|
21
|
+
user.singleton_class.send(:attr_accessor, :remember_token)
|
22
|
+
User.to_adapter.expects(:find_first).returns(nil)
|
23
|
+
|
24
|
+
user.remember_me!
|
25
|
+
existing_token = user.remember_token
|
26
|
+
|
27
|
+
user.remember_me!
|
28
|
+
assert_equal existing_token, user.remember_token
|
16
29
|
end
|
17
30
|
|
18
31
|
test 'forget_me should not clear remember token if using salt' do
|
@@ -22,151 +35,133 @@ class RememberableTest < ActiveSupport::TestCase
|
|
22
35
|
user.forget_me!
|
23
36
|
end
|
24
37
|
|
38
|
+
test 'can generate remember token' do
|
39
|
+
user = create_user
|
40
|
+
user.singleton_class.send(:attr_accessor, :remember_token)
|
41
|
+
User.to_adapter.expects(:find_first).returns(nil)
|
42
|
+
user.remember_me!
|
43
|
+
assert user.remember_token
|
44
|
+
end
|
45
|
+
|
25
46
|
test 'serialize into cookie' do
|
26
47
|
user = create_user
|
27
48
|
user.remember_me!
|
28
|
-
|
49
|
+
id, token, date = User.serialize_into_cookie(user)
|
50
|
+
assert_equal id, user.to_key
|
51
|
+
assert_equal token, user.authenticatable_salt
|
52
|
+
assert date.is_a?(String)
|
29
53
|
end
|
30
54
|
|
31
55
|
test 'serialize from cookie' do
|
32
56
|
user = create_user
|
33
57
|
user.remember_me!
|
34
|
-
assert_equal user, User.serialize_from_cookie(user.to_key, user.authenticatable_salt)
|
58
|
+
assert_equal user, User.serialize_from_cookie(user.to_key, user.authenticatable_salt, Time.now.utc)
|
35
59
|
end
|
36
60
|
|
37
|
-
test '
|
38
|
-
user =
|
39
|
-
user.
|
40
|
-
|
41
|
-
user.rememberable_value
|
42
|
-
end
|
61
|
+
test 'serialize from cookie should accept a String with the datetime seconds and microseconds' do
|
62
|
+
user = create_user
|
63
|
+
user.remember_me!
|
64
|
+
assert_equal user, User.serialize_from_cookie(user.to_key, user.authenticatable_salt, Time.now.utc.to_f.to_json)
|
43
65
|
end
|
44
66
|
|
45
|
-
test 'should
|
46
|
-
|
47
|
-
|
67
|
+
test 'serialize from cookie should return nil with invalid datetime' do
|
68
|
+
user = create_user
|
69
|
+
user.remember_me!
|
70
|
+
assert_nil User.serialize_from_cookie(user.to_key, user.authenticatable_salt, "2013")
|
48
71
|
end
|
49
72
|
|
50
|
-
test '
|
51
|
-
|
52
|
-
resource.remember_me!
|
53
|
-
assert_not resource.remember_created_at.nil?
|
54
|
-
resource.forget_me!
|
55
|
-
assert resource.remember_created_at.nil?
|
73
|
+
test 'serialize from cookie should return nil if no resource is found' do
|
74
|
+
assert_nil resource_class.serialize_from_cookie([0], "123", Time.now.utc)
|
56
75
|
end
|
57
76
|
|
58
|
-
test '
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
resource.expects(:save).never
|
63
|
-
resource.forget_me!
|
77
|
+
test 'serialize from cookie should return nil if no timestamp' do
|
78
|
+
user = create_user
|
79
|
+
user.remember_me!
|
80
|
+
assert_nil User.serialize_from_cookie(user.to_key, user.authenticatable_salt)
|
64
81
|
end
|
65
82
|
|
66
|
-
test '
|
67
|
-
|
83
|
+
test 'serialize from cookie should return nil if timestamp is earlier than token creation' do
|
84
|
+
user = create_user
|
85
|
+
user.remember_me!
|
86
|
+
assert_nil User.serialize_from_cookie(user.to_key, user.authenticatable_salt, 1.day.ago)
|
68
87
|
end
|
69
88
|
|
70
|
-
test 'serialize should return nil if
|
71
|
-
|
89
|
+
test 'serialize from cookie should return nil if timestamp is older than remember_for' do
|
90
|
+
user = create_user
|
91
|
+
user.remember_created_at = 1.month.ago
|
92
|
+
user.remember_me!
|
93
|
+
assert_nil User.serialize_from_cookie(user.to_key, user.authenticatable_salt, 3.weeks.ago)
|
72
94
|
end
|
73
95
|
|
74
|
-
test '
|
75
|
-
|
76
|
-
|
96
|
+
test 'serialize from cookie me return nil if is a valid resource with invalid token' do
|
97
|
+
user = create_user
|
98
|
+
user.remember_me!
|
99
|
+
assert_nil User.serialize_from_cookie(user.to_key, "123", Time.now.utc)
|
77
100
|
end
|
78
101
|
|
79
|
-
test '
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
102
|
+
test 'raises a RuntimeError if authenticatable_salt is nil or empty' do
|
103
|
+
user = User.new
|
104
|
+
def user.authenticable_salt; nil; end
|
105
|
+
assert_raise RuntimeError do
|
106
|
+
user.rememberable_value
|
84
107
|
end
|
85
|
-
end
|
86
108
|
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
assert_equal 3.days.from_now.to_date, resource.remember_expires_at.to_date
|
92
|
-
|
93
|
-
Devise.remember_for = 5.days
|
94
|
-
assert_equal 5.days.from_now.to_date, resource.remember_expires_at.to_date
|
109
|
+
user = User.new
|
110
|
+
def user.authenticable_salt; ""; end
|
111
|
+
assert_raise RuntimeError do
|
112
|
+
user.rememberable_value
|
95
113
|
end
|
96
114
|
end
|
97
115
|
|
98
|
-
test '
|
99
|
-
|
100
|
-
|
101
|
-
resource = create_resource
|
102
|
-
resource.remember_me!
|
103
|
-
assert resource.remember_expired?
|
104
|
-
end
|
116
|
+
test 'should respond to remember_me attribute' do
|
117
|
+
assert resource_class.new.respond_to?(:remember_me)
|
118
|
+
assert resource_class.new.respond_to?(:remember_me=)
|
105
119
|
end
|
106
120
|
|
107
|
-
test '
|
108
|
-
swap Devise, :
|
121
|
+
test 'forget_me should clear remember_created_at if expire_all_remember_me_on_sign_out is true' do
|
122
|
+
swap Devise, expire_all_remember_me_on_sign_out: true do
|
109
123
|
resource = create_resource
|
110
124
|
resource.remember_me!
|
111
|
-
resource.remember_created_at
|
112
|
-
resource.save
|
113
|
-
assert resource.remember_expired?
|
114
|
-
end
|
115
|
-
end
|
125
|
+
assert_not_nil resource.remember_created_at
|
116
126
|
|
117
|
-
|
118
|
-
|
119
|
-
resource = create_resource
|
120
|
-
resource.remember_me!
|
121
|
-
resource.remember_created_at = (30.days.ago + 2.minutes)
|
122
|
-
resource.save
|
123
|
-
assert_not resource.remember_expired?
|
127
|
+
resource.forget_me!
|
128
|
+
assert_nil resource.remember_created_at
|
124
129
|
end
|
125
130
|
end
|
126
131
|
|
127
|
-
test '
|
128
|
-
swap Devise, :
|
132
|
+
test 'forget_me should not clear remember_created_at if expire_all_remember_me_on_sign_out is false' do
|
133
|
+
swap Devise, expire_all_remember_me_on_sign_out: false do
|
129
134
|
resource = create_resource
|
130
|
-
resource.remember_me!
|
131
|
-
assert resource.remember_created_at
|
135
|
+
resource.remember_me!
|
132
136
|
|
133
|
-
resource.remember_created_at
|
134
|
-
resource.save
|
137
|
+
assert_not_nil resource.remember_created_at
|
135
138
|
|
136
|
-
resource.
|
137
|
-
|
139
|
+
resource.forget_me!
|
140
|
+
assert_not_nil resource.remember_created_at
|
138
141
|
end
|
139
142
|
end
|
140
143
|
|
141
|
-
test '
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
assert resource.remember_created_at
|
146
|
-
|
147
|
-
resource.remember_created_at = old = 10.minutes.ago.utc
|
148
|
-
resource.save
|
144
|
+
test 'forget_me should not try to update resource if it has been destroyed' do
|
145
|
+
resource = create_resource
|
146
|
+
resource.expects(:remember_created_at).never
|
147
|
+
resource.expects(:save).never
|
149
148
|
|
150
|
-
|
151
|
-
|
152
|
-
end
|
149
|
+
resource.destroy
|
150
|
+
resource.forget_me!
|
153
151
|
end
|
154
152
|
|
155
|
-
test '
|
156
|
-
swap Devise, :
|
153
|
+
test 'remember expires at uses remember for configuration' do
|
154
|
+
swap Devise, remember_for: 3.days do
|
157
155
|
resource = create_resource
|
158
|
-
resource.remember_me!
|
159
|
-
|
160
|
-
|
161
|
-
resource.remember_created_at = old = 10.minutes.ago
|
162
|
-
resource.save
|
156
|
+
resource.remember_me!
|
157
|
+
assert_equal 3.days.from_now.to_date, resource.remember_expires_at.to_date
|
163
158
|
|
164
|
-
|
165
|
-
|
159
|
+
Devise.remember_for = 5.days
|
160
|
+
assert_equal 5.days.from_now.to_date, resource.remember_expires_at.to_date
|
166
161
|
end
|
167
162
|
end
|
168
163
|
|
169
|
-
test 'should have the
|
164
|
+
test 'should have the required_fields array' do
|
170
165
|
assert_same_content Devise::Models::Rememberable.required_fields(User), [
|
171
166
|
:remember_created_at
|
172
167
|
]
|