devise 3.2.2 → 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 +7 -0
- data/CHANGELOG.md +242 -978
- data/MIT-LICENSE +1 -1
- data/README.md +371 -100
- data/app/controllers/devise/confirmations_controller.rb +11 -5
- data/app/controllers/devise/omniauth_callbacks_controller.rb +12 -6
- data/app/controllers/devise/passwords_controller.rb +21 -8
- data/app/controllers/devise/registrations_controller.rb +59 -26
- data/app/controllers/devise/sessions_controller.rb +47 -17
- data/app/controllers/devise/unlocks_controller.rb +9 -4
- data/app/controllers/devise_controller.rb +67 -31
- data/app/helpers/devise_helper.rb +12 -19
- data/app/mailers/devise/mailer.rb +10 -0
- data/app/views/devise/confirmations/new.html.erb +9 -5
- data/app/views/devise/mailer/confirmation_instructions.html.erb +1 -1
- data/app/views/devise/mailer/email_changed.html.erb +7 -0
- data/app/views/devise/mailer/password_change.html.erb +3 -0
- data/app/views/devise/mailer/reset_password_instructions.html.erb +1 -1
- data/app/views/devise/mailer/unlock_instructions.html.erb +1 -1
- data/app/views/devise/passwords/edit.html.erb +16 -7
- data/app/views/devise/passwords/new.html.erb +9 -5
- data/app/views/devise/registrations/edit.html.erb +29 -15
- data/app/views/devise/registrations/new.html.erb +20 -9
- data/app/views/devise/sessions/new.html.erb +19 -10
- data/app/views/devise/shared/_error_messages.html.erb +15 -0
- data/app/views/devise/shared/{_links.erb → _links.html.erb} +9 -9
- data/app/views/devise/unlocks/new.html.erb +9 -5
- data/config/locales/en.yml +23 -17
- data/lib/devise/controllers/helpers.rb +112 -32
- data/lib/devise/controllers/rememberable.rb +15 -6
- data/lib/devise/controllers/scoped_views.rb +3 -1
- data/lib/devise/controllers/sign_in_out.rb +42 -26
- data/lib/devise/controllers/store_location.rb +31 -5
- data/lib/devise/controllers/url_helpers.rb +9 -7
- data/lib/devise/delegator.rb +2 -0
- data/lib/devise/encryptor.rb +24 -0
- data/lib/devise/failure_app.rb +125 -39
- data/lib/devise/hooks/activatable.rb +7 -6
- data/lib/devise/hooks/csrf_cleaner.rb +5 -1
- data/lib/devise/hooks/forgetable.rb +2 -0
- data/lib/devise/hooks/lockable.rb +7 -2
- data/lib/devise/hooks/proxy.rb +4 -2
- data/lib/devise/hooks/rememberable.rb +4 -2
- data/lib/devise/hooks/timeoutable.rb +16 -9
- data/lib/devise/hooks/trackable.rb +3 -1
- data/lib/devise/mailers/helpers.rb +15 -12
- data/lib/devise/mapping.rb +8 -2
- data/lib/devise/models/authenticatable.rb +82 -56
- data/lib/devise/models/confirmable.rb +125 -42
- data/lib/devise/models/database_authenticatable.rb +110 -32
- data/lib/devise/models/lockable.rb +30 -17
- data/lib/devise/models/omniauthable.rb +3 -1
- data/lib/devise/models/recoverable.rb +62 -26
- data/lib/devise/models/registerable.rb +4 -0
- data/lib/devise/models/rememberable.rb +62 -33
- data/lib/devise/models/timeoutable.rb +4 -8
- data/lib/devise/models/trackable.rb +20 -4
- data/lib/devise/models/validatable.rb +16 -9
- data/lib/devise/models.rb +3 -1
- data/lib/devise/modules.rb +12 -10
- data/lib/devise/omniauth/config.rb +2 -0
- data/lib/devise/omniauth/url_helpers.rb +14 -5
- data/lib/devise/omniauth.rb +2 -0
- data/lib/devise/orm/active_record.rb +5 -1
- data/lib/devise/orm/mongoid.rb +6 -2
- data/lib/devise/parameter_filter.rb +4 -0
- data/lib/devise/parameter_sanitizer.rb +139 -65
- data/lib/devise/rails/routes.rb +147 -116
- data/lib/devise/rails/warden_compat.rb +3 -10
- data/lib/devise/rails.rb +10 -13
- data/lib/devise/secret_key_finder.rb +27 -0
- data/lib/devise/strategies/authenticatable.rb +20 -9
- data/lib/devise/strategies/base.rb +3 -1
- data/lib/devise/strategies/database_authenticatable.rb +14 -6
- data/lib/devise/strategies/rememberable.rb +15 -3
- data/lib/devise/test/controller_helpers.rb +165 -0
- data/lib/devise/test/integration_helpers.rb +63 -0
- data/lib/devise/test_helpers.rb +7 -124
- data/lib/devise/time_inflector.rb +4 -2
- data/lib/devise/token_generator.rb +3 -41
- data/lib/devise/version.rb +3 -1
- data/lib/devise.rb +111 -84
- data/lib/generators/active_record/devise_generator.rb +49 -12
- data/lib/generators/active_record/templates/migration.rb +9 -7
- data/lib/generators/active_record/templates/migration_existing.rb +9 -7
- data/lib/generators/devise/controllers_generator.rb +46 -0
- data/lib/generators/devise/devise_generator.rb +7 -5
- data/lib/generators/devise/install_generator.rb +21 -0
- data/lib/generators/devise/orm_helpers.rb +10 -21
- data/lib/generators/devise/views_generator.rb +49 -28
- data/lib/generators/mongoid/devise_generator.rb +21 -19
- data/lib/generators/templates/README +5 -12
- data/lib/generators/templates/controllers/README +14 -0
- data/lib/generators/templates/controllers/confirmations_controller.rb +30 -0
- data/lib/generators/templates/controllers/omniauth_callbacks_controller.rb +30 -0
- data/lib/generators/templates/controllers/passwords_controller.rb +34 -0
- data/lib/generators/templates/controllers/registrations_controller.rb +62 -0
- data/lib/generators/templates/controllers/sessions_controller.rb +27 -0
- data/lib/generators/templates/controllers/unlocks_controller.rb +30 -0
- data/lib/generators/templates/devise.rb +81 -36
- data/lib/generators/templates/markerb/confirmation_instructions.markerb +1 -1
- data/lib/generators/templates/markerb/email_changed.markerb +7 -0
- 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 +1 -1
- data/lib/generators/templates/simple_form_for/confirmations/new.html.erb +6 -2
- data/lib/generators/templates/simple_form_for/passwords/edit.html.erb +9 -4
- data/lib/generators/templates/simple_form_for/passwords/new.html.erb +5 -2
- data/lib/generators/templates/simple_form_for/registrations/edit.html.erb +14 -6
- data/lib/generators/templates/simple_form_for/registrations/new.html.erb +12 -4
- data/lib/generators/templates/simple_form_for/sessions/new.html.erb +11 -6
- data/lib/generators/templates/simple_form_for/unlocks/new.html.erb +5 -2
- metadata +52 -280
- data/.gitignore +0 -10
- data/.travis.yml +0 -20
- data/.yardopts +0 -9
- data/CONTRIBUTING.md +0 -14
- data/Gemfile +0 -31
- data/Gemfile.lock +0 -160
- data/Rakefile +0 -35
- data/devise.gemspec +0 -27
- data/devise.png +0 -0
- data/gemfiles/Gemfile.rails-3.2.x +0 -31
- data/gemfiles/Gemfile.rails-3.2.x.lock +0 -159
- data/test/controllers/custom_strategy_test.rb +0 -62
- data/test/controllers/helpers_test.rb +0 -276
- data/test/controllers/internal_helpers_test.rb +0 -120
- data/test/controllers/passwords_controller_test.rb +0 -31
- data/test/controllers/sessions_controller_test.rb +0 -99
- data/test/controllers/url_helpers_test.rb +0 -59
- data/test/delegator_test.rb +0 -19
- data/test/devise_test.rb +0 -94
- data/test/failure_app_test.rb +0 -232
- data/test/generators/active_record_generator_test.rb +0 -103
- data/test/generators/devise_generator_test.rb +0 -39
- data/test/generators/install_generator_test.rb +0 -13
- data/test/generators/mongoid_generator_test.rb +0 -23
- data/test/generators/views_generator_test.rb +0 -67
- data/test/helpers/devise_helper_test.rb +0 -51
- data/test/integration/authenticatable_test.rb +0 -713
- data/test/integration/confirmable_test.rb +0 -284
- data/test/integration/database_authenticatable_test.rb +0 -84
- data/test/integration/http_authenticatable_test.rb +0 -105
- data/test/integration/lockable_test.rb +0 -239
- data/test/integration/omniauthable_test.rb +0 -133
- data/test/integration/recoverable_test.rb +0 -334
- data/test/integration/registerable_test.rb +0 -349
- data/test/integration/rememberable_test.rb +0 -167
- data/test/integration/timeoutable_test.rb +0 -183
- data/test/integration/trackable_test.rb +0 -92
- data/test/mailers/confirmation_instructions_test.rb +0 -115
- data/test/mailers/reset_password_instructions_test.rb +0 -96
- data/test/mailers/unlock_instructions_test.rb +0 -91
- data/test/mapping_test.rb +0 -127
- data/test/models/authenticatable_test.rb +0 -13
- data/test/models/confirmable_test.rb +0 -454
- data/test/models/database_authenticatable_test.rb +0 -249
- data/test/models/lockable_test.rb +0 -298
- data/test/models/omniauthable_test.rb +0 -7
- data/test/models/recoverable_test.rb +0 -184
- data/test/models/registerable_test.rb +0 -7
- data/test/models/rememberable_test.rb +0 -183
- data/test/models/serializable_test.rb +0 -49
- data/test/models/timeoutable_test.rb +0 -51
- data/test/models/trackable_test.rb +0 -13
- data/test/models/validatable_test.rb +0 -127
- data/test/models_test.rb +0 -144
- data/test/omniauth/config_test.rb +0 -57
- data/test/omniauth/url_helpers_test.rb +0 -54
- data/test/orm/active_record.rb +0 -10
- data/test/orm/mongoid.rb +0 -13
- data/test/parameter_sanitizer_test.rb +0 -81
- data/test/rails_app/Rakefile +0 -6
- data/test/rails_app/app/active_record/admin.rb +0 -6
- data/test/rails_app/app/active_record/shim.rb +0 -2
- data/test/rails_app/app/active_record/user.rb +0 -6
- data/test/rails_app/app/controllers/admins/sessions_controller.rb +0 -6
- data/test/rails_app/app/controllers/admins_controller.rb +0 -11
- data/test/rails_app/app/controllers/application_controller.rb +0 -9
- data/test/rails_app/app/controllers/home_controller.rb +0 -25
- data/test/rails_app/app/controllers/publisher/registrations_controller.rb +0 -2
- data/test/rails_app/app/controllers/publisher/sessions_controller.rb +0 -2
- data/test/rails_app/app/controllers/users/omniauth_callbacks_controller.rb +0 -14
- data/test/rails_app/app/controllers/users_controller.rb +0 -31
- data/test/rails_app/app/helpers/application_helper.rb +0 -3
- data/test/rails_app/app/mailers/users/mailer.rb +0 -12
- data/test/rails_app/app/mongoid/admin.rb +0 -29
- data/test/rails_app/app/mongoid/shim.rb +0 -23
- data/test/rails_app/app/mongoid/user.rb +0 -39
- 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 -40
- data/test/rails_app/config/boot.rb +0 -14
- data/test/rails_app/config/database.yml +0 -18
- data/test/rails_app/config/environment.rb +0 -5
- data/test/rails_app/config/environments/development.rb +0 -30
- data/test/rails_app/config/environments/production.rb +0 -80
- data/test/rails_app/config/environments/test.rb +0 -36
- data/test/rails_app/config/initializers/backtrace_silencers.rb +0 -7
- data/test/rails_app/config/initializers/devise.rb +0 -181
- data/test/rails_app/config/initializers/inflections.rb +0 -2
- data/test/rails_app/config/initializers/secret_token.rb +0 -8
- data/test/rails_app/config/initializers/session_store.rb +0 -1
- data/test/rails_app/config/routes.rb +0 -104
- data/test/rails_app/config.ru +0 -4
- data/test/rails_app/db/migrate/20100401102949_create_tables.rb +0 -71
- data/test/rails_app/db/schema.rb +0 -55
- data/test/rails_app/lib/shared_admin.rb +0 -17
- data/test/rails_app/lib/shared_user.rb +0 -29
- 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/routes_test.rb +0 -250
- data/test/support/assertions.rb +0 -40
- data/test/support/helpers.rb +0 -70
- data/test/support/integration.rb +0 -92
- data/test/support/locale/en.yml +0 -8
- data/test/support/webrat/integrations/rails.rb +0 -24
- data/test/test_helper.rb +0 -27
- data/test/test_helpers_test.rb +0 -173
- data/test/test_models.rb +0 -33
data/test/devise_test.rb
DELETED
@@ -1,94 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
module Devise
|
4
|
-
def self.yield_and_restore
|
5
|
-
@@warden_configured = nil
|
6
|
-
c, b = @@warden_config, @@warden_config_block
|
7
|
-
yield
|
8
|
-
ensure
|
9
|
-
@@warden_config, @@warden_config_block = c, b
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
class DeviseTest < ActiveSupport::TestCase
|
14
|
-
test 'bcrypt on the class' do
|
15
|
-
password = "super secret"
|
16
|
-
klass = Struct.new(:pepper, :stretches).new("blahblah", 2)
|
17
|
-
hash = Devise.bcrypt(klass, password)
|
18
|
-
assert_equal ::BCrypt::Password.create(hash), hash
|
19
|
-
|
20
|
-
klass = Struct.new(:pepper, :stretches).new("bla", 2)
|
21
|
-
hash = Devise.bcrypt(klass, password)
|
22
|
-
assert_not_equal ::BCrypt::Password.new(hash), hash
|
23
|
-
end
|
24
|
-
|
25
|
-
test 'model options can be configured through Devise' do
|
26
|
-
swap Devise, :allow_unconfirmed_access_for => 113, :pepper => "foo" do
|
27
|
-
assert_equal 113, Devise.allow_unconfirmed_access_for
|
28
|
-
assert_equal "foo", Devise.pepper
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
test 'setup block yields self' do
|
33
|
-
Devise.setup do |config|
|
34
|
-
assert_equal Devise, config
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
test 'stores warden configuration' do
|
39
|
-
assert_kind_of Devise::Delegator, Devise.warden_config.failure_app
|
40
|
-
assert_equal :user, Devise.warden_config.default_scope
|
41
|
-
end
|
42
|
-
|
43
|
-
test 'warden manager user configuration through a block' do
|
44
|
-
Devise.yield_and_restore do
|
45
|
-
@executed = false
|
46
|
-
Devise.warden do |config|
|
47
|
-
@executed = true
|
48
|
-
assert_kind_of Warden::Config, config
|
49
|
-
end
|
50
|
-
|
51
|
-
Devise.configure_warden!
|
52
|
-
assert @executed
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
test 'add new module using the helper method' do
|
57
|
-
assert_nothing_raised(Exception) { Devise.add_module(:coconut) }
|
58
|
-
assert_equal 1, Devise::ALL.select { |v| v == :coconut }.size
|
59
|
-
assert_not Devise::STRATEGIES.include?(:coconut)
|
60
|
-
assert_not defined?(Devise::Models::Coconut)
|
61
|
-
Devise::ALL.delete(:coconut)
|
62
|
-
|
63
|
-
assert_nothing_raised(Exception) { Devise.add_module(:banana, :strategy => :fruits) }
|
64
|
-
assert_equal :fruits, Devise::STRATEGIES[:banana]
|
65
|
-
Devise::ALL.delete(:banana)
|
66
|
-
Devise::STRATEGIES.delete(:banana)
|
67
|
-
|
68
|
-
assert_nothing_raised(Exception) { Devise.add_module(:kivi, :controller => :fruits) }
|
69
|
-
assert_equal :fruits, Devise::CONTROLLERS[:kivi]
|
70
|
-
Devise::ALL.delete(:kivi)
|
71
|
-
Devise::CONTROLLERS.delete(:kivi)
|
72
|
-
end
|
73
|
-
|
74
|
-
test 'should complain when comparing empty or different sized passes' do
|
75
|
-
[nil, ""].each do |empty|
|
76
|
-
assert_not Devise.secure_compare(empty, "something")
|
77
|
-
assert_not Devise.secure_compare("something", empty)
|
78
|
-
assert_not Devise.secure_compare(empty, empty)
|
79
|
-
end
|
80
|
-
assert_not Devise.secure_compare("size_1", "size_four")
|
81
|
-
end
|
82
|
-
|
83
|
-
test 'Devise.email_regexp should match valid email addresses' do
|
84
|
-
valid_emails = ["test@example.com", "jo@jo.co", "f4$_m@you.com", "testing.example@example.com.ua"]
|
85
|
-
non_valid_emails = ["rex", "test@go,com", "test user@example.com", "test_user@example server.com"]
|
86
|
-
|
87
|
-
valid_emails.each do |email|
|
88
|
-
assert_match Devise.email_regexp, email
|
89
|
-
end
|
90
|
-
non_valid_emails.each do |email|
|
91
|
-
assert_no_match Devise.email_regexp, email
|
92
|
-
end
|
93
|
-
end
|
94
|
-
end
|
data/test/failure_app_test.rb
DELETED
@@ -1,232 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
require 'ostruct'
|
3
|
-
|
4
|
-
class FailureTest < ActiveSupport::TestCase
|
5
|
-
class RootFailureApp < Devise::FailureApp
|
6
|
-
def fake_app
|
7
|
-
Object.new
|
8
|
-
end
|
9
|
-
end
|
10
|
-
|
11
|
-
class FailureWithI18nOptions < Devise::FailureApp
|
12
|
-
def i18n_options(options)
|
13
|
-
options.merge(:name => 'Steve')
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
def self.context(name, &block)
|
18
|
-
instance_eval(&block)
|
19
|
-
end
|
20
|
-
|
21
|
-
def call_failure(env_params={})
|
22
|
-
env = {
|
23
|
-
'REQUEST_URI' => 'http://test.host/',
|
24
|
-
'HTTP_HOST' => 'test.host',
|
25
|
-
'REQUEST_METHOD' => 'GET',
|
26
|
-
'warden.options' => { :scope => :user },
|
27
|
-
'rack.session' => {},
|
28
|
-
'action_dispatch.request.formats' => Array(env_params.delete('formats') || Mime::HTML),
|
29
|
-
'rack.input' => "",
|
30
|
-
'warden' => OpenStruct.new(:message => nil)
|
31
|
-
}.merge!(env_params)
|
32
|
-
|
33
|
-
@response = (env.delete(:app) || Devise::FailureApp).call(env).to_a
|
34
|
-
@request = ActionDispatch::Request.new(env)
|
35
|
-
end
|
36
|
-
|
37
|
-
context 'When redirecting' do
|
38
|
-
test 'returns to the default redirect location' do
|
39
|
-
call_failure
|
40
|
-
assert_equal 302, @response.first
|
41
|
-
assert_equal 'You need to sign in or sign up before continuing.', @request.flash[:alert]
|
42
|
-
assert_equal 'http://test.host/users/sign_in', @response.second['Location']
|
43
|
-
end
|
44
|
-
|
45
|
-
test 'returns to the default redirect location for wildcard requests' do
|
46
|
-
call_failure 'action_dispatch.request.formats' => nil, 'HTTP_ACCEPT' => '*/*'
|
47
|
-
assert_equal 302, @response.first
|
48
|
-
assert_equal 'http://test.host/users/sign_in', @response.second['Location']
|
49
|
-
end
|
50
|
-
|
51
|
-
test 'returns to the root path if no session path is available' do
|
52
|
-
swap Devise, :router_name => :fake_app do
|
53
|
-
call_failure :app => RootFailureApp
|
54
|
-
assert_equal 302, @response.first
|
55
|
-
assert_equal 'You need to sign in or sign up before continuing.', @request.flash[:alert]
|
56
|
-
assert_equal 'http://test.host/', @response.second['Location']
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
if Rails.application.config.respond_to?(:relative_url_root)
|
61
|
-
test 'returns to the default redirect location considering the relative url root' do
|
62
|
-
swap Rails.application.config, :relative_url_root => "/sample" do
|
63
|
-
call_failure
|
64
|
-
assert_equal 302, @response.first
|
65
|
-
assert_equal 'http://test.host/sample/users/sign_in', @response.second['Location']
|
66
|
-
end
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
|
-
test 'uses the proxy failure message as symbol' do
|
71
|
-
call_failure('warden' => OpenStruct.new(:message => :invalid))
|
72
|
-
assert_equal 'Invalid email or password.', @request.flash[:alert]
|
73
|
-
assert_equal 'http://test.host/users/sign_in', @response.second["Location"]
|
74
|
-
end
|
75
|
-
|
76
|
-
test 'uses custom i18n options' do
|
77
|
-
call_failure('warden' => OpenStruct.new(:message => :does_not_exist), :app => FailureWithI18nOptions)
|
78
|
-
assert_equal 'User Steve does not exist', @request.flash[:alert]
|
79
|
-
end
|
80
|
-
|
81
|
-
test 'uses the proxy failure message as string' do
|
82
|
-
call_failure('warden' => OpenStruct.new(:message => 'Hello world'))
|
83
|
-
assert_equal 'Hello world', @request.flash[:alert]
|
84
|
-
assert_equal 'http://test.host/users/sign_in', @response.second["Location"]
|
85
|
-
end
|
86
|
-
|
87
|
-
test 'set content type to default text/html' do
|
88
|
-
call_failure
|
89
|
-
assert_equal 'text/html; charset=utf-8', @response.second['Content-Type']
|
90
|
-
end
|
91
|
-
|
92
|
-
test 'setup a default message' do
|
93
|
-
call_failure
|
94
|
-
assert_match(/You are being/, @response.last.body)
|
95
|
-
assert_match(/redirected/, @response.last.body)
|
96
|
-
assert_match(/users\/sign_in/, @response.last.body)
|
97
|
-
end
|
98
|
-
|
99
|
-
test 'works for any navigational format' do
|
100
|
-
swap Devise, :navigational_formats => [:xml] do
|
101
|
-
call_failure('formats' => Mime::XML)
|
102
|
-
assert_equal 302, @response.first
|
103
|
-
end
|
104
|
-
end
|
105
|
-
|
106
|
-
test 'redirects the correct format if it is a non-html format request' do
|
107
|
-
swap Devise, :navigational_formats => [:js] do
|
108
|
-
call_failure('formats' => Mime::JS)
|
109
|
-
assert_equal 'http://test.host/users/sign_in.js', @response.second["Location"]
|
110
|
-
end
|
111
|
-
end
|
112
|
-
end
|
113
|
-
|
114
|
-
context 'For HTTP request' do
|
115
|
-
test 'return 401 status' do
|
116
|
-
call_failure('formats' => Mime::XML)
|
117
|
-
assert_equal 401, @response.first
|
118
|
-
end
|
119
|
-
|
120
|
-
test 'return appropriate body for xml' do
|
121
|
-
call_failure('formats' => Mime::XML)
|
122
|
-
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)
|
123
|
-
assert_equal result, @response.last.body
|
124
|
-
end
|
125
|
-
|
126
|
-
test 'return appropriate body for json' do
|
127
|
-
call_failure('formats' => Mime::JSON)
|
128
|
-
result = %({"error":"You need to sign in or sign up before continuing."})
|
129
|
-
assert_equal result, @response.last.body
|
130
|
-
end
|
131
|
-
|
132
|
-
test 'return 401 status for unknown formats' do
|
133
|
-
call_failure 'formats' => []
|
134
|
-
assert_equal 401, @response.first
|
135
|
-
end
|
136
|
-
|
137
|
-
test 'return WWW-authenticate headers if model allows' do
|
138
|
-
call_failure('formats' => Mime::XML)
|
139
|
-
assert_equal 'Basic realm="Application"', @response.second["WWW-Authenticate"]
|
140
|
-
end
|
141
|
-
|
142
|
-
test 'does not return WWW-authenticate headers if model does not allow' do
|
143
|
-
swap Devise, :http_authenticatable => false do
|
144
|
-
call_failure('formats' => Mime::XML)
|
145
|
-
assert_nil @response.second["WWW-Authenticate"]
|
146
|
-
end
|
147
|
-
end
|
148
|
-
|
149
|
-
test 'works for any non navigational format' do
|
150
|
-
swap Devise, :navigational_formats => [] do
|
151
|
-
call_failure('formats' => Mime::HTML)
|
152
|
-
assert_equal 401, @response.first
|
153
|
-
end
|
154
|
-
end
|
155
|
-
|
156
|
-
test 'uses the failure message as response body' do
|
157
|
-
call_failure('formats' => Mime::XML, 'warden' => OpenStruct.new(:message => :invalid))
|
158
|
-
assert_match '<error>Invalid email or password.</error>', @response.third.body
|
159
|
-
end
|
160
|
-
|
161
|
-
context 'on ajax call' do
|
162
|
-
context 'when http_authenticatable_on_xhr is false' do
|
163
|
-
test 'dont return 401 with navigational formats' do
|
164
|
-
swap Devise, :http_authenticatable_on_xhr => false do
|
165
|
-
call_failure('formats' => Mime::HTML, 'HTTP_X_REQUESTED_WITH' => 'XMLHttpRequest')
|
166
|
-
assert_equal 302, @response.first
|
167
|
-
assert_equal 'http://test.host/users/sign_in', @response.second["Location"]
|
168
|
-
end
|
169
|
-
end
|
170
|
-
|
171
|
-
test 'dont return 401 with non navigational formats' do
|
172
|
-
swap Devise, :http_authenticatable_on_xhr => false do
|
173
|
-
call_failure('formats' => Mime::JSON, 'HTTP_X_REQUESTED_WITH' => 'XMLHttpRequest')
|
174
|
-
assert_equal 302, @response.first
|
175
|
-
assert_equal 'http://test.host/users/sign_in.json', @response.second["Location"]
|
176
|
-
end
|
177
|
-
end
|
178
|
-
end
|
179
|
-
|
180
|
-
context 'when http_authenticatable_on_xhr is true' do
|
181
|
-
test 'return 401' do
|
182
|
-
swap Devise, :http_authenticatable_on_xhr => true do
|
183
|
-
call_failure('formats' => Mime::HTML, 'HTTP_X_REQUESTED_WITH' => 'XMLHttpRequest')
|
184
|
-
assert_equal 401, @response.first
|
185
|
-
end
|
186
|
-
end
|
187
|
-
|
188
|
-
test 'skip WWW-Authenticate header' do
|
189
|
-
swap Devise, :http_authenticatable_on_xhr => true do
|
190
|
-
call_failure('formats' => Mime::HTML, 'HTTP_X_REQUESTED_WITH' => 'XMLHttpRequest')
|
191
|
-
assert_nil @response.second['WWW-Authenticate']
|
192
|
-
end
|
193
|
-
end
|
194
|
-
end
|
195
|
-
end
|
196
|
-
end
|
197
|
-
|
198
|
-
context 'With recall' do
|
199
|
-
test 'calls the original controller if invalid email or password' do
|
200
|
-
env = {
|
201
|
-
"warden.options" => { :recall => "devise/sessions#new", :attempted_path => "/users/sign_in" },
|
202
|
-
"devise.mapping" => Devise.mappings[:user],
|
203
|
-
"warden" => stub_everything
|
204
|
-
}
|
205
|
-
call_failure(env)
|
206
|
-
assert @response.third.body.include?('<h2>Sign in</h2>')
|
207
|
-
assert @response.third.body.include?('Invalid email or password.')
|
208
|
-
end
|
209
|
-
|
210
|
-
test 'calls the original controller if not confirmed email' do
|
211
|
-
env = {
|
212
|
-
"warden.options" => { :recall => "devise/sessions#new", :attempted_path => "/users/sign_in", :message => :unconfirmed },
|
213
|
-
"devise.mapping" => Devise.mappings[:user],
|
214
|
-
"warden" => stub_everything
|
215
|
-
}
|
216
|
-
call_failure(env)
|
217
|
-
assert @response.third.body.include?('<h2>Sign in</h2>')
|
218
|
-
assert @response.third.body.include?('You have to confirm your account before continuing.')
|
219
|
-
end
|
220
|
-
|
221
|
-
test 'calls the original controller if inactive account' do
|
222
|
-
env = {
|
223
|
-
"warden.options" => { :recall => "devise/sessions#new", :attempted_path => "/users/sign_in", :message => :inactive },
|
224
|
-
"devise.mapping" => Devise.mappings[:user],
|
225
|
-
"warden" => stub_everything
|
226
|
-
}
|
227
|
-
call_failure(env)
|
228
|
-
assert @response.third.body.include?('<h2>Sign in</h2>')
|
229
|
-
assert @response.third.body.include?('Your account is not activated yet.')
|
230
|
-
end
|
231
|
-
end
|
232
|
-
end
|
@@ -1,103 +0,0 @@
|
|
1
|
-
require "test_helper"
|
2
|
-
|
3
|
-
if DEVISE_ORM == :active_record
|
4
|
-
require "generators/active_record/devise_generator"
|
5
|
-
|
6
|
-
class ActiveRecordGeneratorTest < Rails::Generators::TestCase
|
7
|
-
tests ActiveRecord::Generators::DeviseGenerator
|
8
|
-
destination File.expand_path("../../tmp", __FILE__)
|
9
|
-
setup :prepare_destination
|
10
|
-
|
11
|
-
test "all files are properly created with rails31 migration syntax" do
|
12
|
-
run_generator %w(monster)
|
13
|
-
assert_migration "db/migrate/devise_create_monsters.rb", /def change/
|
14
|
-
end
|
15
|
-
|
16
|
-
test "all files for namespaced model are properly created" do
|
17
|
-
run_generator %w(admin/monster)
|
18
|
-
assert_migration "db/migrate/devise_create_admin_monsters.rb", /def change/
|
19
|
-
end
|
20
|
-
|
21
|
-
test "update model migration when model exists" do
|
22
|
-
run_generator %w(monster)
|
23
|
-
assert_file "app/models/monster.rb"
|
24
|
-
run_generator %w(monster)
|
25
|
-
assert_migration "db/migrate/add_devise_to_monsters.rb"
|
26
|
-
end
|
27
|
-
|
28
|
-
test "all files are properly deleted" do
|
29
|
-
run_generator %w(monster)
|
30
|
-
run_generator %w(monster)
|
31
|
-
assert_migration "db/migrate/devise_create_monsters.rb"
|
32
|
-
assert_migration "db/migrate/add_devise_to_monsters.rb"
|
33
|
-
run_generator %w(monster), :behavior => :revoke
|
34
|
-
assert_no_migration "db/migrate/add_devise_to_monsters.rb"
|
35
|
-
assert_migration "db/migrate/devise_create_monsters.rb"
|
36
|
-
run_generator %w(monster), :behavior => :revoke
|
37
|
-
assert_no_file "app/models/monster.rb"
|
38
|
-
assert_no_migration "db/migrate/devise_create_monsters.rb"
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
module RailsEngine
|
43
|
-
class Engine < Rails::Engine
|
44
|
-
isolate_namespace RailsEngine
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
def simulate_inside_engine(engine, namespace)
|
49
|
-
if Rails::Generators.respond_to?(:namespace=)
|
50
|
-
swap Rails::Generators, :namespace => namespace do
|
51
|
-
yield
|
52
|
-
end
|
53
|
-
else
|
54
|
-
swap Rails, :application => engine.instance do
|
55
|
-
yield
|
56
|
-
end
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
class ActiveRecordEngineGeneratorTest < Rails::Generators::TestCase
|
61
|
-
tests ActiveRecord::Generators::DeviseGenerator
|
62
|
-
destination File.expand_path("../../tmp", __FILE__)
|
63
|
-
setup :prepare_destination
|
64
|
-
|
65
|
-
test "all files are properly created in rails 4.0" do
|
66
|
-
ActiveRecord::Generators::DeviseGenerator.any_instance.stubs(:rails_3?).returns(false)
|
67
|
-
simulate_inside_engine(RailsEngine::Engine, RailsEngine) do
|
68
|
-
run_generator ["monster"]
|
69
|
-
|
70
|
-
assert_file "app/models/rails_engine/monster.rb", /devise/
|
71
|
-
assert_file "app/models/rails_engine/monster.rb" do |content|
|
72
|
-
assert_no_match /attr_accessible :email/, content
|
73
|
-
end
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
test "all files are properly created in rails 3.2 when strong_parameters gem is not installed" do
|
78
|
-
ActiveRecord::Generators::DeviseGenerator.any_instance.stubs(:rails_3?).returns(true)
|
79
|
-
ActiveRecord::Generators::DeviseGenerator.any_instance.stubs(:strong_parameters_enabled?).returns(false)
|
80
|
-
simulate_inside_engine(RailsEngine::Engine, RailsEngine) do
|
81
|
-
run_generator ["monster"]
|
82
|
-
|
83
|
-
assert_file "app/models/rails_engine/monster.rb", /devise/
|
84
|
-
assert_file "app/models/rails_engine/monster.rb" do |content|
|
85
|
-
assert_match /attr_accessible :email/, content
|
86
|
-
end
|
87
|
-
end
|
88
|
-
end
|
89
|
-
|
90
|
-
test "all files are properly created in rails 3.2 when strong_parameters gem is installed" do
|
91
|
-
ActiveRecord::Generators::DeviseGenerator.any_instance.stubs(:rails_3?).returns(true)
|
92
|
-
ActiveRecord::Generators::DeviseGenerator.any_instance.stubs(:strong_parameters_enabled?).returns(true)
|
93
|
-
simulate_inside_engine(RailsEngine::Engine, RailsEngine) do
|
94
|
-
run_generator ["monster"]
|
95
|
-
|
96
|
-
assert_file "app/models/rails_engine/monster.rb", /devise/
|
97
|
-
assert_file "app/models/rails_engine/monster.rb" do |content|
|
98
|
-
assert_no_match /attr_accessible :email/, content
|
99
|
-
end
|
100
|
-
end
|
101
|
-
end
|
102
|
-
end
|
103
|
-
end
|
@@ -1,39 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
require "generators/devise/devise_generator"
|
4
|
-
|
5
|
-
class DeviseGeneratorTest < Rails::Generators::TestCase
|
6
|
-
tests Devise::Generators::DeviseGenerator
|
7
|
-
destination File.expand_path("../../tmp", __FILE__)
|
8
|
-
|
9
|
-
setup do
|
10
|
-
prepare_destination
|
11
|
-
copy_routes
|
12
|
-
end
|
13
|
-
|
14
|
-
test "route generation for simple model names" do
|
15
|
-
run_generator %w(monster name:string)
|
16
|
-
assert_file "config/routes.rb", /devise_for :monsters/
|
17
|
-
end
|
18
|
-
|
19
|
-
test "route generation for namespaced model names" do
|
20
|
-
run_generator %w(monster/goblin name:string)
|
21
|
-
match = /devise_for :goblins, :class_name => "Monster::Goblin"/
|
22
|
-
assert_file "config/routes.rb", match
|
23
|
-
end
|
24
|
-
|
25
|
-
test "route generation with skip routes" do
|
26
|
-
run_generator %w(monster name:string --skip-routes)
|
27
|
-
match = /devise_for :monsters, :skip => :all/
|
28
|
-
assert_file "config/routes.rb", match
|
29
|
-
end
|
30
|
-
|
31
|
-
def copy_routes
|
32
|
-
routes = File.expand_path("../../rails_app/config/routes.rb", __FILE__)
|
33
|
-
destination = File.join(destination_root, "config")
|
34
|
-
|
35
|
-
FileUtils.mkdir_p(destination)
|
36
|
-
FileUtils.cp routes, destination
|
37
|
-
end
|
38
|
-
|
39
|
-
end
|
@@ -1,13 +0,0 @@
|
|
1
|
-
require "test_helper"
|
2
|
-
|
3
|
-
class InstallGeneratorTest < Rails::Generators::TestCase
|
4
|
-
tests Devise::Generators::InstallGenerator
|
5
|
-
destination File.expand_path("../../tmp", __FILE__)
|
6
|
-
setup :prepare_destination
|
7
|
-
|
8
|
-
test "Assert all files are properly created" do
|
9
|
-
run_generator
|
10
|
-
assert_file "config/initializers/devise.rb"
|
11
|
-
assert_file "config/locales/devise.en.yml"
|
12
|
-
end
|
13
|
-
end
|
@@ -1,23 +0,0 @@
|
|
1
|
-
require "test_helper"
|
2
|
-
|
3
|
-
if DEVISE_ORM == :mongoid
|
4
|
-
require "generators/mongoid/devise_generator"
|
5
|
-
|
6
|
-
class MongoidGeneratorTest < Rails::Generators::TestCase
|
7
|
-
tests Mongoid::Generators::DeviseGenerator
|
8
|
-
destination File.expand_path("../../tmp", __FILE__)
|
9
|
-
setup :prepare_destination
|
10
|
-
|
11
|
-
test "all files are properly created" do
|
12
|
-
run_generator %w(monster)
|
13
|
-
assert_file "app/models/monster.rb", /devise/
|
14
|
-
end
|
15
|
-
|
16
|
-
test "all files are properly deleted" do
|
17
|
-
run_generator %w(monster)
|
18
|
-
run_generator %w(monster), :behavior => :revoke
|
19
|
-
assert_no_file "app/models/monster.rb"
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
@@ -1,67 +0,0 @@
|
|
1
|
-
require "test_helper"
|
2
|
-
|
3
|
-
class ViewsGeneratorTest < Rails::Generators::TestCase
|
4
|
-
tests Devise::Generators::ViewsGenerator
|
5
|
-
destination File.expand_path("../../tmp", __FILE__)
|
6
|
-
setup :prepare_destination
|
7
|
-
|
8
|
-
test "Assert all views are properly created with no params" do
|
9
|
-
run_generator
|
10
|
-
assert_files
|
11
|
-
assert_shared_links
|
12
|
-
end
|
13
|
-
|
14
|
-
test "Assert all views are properly created with scope param" do
|
15
|
-
run_generator %w(users)
|
16
|
-
assert_files "users"
|
17
|
-
assert_shared_links "users"
|
18
|
-
|
19
|
-
run_generator %w(admins)
|
20
|
-
assert_files "admins"
|
21
|
-
assert_shared_links "admins"
|
22
|
-
end
|
23
|
-
|
24
|
-
test "Assert views with simple form" do
|
25
|
-
run_generator %w(-b simple_form_for)
|
26
|
-
assert_files
|
27
|
-
assert_file "app/views/devise/confirmations/new.html.erb", /simple_form_for/
|
28
|
-
|
29
|
-
run_generator %w(users -b simple_form_for)
|
30
|
-
assert_files "users"
|
31
|
-
assert_file "app/views/users/confirmations/new.html.erb", /simple_form_for/
|
32
|
-
end
|
33
|
-
|
34
|
-
test "Assert views with markerb" do
|
35
|
-
run_generator %w(--markerb)
|
36
|
-
assert_files nil, :mail_template_engine => "markerb"
|
37
|
-
end
|
38
|
-
|
39
|
-
def assert_files(scope = nil, options={})
|
40
|
-
scope = "devise" if scope.nil?
|
41
|
-
mail_template_engine = options[:mail_template_engine] || "html.erb"
|
42
|
-
|
43
|
-
assert_file "app/views/#{scope}/confirmations/new.html.erb"
|
44
|
-
assert_file "app/views/#{scope}/mailer/confirmation_instructions.#{mail_template_engine}"
|
45
|
-
assert_file "app/views/#{scope}/mailer/reset_password_instructions.#{mail_template_engine}"
|
46
|
-
assert_file "app/views/#{scope}/mailer/unlock_instructions.#{mail_template_engine}"
|
47
|
-
assert_file "app/views/#{scope}/passwords/edit.html.erb"
|
48
|
-
assert_file "app/views/#{scope}/passwords/new.html.erb"
|
49
|
-
assert_file "app/views/#{scope}/registrations/new.html.erb"
|
50
|
-
assert_file "app/views/#{scope}/registrations/edit.html.erb"
|
51
|
-
assert_file "app/views/#{scope}/sessions/new.html.erb"
|
52
|
-
assert_file "app/views/#{scope}/shared/_links.erb"
|
53
|
-
assert_file "app/views/#{scope}/unlocks/new.html.erb"
|
54
|
-
end
|
55
|
-
|
56
|
-
def assert_shared_links(scope = nil)
|
57
|
-
scope = "devise" if scope.nil?
|
58
|
-
link = /<%= render \"#{scope}\/shared\/links\" %>/
|
59
|
-
|
60
|
-
assert_file "app/views/#{scope}/passwords/edit.html.erb", link
|
61
|
-
assert_file "app/views/#{scope}/passwords/new.html.erb", link
|
62
|
-
assert_file "app/views/#{scope}/confirmations/new.html.erb", link
|
63
|
-
assert_file "app/views/#{scope}/registrations/new.html.erb", link
|
64
|
-
assert_file "app/views/#{scope}/sessions/new.html.erb", link
|
65
|
-
assert_file "app/views/#{scope}/unlocks/new.html.erb", link
|
66
|
-
end
|
67
|
-
end
|
@@ -1,51 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
class DeviseHelperTest < ActionDispatch::IntegrationTest
|
4
|
-
setup do
|
5
|
-
model_labels = { :models => { :user => "utilisateur" } }
|
6
|
-
|
7
|
-
I18n.backend.store_translations :fr,
|
8
|
-
{
|
9
|
-
:errors => { :messages => { :not_saved => {
|
10
|
-
:one => "Erreur lors de l'enregistrement de '%{resource}': 1 erreur.",
|
11
|
-
:other => "Erreur lors de l'enregistrement de '%{resource}': %{count} erreurs."
|
12
|
-
} } },
|
13
|
-
:activerecord => model_labels,
|
14
|
-
:mongoid => model_labels
|
15
|
-
}
|
16
|
-
|
17
|
-
I18n.locale = 'fr'
|
18
|
-
end
|
19
|
-
|
20
|
-
teardown do
|
21
|
-
I18n.locale = 'en'
|
22
|
-
end
|
23
|
-
|
24
|
-
test 'test errors.messages.not_saved with single error from i18n' do
|
25
|
-
get new_user_registration_path
|
26
|
-
|
27
|
-
fill_in 'password', :with => 'new_user123'
|
28
|
-
fill_in 'password confirmation', :with => 'new_user123'
|
29
|
-
click_button 'Sign up'
|
30
|
-
|
31
|
-
assert_have_selector '#error_explanation'
|
32
|
-
assert_contain "Erreur lors de l'enregistrement de 'utilisateur': 1 erreur"
|
33
|
-
end
|
34
|
-
|
35
|
-
test 'test errors.messages.not_saved with multiple errors from i18n' do
|
36
|
-
# Dirty tracking behavior prevents email validations from being applied:
|
37
|
-
# https://github.com/mongoid/mongoid/issues/756
|
38
|
-
(pending "Fails on Mongoid < 2.1"; break) if defined?(Mongoid) && Mongoid::VERSION.to_f < 2.1
|
39
|
-
|
40
|
-
get new_user_registration_path
|
41
|
-
|
42
|
-
fill_in 'email', :with => 'invalid_email'
|
43
|
-
fill_in 'password', :with => 'new_user123'
|
44
|
-
fill_in 'password confirmation', :with => 'new_user321'
|
45
|
-
click_button 'Sign up'
|
46
|
-
|
47
|
-
assert_have_selector '#error_explanation'
|
48
|
-
assert_contain "Erreur lors de l'enregistrement de 'utilisateur': 2 erreurs"
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|