loyal_devise 2.1.2 → 2.1.3
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +2 -0
- data/.travis.yml +14 -9
- data/.yardopts +9 -0
- data/CHANGELOG.rdoc +60 -5
- data/CONTRIBUTING.md +4 -2
- data/Gemfile +7 -7
- data/Gemfile.lock +107 -101
- data/MIT-LICENSE +1 -1
- data/README.md +110 -48
- data/Rakefile +1 -0
- data/app/controllers/devise/confirmations_controller.rb +2 -4
- data/app/controllers/devise/omniauth_callbacks_controller.rb +0 -1
- data/app/controllers/devise/passwords_controller.rb +16 -5
- data/app/controllers/devise/registrations_controller.rb +13 -7
- data/app/controllers/devise/sessions_controller.rb +6 -6
- data/app/controllers/devise/unlocks_controller.rb +3 -4
- data/app/controllers/devise_controller.rb +12 -33
- data/app/helpers/devise_helper.rb +0 -1
- data/app/mailers/devise/mailer.rb +7 -8
- data/app/views/devise/mailer/confirmation_instructions.html.erb +1 -1
- data/app/views/devise/mailer/reset_password_instructions.html.erb +1 -1
- data/app/views/devise/registrations/edit.html.erb +5 -1
- data/config/locales/en.yml +48 -48
- data/devise.gemspec +6 -6
- data/devise.png +0 -0
- data/gemfiles/{Gemfile.rails-3.1.x → Gemfile.rails-3.2.x} +8 -12
- data/gemfiles/Gemfile.rails-3.2.x.lock +156 -0
- data/lib/devise.rb +34 -11
- data/lib/devise/controllers/helpers.rb +33 -7
- data/lib/devise/controllers/rememberable.rb +6 -3
- data/lib/devise/controllers/scoped_views.rb +1 -2
- data/lib/devise/controllers/url_helpers.rb +0 -1
- data/lib/devise/delegator.rb +0 -1
- data/lib/devise/failure_app.rb +8 -2
- data/lib/devise/hooks/activatable.rb +1 -2
- data/lib/devise/hooks/forgetable.rb +0 -1
- data/lib/devise/hooks/lockable.rb +1 -2
- data/lib/devise/hooks/rememberable.rb +1 -2
- data/lib/devise/hooks/timeoutable.rb +0 -1
- data/lib/devise/hooks/trackable.rb +0 -1
- data/lib/devise/mailers/helpers.rb +18 -14
- data/lib/devise/mapping.rb +6 -7
- data/lib/devise/models.rb +0 -1
- data/lib/devise/models/authenticatable.rb +50 -27
- data/lib/devise/models/confirmable.rb +37 -16
- data/lib/devise/models/database_authenticatable.rb +17 -3
- data/lib/devise/models/lockable.rb +1 -2
- data/lib/devise/models/omniauthable.rb +1 -2
- data/lib/devise/models/recoverable.rb +10 -6
- data/lib/devise/models/registerable.rb +0 -1
- data/lib/devise/models/rememberable.rb +1 -2
- data/lib/devise/models/timeoutable.rb +1 -2
- data/lib/devise/models/token_authenticatable.rb +0 -1
- data/lib/devise/models/trackable.rb +0 -1
- data/lib/devise/models/validatable.rb +0 -1
- data/lib/devise/modules.rb +1 -2
- data/lib/devise/omniauth.rb +0 -1
- data/lib/devise/omniauth/config.rb +0 -1
- data/lib/devise/omniauth/url_helpers.rb +0 -1
- data/lib/devise/orm/active_record.rb +1 -2
- data/lib/devise/orm/mongoid.rb +1 -2
- data/lib/devise/{param_filter.rb → parameter_filter.rb} +10 -12
- data/lib/devise/parameter_sanitizer.rb +59 -0
- data/lib/devise/rails.rb +0 -1
- data/lib/devise/rails/routes.rb +22 -18
- data/lib/devise/rails/warden_compat.rb +0 -30
- data/lib/devise/strategies/authenticatable.rb +8 -6
- data/lib/devise/strategies/base.rb +1 -2
- data/lib/devise/strategies/database_authenticatable.rb +1 -2
- data/lib/devise/strategies/rememberable.rb +1 -2
- data/lib/devise/strategies/token_authenticatable.rb +38 -4
- data/lib/devise/test_helpers.rb +0 -1
- data/lib/devise/time_inflector.rb +1 -2
- data/lib/devise/version.rb +1 -2
- data/lib/generators/active_record/devise_generator.rb +1 -5
- data/lib/generators/active_record/templates/migration.rb +0 -1
- data/lib/generators/active_record/templates/migration_existing.rb +0 -1
- data/lib/generators/devise/devise_generator.rb +0 -1
- data/lib/generators/devise/install_generator.rb +0 -1
- data/lib/generators/devise/orm_helpers.rb +1 -2
- data/lib/generators/devise/views_generator.rb +8 -3
- data/lib/generators/mongoid/devise_generator.rb +1 -2
- data/lib/generators/templates/README +1 -1
- data/lib/generators/templates/devise.rb +10 -5
- data/lib/generators/templates/markerb/confirmation_instructions.markerb +1 -1
- data/lib/generators/templates/simple_form_for/confirmations/new.html.erb +1 -0
- data/lib/generators/templates/simple_form_for/registrations/edit.html.erb +6 -1
- data/lib/generators/templates/simple_form_for/unlocks/new.html.erb +1 -0
- data/loyal_devise.gemspec +27 -0
- data/test/controllers/custom_strategy_test.rb +0 -1
- data/test/controllers/helpers_test.rb +0 -1
- data/test/controllers/internal_helpers_test.rb +13 -4
- data/test/controllers/passwords_controller_test.rb +32 -0
- data/test/controllers/sessions_controller_test.rb +28 -1
- data/test/controllers/url_helpers_test.rb +0 -1
- data/test/delegator_test.rb +0 -1
- data/test/devise_test.rb +12 -2
- data/test/failure_app_test.rb +3 -4
- data/test/generators/active_record_generator_test.rb +1 -4
- data/test/generators/devise_generator_test.rb +0 -1
- data/test/generators/install_generator_test.rb +0 -1
- data/test/generators/mongoid_generator_test.rb +0 -1
- data/test/generators/views_generator_test.rb +16 -2
- data/test/helpers/devise_helper_test.rb +1 -2
- data/test/integration/authenticatable_test.rb +92 -27
- data/test/integration/confirmable_test.rb +7 -7
- data/test/integration/database_authenticatable_test.rb +8 -7
- data/test/integration/http_authenticatable_test.rb +19 -2
- data/test/integration/lockable_test.rb +1 -2
- data/test/integration/omniauthable_test.rb +2 -3
- data/test/integration/recoverable_test.rb +40 -12
- data/test/integration/registerable_test.rb +17 -14
- data/test/integration/rememberable_test.rb +16 -10
- data/test/integration/timeoutable_test.rb +11 -2
- data/test/integration/token_authenticatable_test.rb +45 -2
- data/test/integration/trackable_test.rb +1 -2
- data/test/mailers/confirmation_instructions_test.rb +11 -3
- data/test/mailers/reset_password_instructions_test.rb +11 -3
- data/test/mailers/unlock_instructions_test.rb +11 -2
- data/test/mapping_test.rb +0 -1
- data/test/models/authenticatable_test.rb +6 -1
- data/test/models/confirmable_test.rb +53 -2
- data/test/models/database_authenticatable_test.rb +57 -21
- data/test/models/lockable_test.rb +1 -2
- data/test/models/omniauthable_test.rb +0 -1
- data/test/models/recoverable_test.rb +21 -5
- data/test/models/registerable_test.rb +0 -1
- data/test/models/rememberable_test.rb +4 -4
- data/test/models/serializable_test.rb +8 -8
- data/test/models/timeoutable_test.rb +0 -1
- data/test/models/token_authenticatable_test.rb +0 -1
- data/test/models/trackable_test.rb +0 -1
- data/test/models/validatable_test.rb +16 -6
- data/test/models_test.rb +7 -24
- data/test/omniauth/config_test.rb +1 -2
- data/test/omniauth/url_helpers_test.rb +4 -2
- data/test/orm/active_record.rb +1 -1
- data/test/orm/mongoid.rb +2 -4
- data/test/parameter_sanitizer_test.rb +51 -0
- data/test/rails_app/Rakefile +0 -4
- data/test/rails_app/app/active_record/admin.rb +0 -1
- data/test/rails_app/app/active_record/shim.rb +1 -2
- data/test/rails_app/app/active_record/user.rb +0 -1
- data/test/rails_app/app/controllers/admins/sessions_controller.rb +1 -2
- data/test/rails_app/app/controllers/admins_controller.rb +0 -1
- data/test/rails_app/app/controllers/application_controller.rb +1 -1
- data/test/rails_app/app/controllers/home_controller.rb +0 -1
- data/test/rails_app/app/controllers/publisher/registrations_controller.rb +1 -2
- data/test/rails_app/app/controllers/publisher/sessions_controller.rb +1 -2
- data/test/rails_app/app/controllers/users/omniauth_callbacks_controller.rb +1 -2
- data/test/rails_app/app/controllers/users_controller.rb +8 -1
- data/test/rails_app/app/helpers/application_helper.rb +0 -1
- data/test/rails_app/app/mailers/users/mailer.rb +4 -1
- data/test/rails_app/app/mongoid/admin.rb +4 -3
- data/test/rails_app/app/mongoid/shim.rb +3 -5
- data/test/rails_app/app/mongoid/user.rb +2 -3
- 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 +1 -3
- data/test/rails_app/config/boot.rb +3 -4
- data/test/rails_app/config/environment.rb +2 -3
- data/test/rails_app/config/environments/development.rb +23 -8
- data/test/rails_app/config/environments/production.rb +68 -18
- data/test/rails_app/config/environments/test.rb +18 -16
- data/test/rails_app/config/initializers/backtrace_silencers.rb +0 -1
- data/test/rails_app/config/initializers/devise.rb +0 -1
- data/test/rails_app/config/initializers/inflections.rb +0 -1
- data/test/rails_app/config/initializers/secret_token.rb +8 -3
- data/test/rails_app/config/initializers/session_store.rb +1 -0
- data/test/rails_app/config/routes.rb +20 -17
- data/test/rails_app/db/migrate/20100401102949_create_tables.rb +0 -1
- data/test/rails_app/db/schema.rb +0 -1
- data/test/rails_app/lib/shared_admin.rb +0 -1
- data/test/rails_app/lib/shared_user.rb +0 -2
- data/test/routes_test.rb +22 -21
- data/test/support/assertions.rb +0 -1
- data/test/support/helpers.rb +1 -2
- data/test/support/integration.rb +0 -1
- data/test/support/webrat/integrations/rails.rb +0 -1
- data/test/test_helper.rb +8 -2
- data/test/test_helpers_test.rb +0 -1
- data/test/test_models.rb +26 -0
- metadata +65 -27
- data/gemfiles/Gemfile.rails-3.1.x.lock +0 -167
- data/test/indifferent_hash.rb +0 -34
- data/test/rails_app/script/rails +0 -10
@@ -1,7 +1,6 @@
|
|
1
|
-
# -*- encoding : utf-8 -*-
|
2
1
|
require 'test_helper'
|
3
2
|
|
4
|
-
class HttpAuthenticationTest <
|
3
|
+
class HttpAuthenticationTest < ActionDispatch::IntegrationTest
|
5
4
|
test 'handles unverified requests gets rid of caches but continues signed in' do
|
6
5
|
swap UsersController, :allow_forgery_protection => true do
|
7
6
|
create_user
|
@@ -63,6 +62,24 @@ class HttpAuthenticationTest < ActionController::IntegrationTest
|
|
63
62
|
end
|
64
63
|
end
|
65
64
|
|
65
|
+
test 'it uses appropriate authentication_keys when configured with hash' do
|
66
|
+
swap Devise, :authentication_keys => ActiveSupport::OrderedHash[:username, false, :email, false] do
|
67
|
+
sign_in_as_new_user_with_http("usertest")
|
68
|
+
assert_response :success
|
69
|
+
assert_match '<email>user@test.com</email>', response.body
|
70
|
+
assert warden.authenticated?(:user)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
test 'it uses the appropriate key when configured explicitly' do
|
75
|
+
swap Devise, :authentication_keys => ActiveSupport::OrderedHash[:email, false, :username, false], :http_authentication_key => :username do
|
76
|
+
sign_in_as_new_user_with_http("usertest")
|
77
|
+
assert_response :success
|
78
|
+
assert_match '<email>user@test.com</email>', response.body
|
79
|
+
assert warden.authenticated?(:user)
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
66
83
|
test 'test request with oauth2 header doesnt get mistaken for basic authentication' do
|
67
84
|
swap Devise, :http_authenticatable => true do
|
68
85
|
add_oauth2_header
|
@@ -1,8 +1,7 @@
|
|
1
|
-
# -*- encoding : utf-8 -*-
|
2
1
|
require 'test_helper'
|
3
2
|
|
4
3
|
|
5
|
-
class OmniauthableIntegrationTest <
|
4
|
+
class OmniauthableIntegrationTest < ActionDispatch::IntegrationTest
|
6
5
|
FACEBOOK_INFO = {
|
7
6
|
"id" => '12345',
|
8
7
|
"link" => 'http://facebook.com/josevalim',
|
@@ -91,7 +90,7 @@ class OmniauthableIntegrationTest < ActionController::IntegrationTest
|
|
91
90
|
end
|
92
91
|
|
93
92
|
assert session["devise.facebook_data"]
|
94
|
-
|
93
|
+
sign_in_as_user
|
95
94
|
assert !session["devise.facebook_data"]
|
96
95
|
end
|
97
96
|
|
@@ -1,7 +1,6 @@
|
|
1
|
-
# -*- encoding : utf-8 -*-
|
2
1
|
require 'test_helper'
|
3
2
|
|
4
|
-
class PasswordTest <
|
3
|
+
class PasswordTest < ActionDispatch::IntegrationTest
|
5
4
|
|
6
5
|
def visit_new_password_path
|
7
6
|
visit new_user_session_path
|
@@ -154,7 +153,8 @@ class PasswordTest < ActionController::IntegrationTest
|
|
154
153
|
assert_response :success
|
155
154
|
assert_current_url '/users/password'
|
156
155
|
assert_have_selector '#error_explanation'
|
157
|
-
assert_contain
|
156
|
+
assert_contain Devise.rails4? ?
|
157
|
+
"Password confirmation doesn't match Password" : "Password doesn't match confirmation"
|
158
158
|
assert_not user.reload.valid_password?('987654321')
|
159
159
|
end
|
160
160
|
|
@@ -191,15 +191,43 @@ class PasswordTest < ActionController::IntegrationTest
|
|
191
191
|
assert warden.authenticated?(:user)
|
192
192
|
end
|
193
193
|
|
194
|
-
test 'does not sign in user automatically after changing its password if it\'s locked' do
|
195
|
-
|
196
|
-
|
197
|
-
|
194
|
+
test 'does not sign in user automatically after changing its password if it\'s locked and unlock strategy is :none or :time' do
|
195
|
+
[:none, :time].each do |strategy|
|
196
|
+
swap Devise, :unlock_strategy => strategy do
|
197
|
+
user = create_user(:locked => true)
|
198
|
+
request_forgot_password
|
199
|
+
reset_password :reset_password_token => user.reload.reset_password_token
|
200
|
+
|
201
|
+
assert_contain 'Your password was changed successfully.'
|
202
|
+
assert_not_contain 'You are now signed in.'
|
203
|
+
assert_equal new_user_session_path, @request.path
|
204
|
+
assert !warden.authenticated?(:user)
|
205
|
+
end
|
206
|
+
end
|
207
|
+
end
|
198
208
|
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
209
|
+
test 'unlocks and signs in locked user automatically after changing it\'s password if unlock strategy is :email' do
|
210
|
+
swap Devise, :unlock_strategy => :email do
|
211
|
+
user = create_user(:locked => true)
|
212
|
+
request_forgot_password
|
213
|
+
reset_password :reset_password_token => user.reload.reset_password_token
|
214
|
+
|
215
|
+
assert_contain 'Your password was changed successfully.'
|
216
|
+
assert !user.reload.access_locked?
|
217
|
+
assert warden.authenticated?(:user)
|
218
|
+
end
|
219
|
+
end
|
220
|
+
|
221
|
+
test 'unlocks and signs in locked user automatically after changing it\'s password if unlock strategy is :both' do
|
222
|
+
swap Devise, :unlock_strategy => :both do
|
223
|
+
user = create_user(:locked => true)
|
224
|
+
request_forgot_password
|
225
|
+
reset_password :reset_password_token => user.reload.reset_password_token
|
226
|
+
|
227
|
+
assert_contain 'Your password was changed successfully.'
|
228
|
+
assert !user.reload.access_locked?
|
229
|
+
assert warden.authenticated?(:user)
|
230
|
+
end
|
203
231
|
end
|
204
232
|
|
205
233
|
test 'sign in user automatically and confirm after changing its password if it\'s not confirmed' do
|
@@ -243,7 +271,7 @@ class PasswordTest < ActionController::IntegrationTest
|
|
243
271
|
end
|
244
272
|
|
245
273
|
test 'change password with invalid token in XML format should return invalid response' do
|
246
|
-
|
274
|
+
create_user
|
247
275
|
request_forgot_password
|
248
276
|
put user_password_path(:format => 'xml'), :user => {:reset_password_token => 'invalid.token', :password => '987654321', :password_confirmation => '987654321'}
|
249
277
|
assert_response :unprocessable_entity
|
@@ -1,7 +1,6 @@
|
|
1
|
-
# -*- encoding : utf-8 -*-
|
2
1
|
require 'test_helper'
|
3
2
|
|
4
|
-
class RegistrationTest <
|
3
|
+
class RegistrationTest < ActionDispatch::IntegrationTest
|
5
4
|
|
6
5
|
test 'a guest admin should be able to sign in successfully' do
|
7
6
|
get new_admin_session_path
|
@@ -18,7 +17,7 @@ class RegistrationTest < ActionController::IntegrationTest
|
|
18
17
|
assert warden.authenticated?(:admin)
|
19
18
|
assert_current_url "/admin_area/home"
|
20
19
|
|
21
|
-
admin = Admin.
|
20
|
+
admin = Admin.order(:id).last
|
22
21
|
assert_equal admin.email, 'new_user@test.com'
|
23
22
|
end
|
24
23
|
|
@@ -57,7 +56,7 @@ class RegistrationTest < ActionController::IntegrationTest
|
|
57
56
|
|
58
57
|
assert_not warden.authenticated?(:user)
|
59
58
|
|
60
|
-
user = User.
|
59
|
+
user = User.order(:id).last
|
61
60
|
assert_equal user.email, 'new_user@test.com'
|
62
61
|
assert_not user.confirmed?
|
63
62
|
end
|
@@ -101,7 +100,8 @@ class RegistrationTest < ActionController::IntegrationTest
|
|
101
100
|
assert_template 'registrations/new'
|
102
101
|
assert_have_selector '#error_explanation'
|
103
102
|
assert_contain "Email is invalid"
|
104
|
-
assert_contain
|
103
|
+
assert_contain Devise.rails4? ?
|
104
|
+
"Password confirmation doesn't match Password" : "Password doesn't match confirmation"
|
105
105
|
assert_contain "2 errors prohibited"
|
106
106
|
assert_nil User.first
|
107
107
|
|
@@ -113,7 +113,7 @@ class RegistrationTest < ActionController::IntegrationTest
|
|
113
113
|
# https://github.com/mongoid/mongoid/issues/756
|
114
114
|
(pending "Fails on Mongoid < 2.1"; break) if defined?(Mongoid) && Mongoid::VERSION.to_f < 2.1
|
115
115
|
|
116
|
-
|
116
|
+
create_user
|
117
117
|
get new_user_registration_path
|
118
118
|
|
119
119
|
fill_in 'email', :with => 'user@test.com'
|
@@ -204,10 +204,11 @@ class RegistrationTest < ActionController::IntegrationTest
|
|
204
204
|
|
205
205
|
fill_in 'password', :with => 'pas123'
|
206
206
|
fill_in 'password confirmation', :with => ''
|
207
|
-
fill_in 'current password', :with => '
|
207
|
+
fill_in 'current password', :with => '12345678'
|
208
208
|
click_button 'Update'
|
209
209
|
|
210
|
-
assert_contain
|
210
|
+
assert_contain Devise.rails4? ?
|
211
|
+
"Password confirmation doesn't match Password" : "Password doesn't match confirmation"
|
211
212
|
assert_not User.first.valid_password?('pas123')
|
212
213
|
end
|
213
214
|
|
@@ -215,7 +216,7 @@ class RegistrationTest < ActionController::IntegrationTest
|
|
215
216
|
sign_in_as_user
|
216
217
|
get edit_user_registration_path
|
217
218
|
|
218
|
-
|
219
|
+
click_button "Cancel my account"
|
219
220
|
assert_contain "Bye! Your account was successfully cancelled. We hope to see you again soon."
|
220
221
|
|
221
222
|
assert User.all.empty?
|
@@ -252,7 +253,7 @@ class RegistrationTest < ActionController::IntegrationTest
|
|
252
253
|
assert_response :success
|
253
254
|
assert response.body.include? %(<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<admin>)
|
254
255
|
|
255
|
-
admin = Admin.
|
256
|
+
admin = Admin.order(:id).last
|
256
257
|
assert_equal admin.email, 'new_user@test.com'
|
257
258
|
end
|
258
259
|
|
@@ -261,7 +262,7 @@ class RegistrationTest < ActionController::IntegrationTest
|
|
261
262
|
assert_response :success
|
262
263
|
assert response.body.include? %(<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<user>)
|
263
264
|
|
264
|
-
user = User.
|
265
|
+
user = User.order(:id).last
|
265
266
|
assert_equal user.email, 'new_user@test.com'
|
266
267
|
end
|
267
268
|
|
@@ -286,14 +287,14 @@ class RegistrationTest < ActionController::IntegrationTest
|
|
286
287
|
end
|
287
288
|
|
288
289
|
test 'a user cancel his account in XML format should return valid response' do
|
289
|
-
|
290
|
+
sign_in_as_user
|
290
291
|
delete user_registration_path(:format => 'xml')
|
291
292
|
assert_response :success
|
292
293
|
assert_equal User.count, 0
|
293
294
|
end
|
294
295
|
end
|
295
296
|
|
296
|
-
class ReconfirmableRegistrationTest <
|
297
|
+
class ReconfirmableRegistrationTest < ActionDispatch::IntegrationTest
|
297
298
|
test 'a signed in admin should see a more appropriate flash message when editing his account if reconfirmable is enabled' do
|
298
299
|
sign_in_as_admin
|
299
300
|
get edit_admin_registration_path
|
@@ -304,8 +305,10 @@ class ReconfirmableRegistrationTest < ActionController::IntegrationTest
|
|
304
305
|
|
305
306
|
assert_current_url '/admin_area/home'
|
306
307
|
assert_contain 'but we need to verify your new email address'
|
308
|
+
assert_equal 'admin.new@example.com', Admin.first.unconfirmed_email
|
307
309
|
|
308
|
-
|
310
|
+
get edit_admin_registration_path
|
311
|
+
assert_contain 'Currently waiting confirmation for: admin.new@example.com'
|
309
312
|
end
|
310
313
|
|
311
314
|
test 'a signed in admin should not see a reconfirmation message if they did not change their password' do
|
@@ -1,7 +1,6 @@
|
|
1
|
-
# -*- encoding : utf-8 -*-
|
2
1
|
require 'test_helper'
|
3
2
|
|
4
|
-
class RememberMeTest <
|
3
|
+
class RememberMeTest < ActionDispatch::IntegrationTest
|
5
4
|
def create_user_and_remember(add_to_token='')
|
6
5
|
user = create_user
|
7
6
|
user.remember_me!
|
@@ -27,7 +26,7 @@ class RememberMeTest < ActionController::IntegrationTest
|
|
27
26
|
end
|
28
27
|
|
29
28
|
test 'do not remember the user if he has not checked remember me option' do
|
30
|
-
|
29
|
+
sign_in_as_user
|
31
30
|
assert_nil request.cookies["remember_user_cookie"]
|
32
31
|
end
|
33
32
|
|
@@ -44,7 +43,7 @@ class RememberMeTest < ActionController::IntegrationTest
|
|
44
43
|
end
|
45
44
|
|
46
45
|
test 'generate remember token after sign in' do
|
47
|
-
|
46
|
+
sign_in_as_user :remember_me => true
|
48
47
|
assert request.cookies["remember_user_token"]
|
49
48
|
end
|
50
49
|
|
@@ -58,6 +57,13 @@ class RememberMeTest < ActionController::IntegrationTest
|
|
58
57
|
end
|
59
58
|
end
|
60
59
|
|
60
|
+
test 'generate remember token with a custom key' do
|
61
|
+
swap Devise, :rememberable_options => { :key => "v1lat_token" } do
|
62
|
+
user = sign_in_as_user :remember_me => true
|
63
|
+
assert request.cookies["v1lat_token"]
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
61
67
|
test 'generate remember token after sign in setting session options' do
|
62
68
|
begin
|
63
69
|
Rails.configuration.session_options[:domain] = "omg.somewhere.com"
|
@@ -78,7 +84,7 @@ class RememberMeTest < ActionController::IntegrationTest
|
|
78
84
|
end
|
79
85
|
|
80
86
|
test 'remember the user before sign up and redirect him to his home' do
|
81
|
-
|
87
|
+
create_user_and_remember
|
82
88
|
get new_user_registration_path
|
83
89
|
assert warden.authenticated?(:user)
|
84
90
|
assert_redirected_to root_path
|
@@ -86,7 +92,7 @@ class RememberMeTest < ActionController::IntegrationTest
|
|
86
92
|
|
87
93
|
test 'cookies are destroyed on unverified requests' do
|
88
94
|
swap ApplicationController, :allow_forgery_protection => true do
|
89
|
-
|
95
|
+
create_user_and_remember
|
90
96
|
get users_path
|
91
97
|
assert warden.authenticated?(:user)
|
92
98
|
post root_path, :authenticity_token => 'INVALID'
|
@@ -111,7 +117,7 @@ class RememberMeTest < ActionController::IntegrationTest
|
|
111
117
|
end
|
112
118
|
|
113
119
|
test 'do not remember other scopes' do
|
114
|
-
|
120
|
+
create_user_and_remember
|
115
121
|
get root_path
|
116
122
|
assert_response :success
|
117
123
|
assert warden.authenticated?(:user)
|
@@ -119,14 +125,14 @@ class RememberMeTest < ActionController::IntegrationTest
|
|
119
125
|
end
|
120
126
|
|
121
127
|
test 'do not remember with invalid token' do
|
122
|
-
|
128
|
+
create_user_and_remember('add')
|
123
129
|
get users_path
|
124
130
|
assert_not warden.authenticated?(:user)
|
125
131
|
assert_redirected_to new_user_session_path
|
126
132
|
end
|
127
133
|
|
128
134
|
test 'do not remember with expired token' do
|
129
|
-
|
135
|
+
create_user_and_remember
|
130
136
|
swap Devise, :remember_for => 0 do
|
131
137
|
get users_path
|
132
138
|
assert_not warden.authenticated?(:user)
|
@@ -135,7 +141,7 @@ class RememberMeTest < ActionController::IntegrationTest
|
|
135
141
|
end
|
136
142
|
|
137
143
|
test 'do not remember the user anymore after forget' do
|
138
|
-
|
144
|
+
create_user_and_remember
|
139
145
|
get users_path
|
140
146
|
assert warden.authenticated?(:user)
|
141
147
|
|
@@ -1,7 +1,6 @@
|
|
1
|
-
# -*- encoding : utf-8 -*-
|
2
1
|
require 'test_helper'
|
3
2
|
|
4
|
-
class SessionTimeoutTest <
|
3
|
+
class SessionTimeoutTest < ActionDispatch::IntegrationTest
|
5
4
|
|
6
5
|
def last_request_at
|
7
6
|
@controller.user_session['last_request_at']
|
@@ -46,6 +45,16 @@ class SessionTimeoutTest < ActionController::IntegrationTest
|
|
46
45
|
assert_not warden.authenticated?(:user)
|
47
46
|
end
|
48
47
|
|
48
|
+
test 'time out user session after deault limit time and redirect to latest get request' do
|
49
|
+
user = sign_in_as_user
|
50
|
+
visit edit_form_user_path(user)
|
51
|
+
|
52
|
+
click_button 'Update'
|
53
|
+
sign_in_as_user
|
54
|
+
|
55
|
+
assert_equal edit_form_user_url(user), current_url
|
56
|
+
end
|
57
|
+
|
49
58
|
test 'time out is not triggered on sign out' do
|
50
59
|
user = sign_in_as_user
|
51
60
|
get expire_user_path(user)
|
@@ -1,7 +1,6 @@
|
|
1
|
-
# -*- encoding : utf-8 -*-
|
2
1
|
require 'test_helper'
|
3
2
|
|
4
|
-
class TokenAuthenticationTest <
|
3
|
+
class TokenAuthenticationTest < ActionDispatch::IntegrationTest
|
5
4
|
|
6
5
|
test 'authenticate with valid authentication token key and value through params' do
|
7
6
|
swap Devise, :token_authentication_key => :secret_token do
|
@@ -130,6 +129,46 @@ class TokenAuthenticationTest < ActionController::IntegrationTest
|
|
130
129
|
end
|
131
130
|
end
|
132
131
|
|
132
|
+
test 'authenticate with valid authentication token key and value through http header' do
|
133
|
+
swap Devise, :token_authentication_key => :secret_token do
|
134
|
+
sign_in_as_new_user_with_token(:token_auth => true)
|
135
|
+
|
136
|
+
assert_response :success
|
137
|
+
assert_match '<email>user@test.com</email>', response.body
|
138
|
+
assert_equal request.env['devise.token_options'], {}
|
139
|
+
assert warden.authenticated?(:user)
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
test 'authenticate with valid authentication token key and value through http header, with options' do
|
144
|
+
swap Devise, :token_authentication_key => :secret_token, :http_authenticatable => [:token_options] do
|
145
|
+
signature = "**TESTSIGNATURE**"
|
146
|
+
sign_in_as_new_user_with_token(:token_auth => true, :token_options => {:signature => signature, :nonce => 'def'})
|
147
|
+
|
148
|
+
assert_response :success
|
149
|
+
assert_match '<email>user@test.com</email>', response.body
|
150
|
+
assert_equal request.env['devise.token_options'][:signature], signature
|
151
|
+
assert_equal request.env['devise.token_options'][:nonce], 'def'
|
152
|
+
assert warden.authenticated?(:user)
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
156
|
+
test 'authenticate with valid authentication token key and value through http header without allowing token authorization setting is denied' do
|
157
|
+
swap Devise, :token_authentication_key => :secret_token, :http_authenticatable => false do
|
158
|
+
sign_in_as_new_user_with_token(:token_auth => true)
|
159
|
+
|
160
|
+
assert_response :unauthorized
|
161
|
+
assert_nil warden.user(:user)
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
165
|
+
test 'does not authenticate with improper authentication token value in header' do
|
166
|
+
sign_in_as_new_user_with_token(:token_auth => true, :auth_token => '*** INVALID TOKEN ***')
|
167
|
+
|
168
|
+
assert_response :unauthorized
|
169
|
+
assert_nil warden.user(:user)
|
170
|
+
end
|
171
|
+
|
133
172
|
private
|
134
173
|
|
135
174
|
def sign_in_as_new_user_with_token(options = {})
|
@@ -141,6 +180,10 @@ class TokenAuthenticationTest < ActionController::IntegrationTest
|
|
141
180
|
if options[:http_auth]
|
142
181
|
header = "Basic #{Base64.encode64("#{VALID_AUTHENTICATION_TOKEN}:X")}"
|
143
182
|
get users_path(:format => :xml), {}, "HTTP_AUTHORIZATION" => header
|
183
|
+
elsif options[:token_auth]
|
184
|
+
token_options = options[:token_options] || {}
|
185
|
+
header = ActionController::HttpAuthentication::Token.encode_credentials(options[:auth_token], token_options)
|
186
|
+
get users_path(:format => :xml), {}, "HTTP_AUTHORIZATION" => header
|
144
187
|
else
|
145
188
|
visit users_path(options[:auth_token_key].to_sym => options[:auth_token])
|
146
189
|
end
|
@@ -1,7 +1,6 @@
|
|
1
|
-
# -*- encoding : utf-8 -*-
|
2
1
|
require 'test_helper'
|
3
2
|
|
4
|
-
class TrackableHooksTest <
|
3
|
+
class TrackableHooksTest < ActionDispatch::IntegrationTest
|
5
4
|
|
6
5
|
test "current and last sign in timestamps are updated on each sign in" do
|
7
6
|
user = create_user
|
@@ -1,4 +1,3 @@
|
|
1
|
-
# -*- encoding : utf-8 -*-
|
2
1
|
require 'test_helper'
|
3
2
|
|
4
3
|
class ConfirmationInstructionsTest < ActionMailer::TestCase
|
@@ -47,6 +46,16 @@ class ConfirmationInstructionsTest < ActionMailer::TestCase
|
|
47
46
|
assert_equal ['custom@example.com'], mail.from
|
48
47
|
end
|
49
48
|
|
49
|
+
test 'setup sender from custom mailer defaults with proc' do
|
50
|
+
Devise.mailer = 'Users::FromProcMailer'
|
51
|
+
assert_equal ['custom@example.com'], mail.from
|
52
|
+
end
|
53
|
+
|
54
|
+
test 'custom mailer renders parent mailer template' do
|
55
|
+
Devise.mailer = 'Users::Mailer'
|
56
|
+
assert_not_blank mail.body.encoded
|
57
|
+
end
|
58
|
+
|
50
59
|
test 'setup reply to as copy from sender' do
|
51
60
|
assert_equal ['test@example.com'], mail.reply_to
|
52
61
|
end
|
@@ -57,7 +66,6 @@ class ConfirmationInstructionsTest < ActionMailer::TestCase
|
|
57
66
|
assert_equal ['custom_reply_to@example.com'], mail.reply_to
|
58
67
|
end
|
59
68
|
|
60
|
-
|
61
69
|
test 'setup subject from I18n' do
|
62
70
|
store_translations :en, :devise => { :mailer => { :confirmation_instructions => { :subject => 'Account Confirmation' } } } do
|
63
71
|
assert_equal 'Account Confirmation', mail.subject
|
@@ -71,7 +79,7 @@ class ConfirmationInstructionsTest < ActionMailer::TestCase
|
|
71
79
|
end
|
72
80
|
|
73
81
|
test 'body should have user info' do
|
74
|
-
assert_match
|
82
|
+
assert_match user.email, mail.body.encoded
|
75
83
|
end
|
76
84
|
|
77
85
|
test 'body should have link to confirm the account' do
|