devise 4.5.0 → 4.6.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of devise might be problematic. Click here for more details.
- checksums.yaml +5 -5
- data/CHANGELOG.md +30 -1
- data/MIT-LICENSE +1 -1
- data/README.md +18 -0
- data/app/controllers/devise/passwords_controller.rb +1 -0
- data/app/controllers/devise/registrations_controller.rb +25 -7
- data/app/helpers/devise_helper.rb +10 -19
- data/app/views/devise/confirmations/new.html.erb +1 -1
- data/app/views/devise/passwords/edit.html.erb +1 -1
- data/app/views/devise/passwords/new.html.erb +1 -1
- data/app/views/devise/registrations/edit.html.erb +1 -1
- data/app/views/devise/registrations/new.html.erb +1 -1
- data/app/views/devise/sessions/new.html.erb +2 -2
- data/app/views/devise/shared/_error_messages.html.erb +15 -0
- data/app/views/devise/shared/_links.html.erb +7 -7
- data/app/views/devise/unlocks/new.html.erb +1 -1
- data/config/locales/en.yml +1 -0
- data/lib/devise.rb +4 -0
- data/lib/devise/controllers/helpers.rb +1 -1
- data/lib/devise/failure_app.rb +28 -3
- data/lib/devise/models/authenticatable.rb +7 -15
- data/lib/devise/models/confirmable.rb +4 -1
- data/lib/devise/models/database_authenticatable.rb +41 -6
- data/lib/devise/models/lockable.rb +2 -2
- data/lib/devise/models/registerable.rb +2 -0
- data/lib/devise/strategies/database_authenticatable.rb +3 -0
- data/lib/devise/test/controller_helpers.rb +1 -1
- data/lib/devise/version.rb +1 -1
- data/lib/generators/active_record/devise_generator.rb +4 -4
- data/lib/generators/devise/controllers_generator.rb +1 -1
- data/lib/generators/templates/devise.rb +12 -3
- data/lib/generators/templates/simple_form_for/registrations/edit.html.erb +1 -1
- data/lib/generators/templates/simple_form_for/registrations/new.html.erb +1 -1
- metadata +5 -305
- data/.gitignore +0 -10
- data/.travis.yml +0 -69
- data/.yardopts +0 -9
- data/CODE_OF_CONDUCT.md +0 -22
- data/CONTRIBUTING.md +0 -79
- data/Gemfile +0 -39
- data/Gemfile.lock +0 -202
- data/ISSUE_TEMPLATE.md +0 -19
- data/Rakefile +0 -37
- data/bin/test +0 -13
- data/devise.gemspec +0 -28
- data/devise.png +0 -0
- data/gemfiles/Gemfile.rails-4.1-stable +0 -32
- data/gemfiles/Gemfile.rails-4.1-stable.lock +0 -171
- data/gemfiles/Gemfile.rails-4.2-stable +0 -32
- data/gemfiles/Gemfile.rails-4.2-stable.lock +0 -192
- data/gemfiles/Gemfile.rails-5.0-stable +0 -33
- data/gemfiles/Gemfile.rails-5.0-stable.lock +0 -192
- data/gemfiles/Gemfile.rails-5.2-rc1 +0 -26
- data/gemfiles/Gemfile.rails-5.2-rc1.lock +0 -201
- data/guides/bug_report_templates/integration_test.rb +0 -106
- data/test/controllers/custom_registrations_controller_test.rb +0 -42
- data/test/controllers/custom_strategy_test.rb +0 -66
- data/test/controllers/helper_methods_test.rb +0 -24
- data/test/controllers/helpers_test.rb +0 -318
- data/test/controllers/inherited_controller_i18n_messages_test.rb +0 -53
- data/test/controllers/internal_helpers_test.rb +0 -129
- data/test/controllers/load_hooks_controller_test.rb +0 -21
- data/test/controllers/passwords_controller_test.rb +0 -34
- data/test/controllers/sessions_controller_test.rb +0 -108
- data/test/controllers/url_helpers_test.rb +0 -67
- data/test/delegator_test.rb +0 -21
- data/test/devise_test.rb +0 -109
- data/test/failure_app_test.rb +0 -346
- data/test/generators/active_record_generator_test.rb +0 -130
- data/test/generators/controllers_generator_test.rb +0 -50
- data/test/generators/devise_generator_test.rb +0 -41
- data/test/generators/install_generator_test.rb +0 -26
- data/test/generators/mongoid_generator_test.rb +0 -25
- data/test/generators/views_generator_test.rb +0 -105
- data/test/helpers/devise_helper_test.rb +0 -51
- data/test/integration/authenticatable_test.rb +0 -706
- data/test/integration/confirmable_test.rb +0 -326
- data/test/integration/database_authenticatable_test.rb +0 -110
- data/test/integration/http_authenticatable_test.rb +0 -114
- data/test/integration/lockable_test.rb +0 -242
- data/test/integration/mounted_engine_test.rb +0 -38
- data/test/integration/omniauthable_test.rb +0 -148
- data/test/integration/recoverable_test.rb +0 -349
- data/test/integration/registerable_test.rb +0 -365
- data/test/integration/rememberable_test.rb +0 -219
- data/test/integration/timeoutable_test.rb +0 -186
- data/test/integration/trackable_test.rb +0 -99
- data/test/mailers/confirmation_instructions_test.rb +0 -117
- data/test/mailers/email_changed_test.rb +0 -132
- data/test/mailers/mailer_test.rb +0 -20
- data/test/mailers/reset_password_instructions_test.rb +0 -98
- data/test/mailers/unlock_instructions_test.rb +0 -93
- data/test/mapping_test.rb +0 -136
- data/test/models/authenticatable_test.rb +0 -25
- data/test/models/confirmable_test.rb +0 -549
- data/test/models/database_authenticatable_test.rb +0 -290
- data/test/models/lockable_test.rb +0 -352
- data/test/models/omniauthable_test.rb +0 -9
- data/test/models/recoverable_test.rb +0 -263
- data/test/models/registerable_test.rb +0 -9
- data/test/models/rememberable_test.rb +0 -184
- data/test/models/serializable_test.rb +0 -60
- data/test/models/timeoutable_test.rb +0 -53
- data/test/models/trackable_test.rb +0 -80
- data/test/models/validatable_test.rb +0 -121
- data/test/models_test.rb +0 -155
- data/test/omniauth/config_test.rb +0 -61
- data/test/omniauth/url_helpers_test.rb +0 -53
- data/test/orm/active_record.rb +0 -24
- data/test/orm/mongoid.rb +0 -15
- data/test/parameter_sanitizer_test.rb +0 -105
- data/test/rails_app/Rakefile +0 -6
- data/test/rails_app/app/active_record/admin.rb +0 -8
- data/test/rails_app/app/active_record/shim.rb +0 -4
- data/test/rails_app/app/active_record/user.rb +0 -20
- data/test/rails_app/app/active_record/user_on_engine.rb +0 -9
- data/test/rails_app/app/active_record/user_on_main_app.rb +0 -9
- data/test/rails_app/app/active_record/user_with_validations.rb +0 -12
- data/test/rails_app/app/active_record/user_without_email.rb +0 -10
- data/test/rails_app/app/controllers/admins/sessions_controller.rb +0 -8
- data/test/rails_app/app/controllers/admins_controller.rb +0 -8
- data/test/rails_app/app/controllers/application_controller.rb +0 -13
- data/test/rails_app/app/controllers/application_with_fake_engine.rb +0 -32
- data/test/rails_app/app/controllers/custom/registrations_controller.rb +0 -33
- data/test/rails_app/app/controllers/home_controller.rb +0 -31
- data/test/rails_app/app/controllers/publisher/registrations_controller.rb +0 -4
- data/test/rails_app/app/controllers/publisher/sessions_controller.rb +0 -4
- data/test/rails_app/app/controllers/users/omniauth_callbacks_controller.rb +0 -16
- data/test/rails_app/app/controllers/users_controller.rb +0 -33
- data/test/rails_app/app/helpers/application_helper.rb +0 -5
- data/test/rails_app/app/mailers/users/from_proc_mailer.rb +0 -5
- data/test/rails_app/app/mailers/users/mailer.rb +0 -5
- data/test/rails_app/app/mailers/users/reply_to_mailer.rb +0 -6
- data/test/rails_app/app/mongoid/admin.rb +0 -31
- data/test/rails_app/app/mongoid/shim.rb +0 -25
- data/test/rails_app/app/mongoid/user.rb +0 -50
- data/test/rails_app/app/mongoid/user_on_engine.rb +0 -41
- data/test/rails_app/app/mongoid/user_on_main_app.rb +0 -41
- data/test/rails_app/app/mongoid/user_with_validations.rb +0 -37
- data/test/rails_app/app/mongoid/user_without_email.rb +0 -35
- data/test/rails_app/app/views/admins/index.html.erb +0 -1
- data/test/rails_app/app/views/admins/sessions/new.html.erb +0 -2
- data/test/rails_app/app/views/home/admin_dashboard.html.erb +0 -1
- data/test/rails_app/app/views/home/index.html.erb +0 -1
- data/test/rails_app/app/views/home/join.html.erb +0 -1
- data/test/rails_app/app/views/home/private.html.erb +0 -1
- data/test/rails_app/app/views/home/user_dashboard.html.erb +0 -1
- data/test/rails_app/app/views/layouts/application.html.erb +0 -24
- data/test/rails_app/app/views/users/edit_form.html.erb +0 -1
- data/test/rails_app/app/views/users/index.html.erb +0 -1
- data/test/rails_app/app/views/users/mailer/confirmation_instructions.erb +0 -1
- data/test/rails_app/app/views/users/sessions/new.html.erb +0 -1
- data/test/rails_app/bin/bundle +0 -3
- data/test/rails_app/bin/rails +0 -4
- data/test/rails_app/bin/rake +0 -4
- data/test/rails_app/config.ru +0 -4
- data/test/rails_app/config/application.rb +0 -48
- data/test/rails_app/config/boot.rb +0 -27
- data/test/rails_app/config/database.yml +0 -18
- data/test/rails_app/config/environment.rb +0 -7
- data/test/rails_app/config/environments/development.rb +0 -32
- data/test/rails_app/config/environments/production.rb +0 -88
- data/test/rails_app/config/environments/test.rb +0 -47
- data/test/rails_app/config/initializers/backtrace_silencers.rb +0 -9
- data/test/rails_app/config/initializers/devise.rb +0 -187
- data/test/rails_app/config/initializers/inflections.rb +0 -4
- data/test/rails_app/config/initializers/secret_token.rb +0 -5
- data/test/rails_app/config/initializers/session_store.rb +0 -3
- data/test/rails_app/config/routes.rb +0 -128
- data/test/rails_app/db/migrate/20100401102949_create_tables.rb +0 -77
- data/test/rails_app/db/schema.rb +0 -57
- data/test/rails_app/lib/lazy_load_test_module.rb +0 -5
- data/test/rails_app/lib/shared_admin.rb +0 -23
- data/test/rails_app/lib/shared_user.rb +0 -32
- data/test/rails_app/lib/shared_user_without_email.rb +0 -28
- data/test/rails_app/lib/shared_user_without_omniauth.rb +0 -15
- data/test/rails_app/public/404.html +0 -26
- data/test/rails_app/public/422.html +0 -26
- data/test/rails_app/public/500.html +0 -26
- data/test/rails_app/public/favicon.ico +0 -0
- data/test/rails_test.rb +0 -11
- data/test/routes_test.rb +0 -281
- data/test/secret_key_finder_test.rb +0 -121
- data/test/support/action_controller/record_identifier.rb +0 -12
- data/test/support/assertions.rb +0 -30
- data/test/support/helpers.rb +0 -83
- data/test/support/http_method_compatibility.rb +0 -53
- data/test/support/integration.rb +0 -95
- data/test/support/locale/en.yml +0 -8
- data/test/support/mongoid.yml +0 -6
- data/test/support/webrat/integrations/rails.rb +0 -35
- data/test/test/controller_helpers_test.rb +0 -193
- data/test/test/integration_helpers_test.rb +0 -34
- data/test/test_helper.rb +0 -36
- data/test/test_models.rb +0 -35
data/test/failure_app_test.rb
DELETED
@@ -1,346 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'test_helper'
|
4
|
-
require 'ostruct'
|
5
|
-
|
6
|
-
class FailureTest < ActiveSupport::TestCase
|
7
|
-
class RootFailureApp < Devise::FailureApp
|
8
|
-
def fake_app
|
9
|
-
Object.new
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
class FailureWithSubdomain < RootFailureApp
|
14
|
-
routes = ActionDispatch::Routing::RouteSet.new
|
15
|
-
|
16
|
-
routes.draw do
|
17
|
-
scope subdomain: 'sub' do
|
18
|
-
root to: 'foo#bar'
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
include routes.url_helpers
|
23
|
-
end
|
24
|
-
|
25
|
-
class FailureWithI18nOptions < Devise::FailureApp
|
26
|
-
def i18n_options(options)
|
27
|
-
options.merge(name: 'Steve')
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
class FakeEngineApp < Devise::FailureApp
|
32
|
-
class FakeEngine
|
33
|
-
def new_user_on_engine_session_url _
|
34
|
-
'/user_on_engines/sign_in'
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
def main_app
|
39
|
-
raise 'main_app router called instead of fake_engine'
|
40
|
-
end
|
41
|
-
|
42
|
-
def fake_engine
|
43
|
-
@fake_engine ||= FakeEngine.new
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
def self.context(name, &block)
|
48
|
-
instance_eval(&block)
|
49
|
-
end
|
50
|
-
|
51
|
-
def call_failure(env_params={})
|
52
|
-
env = {
|
53
|
-
'REQUEST_URI' => 'http://test.host/',
|
54
|
-
'HTTP_HOST' => 'test.host',
|
55
|
-
'REQUEST_METHOD' => 'GET',
|
56
|
-
'warden.options' => { scope: :user },
|
57
|
-
'rack.session' => {},
|
58
|
-
'action_dispatch.request.formats' => Array(env_params.delete('formats') || Mime[:html]),
|
59
|
-
'rack.input' => "",
|
60
|
-
'warden' => OpenStruct.new(message: nil)
|
61
|
-
}.merge!(env_params)
|
62
|
-
|
63
|
-
# Passing nil for action_dispatch.request.formats prevents the default from being used in Rails 5, need to remove it
|
64
|
-
if env.has_key?('action_dispatch.request.formats') && env['action_dispatch.request.formats'].nil?
|
65
|
-
env.delete 'action_dispatch.request.formats' unless env['action_dispatch.request.formats']
|
66
|
-
end
|
67
|
-
|
68
|
-
@response = (env.delete(:app) || Devise::FailureApp).call(env).to_a
|
69
|
-
@request = ActionDispatch::Request.new(env)
|
70
|
-
end
|
71
|
-
|
72
|
-
context 'When redirecting' do
|
73
|
-
test 'returns to the default redirect location' do
|
74
|
-
call_failure
|
75
|
-
assert_equal 302, @response.first
|
76
|
-
assert_equal 'You need to sign in or sign up before continuing.', @request.flash[:alert]
|
77
|
-
assert_equal 'http://test.host/users/sign_in', @response.second['Location']
|
78
|
-
end
|
79
|
-
|
80
|
-
test 'returns to the default redirect location considering subdomain' do
|
81
|
-
call_failure('warden.options' => { scope: :subdomain_user })
|
82
|
-
assert_equal 302, @response.first
|
83
|
-
assert_equal 'You need to sign in or sign up before continuing.', @request.flash[:alert]
|
84
|
-
assert_equal 'http://sub.test.host/subdomain_users/sign_in', @response.second['Location']
|
85
|
-
end
|
86
|
-
|
87
|
-
test 'returns to the default redirect location for wildcard requests' do
|
88
|
-
call_failure 'action_dispatch.request.formats' => nil, 'HTTP_ACCEPT' => '*/*'
|
89
|
-
assert_equal 302, @response.first
|
90
|
-
assert_equal 'http://test.host/users/sign_in', @response.second['Location']
|
91
|
-
end
|
92
|
-
|
93
|
-
test 'returns to the root path if no session path is available' do
|
94
|
-
swap Devise, router_name: :fake_app do
|
95
|
-
call_failure app: RootFailureApp
|
96
|
-
assert_equal 302, @response.first
|
97
|
-
assert_equal 'You need to sign in or sign up before continuing.', @request.flash[:alert]
|
98
|
-
assert_equal 'http://test.host/', @response.second['Location']
|
99
|
-
end
|
100
|
-
end
|
101
|
-
|
102
|
-
test 'returns to the root path considering subdomain if no session path is available' do
|
103
|
-
swap Devise, router_name: :fake_app do
|
104
|
-
call_failure app: FailureWithSubdomain
|
105
|
-
assert_equal 302, @response.first
|
106
|
-
assert_equal 'You need to sign in or sign up before continuing.', @request.flash[:alert]
|
107
|
-
assert_equal 'http://sub.test.host/', @response.second['Location']
|
108
|
-
end
|
109
|
-
end
|
110
|
-
|
111
|
-
test 'returns to the default redirect location considering the router for supplied scope' do
|
112
|
-
call_failure app: FakeEngineApp, 'warden.options' => { scope: :user_on_engine }
|
113
|
-
assert_equal 302, @response.first
|
114
|
-
assert_equal 'You need to sign in or sign up before continuing.', @request.flash[:alert]
|
115
|
-
assert_equal 'http://test.host/user_on_engines/sign_in', @response.second['Location']
|
116
|
-
end
|
117
|
-
|
118
|
-
if Rails.application.config.respond_to?(:relative_url_root)
|
119
|
-
test 'returns to the default redirect location considering the relative url root' do
|
120
|
-
swap Rails.application.config, relative_url_root: "/sample" do
|
121
|
-
call_failure
|
122
|
-
assert_equal 302, @response.first
|
123
|
-
assert_equal 'http://test.host/sample/users/sign_in', @response.second['Location']
|
124
|
-
end
|
125
|
-
end
|
126
|
-
|
127
|
-
test 'returns to the default redirect location considering the relative url root and subdomain' do
|
128
|
-
swap Rails.application.config, relative_url_root: "/sample" do
|
129
|
-
call_failure('warden.options' => { scope: :subdomain_user })
|
130
|
-
assert_equal 302, @response.first
|
131
|
-
assert_equal 'http://sub.test.host/sample/subdomain_users/sign_in', @response.second['Location']
|
132
|
-
end
|
133
|
-
end
|
134
|
-
end
|
135
|
-
|
136
|
-
if Rails.application.config.action_controller.respond_to?(:relative_url_root)
|
137
|
-
test "returns to the default redirect location considering action_controller's relative url root" do
|
138
|
-
swap Rails.application.config.action_controller, relative_url_root: "/sample" do
|
139
|
-
call_failure
|
140
|
-
assert_equal 302, @response.first
|
141
|
-
assert_equal 'http://test.host/sample/users/sign_in', @response.second['Location']
|
142
|
-
end
|
143
|
-
end
|
144
|
-
|
145
|
-
test "returns to the default redirect location considering action_controller's relative url root and subdomain" do
|
146
|
-
swap Rails.application.config.action_controller, relative_url_root: "/sample" do
|
147
|
-
call_failure('warden.options' => { scope: :subdomain_user })
|
148
|
-
assert_equal 302, @response.first
|
149
|
-
assert_equal 'http://sub.test.host/sample/subdomain_users/sign_in', @response.second['Location']
|
150
|
-
end
|
151
|
-
end
|
152
|
-
end
|
153
|
-
|
154
|
-
test 'uses the proxy failure message as symbol' do
|
155
|
-
call_failure('warden' => OpenStruct.new(message: :invalid))
|
156
|
-
assert_equal 'Invalid Email or password.', @request.flash[:alert]
|
157
|
-
assert_equal 'http://test.host/users/sign_in', @response.second["Location"]
|
158
|
-
end
|
159
|
-
|
160
|
-
test 'supports authentication_keys as a Hash for the flash message' do
|
161
|
-
swap Devise, authentication_keys: { email: true, login: true } do
|
162
|
-
call_failure('warden' => OpenStruct.new(message: :invalid))
|
163
|
-
assert_equal 'Invalid Email, Login or password.', @request.flash[:alert]
|
164
|
-
end
|
165
|
-
end
|
166
|
-
|
167
|
-
test 'uses custom i18n options' do
|
168
|
-
call_failure('warden' => OpenStruct.new(message: :does_not_exist), app: FailureWithI18nOptions)
|
169
|
-
assert_equal 'User Steve does not exist', @request.flash[:alert]
|
170
|
-
end
|
171
|
-
|
172
|
-
test 'uses the proxy failure message as string' do
|
173
|
-
call_failure('warden' => OpenStruct.new(message: 'Hello world'))
|
174
|
-
assert_equal 'Hello world', @request.flash[:alert]
|
175
|
-
assert_equal 'http://test.host/users/sign_in', @response.second["Location"]
|
176
|
-
end
|
177
|
-
|
178
|
-
test 'set content type to default text/html' do
|
179
|
-
call_failure
|
180
|
-
assert_equal 'text/html; charset=utf-8', @response.second['Content-Type']
|
181
|
-
end
|
182
|
-
|
183
|
-
test 'set up a default message' do
|
184
|
-
call_failure
|
185
|
-
assert_match(/You are being/, @response.last.body)
|
186
|
-
assert_match(/redirected/, @response.last.body)
|
187
|
-
assert_match(/users\/sign_in/, @response.last.body)
|
188
|
-
end
|
189
|
-
|
190
|
-
test 'works for any navigational format' do
|
191
|
-
swap Devise, navigational_formats: [:xml] do
|
192
|
-
call_failure('formats' => Mime[:xml])
|
193
|
-
assert_equal 302, @response.first
|
194
|
-
end
|
195
|
-
end
|
196
|
-
|
197
|
-
test 'redirects the correct format if it is a non-html format request' do
|
198
|
-
swap Devise, navigational_formats: [:js] do
|
199
|
-
call_failure('formats' => Mime[:js])
|
200
|
-
assert_equal 'http://test.host/users/sign_in.js', @response.second["Location"]
|
201
|
-
end
|
202
|
-
end
|
203
|
-
end
|
204
|
-
|
205
|
-
context 'For HTTP request' do
|
206
|
-
test 'return 401 status' do
|
207
|
-
call_failure('formats' => Mime[:xml])
|
208
|
-
assert_equal 401, @response.first
|
209
|
-
end
|
210
|
-
|
211
|
-
test 'return appropriate body for xml' do
|
212
|
-
call_failure('formats' => Mime[:xml])
|
213
|
-
result = %(<?xml version="1.0" encoding="UTF-8"?>\n<errors>\n <error>You need to sign in or sign up before continuing.</error>\n</errors>\n)
|
214
|
-
assert_equal result, @response.last.body
|
215
|
-
end
|
216
|
-
|
217
|
-
test 'return appropriate body for json' do
|
218
|
-
call_failure('formats' => Mime[:json])
|
219
|
-
result = %({"error":"You need to sign in or sign up before continuing."})
|
220
|
-
assert_equal result, @response.last.body
|
221
|
-
end
|
222
|
-
|
223
|
-
test 'return 401 status for unknown formats' do
|
224
|
-
call_failure 'formats' => []
|
225
|
-
assert_equal 401, @response.first
|
226
|
-
end
|
227
|
-
|
228
|
-
test 'return WWW-authenticate headers if model allows' do
|
229
|
-
call_failure('formats' => Mime[:xml])
|
230
|
-
assert_equal 'Basic realm="Application"', @response.second["WWW-Authenticate"]
|
231
|
-
end
|
232
|
-
|
233
|
-
test 'does not return WWW-authenticate headers if model does not allow' do
|
234
|
-
swap Devise, http_authenticatable: false do
|
235
|
-
call_failure('formats' => Mime[:xml])
|
236
|
-
assert_nil @response.second["WWW-Authenticate"]
|
237
|
-
end
|
238
|
-
end
|
239
|
-
|
240
|
-
test 'works for any non navigational format' do
|
241
|
-
swap Devise, navigational_formats: [] do
|
242
|
-
call_failure('formats' => Mime[:html])
|
243
|
-
assert_equal 401, @response.first
|
244
|
-
end
|
245
|
-
end
|
246
|
-
|
247
|
-
test 'uses the failure message as response body' do
|
248
|
-
call_failure('formats' => Mime[:xml], 'warden' => OpenStruct.new(message: :invalid))
|
249
|
-
assert_match '<error>Invalid Email or password.</error>', @response.third.body
|
250
|
-
end
|
251
|
-
|
252
|
-
context 'on ajax call' do
|
253
|
-
context 'when http_authenticatable_on_xhr is false' do
|
254
|
-
test 'dont return 401 with navigational formats' do
|
255
|
-
swap Devise, http_authenticatable_on_xhr: false do
|
256
|
-
call_failure('formats' => Mime[:html], 'HTTP_X_REQUESTED_WITH' => 'XMLHttpRequest')
|
257
|
-
assert_equal 302, @response.first
|
258
|
-
assert_equal 'http://test.host/users/sign_in', @response.second["Location"]
|
259
|
-
end
|
260
|
-
end
|
261
|
-
|
262
|
-
test 'dont return 401 with non navigational formats' do
|
263
|
-
swap Devise, http_authenticatable_on_xhr: false do
|
264
|
-
call_failure('formats' => Mime[:json], 'HTTP_X_REQUESTED_WITH' => 'XMLHttpRequest')
|
265
|
-
assert_equal 302, @response.first
|
266
|
-
assert_equal 'http://test.host/users/sign_in.json', @response.second["Location"]
|
267
|
-
end
|
268
|
-
end
|
269
|
-
end
|
270
|
-
|
271
|
-
context 'when http_authenticatable_on_xhr is true' do
|
272
|
-
test 'return 401' do
|
273
|
-
swap Devise, http_authenticatable_on_xhr: true do
|
274
|
-
call_failure('formats' => Mime[:html], 'HTTP_X_REQUESTED_WITH' => 'XMLHttpRequest')
|
275
|
-
assert_equal 401, @response.first
|
276
|
-
end
|
277
|
-
end
|
278
|
-
|
279
|
-
test 'skip WWW-Authenticate header' do
|
280
|
-
swap Devise, http_authenticatable_on_xhr: true do
|
281
|
-
call_failure('formats' => Mime[:html], 'HTTP_X_REQUESTED_WITH' => 'XMLHttpRequest')
|
282
|
-
assert_nil @response.second['WWW-Authenticate']
|
283
|
-
end
|
284
|
-
end
|
285
|
-
end
|
286
|
-
end
|
287
|
-
end
|
288
|
-
|
289
|
-
context 'With recall' do
|
290
|
-
test 'calls the original controller if invalid email or password' do
|
291
|
-
env = {
|
292
|
-
"warden.options" => { recall: "devise/sessions#new", attempted_path: "/users/sign_in" },
|
293
|
-
"devise.mapping" => Devise.mappings[:user],
|
294
|
-
"warden" => stub_everything
|
295
|
-
}
|
296
|
-
call_failure(env)
|
297
|
-
assert @response.third.body.include?('<h2>Log in</h2>')
|
298
|
-
assert @response.third.body.include?('Invalid Email or password.')
|
299
|
-
end
|
300
|
-
|
301
|
-
test 'calls the original controller if not confirmed email' do
|
302
|
-
env = {
|
303
|
-
"warden.options" => { recall: "devise/sessions#new", attempted_path: "/users/sign_in", message: :unconfirmed },
|
304
|
-
"devise.mapping" => Devise.mappings[:user],
|
305
|
-
"warden" => stub_everything
|
306
|
-
}
|
307
|
-
call_failure(env)
|
308
|
-
assert @response.third.body.include?('<h2>Log in</h2>')
|
309
|
-
assert @response.third.body.include?('You have to confirm your email address before continuing.')
|
310
|
-
end
|
311
|
-
|
312
|
-
test 'calls the original controller if inactive account' do
|
313
|
-
env = {
|
314
|
-
"warden.options" => { recall: "devise/sessions#new", attempted_path: "/users/sign_in", message: :inactive },
|
315
|
-
"devise.mapping" => Devise.mappings[:user],
|
316
|
-
"warden" => stub_everything
|
317
|
-
}
|
318
|
-
call_failure(env)
|
319
|
-
assert @response.third.body.include?('<h2>Log in</h2>')
|
320
|
-
assert @response.third.body.include?('Your account is not activated yet.')
|
321
|
-
end
|
322
|
-
|
323
|
-
if Rails.application.config.respond_to?(:relative_url_root)
|
324
|
-
test 'calls the original controller with the proper environment considering the relative url root' do
|
325
|
-
swap Rails.application.config, relative_url_root: "/sample" do
|
326
|
-
env = {
|
327
|
-
"warden.options" => { recall: "devise/sessions#new", attempted_path: "/sample/users/sign_in"},
|
328
|
-
"devise.mapping" => Devise.mappings[:user],
|
329
|
-
"warden" => stub_everything
|
330
|
-
}
|
331
|
-
call_failure(env)
|
332
|
-
assert @response.third.body.include?('<h2>Log in</h2>')
|
333
|
-
assert @response.third.body.include?('Invalid Email or password.')
|
334
|
-
assert_equal @request.env["SCRIPT_NAME"], '/sample'
|
335
|
-
assert_equal @request.env["PATH_INFO"], '/users/sign_in'
|
336
|
-
end
|
337
|
-
end
|
338
|
-
end
|
339
|
-
end
|
340
|
-
|
341
|
-
context "Lazy loading" do
|
342
|
-
test "loads" do
|
343
|
-
assert_equal Devise::FailureApp.new.lazy_loading_works?, "yes it does"
|
344
|
-
end
|
345
|
-
end
|
346
|
-
end
|
@@ -1,130 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "test_helper"
|
4
|
-
|
5
|
-
if DEVISE_ORM == :active_record
|
6
|
-
require "generators/active_record/devise_generator"
|
7
|
-
|
8
|
-
class ActiveRecordGeneratorTest < Rails::Generators::TestCase
|
9
|
-
tests ActiveRecord::Generators::DeviseGenerator
|
10
|
-
destination File.expand_path("../../tmp", __FILE__)
|
11
|
-
setup :prepare_destination
|
12
|
-
|
13
|
-
test "all files are properly created with rails31 migration syntax" do
|
14
|
-
run_generator %w(monster)
|
15
|
-
assert_migration "db/migrate/devise_create_monsters.rb", /def change/
|
16
|
-
end
|
17
|
-
|
18
|
-
test "all files are properly created with changed db/migrate path in application configuration" do
|
19
|
-
old_paths = Rails.application.config.paths["db/migrate"]
|
20
|
-
Rails.application.config.paths.add "db/migrate", with: "db2/migrate"
|
21
|
-
|
22
|
-
run_generator %w(monster)
|
23
|
-
if Rails.version >= '5.0.3'
|
24
|
-
assert_migration "db2/migrate/devise_create_monsters.rb", /def change/
|
25
|
-
else
|
26
|
-
assert_migration "db/migrate/devise_create_monsters.rb", /def change/
|
27
|
-
end
|
28
|
-
|
29
|
-
Rails.application.config.paths["db/migrate"] = old_paths
|
30
|
-
end
|
31
|
-
|
32
|
-
test "all files for namespaced model are properly created" do
|
33
|
-
run_generator %w(admin/monster)
|
34
|
-
assert_migration "db/migrate/devise_create_admin_monsters.rb", /def change/
|
35
|
-
end
|
36
|
-
|
37
|
-
test "update model migration when model exists" do
|
38
|
-
run_generator %w(monster)
|
39
|
-
assert_file "app/models/monster.rb"
|
40
|
-
run_generator %w(monster)
|
41
|
-
assert_migration "db/migrate/add_devise_to_monsters.rb"
|
42
|
-
end
|
43
|
-
|
44
|
-
test "update model migration when model exists with changed db/migrate path in application configuration" do
|
45
|
-
old_paths = Rails.application.config.paths["db/migrate"]
|
46
|
-
Rails.application.config.paths.add "db/migrate", with: "db2/migrate"
|
47
|
-
|
48
|
-
run_generator %w(monster)
|
49
|
-
assert_file "app/models/monster.rb"
|
50
|
-
run_generator %w(monster)
|
51
|
-
|
52
|
-
if Rails.version >= '5.0.3'
|
53
|
-
assert_migration "db2/migrate/add_devise_to_monsters.rb"
|
54
|
-
else
|
55
|
-
assert_migration "db/migrate/add_devise_to_monsters.rb"
|
56
|
-
end
|
57
|
-
|
58
|
-
Rails.application.config.paths["db/migrate"] = old_paths
|
59
|
-
end
|
60
|
-
|
61
|
-
test "all files are properly deleted" do
|
62
|
-
run_generator %w(monster)
|
63
|
-
run_generator %w(monster)
|
64
|
-
assert_migration "db/migrate/devise_create_monsters.rb"
|
65
|
-
assert_migration "db/migrate/add_devise_to_monsters.rb"
|
66
|
-
run_generator %w(monster), behavior: :revoke
|
67
|
-
assert_no_migration "db/migrate/add_devise_to_monsters.rb"
|
68
|
-
assert_migration "db/migrate/devise_create_monsters.rb"
|
69
|
-
run_generator %w(monster), behavior: :revoke
|
70
|
-
assert_no_file "app/models/monster.rb"
|
71
|
-
assert_no_migration "db/migrate/devise_create_monsters.rb"
|
72
|
-
end
|
73
|
-
|
74
|
-
test "use string column type for ip addresses" do
|
75
|
-
run_generator %w(monster)
|
76
|
-
assert_migration "db/migrate/devise_create_monsters.rb", /t.string :current_sign_in_ip/
|
77
|
-
assert_migration "db/migrate/devise_create_monsters.rb", /t.string :last_sign_in_ip/
|
78
|
-
end
|
79
|
-
|
80
|
-
test "do NOT add primary key type when NOT specified in rails generator" do
|
81
|
-
run_generator %w(monster)
|
82
|
-
assert_migration "db/migrate/devise_create_monsters.rb", /create_table :monsters do/
|
83
|
-
end
|
84
|
-
|
85
|
-
test "add primary key type with rails 5 when specified in rails generator" do
|
86
|
-
run_generator ["monster", "--primary_key_type=uuid"]
|
87
|
-
if Rails.version.start_with? '5'
|
88
|
-
assert_migration "db/migrate/devise_create_monsters.rb", /create_table :monsters, id: :uuid do/
|
89
|
-
else
|
90
|
-
assert_migration "db/migrate/devise_create_monsters.rb", /create_table :monsters do/
|
91
|
-
end
|
92
|
-
end
|
93
|
-
end
|
94
|
-
|
95
|
-
module RailsEngine
|
96
|
-
class Engine < Rails::Engine
|
97
|
-
isolate_namespace RailsEngine
|
98
|
-
end
|
99
|
-
end
|
100
|
-
|
101
|
-
def simulate_inside_engine(engine, namespace)
|
102
|
-
if Rails::Generators.respond_to?(:namespace=)
|
103
|
-
swap Rails::Generators, namespace: namespace do
|
104
|
-
yield
|
105
|
-
end
|
106
|
-
else
|
107
|
-
swap Rails, application: engine.instance do
|
108
|
-
yield
|
109
|
-
end
|
110
|
-
end
|
111
|
-
end
|
112
|
-
|
113
|
-
class ActiveRecordEngineGeneratorTest < Rails::Generators::TestCase
|
114
|
-
tests ActiveRecord::Generators::DeviseGenerator
|
115
|
-
destination File.expand_path("../../tmp", __FILE__)
|
116
|
-
setup :prepare_destination
|
117
|
-
|
118
|
-
test "all files are properly created in rails 4.0" do
|
119
|
-
simulate_inside_engine(RailsEngine::Engine, RailsEngine) do
|
120
|
-
run_generator ["monster"]
|
121
|
-
|
122
|
-
assert_file "app/models/rails_engine/monster.rb", /devise/
|
123
|
-
assert_file "app/models/rails_engine/monster.rb" do |content|
|
124
|
-
assert_no_match %r{attr_accessible :email}, content
|
125
|
-
end
|
126
|
-
end
|
127
|
-
end
|
128
|
-
|
129
|
-
end
|
130
|
-
end
|