devise 4.4.3 → 4.9.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +174 -4
- data/MIT-LICENSE +2 -1
- data/README.md +129 -65
- data/app/controllers/devise/confirmations_controller.rb +1 -0
- data/app/controllers/devise/passwords_controller.rb +3 -2
- data/app/controllers/devise/registrations_controller.rb +27 -9
- data/app/controllers/devise/sessions_controller.rb +2 -2
- data/app/controllers/devise/unlocks_controller.rb +1 -0
- data/app/controllers/devise_controller.rb +17 -3
- data/app/helpers/devise_helper.rb +21 -18
- data/app/mailers/devise/mailer.rb +5 -5
- data/app/views/devise/confirmations/new.html.erb +1 -1
- data/app/views/devise/passwords/edit.html.erb +3 -3
- data/app/views/devise/passwords/new.html.erb +1 -1
- data/app/views/devise/registrations/edit.html.erb +5 -5
- data/app/views/devise/registrations/new.html.erb +3 -3
- data/app/views/devise/sessions/new.html.erb +3 -3
- data/app/views/devise/shared/_error_messages.html.erb +15 -0
- data/app/views/devise/shared/_links.html.erb +8 -8
- data/app/views/devise/unlocks/new.html.erb +1 -1
- data/config/locales/en.yml +3 -2
- data/lib/devise/controllers/helpers.rb +10 -8
- data/lib/devise/controllers/responder.rb +35 -0
- data/lib/devise/controllers/sign_in_out.rb +9 -4
- data/lib/devise/controllers/url_helpers.rb +1 -1
- data/lib/devise/failure_app.rb +41 -8
- data/lib/devise/hooks/csrf_cleaner.rb +6 -1
- data/lib/devise/hooks/lockable.rb +2 -5
- data/lib/devise/hooks/timeoutable.rb +2 -2
- data/lib/devise/mapping.rb +1 -1
- data/lib/devise/models/authenticatable.rb +51 -48
- data/lib/devise/models/confirmable.rb +34 -40
- data/lib/devise/models/database_authenticatable.rb +54 -35
- data/lib/devise/models/lockable.rb +13 -5
- data/lib/devise/models/omniauthable.rb +2 -2
- data/lib/devise/models/recoverable.rb +8 -19
- data/lib/devise/models/registerable.rb +2 -0
- data/lib/devise/models/rememberable.rb +2 -2
- data/lib/devise/models/timeoutable.rb +1 -1
- data/lib/devise/models/trackable.rb +9 -2
- data/lib/devise/models/validatable.rb +4 -9
- data/lib/devise/models.rb +1 -0
- data/lib/devise/omniauth.rb +2 -5
- data/lib/devise/orm.rb +71 -0
- data/lib/devise/parameter_filter.rb +2 -0
- data/lib/devise/parameter_sanitizer.rb +13 -1
- data/lib/devise/rails/deprecated_constant_accessor.rb +39 -0
- data/lib/devise/rails/routes.rb +6 -6
- data/lib/devise/rails.rb +4 -0
- data/lib/devise/secret_key_finder.rb +2 -0
- data/lib/devise/strategies/authenticatable.rb +1 -1
- data/lib/devise/strategies/database_authenticatable.rb +6 -1
- data/lib/devise/test/controller_helpers.rb +5 -3
- data/lib/devise/test/integration_helpers.rb +1 -1
- data/lib/devise/test_helpers.rb +1 -1
- data/lib/devise/version.rb +1 -1
- data/lib/devise.rb +38 -11
- data/lib/generators/active_record/devise_generator.rb +26 -11
- data/lib/generators/devise/controllers_generator.rb +1 -1
- data/lib/generators/devise/devise_generator.rb +1 -1
- data/lib/generators/devise/install_generator.rb +1 -5
- data/lib/generators/devise/orm_helpers.rb +2 -2
- data/lib/generators/devise/views_generator.rb +1 -1
- data/lib/generators/mongoid/devise_generator.rb +5 -5
- data/lib/generators/templates/README +9 -1
- data/lib/generators/templates/controllers/omniauth_callbacks_controller.rb +1 -1
- data/lib/generators/templates/devise.rb +38 -8
- data/lib/generators/templates/simple_form_for/confirmations/new.html.erb +5 -1
- data/lib/generators/templates/simple_form_for/passwords/edit.html.erb +10 -2
- data/lib/generators/templates/simple_form_for/passwords/new.html.erb +4 -1
- data/lib/generators/templates/simple_form_for/registrations/edit.html.erb +12 -4
- data/lib/generators/templates/simple_form_for/registrations/new.html.erb +11 -3
- data/lib/generators/templates/simple_form_for/sessions/new.html.erb +7 -2
- data/lib/generators/templates/simple_form_for/unlocks/new.html.erb +4 -1
- metadata +23 -316
- data/.gitignore +0 -10
- data/.travis.yml +0 -68
- data/.yardopts +0 -9
- data/CODE_OF_CONDUCT.md +0 -22
- data/CONTRIBUTING.md +0 -79
- data/Gemfile +0 -39
- data/Gemfile.lock +0 -193
- data/ISSUE_TEMPLATE.md +0 -19
- data/Rakefile +0 -37
- data/bin/test +0 -13
- data/devise.gemspec +0 -28
- data/devise.png +0 -0
- data/gemfiles/Gemfile.rails-4.1-stable +0 -32
- data/gemfiles/Gemfile.rails-4.1-stable.lock +0 -171
- data/gemfiles/Gemfile.rails-4.2-stable +0 -32
- data/gemfiles/Gemfile.rails-4.2-stable.lock +0 -192
- data/gemfiles/Gemfile.rails-5.0-stable +0 -33
- data/gemfiles/Gemfile.rails-5.0-stable.lock +0 -192
- data/gemfiles/Gemfile.rails-5.2-rc1 +0 -26
- data/gemfiles/Gemfile.rails-5.2-rc1.lock +0 -201
- data/guides/bug_report_templates/integration_test.rb +0 -106
- data/test/controllers/custom_registrations_controller_test.rb +0 -42
- data/test/controllers/custom_strategy_test.rb +0 -66
- data/test/controllers/helper_methods_test.rb +0 -24
- data/test/controllers/helpers_test.rb +0 -318
- data/test/controllers/inherited_controller_i18n_messages_test.rb +0 -53
- data/test/controllers/internal_helpers_test.rb +0 -129
- data/test/controllers/load_hooks_controller_test.rb +0 -21
- data/test/controllers/passwords_controller_test.rb +0 -34
- data/test/controllers/sessions_controller_test.rb +0 -108
- data/test/controllers/url_helpers_test.rb +0 -67
- data/test/delegator_test.rb +0 -21
- data/test/devise_test.rb +0 -109
- data/test/failure_app_test.rb +0 -340
- data/test/generators/active_record_generator_test.rb +0 -130
- data/test/generators/controllers_generator_test.rb +0 -50
- data/test/generators/devise_generator_test.rb +0 -41
- data/test/generators/install_generator_test.rb +0 -26
- data/test/generators/mongoid_generator_test.rb +0 -25
- data/test/generators/views_generator_test.rb +0 -105
- data/test/helpers/devise_helper_test.rb +0 -51
- data/test/integration/authenticatable_test.rb +0 -706
- data/test/integration/confirmable_test.rb +0 -326
- data/test/integration/database_authenticatable_test.rb +0 -97
- data/test/integration/http_authenticatable_test.rb +0 -114
- data/test/integration/lockable_test.rb +0 -242
- data/test/integration/mounted_engine_test.rb +0 -38
- data/test/integration/omniauthable_test.rb +0 -148
- data/test/integration/recoverable_test.rb +0 -349
- data/test/integration/registerable_test.rb +0 -365
- data/test/integration/rememberable_test.rb +0 -219
- data/test/integration/timeoutable_test.rb +0 -186
- data/test/integration/trackable_test.rb +0 -99
- data/test/mailers/confirmation_instructions_test.rb +0 -117
- data/test/mailers/email_changed_test.rb +0 -132
- data/test/mailers/mailer_test.rb +0 -20
- data/test/mailers/reset_password_instructions_test.rb +0 -98
- data/test/mailers/unlock_instructions_test.rb +0 -93
- data/test/mapping_test.rb +0 -136
- data/test/models/authenticatable_test.rb +0 -25
- data/test/models/confirmable_test.rb +0 -549
- data/test/models/database_authenticatable_test.rb +0 -283
- data/test/models/lockable_test.rb +0 -352
- data/test/models/omniauthable_test.rb +0 -9
- data/test/models/recoverable_test.rb +0 -263
- data/test/models/registerable_test.rb +0 -9
- data/test/models/rememberable_test.rb +0 -184
- data/test/models/serializable_test.rb +0 -60
- data/test/models/timeoutable_test.rb +0 -53
- data/test/models/trackable_test.rb +0 -62
- data/test/models/validatable_test.rb +0 -121
- data/test/models_test.rb +0 -155
- data/test/omniauth/config_test.rb +0 -61
- data/test/omniauth/url_helpers_test.rb +0 -53
- data/test/orm/active_record.rb +0 -24
- data/test/orm/mongoid.rb +0 -15
- data/test/parameter_sanitizer_test.rb +0 -77
- data/test/rails_app/Rakefile +0 -6
- data/test/rails_app/app/active_record/admin.rb +0 -8
- data/test/rails_app/app/active_record/shim.rb +0 -4
- data/test/rails_app/app/active_record/user.rb +0 -20
- data/test/rails_app/app/active_record/user_on_engine.rb +0 -9
- data/test/rails_app/app/active_record/user_on_main_app.rb +0 -9
- data/test/rails_app/app/active_record/user_with_validations.rb +0 -12
- data/test/rails_app/app/active_record/user_without_email.rb +0 -10
- data/test/rails_app/app/controllers/admins/sessions_controller.rb +0 -8
- data/test/rails_app/app/controllers/admins_controller.rb +0 -8
- data/test/rails_app/app/controllers/application_controller.rb +0 -13
- data/test/rails_app/app/controllers/application_with_fake_engine.rb +0 -32
- data/test/rails_app/app/controllers/custom/registrations_controller.rb +0 -33
- data/test/rails_app/app/controllers/home_controller.rb +0 -31
- data/test/rails_app/app/controllers/publisher/registrations_controller.rb +0 -4
- data/test/rails_app/app/controllers/publisher/sessions_controller.rb +0 -4
- data/test/rails_app/app/controllers/users/omniauth_callbacks_controller.rb +0 -16
- data/test/rails_app/app/controllers/users_controller.rb +0 -33
- data/test/rails_app/app/helpers/application_helper.rb +0 -5
- data/test/rails_app/app/mailers/users/from_proc_mailer.rb +0 -5
- data/test/rails_app/app/mailers/users/mailer.rb +0 -5
- data/test/rails_app/app/mailers/users/reply_to_mailer.rb +0 -6
- data/test/rails_app/app/mongoid/admin.rb +0 -31
- data/test/rails_app/app/mongoid/shim.rb +0 -25
- data/test/rails_app/app/mongoid/user.rb +0 -50
- data/test/rails_app/app/mongoid/user_on_engine.rb +0 -41
- data/test/rails_app/app/mongoid/user_on_main_app.rb +0 -41
- data/test/rails_app/app/mongoid/user_with_validations.rb +0 -37
- data/test/rails_app/app/mongoid/user_without_email.rb +0 -35
- data/test/rails_app/app/views/admins/index.html.erb +0 -1
- data/test/rails_app/app/views/admins/sessions/new.html.erb +0 -2
- data/test/rails_app/app/views/home/admin_dashboard.html.erb +0 -1
- data/test/rails_app/app/views/home/index.html.erb +0 -1
- data/test/rails_app/app/views/home/join.html.erb +0 -1
- data/test/rails_app/app/views/home/private.html.erb +0 -1
- data/test/rails_app/app/views/home/user_dashboard.html.erb +0 -1
- data/test/rails_app/app/views/layouts/application.html.erb +0 -24
- data/test/rails_app/app/views/users/edit_form.html.erb +0 -1
- data/test/rails_app/app/views/users/index.html.erb +0 -1
- data/test/rails_app/app/views/users/mailer/confirmation_instructions.erb +0 -1
- data/test/rails_app/app/views/users/sessions/new.html.erb +0 -1
- data/test/rails_app/bin/bundle +0 -3
- data/test/rails_app/bin/rails +0 -4
- data/test/rails_app/bin/rake +0 -4
- data/test/rails_app/config/application.rb +0 -48
- data/test/rails_app/config/boot.rb +0 -27
- data/test/rails_app/config/database.yml +0 -18
- data/test/rails_app/config/environment.rb +0 -7
- data/test/rails_app/config/environments/development.rb +0 -32
- data/test/rails_app/config/environments/production.rb +0 -88
- data/test/rails_app/config/environments/test.rb +0 -47
- data/test/rails_app/config/initializers/backtrace_silencers.rb +0 -9
- data/test/rails_app/config/initializers/devise.rb +0 -182
- data/test/rails_app/config/initializers/inflections.rb +0 -4
- data/test/rails_app/config/initializers/secret_token.rb +0 -5
- data/test/rails_app/config/initializers/session_store.rb +0 -3
- data/test/rails_app/config/routes.rb +0 -128
- data/test/rails_app/config.ru +0 -4
- data/test/rails_app/db/migrate/20100401102949_create_tables.rb +0 -77
- data/test/rails_app/db/schema.rb +0 -57
- data/test/rails_app/lib/shared_admin.rb +0 -23
- data/test/rails_app/lib/shared_user.rb +0 -32
- data/test/rails_app/lib/shared_user_without_email.rb +0 -28
- data/test/rails_app/lib/shared_user_without_omniauth.rb +0 -15
- data/test/rails_app/public/404.html +0 -26
- data/test/rails_app/public/422.html +0 -26
- data/test/rails_app/public/500.html +0 -26
- data/test/rails_app/public/favicon.ico +0 -0
- data/test/rails_test.rb +0 -11
- data/test/routes_test.rb +0 -281
- data/test/secret_key_finder_test.rb +0 -97
- data/test/support/action_controller/record_identifier.rb +0 -12
- data/test/support/assertions.rb +0 -30
- data/test/support/helpers.rb +0 -83
- data/test/support/http_method_compatibility.rb +0 -53
- data/test/support/integration.rb +0 -95
- data/test/support/locale/en.yml +0 -8
- data/test/support/mongoid.yml +0 -6
- data/test/support/webrat/integrations/rails.rb +0 -35
- data/test/test/controller_helpers_test.rb +0 -193
- data/test/test/integration_helpers_test.rb +0 -34
- data/test/test_helper.rb +0 -36
- data/test/test_models.rb +0 -35
@@ -1,186 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'test_helper'
|
4
|
-
|
5
|
-
class SessionTimeoutTest < Devise::IntegrationTest
|
6
|
-
|
7
|
-
def last_request_at
|
8
|
-
@controller.user_session['last_request_at']
|
9
|
-
end
|
10
|
-
|
11
|
-
test 'set last request at in user session after each request' do
|
12
|
-
sign_in_as_user
|
13
|
-
assert_not_nil last_request_at
|
14
|
-
|
15
|
-
@controller.user_session.delete('last_request_at')
|
16
|
-
get users_path
|
17
|
-
assert_not_nil last_request_at
|
18
|
-
end
|
19
|
-
|
20
|
-
test 'set last request at in user session after each request is skipped if tracking is disabled' do
|
21
|
-
sign_in_as_user
|
22
|
-
old_last_request = last_request_at
|
23
|
-
assert_not_nil last_request_at
|
24
|
-
|
25
|
-
get users_path, headers: { 'devise.skip_trackable' => true }
|
26
|
-
assert_equal old_last_request, last_request_at
|
27
|
-
end
|
28
|
-
|
29
|
-
test 'does not set last request at in user session after each request if timeoutable is disabled' do
|
30
|
-
sign_in_as_user
|
31
|
-
old_last_request = last_request_at
|
32
|
-
assert_not_nil last_request_at
|
33
|
-
|
34
|
-
new_time = 2.seconds.from_now
|
35
|
-
Time.stubs(:now).returns(new_time)
|
36
|
-
|
37
|
-
get users_path, headers: { 'devise.skip_timeoutable' => true }
|
38
|
-
assert_equal old_last_request, last_request_at
|
39
|
-
end
|
40
|
-
|
41
|
-
test 'does not time out user session before default limit time' do
|
42
|
-
sign_in_as_user
|
43
|
-
assert_response :success
|
44
|
-
assert warden.authenticated?(:user)
|
45
|
-
|
46
|
-
get users_path
|
47
|
-
assert_response :success
|
48
|
-
assert warden.authenticated?(:user)
|
49
|
-
end
|
50
|
-
|
51
|
-
test 'time out user session after default limit time when sign_out_all_scopes is false' do
|
52
|
-
swap Devise, sign_out_all_scopes: false do
|
53
|
-
sign_in_as_admin
|
54
|
-
|
55
|
-
user = sign_in_as_user
|
56
|
-
get expire_user_path(user)
|
57
|
-
assert_not_nil last_request_at
|
58
|
-
|
59
|
-
get users_path
|
60
|
-
assert_redirected_to users_path
|
61
|
-
refute warden.authenticated?(:user)
|
62
|
-
assert warden.authenticated?(:admin)
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
test 'time out all sessions after default limit time when sign_out_all_scopes is true' do
|
67
|
-
swap Devise, sign_out_all_scopes: true do
|
68
|
-
sign_in_as_admin
|
69
|
-
|
70
|
-
user = sign_in_as_user
|
71
|
-
get expire_user_path(user)
|
72
|
-
assert_not_nil last_request_at
|
73
|
-
|
74
|
-
get root_path
|
75
|
-
refute warden.authenticated?(:user)
|
76
|
-
refute warden.authenticated?(:admin)
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
|
-
test 'time out user session after deault limit time and redirect to latest get request' do
|
81
|
-
user = sign_in_as_user
|
82
|
-
visit edit_form_user_path(user)
|
83
|
-
|
84
|
-
click_button 'Update'
|
85
|
-
sign_in_as_user
|
86
|
-
|
87
|
-
assert_equal edit_form_user_url(user), current_url
|
88
|
-
end
|
89
|
-
|
90
|
-
test 'time out is not triggered on sign out' do
|
91
|
-
user = sign_in_as_user
|
92
|
-
get expire_user_path(user)
|
93
|
-
|
94
|
-
delete destroy_user_session_path
|
95
|
-
|
96
|
-
assert_response :redirect
|
97
|
-
assert_redirected_to root_path
|
98
|
-
follow_redirect!
|
99
|
-
assert_contain 'Signed out successfully'
|
100
|
-
end
|
101
|
-
|
102
|
-
test 'expired session is not extended by sign in page' do
|
103
|
-
user = sign_in_as_user
|
104
|
-
get expire_user_path(user)
|
105
|
-
assert warden.authenticated?(:user)
|
106
|
-
|
107
|
-
get "/users/sign_in"
|
108
|
-
assert_redirected_to "/users/sign_in"
|
109
|
-
follow_redirect!
|
110
|
-
|
111
|
-
assert_response :success
|
112
|
-
assert_contain 'Sign in'
|
113
|
-
refute warden.authenticated?(:user)
|
114
|
-
end
|
115
|
-
|
116
|
-
test 'time out is not triggered on sign in' do
|
117
|
-
user = sign_in_as_user
|
118
|
-
get expire_user_path(user)
|
119
|
-
|
120
|
-
post "/users/sign_in", params: { email: user.email, password: "123456" }
|
121
|
-
|
122
|
-
assert_response :redirect
|
123
|
-
follow_redirect!
|
124
|
-
assert_contain 'You are signed in'
|
125
|
-
end
|
126
|
-
|
127
|
-
test 'user configured timeout limit' do
|
128
|
-
swap Devise, timeout_in: 8.minutes do
|
129
|
-
user = sign_in_as_user
|
130
|
-
|
131
|
-
get users_path
|
132
|
-
assert_not_nil last_request_at
|
133
|
-
assert_response :success
|
134
|
-
assert warden.authenticated?(:user)
|
135
|
-
|
136
|
-
get expire_user_path(user)
|
137
|
-
get users_path
|
138
|
-
assert_redirected_to users_path
|
139
|
-
refute warden.authenticated?(:user)
|
140
|
-
end
|
141
|
-
end
|
142
|
-
|
143
|
-
test 'error message with i18n' do
|
144
|
-
store_translations :en, devise: {
|
145
|
-
failure: { user: { timeout: 'Session expired!' } }
|
146
|
-
} do
|
147
|
-
user = sign_in_as_user
|
148
|
-
|
149
|
-
get expire_user_path(user)
|
150
|
-
get root_path
|
151
|
-
follow_redirect!
|
152
|
-
assert_contain 'Session expired!'
|
153
|
-
end
|
154
|
-
end
|
155
|
-
|
156
|
-
test 'error message with i18n with double redirect' do
|
157
|
-
store_translations :en, devise: {
|
158
|
-
failure: { user: { timeout: 'Session expired!' } }
|
159
|
-
} do
|
160
|
-
user = sign_in_as_user
|
161
|
-
|
162
|
-
get expire_user_path(user)
|
163
|
-
get users_path
|
164
|
-
follow_redirect!
|
165
|
-
follow_redirect!
|
166
|
-
assert_contain 'Session expired!'
|
167
|
-
end
|
168
|
-
end
|
169
|
-
|
170
|
-
test 'time out not triggered if remembered' do
|
171
|
-
user = sign_in_as_user remember_me: true
|
172
|
-
get expire_user_path(user)
|
173
|
-
assert_not_nil last_request_at
|
174
|
-
|
175
|
-
get users_path
|
176
|
-
assert_response :success
|
177
|
-
assert warden.authenticated?(:user)
|
178
|
-
end
|
179
|
-
|
180
|
-
test 'does not crash when the last_request_at is a String' do
|
181
|
-
user = sign_in_as_user
|
182
|
-
|
183
|
-
get edit_form_user_path(user, last_request_at: Time.now.utc.to_s)
|
184
|
-
get users_path
|
185
|
-
end
|
186
|
-
end
|
@@ -1,99 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'test_helper'
|
4
|
-
|
5
|
-
class TrackableHooksTest < Devise::IntegrationTest
|
6
|
-
test "trackable should not run model validations" do
|
7
|
-
sign_in_as_user
|
8
|
-
|
9
|
-
refute User.validations_performed
|
10
|
-
end
|
11
|
-
|
12
|
-
test "current and last sign in timestamps are updated on each sign in" do
|
13
|
-
user = create_user
|
14
|
-
assert_nil user.current_sign_in_at
|
15
|
-
assert_nil user.last_sign_in_at
|
16
|
-
|
17
|
-
sign_in_as_user
|
18
|
-
user.reload
|
19
|
-
|
20
|
-
assert user.current_sign_in_at.acts_like?(:time)
|
21
|
-
assert user.last_sign_in_at.acts_like?(:time)
|
22
|
-
|
23
|
-
assert_equal user.current_sign_in_at, user.last_sign_in_at
|
24
|
-
assert user.current_sign_in_at >= user.created_at
|
25
|
-
|
26
|
-
delete destroy_user_session_path
|
27
|
-
new_time = 2.seconds.from_now
|
28
|
-
Time.stubs(:now).returns(new_time)
|
29
|
-
|
30
|
-
sign_in_as_user
|
31
|
-
user.reload
|
32
|
-
assert user.current_sign_in_at > user.last_sign_in_at
|
33
|
-
end
|
34
|
-
|
35
|
-
test "current and last sign in remote ip are updated on each sign in" do
|
36
|
-
user = create_user
|
37
|
-
assert_nil user.current_sign_in_ip
|
38
|
-
assert_nil user.last_sign_in_ip
|
39
|
-
|
40
|
-
sign_in_as_user
|
41
|
-
user.reload
|
42
|
-
|
43
|
-
assert_equal "127.0.0.1", user.current_sign_in_ip
|
44
|
-
assert_equal "127.0.0.1", user.last_sign_in_ip
|
45
|
-
end
|
46
|
-
|
47
|
-
test "current remote ip returns original ip behind a non transparent proxy" do
|
48
|
-
user = create_user
|
49
|
-
|
50
|
-
arbitrary_ip = '200.121.1.69'
|
51
|
-
sign_in_as_user do
|
52
|
-
header 'HTTP_X_FORWARDED_FOR', arbitrary_ip
|
53
|
-
end
|
54
|
-
user.reload
|
55
|
-
assert_equal arbitrary_ip, user.current_sign_in_ip
|
56
|
-
end
|
57
|
-
|
58
|
-
test "increase sign in count" do
|
59
|
-
user = create_user
|
60
|
-
assert_equal 0, user.sign_in_count
|
61
|
-
|
62
|
-
sign_in_as_user
|
63
|
-
user.reload
|
64
|
-
assert_equal 1, user.sign_in_count
|
65
|
-
|
66
|
-
delete destroy_user_session_path
|
67
|
-
sign_in_as_user
|
68
|
-
user.reload
|
69
|
-
assert_equal 2, user.sign_in_count
|
70
|
-
end
|
71
|
-
|
72
|
-
test "does not update anything if user has signed out along the way" do
|
73
|
-
swap Devise, allow_unconfirmed_access_for: 0.days do
|
74
|
-
user = create_user(confirm: false)
|
75
|
-
sign_in_as_user
|
76
|
-
|
77
|
-
user.reload
|
78
|
-
assert_nil user.current_sign_in_at
|
79
|
-
assert_nil user.last_sign_in_at
|
80
|
-
end
|
81
|
-
end
|
82
|
-
|
83
|
-
test "do not track if devise.skip_trackable is set" do
|
84
|
-
user = create_user
|
85
|
-
sign_in_as_user do
|
86
|
-
header 'devise.skip_trackable', '1'
|
87
|
-
end
|
88
|
-
user.reload
|
89
|
-
assert_equal 0, user.sign_in_count
|
90
|
-
delete destroy_user_session_path
|
91
|
-
|
92
|
-
sign_in_as_user do
|
93
|
-
header 'devise.skip_trackable', false
|
94
|
-
end
|
95
|
-
user.reload
|
96
|
-
assert_equal 1, user.sign_in_count
|
97
|
-
end
|
98
|
-
|
99
|
-
end
|
@@ -1,117 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'test_helper'
|
4
|
-
|
5
|
-
class ConfirmationInstructionsTest < ActionMailer::TestCase
|
6
|
-
|
7
|
-
def setup
|
8
|
-
setup_mailer
|
9
|
-
Devise.mailer = 'Devise::Mailer'
|
10
|
-
Devise.mailer_sender = 'test@example.com'
|
11
|
-
end
|
12
|
-
|
13
|
-
def teardown
|
14
|
-
Devise.mailer = 'Devise::Mailer'
|
15
|
-
Devise.mailer_sender = 'please-change-me@config-initializers-devise.com'
|
16
|
-
end
|
17
|
-
|
18
|
-
def user
|
19
|
-
@user ||= create_user
|
20
|
-
end
|
21
|
-
|
22
|
-
def mail
|
23
|
-
@mail ||= begin
|
24
|
-
user
|
25
|
-
ActionMailer::Base.deliveries.first
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
test 'email sent after creating the user' do
|
30
|
-
assert_not_nil mail
|
31
|
-
end
|
32
|
-
|
33
|
-
test 'content type should be set to html' do
|
34
|
-
assert mail.content_type.include?('text/html')
|
35
|
-
end
|
36
|
-
|
37
|
-
test 'send confirmation instructions to the user email' do
|
38
|
-
mail
|
39
|
-
assert_equal [user.email], mail.to
|
40
|
-
end
|
41
|
-
|
42
|
-
test 'set up sender from configuration' do
|
43
|
-
assert_equal ['test@example.com'], mail.from
|
44
|
-
end
|
45
|
-
|
46
|
-
test 'set up sender from custom mailer defaults' do
|
47
|
-
Devise.mailer = 'Users::Mailer'
|
48
|
-
assert_equal ['custom@example.com'], mail.from
|
49
|
-
end
|
50
|
-
|
51
|
-
test 'set up sender from custom mailer defaults with proc' do
|
52
|
-
Devise.mailer = 'Users::FromProcMailer'
|
53
|
-
assert_equal ['custom@example.com'], mail.from
|
54
|
-
end
|
55
|
-
|
56
|
-
test 'custom mailer renders parent mailer template' do
|
57
|
-
Devise.mailer = 'Users::Mailer'
|
58
|
-
assert_present mail.body.encoded
|
59
|
-
end
|
60
|
-
|
61
|
-
test 'set up reply to as copy from sender' do
|
62
|
-
assert_equal ['test@example.com'], mail.reply_to
|
63
|
-
end
|
64
|
-
|
65
|
-
test 'set up reply to as different if set in defaults' do
|
66
|
-
Devise.mailer = 'Users::ReplyToMailer'
|
67
|
-
assert_equal ['custom@example.com'], mail.from
|
68
|
-
assert_equal ['custom_reply_to@example.com'], mail.reply_to
|
69
|
-
end
|
70
|
-
|
71
|
-
test 'set up subject from I18n' do
|
72
|
-
store_translations :en, devise: { mailer: { confirmation_instructions: { subject: 'Account Confirmation' } } } do
|
73
|
-
assert_equal 'Account Confirmation', mail.subject
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
test 'subject namespaced by model' do
|
78
|
-
store_translations :en, devise: { mailer: { confirmation_instructions: { user_subject: 'User Account Confirmation' } } } do
|
79
|
-
assert_equal 'User Account Confirmation', mail.subject
|
80
|
-
end
|
81
|
-
end
|
82
|
-
|
83
|
-
test 'body should have user info' do
|
84
|
-
assert_match user.email, mail.body.encoded
|
85
|
-
end
|
86
|
-
|
87
|
-
test 'body should have link to confirm the account' do
|
88
|
-
host, port = ActionMailer::Base.default_url_options.values_at :host, :port
|
89
|
-
|
90
|
-
if mail.body.encoded =~ %r{<a href=\"http://#{host}:#{port}/users/confirmation\?confirmation_token=([^"]+)">}
|
91
|
-
assert_equal $1, user.confirmation_token
|
92
|
-
else
|
93
|
-
flunk "expected confirmation url regex to match"
|
94
|
-
end
|
95
|
-
end
|
96
|
-
|
97
|
-
test 'renders a scoped if scoped_views is set to true' do
|
98
|
-
swap Devise, scoped_views: true do
|
99
|
-
assert_equal user.email, mail.body.decoded
|
100
|
-
end
|
101
|
-
end
|
102
|
-
|
103
|
-
test 'renders a scoped if scoped_views is set in the mailer class' do
|
104
|
-
begin
|
105
|
-
Devise::Mailer.scoped_views = true
|
106
|
-
assert_equal user.email, mail.body.decoded
|
107
|
-
ensure
|
108
|
-
Devise::Mailer.send :remove_instance_variable, :@scoped_views
|
109
|
-
end
|
110
|
-
end
|
111
|
-
|
112
|
-
test 'mailer sender accepts a proc' do
|
113
|
-
swap Devise, mailer_sender: proc { "another@example.com" } do
|
114
|
-
assert_equal ['another@example.com'], mail.from
|
115
|
-
end
|
116
|
-
end
|
117
|
-
end
|
@@ -1,132 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'test_helper'
|
4
|
-
|
5
|
-
class EmailChangedTest < ActionMailer::TestCase
|
6
|
-
def setup
|
7
|
-
setup_mailer
|
8
|
-
Devise.mailer = 'Devise::Mailer'
|
9
|
-
Devise.mailer_sender = 'test@example.com'
|
10
|
-
Devise.send_email_changed_notification = true
|
11
|
-
end
|
12
|
-
|
13
|
-
def teardown
|
14
|
-
Devise.mailer = 'Devise::Mailer'
|
15
|
-
Devise.mailer_sender = 'please-change-me@config-initializers-devise.com'
|
16
|
-
Devise.send_email_changed_notification = false
|
17
|
-
end
|
18
|
-
|
19
|
-
def user
|
20
|
-
@user ||= create_user.tap { |u|
|
21
|
-
@original_user_email = u.email
|
22
|
-
u.update_attributes!(email: 'new-email@example.com')
|
23
|
-
}
|
24
|
-
end
|
25
|
-
|
26
|
-
def mail
|
27
|
-
@mail ||= begin
|
28
|
-
user
|
29
|
-
ActionMailer::Base.deliveries.last
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
test 'email sent after changing the user email' do
|
34
|
-
assert_not_nil mail
|
35
|
-
end
|
36
|
-
|
37
|
-
test 'content type should be set to html' do
|
38
|
-
assert mail.content_type.include?('text/html')
|
39
|
-
end
|
40
|
-
|
41
|
-
test 'send email changed to the original user email' do
|
42
|
-
mail
|
43
|
-
assert_equal [@original_user_email], mail.to
|
44
|
-
end
|
45
|
-
|
46
|
-
test 'set up sender from configuration' do
|
47
|
-
assert_equal ['test@example.com'], mail.from
|
48
|
-
end
|
49
|
-
|
50
|
-
test 'set up sender from custom mailer defaults' do
|
51
|
-
Devise.mailer = 'Users::Mailer'
|
52
|
-
assert_equal ['custom@example.com'], mail.from
|
53
|
-
end
|
54
|
-
|
55
|
-
test 'set up sender from custom mailer defaults with proc' do
|
56
|
-
Devise.mailer = 'Users::FromProcMailer'
|
57
|
-
assert_equal ['custom@example.com'], mail.from
|
58
|
-
end
|
59
|
-
|
60
|
-
test 'custom mailer renders parent mailer template' do
|
61
|
-
Devise.mailer = 'Users::Mailer'
|
62
|
-
assert_present mail.body.encoded
|
63
|
-
end
|
64
|
-
|
65
|
-
test 'set up reply to as copy from sender' do
|
66
|
-
assert_equal ['test@example.com'], mail.reply_to
|
67
|
-
end
|
68
|
-
|
69
|
-
test 'set up reply to as different if set in defaults' do
|
70
|
-
Devise.mailer = 'Users::ReplyToMailer'
|
71
|
-
assert_equal ['custom@example.com'], mail.from
|
72
|
-
assert_equal ['custom_reply_to@example.com'], mail.reply_to
|
73
|
-
end
|
74
|
-
|
75
|
-
test 'set up subject from I18n' do
|
76
|
-
store_translations :en, devise: { mailer: { email_changed: { subject: 'Email Has Changed' } } } do
|
77
|
-
assert_equal 'Email Has Changed', mail.subject
|
78
|
-
end
|
79
|
-
end
|
80
|
-
|
81
|
-
test 'subject namespaced by model' do
|
82
|
-
store_translations :en, devise: { mailer: { email_changed: { user_subject: 'User Email Has Changed' } } } do
|
83
|
-
assert_equal 'User Email Has Changed', mail.subject
|
84
|
-
end
|
85
|
-
end
|
86
|
-
|
87
|
-
test 'body should have user info' do
|
88
|
-
body = mail.body.encoded
|
89
|
-
assert_match "Hello #{@original_user_email}", body
|
90
|
-
assert_match "has been changed to #{user.email}", body
|
91
|
-
end
|
92
|
-
end
|
93
|
-
|
94
|
-
class EmailChangedReconfirmationTest < ActionMailer::TestCase
|
95
|
-
def setup
|
96
|
-
setup_mailer
|
97
|
-
Devise.mailer = 'Devise::Mailer'
|
98
|
-
Devise.mailer_sender = 'test@example.com'
|
99
|
-
Devise.send_email_changed_notification = true
|
100
|
-
end
|
101
|
-
|
102
|
-
def teardown
|
103
|
-
Devise.mailer = 'Devise::Mailer'
|
104
|
-
Devise.mailer_sender = 'please-change-me@config-initializers-devise.com'
|
105
|
-
Devise.send_email_changed_notification = false
|
106
|
-
end
|
107
|
-
|
108
|
-
def admin
|
109
|
-
@admin ||= create_admin.tap { |u|
|
110
|
-
@original_admin_email = u.email
|
111
|
-
u.update_attributes!(email: 'new-email@example.com')
|
112
|
-
}
|
113
|
-
end
|
114
|
-
|
115
|
-
def mail
|
116
|
-
@mail ||= begin
|
117
|
-
admin
|
118
|
-
ActionMailer::Base.deliveries[-2]
|
119
|
-
end
|
120
|
-
end
|
121
|
-
|
122
|
-
test 'send email changed to the original user email' do
|
123
|
-
mail
|
124
|
-
assert_equal [@original_admin_email], mail.to
|
125
|
-
end
|
126
|
-
|
127
|
-
test 'body should have unconfirmed user info' do
|
128
|
-
body = mail.body.encoded
|
129
|
-
assert_match admin.email, body
|
130
|
-
assert_match "is being changed to #{admin.unconfirmed_email}", body
|
131
|
-
end
|
132
|
-
end
|
data/test/mailers/mailer_test.rb
DELETED
@@ -1,20 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "test_helper"
|
4
|
-
|
5
|
-
class MailerTest < ActionMailer::TestCase
|
6
|
-
test "pass given block to #mail call" do
|
7
|
-
class TestMailer < Devise::Mailer
|
8
|
-
def confirmation_instructions(record, token, opts = {})
|
9
|
-
@token = token
|
10
|
-
devise_mail(record, :confirmation_instructions, opts) do |format|
|
11
|
-
format.html(content_transfer_encoding: "7bit")
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
mail = TestMailer.confirmation_instructions(create_user, "confirmation-token")
|
17
|
-
|
18
|
-
assert mail.content_transfer_encoding, "7bit"
|
19
|
-
end
|
20
|
-
end
|
@@ -1,98 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'test_helper'
|
4
|
-
|
5
|
-
class ResetPasswordInstructionsTest < ActionMailer::TestCase
|
6
|
-
def setup
|
7
|
-
setup_mailer
|
8
|
-
Devise.mailer = 'Devise::Mailer'
|
9
|
-
Devise.mailer_sender = 'test@example.com'
|
10
|
-
end
|
11
|
-
|
12
|
-
def teardown
|
13
|
-
Devise.mailer = 'Devise::Mailer'
|
14
|
-
Devise.mailer_sender = 'please-change-me@config-initializers-devise.com'
|
15
|
-
end
|
16
|
-
|
17
|
-
def user
|
18
|
-
@user ||= begin
|
19
|
-
user = create_user
|
20
|
-
user.send_reset_password_instructions
|
21
|
-
user
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
def mail
|
26
|
-
@mail ||= begin
|
27
|
-
user
|
28
|
-
ActionMailer::Base.deliveries.last
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
test 'email sent after reseting the user password' do
|
33
|
-
assert_not_nil mail
|
34
|
-
end
|
35
|
-
|
36
|
-
test 'content type should be set to html' do
|
37
|
-
assert mail.content_type.include?('text/html')
|
38
|
-
end
|
39
|
-
|
40
|
-
test 'send confirmation instructions to the user email' do
|
41
|
-
assert_equal [user.email], mail.to
|
42
|
-
end
|
43
|
-
|
44
|
-
test 'set up sender from configuration' do
|
45
|
-
assert_equal ['test@example.com'], mail.from
|
46
|
-
end
|
47
|
-
|
48
|
-
test 'set up sender from custom mailer defaults' do
|
49
|
-
Devise.mailer = 'Users::Mailer'
|
50
|
-
assert_equal ['custom@example.com'], mail.from
|
51
|
-
end
|
52
|
-
|
53
|
-
test 'set up sender from custom mailer defaults with proc' do
|
54
|
-
Devise.mailer = 'Users::FromProcMailer'
|
55
|
-
assert_equal ['custom@example.com'], mail.from
|
56
|
-
end
|
57
|
-
|
58
|
-
test 'custom mailer renders parent mailer template' do
|
59
|
-
Devise.mailer = 'Users::Mailer'
|
60
|
-
assert_present mail.body.encoded
|
61
|
-
end
|
62
|
-
|
63
|
-
test 'set up reply to as copy from sender' do
|
64
|
-
assert_equal ['test@example.com'], mail.reply_to
|
65
|
-
end
|
66
|
-
|
67
|
-
test 'set up subject from I18n' do
|
68
|
-
store_translations :en, devise: { mailer: { reset_password_instructions: { subject: 'Reset instructions' } } } do
|
69
|
-
assert_equal 'Reset instructions', mail.subject
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
|
-
test 'subject namespaced by model' do
|
74
|
-
store_translations :en, devise: { mailer: { reset_password_instructions: { user_subject: 'User Reset Instructions' } } } do
|
75
|
-
assert_equal 'User Reset Instructions', mail.subject
|
76
|
-
end
|
77
|
-
end
|
78
|
-
|
79
|
-
test 'body should have user info' do
|
80
|
-
assert_match user.email, mail.body.encoded
|
81
|
-
end
|
82
|
-
|
83
|
-
test 'body should have link to confirm the account' do
|
84
|
-
host, port = ActionMailer::Base.default_url_options.values_at :host, :port
|
85
|
-
|
86
|
-
if mail.body.encoded =~ %r{<a href=\"http://#{host}:#{port}/users/password/edit\?reset_password_token=([^"]+)">}
|
87
|
-
assert_equal Devise.token_generator.digest(user.class, :reset_password_token, $1), user.reset_password_token
|
88
|
-
else
|
89
|
-
flunk "expected reset password url regex to match"
|
90
|
-
end
|
91
|
-
end
|
92
|
-
|
93
|
-
test 'mailer sender accepts a proc' do
|
94
|
-
swap Devise, mailer_sender: proc { "another@example.com" } do
|
95
|
-
assert_equal ['another@example.com'], mail.from
|
96
|
-
end
|
97
|
-
end
|
98
|
-
end
|