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
@@ -1,10 +1,15 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
|
-
class RememberMeTest <
|
3
|
+
class RememberMeTest < ActionDispatch::IntegrationTest
|
4
|
+
if (Rails::VERSION::MAJOR < 4) || (Rails::VERSION::MAJOR >= 4 && Rails::VERSION::MINOR < 1)
|
5
|
+
require 'time_helpers'
|
6
|
+
include ActiveSupport::Testing::TimeHelpers
|
7
|
+
end
|
8
|
+
|
4
9
|
def create_user_and_remember(add_to_token='')
|
5
10
|
user = create_user
|
6
11
|
user.remember_me!
|
7
|
-
raw_cookie = User.serialize_into_cookie(user).tap { |a| a
|
12
|
+
raw_cookie = User.serialize_into_cookie(user).tap { |a| a[1] << add_to_token }
|
8
13
|
cookies['remember_user_token'] = generate_signed_cookie(raw_cookie)
|
9
14
|
user
|
10
15
|
end
|
@@ -25,13 +30,13 @@ class RememberMeTest < ActionController::IntegrationTest
|
|
25
30
|
Time.parse(expires).utc
|
26
31
|
end
|
27
32
|
|
28
|
-
test 'do not remember the user if
|
29
|
-
|
33
|
+
test 'do not remember the user if they have not checked remember me option' do
|
34
|
+
sign_in_as_user
|
30
35
|
assert_nil request.cookies["remember_user_cookie"]
|
31
36
|
end
|
32
37
|
|
33
|
-
test '
|
34
|
-
swap
|
38
|
+
test 'handle unverified requests gets rid of caches' do
|
39
|
+
swap ApplicationController, allow_forgery_protection: true do
|
35
40
|
post exhibit_user_url(1)
|
36
41
|
assert_not warden.authenticated?(:user)
|
37
42
|
|
@@ -42,25 +47,44 @@ class RememberMeTest < ActionController::IntegrationTest
|
|
42
47
|
end
|
43
48
|
end
|
44
49
|
|
50
|
+
test 'handle unverified requests does not create cookies on sign in' do
|
51
|
+
swap ApplicationController, allow_forgery_protection: true do
|
52
|
+
get new_user_session_path
|
53
|
+
assert request.session[:_csrf_token]
|
54
|
+
|
55
|
+
post user_session_path, authenticity_token: "oops", user:
|
56
|
+
{ email: "jose.valim@gmail.com", password: "123456", remember_me: "1" }
|
57
|
+
assert_not warden.authenticated?(:user)
|
58
|
+
assert_not request.cookies['remember_user_token']
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
45
62
|
test 'generate remember token after sign in' do
|
46
|
-
|
47
|
-
assert request.cookies[
|
63
|
+
sign_in_as_user remember_me: true
|
64
|
+
assert request.cookies['remember_user_token']
|
48
65
|
end
|
49
66
|
|
50
67
|
test 'generate remember token after sign in setting cookie options' do
|
51
68
|
# We test this by asserting the cookie is not sent after the redirect
|
52
69
|
# since we changed the domain. This is the only difference with the
|
53
70
|
# previous test.
|
54
|
-
swap Devise, :
|
55
|
-
|
71
|
+
swap Devise, rememberable_options: { domain: "omg.somewhere.com" } do
|
72
|
+
sign_in_as_user remember_me: true
|
56
73
|
assert_nil request.cookies["remember_user_token"]
|
57
74
|
end
|
58
75
|
end
|
59
76
|
|
77
|
+
test 'generate remember token with a custom key' do
|
78
|
+
swap Devise, rememberable_options: { key: "v1lat_token" } do
|
79
|
+
sign_in_as_user remember_me: true
|
80
|
+
assert request.cookies["v1lat_token"]
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
60
84
|
test 'generate remember token after sign in setting session options' do
|
61
85
|
begin
|
62
86
|
Rails.configuration.session_options[:domain] = "omg.somewhere.com"
|
63
|
-
|
87
|
+
sign_in_as_user remember_me: true
|
64
88
|
assert_nil request.cookies["remember_user_token"]
|
65
89
|
ensure
|
66
90
|
Rails.configuration.session_options.delete(:domain)
|
@@ -73,35 +97,24 @@ class RememberMeTest < ActionController::IntegrationTest
|
|
73
97
|
assert_response :success
|
74
98
|
assert warden.authenticated?(:user)
|
75
99
|
assert warden.user(:user) == user
|
76
|
-
assert_match /remember_user_token[^\n]*HttpOnly/, response.headers["Set-Cookie"], "Expected Set-Cookie header in response to set HttpOnly flag on remember_user_token cookie."
|
77
100
|
end
|
78
101
|
|
79
|
-
test 'remember the user before sign up and redirect
|
80
|
-
|
102
|
+
test 'remember the user before sign up and redirect them to their home' do
|
103
|
+
create_user_and_remember
|
81
104
|
get new_user_registration_path
|
82
105
|
assert warden.authenticated?(:user)
|
83
106
|
assert_redirected_to root_path
|
84
107
|
end
|
85
108
|
|
86
|
-
test 'cookies are destroyed on unverified requests' do
|
87
|
-
swap ApplicationController, :allow_forgery_protection => true do
|
88
|
-
user = create_user_and_remember
|
89
|
-
get users_path
|
90
|
-
assert warden.authenticated?(:user)
|
91
|
-
post root_path, :authenticity_token => 'INVALID'
|
92
|
-
assert_not warden.authenticated?(:user)
|
93
|
-
end
|
94
|
-
end
|
95
|
-
|
96
109
|
test 'does not extend remember period through sign in' do
|
97
|
-
swap Devise, :
|
110
|
+
swap Devise, extend_remember_period: true, remember_for: 1.year do
|
98
111
|
user = create_user
|
99
112
|
user.remember_me!
|
100
113
|
|
101
114
|
user.remember_created_at = old = 10.days.ago
|
102
115
|
user.save
|
103
116
|
|
104
|
-
sign_in_as_user :
|
117
|
+
sign_in_as_user remember_me: true
|
105
118
|
user.reload
|
106
119
|
|
107
120
|
assert warden.user(:user) == user
|
@@ -109,8 +122,42 @@ class RememberMeTest < ActionController::IntegrationTest
|
|
109
122
|
end
|
110
123
|
end
|
111
124
|
|
125
|
+
test 'extends remember period when extend remember period config is true' do
|
126
|
+
swap Devise, extend_remember_period: true, remember_for: 1.year do
|
127
|
+
user = create_user_and_remember
|
128
|
+
old_remember_token = nil
|
129
|
+
|
130
|
+
travel_to 1.day.ago do
|
131
|
+
get root_path
|
132
|
+
old_remember_token = request.cookies['remember_user_token']
|
133
|
+
end
|
134
|
+
|
135
|
+
get root_path
|
136
|
+
current_remember_token = request.cookies['remember_user_token']
|
137
|
+
|
138
|
+
refute_equal old_remember_token, current_remember_token
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
test 'does not extend remember period when extend period config is false' do
|
143
|
+
swap Devise, extend_remember_period: false, remember_for: 1.year do
|
144
|
+
user = create_user_and_remember
|
145
|
+
old_remember_token = nil
|
146
|
+
|
147
|
+
travel_to 1.day.ago do
|
148
|
+
get root_path
|
149
|
+
old_remember_token = request.cookies['remember_user_token']
|
150
|
+
end
|
151
|
+
|
152
|
+
get root_path
|
153
|
+
current_remember_token = request.cookies['remember_user_token']
|
154
|
+
|
155
|
+
assert_equal old_remember_token, current_remember_token
|
156
|
+
end
|
157
|
+
end
|
158
|
+
|
112
159
|
test 'do not remember other scopes' do
|
113
|
-
|
160
|
+
create_user_and_remember
|
114
161
|
get root_path
|
115
162
|
assert_response :success
|
116
163
|
assert warden.authenticated?(:user)
|
@@ -118,15 +165,15 @@ class RememberMeTest < ActionController::IntegrationTest
|
|
118
165
|
end
|
119
166
|
|
120
167
|
test 'do not remember with invalid token' do
|
121
|
-
|
168
|
+
create_user_and_remember('add')
|
122
169
|
get users_path
|
123
170
|
assert_not warden.authenticated?(:user)
|
124
171
|
assert_redirected_to new_user_session_path
|
125
172
|
end
|
126
173
|
|
127
174
|
test 'do not remember with expired token' do
|
128
|
-
|
129
|
-
swap Devise, :
|
175
|
+
create_user_and_remember
|
176
|
+
swap Devise, remember_for: 0.days do
|
130
177
|
get users_path
|
131
178
|
assert_not warden.authenticated?(:user)
|
132
179
|
assert_redirected_to new_user_session_path
|
@@ -134,7 +181,7 @@ class RememberMeTest < ActionController::IntegrationTest
|
|
134
181
|
end
|
135
182
|
|
136
183
|
test 'do not remember the user anymore after forget' do
|
137
|
-
|
184
|
+
create_user_and_remember
|
138
185
|
get users_path
|
139
186
|
assert warden.authenticated?(:user)
|
140
187
|
|
@@ -155,4 +202,13 @@ class RememberMeTest < ActionController::IntegrationTest
|
|
155
202
|
get users_path
|
156
203
|
assert_not warden.authenticated?(:user)
|
157
204
|
end
|
205
|
+
|
206
|
+
test 'valid sign in calls after_remembered callback' do
|
207
|
+
user = create_user_and_remember
|
208
|
+
|
209
|
+
User.expects(:serialize_from_cookie).returns user
|
210
|
+
user.expects :after_remembered
|
211
|
+
|
212
|
+
get new_user_registration_path
|
213
|
+
end
|
158
214
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
|
-
class SessionTimeoutTest <
|
3
|
+
class SessionTimeoutTest < ActionDispatch::IntegrationTest
|
4
4
|
|
5
5
|
def last_request_at
|
6
6
|
@controller.user_session['last_request_at']
|
@@ -8,12 +8,11 @@ class SessionTimeoutTest < ActionController::IntegrationTest
|
|
8
8
|
|
9
9
|
test 'set last request at in user session after each request' do
|
10
10
|
sign_in_as_user
|
11
|
-
old_last_request = last_request_at
|
12
11
|
assert_not_nil last_request_at
|
13
12
|
|
13
|
+
@controller.user_session.delete('last_request_at')
|
14
14
|
get users_path
|
15
15
|
assert_not_nil last_request_at
|
16
|
-
assert_not_equal old_last_request, last_request_at
|
17
16
|
end
|
18
17
|
|
19
18
|
test 'set last request at in user session after each request is skipped if tracking is disabled' do
|
@@ -25,6 +24,18 @@ class SessionTimeoutTest < ActionController::IntegrationTest
|
|
25
24
|
assert_equal old_last_request, last_request_at
|
26
25
|
end
|
27
26
|
|
27
|
+
test 'does not set last request at in user session after each request if timeoutable is disabled' do
|
28
|
+
sign_in_as_user
|
29
|
+
old_last_request = last_request_at
|
30
|
+
assert_not_nil last_request_at
|
31
|
+
|
32
|
+
new_time = 2.seconds.from_now
|
33
|
+
Time.stubs(:now).returns(new_time)
|
34
|
+
|
35
|
+
get users_path, {}, 'devise.skip_timeoutable' => true
|
36
|
+
assert_equal old_last_request, last_request_at
|
37
|
+
end
|
38
|
+
|
28
39
|
test 'does not time out user session before default limit time' do
|
29
40
|
sign_in_as_user
|
30
41
|
assert_response :success
|
@@ -35,14 +46,43 @@ class SessionTimeoutTest < ActionController::IntegrationTest
|
|
35
46
|
assert warden.authenticated?(:user)
|
36
47
|
end
|
37
48
|
|
38
|
-
test 'time out user session after default limit time' do
|
49
|
+
test 'time out user session after default limit time when sign_out_all_scopes is false' do
|
50
|
+
swap Devise, sign_out_all_scopes: false do
|
51
|
+
sign_in_as_admin
|
52
|
+
|
53
|
+
user = sign_in_as_user
|
54
|
+
get expire_user_path(user)
|
55
|
+
assert_not_nil last_request_at
|
56
|
+
|
57
|
+
get users_path
|
58
|
+
assert_redirected_to users_path
|
59
|
+
assert_not warden.authenticated?(:user)
|
60
|
+
assert warden.authenticated?(:admin)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
test 'time out all sessions after default limit time when sign_out_all_scopes is true' do
|
65
|
+
swap Devise, sign_out_all_scopes: true do
|
66
|
+
sign_in_as_admin
|
67
|
+
|
68
|
+
user = sign_in_as_user
|
69
|
+
get expire_user_path(user)
|
70
|
+
assert_not_nil last_request_at
|
71
|
+
|
72
|
+
get root_path
|
73
|
+
assert_not warden.authenticated?(:user)
|
74
|
+
assert_not warden.authenticated?(:admin)
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
test 'time out user session after deault limit time and redirect to latest get request' do
|
39
79
|
user = sign_in_as_user
|
40
|
-
|
41
|
-
assert_not_nil last_request_at
|
80
|
+
visit edit_form_user_path(user)
|
42
81
|
|
43
|
-
|
44
|
-
|
45
|
-
|
82
|
+
click_button 'Update'
|
83
|
+
sign_in_as_user
|
84
|
+
|
85
|
+
assert_equal edit_form_user_url(user), current_url
|
46
86
|
end
|
47
87
|
|
48
88
|
test 'time out is not triggered on sign out' do
|
@@ -57,36 +97,33 @@ class SessionTimeoutTest < ActionController::IntegrationTest
|
|
57
97
|
assert_contain 'Signed out successfully'
|
58
98
|
end
|
59
99
|
|
60
|
-
test '
|
100
|
+
test 'expired session is not extended by sign in page' do
|
61
101
|
user = sign_in_as_user
|
62
102
|
get expire_user_path(user)
|
103
|
+
assert warden.authenticated?(:user)
|
63
104
|
|
64
|
-
|
65
|
-
|
66
|
-
assert_response :redirect
|
105
|
+
get "/users/sign_in"
|
106
|
+
assert_redirected_to "/users/sign_in"
|
67
107
|
follow_redirect!
|
68
|
-
|
108
|
+
|
109
|
+
assert_response :success
|
110
|
+
assert_contain 'Sign in'
|
111
|
+
assert_not warden.authenticated?(:user)
|
69
112
|
end
|
70
113
|
|
71
|
-
test '
|
72
|
-
|
73
|
-
get
|
114
|
+
test 'time out is not triggered on sign in' do
|
115
|
+
user = sign_in_as_user
|
116
|
+
get expire_user_path(user)
|
74
117
|
|
75
|
-
|
76
|
-
nil
|
77
|
-
end
|
118
|
+
post "/users/sign_in", email: user.email, password: "123456"
|
78
119
|
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
assert_not warden.authenticated?(:admin)
|
83
|
-
ensure
|
84
|
-
Admin.send(:remove_method, :reset_authentication_token!)
|
85
|
-
end
|
120
|
+
assert_response :redirect
|
121
|
+
follow_redirect!
|
122
|
+
assert_contain 'You are signed in'
|
86
123
|
end
|
87
124
|
|
88
125
|
test 'user configured timeout limit' do
|
89
|
-
swap Devise, :
|
126
|
+
swap Devise, timeout_in: 8.minutes do
|
90
127
|
user = sign_in_as_user
|
91
128
|
|
92
129
|
get users_path
|
@@ -102,8 +139,8 @@ class SessionTimeoutTest < ActionController::IntegrationTest
|
|
102
139
|
end
|
103
140
|
|
104
141
|
test 'error message with i18n' do
|
105
|
-
store_translations :en, :
|
106
|
-
:
|
142
|
+
store_translations :en, devise: {
|
143
|
+
failure: { user: { timeout: 'Session expired!' } }
|
107
144
|
} do
|
108
145
|
user = sign_in_as_user
|
109
146
|
|
@@ -115,8 +152,8 @@ class SessionTimeoutTest < ActionController::IntegrationTest
|
|
115
152
|
end
|
116
153
|
|
117
154
|
test 'error message with i18n with double redirect' do
|
118
|
-
store_translations :en, :
|
119
|
-
:
|
155
|
+
store_translations :en, devise: {
|
156
|
+
failure: { user: { timeout: 'Session expired!' } }
|
120
157
|
} do
|
121
158
|
user = sign_in_as_user
|
122
159
|
|
@@ -129,7 +166,7 @@ class SessionTimeoutTest < ActionController::IntegrationTest
|
|
129
166
|
end
|
130
167
|
|
131
168
|
test 'time out not triggered if remembered' do
|
132
|
-
user = sign_in_as_user :
|
169
|
+
user = sign_in_as_user remember_me: true
|
133
170
|
get expire_user_path(user)
|
134
171
|
assert_not_nil last_request_at
|
135
172
|
|
@@ -137,4 +174,11 @@ class SessionTimeoutTest < ActionController::IntegrationTest
|
|
137
174
|
assert_response :success
|
138
175
|
assert warden.authenticated?(:user)
|
139
176
|
end
|
177
|
+
|
178
|
+
test 'does not crash when the last_request_at is a String' do
|
179
|
+
user = sign_in_as_user
|
180
|
+
|
181
|
+
get edit_form_user_path(user, last_request_at: Time.now.utc.to_s)
|
182
|
+
get users_path
|
183
|
+
end
|
140
184
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
|
-
class TrackableHooksTest <
|
3
|
+
class TrackableHooksTest < ActionDispatch::IntegrationTest
|
4
4
|
|
5
5
|
test "current and last sign in timestamps are updated on each sign in" do
|
6
6
|
user = create_user
|
@@ -10,8 +10,8 @@ class TrackableHooksTest < ActionController::IntegrationTest
|
|
10
10
|
sign_in_as_user
|
11
11
|
user.reload
|
12
12
|
|
13
|
-
|
14
|
-
|
13
|
+
assert user.current_sign_in_at.acts_like?(:time)
|
14
|
+
assert user.last_sign_in_at.acts_like?(:time)
|
15
15
|
|
16
16
|
assert_equal user.current_sign_in_at, user.last_sign_in_at
|
17
17
|
assert user.current_sign_in_at >= user.created_at
|
@@ -63,8 +63,8 @@ class TrackableHooksTest < ActionController::IntegrationTest
|
|
63
63
|
end
|
64
64
|
|
65
65
|
test "does not update anything if user has signed out along the way" do
|
66
|
-
swap Devise, :
|
67
|
-
user = create_user(:
|
66
|
+
swap Devise, allow_unconfirmed_access_for: 0.days do
|
67
|
+
user = create_user(confirm: false)
|
68
68
|
sign_in_as_user
|
69
69
|
|
70
70
|
user.reload
|
@@ -46,34 +46,54 @@ class ConfirmationInstructionsTest < ActionMailer::TestCase
|
|
46
46
|
assert_equal ['custom@example.com'], mail.from
|
47
47
|
end
|
48
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_present mail.body.encoded
|
57
|
+
end
|
58
|
+
|
49
59
|
test 'setup reply to as copy from sender' do
|
50
60
|
assert_equal ['test@example.com'], mail.reply_to
|
51
61
|
end
|
52
62
|
|
63
|
+
test 'setup reply to as different if set in defaults' do
|
64
|
+
Devise.mailer = 'Users::ReplyToMailer'
|
65
|
+
assert_equal ['custom@example.com'], mail.from
|
66
|
+
assert_equal ['custom_reply_to@example.com'], mail.reply_to
|
67
|
+
end
|
68
|
+
|
53
69
|
test 'setup subject from I18n' do
|
54
|
-
store_translations :en, :
|
70
|
+
store_translations :en, devise: { mailer: { confirmation_instructions: { subject: 'Account Confirmation' } } } do
|
55
71
|
assert_equal 'Account Confirmation', mail.subject
|
56
72
|
end
|
57
73
|
end
|
58
74
|
|
59
75
|
test 'subject namespaced by model' do
|
60
|
-
store_translations :en, :
|
76
|
+
store_translations :en, devise: { mailer: { confirmation_instructions: { user_subject: 'User Account Confirmation' } } } do
|
61
77
|
assert_equal 'User Account Confirmation', mail.subject
|
62
78
|
end
|
63
79
|
end
|
64
80
|
|
65
81
|
test 'body should have user info' do
|
66
|
-
assert_match
|
82
|
+
assert_match user.email, mail.body.encoded
|
67
83
|
end
|
68
84
|
|
69
85
|
test 'body should have link to confirm the account' do
|
70
|
-
host = ActionMailer::Base.default_url_options
|
71
|
-
|
72
|
-
|
86
|
+
host, port = ActionMailer::Base.default_url_options.values_at :host, :port
|
87
|
+
|
88
|
+
if mail.body.encoded =~ %r{<a href=\"http://#{host}:#{port}/users/confirmation\?confirmation_token=([^"]+)">}
|
89
|
+
assert_equal $1, user.confirmation_token
|
90
|
+
else
|
91
|
+
flunk "expected confirmation url regex to match"
|
92
|
+
end
|
73
93
|
end
|
74
94
|
|
75
95
|
test 'renders a scoped if scoped_views is set to true' do
|
76
|
-
swap Devise, :
|
96
|
+
swap Devise, scoped_views: true do
|
77
97
|
assert_equal user.email, mail.body.decoded
|
78
98
|
end
|
79
99
|
end
|
@@ -88,7 +108,7 @@ class ConfirmationInstructionsTest < ActionMailer::TestCase
|
|
88
108
|
end
|
89
109
|
|
90
110
|
test 'mailer sender accepts a proc' do
|
91
|
-
swap Devise, :
|
111
|
+
swap Devise, mailer_sender: proc { "another@example.com" } do
|
92
112
|
assert_equal ['another@example.com'], mail.from
|
93
113
|
end
|
94
114
|
end
|