devise 2.1.2 → 3.5.10
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of devise might be problematic. Click here for more details.
- checksums.yaml +7 -0
- data/.travis.yml +39 -10
- data/.yardopts +9 -0
- data/{CHANGELOG.rdoc → CHANGELOG.md} +445 -112
- data/CODE_OF_CONDUCT.md +22 -0
- data/CONTRIBUTING.md +16 -0
- data/Gemfile +10 -15
- data/Gemfile.lock +151 -129
- data/MIT-LICENSE +1 -1
- data/README.md +256 -96
- data/Rakefile +4 -2
- data/app/controllers/devise/confirmations_controller.rb +15 -7
- data/app/controllers/devise/omniauth_callbacks_controller.rb +6 -2
- data/app/controllers/devise/passwords_controller.rb +33 -9
- data/app/controllers/devise/registrations_controller.rb +66 -26
- data/app/controllers/devise/sessions_controller.rb +52 -21
- data/app/controllers/devise/unlocks_controller.rb +11 -6
- data/app/controllers/devise_controller.rb +65 -58
- data/app/helpers/devise_helper.rb +2 -2
- data/app/mailers/devise/mailer.rb +19 -10
- data/app/views/devise/confirmations/new.html.erb +8 -4
- data/app/views/devise/mailer/confirmation_instructions.html.erb +2 -2
- data/app/views/devise/mailer/password_change.html.erb +3 -0
- data/app/views/devise/mailer/reset_password_instructions.html.erb +2 -2
- data/app/views/devise/mailer/unlock_instructions.html.erb +2 -2
- data/app/views/devise/passwords/edit.html.erb +15 -6
- data/app/views/devise/passwords/new.html.erb +8 -4
- data/app/views/devise/registrations/edit.html.erb +29 -15
- data/app/views/devise/registrations/new.html.erb +19 -8
- data/app/views/devise/sessions/new.html.erb +17 -8
- data/app/views/devise/shared/{_links.erb → _links.html.erb} +4 -4
- data/app/views/devise/unlocks/new.html.erb +8 -4
- data/config/locales/en.yml +51 -47
- data/devise.gemspec +8 -6
- data/devise.png +0 -0
- data/gemfiles/Gemfile.rails-3.2-stable +29 -0
- data/gemfiles/Gemfile.rails-3.2-stable.lock +172 -0
- data/gemfiles/Gemfile.rails-4.0-stable +30 -0
- data/gemfiles/Gemfile.rails-4.0-stable.lock +166 -0
- data/gemfiles/Gemfile.rails-4.1-stable +30 -0
- data/gemfiles/Gemfile.rails-4.1-stable.lock +171 -0
- data/gemfiles/Gemfile.rails-4.2-stable +30 -0
- data/gemfiles/Gemfile.rails-4.2-stable.lock +193 -0
- data/lib/devise/controllers/helpers.rb +126 -108
- data/lib/devise/controllers/rememberable.rb +19 -17
- data/lib/devise/controllers/scoped_views.rb +1 -1
- data/lib/devise/controllers/sign_in_out.rb +96 -0
- data/lib/devise/controllers/store_location.rb +58 -0
- data/lib/devise/controllers/url_helpers.rb +7 -7
- data/lib/devise/encryptor.rb +22 -0
- data/lib/devise/failure_app.rb +85 -25
- data/lib/devise/hooks/activatable.rb +5 -6
- data/lib/devise/hooks/csrf_cleaner.rb +7 -0
- data/lib/devise/hooks/forgetable.rb +1 -1
- data/lib/devise/hooks/lockable.rb +2 -2
- data/lib/devise/hooks/proxy.rb +21 -0
- data/lib/devise/hooks/rememberable.rb +5 -4
- data/lib/devise/hooks/timeoutable.rb +16 -8
- data/lib/devise/hooks/trackable.rb +1 -1
- data/lib/devise/mailers/helpers.rb +27 -23
- data/lib/devise/mapping.rb +11 -7
- data/lib/devise/models/authenticatable.rb +82 -66
- data/lib/devise/models/confirmable.rb +142 -55
- data/lib/devise/models/database_authenticatable.rb +59 -15
- data/lib/devise/models/lockable.rb +41 -30
- data/lib/devise/models/omniauthable.rb +3 -3
- data/lib/devise/models/recoverable.rb +56 -41
- data/lib/devise/models/rememberable.rb +65 -27
- data/lib/devise/models/timeoutable.rb +2 -8
- data/lib/devise/models/trackable.rb +6 -4
- data/lib/devise/models/validatable.rb +9 -9
- data/lib/devise/models.rb +4 -13
- data/lib/devise/modules.rb +10 -11
- data/lib/devise/omniauth/url_helpers.rb +2 -2
- data/lib/devise/orm/active_record.rb +1 -1
- data/lib/devise/orm/mongoid.rb +1 -1
- data/lib/devise/{param_filter.rb → parameter_filter.rb} +10 -11
- data/lib/devise/parameter_sanitizer.rb +99 -0
- data/lib/devise/rails/routes.rb +173 -115
- data/lib/devise/rails/warden_compat.rb +10 -31
- data/lib/devise/rails.rb +14 -12
- data/lib/devise/strategies/authenticatable.rb +26 -26
- data/lib/devise/strategies/base.rb +1 -1
- data/lib/devise/strategies/database_authenticatable.rb +8 -4
- data/lib/devise/strategies/rememberable.rb +15 -5
- data/lib/devise/test_helpers.rb +7 -5
- data/lib/devise/time_inflector.rb +14 -0
- data/lib/devise/token_generator.rb +70 -0
- data/lib/devise/version.rb +1 -1
- data/lib/devise.rb +110 -52
- data/lib/generators/active_record/devise_generator.rb +34 -18
- data/lib/generators/active_record/templates/migration.rb +5 -6
- data/lib/generators/active_record/templates/migration_existing.rb +5 -6
- data/lib/generators/devise/controllers_generator.rb +44 -0
- data/lib/generators/devise/devise_generator.rb +5 -3
- data/lib/generators/devise/install_generator.rb +5 -0
- data/lib/generators/devise/orm_helpers.rb +25 -6
- data/lib/generators/devise/views_generator.rb +52 -22
- data/lib/generators/mongoid/devise_generator.rb +21 -26
- data/lib/generators/templates/README +9 -5
- data/lib/generators/templates/controllers/README +14 -0
- data/lib/generators/templates/controllers/confirmations_controller.rb +28 -0
- data/lib/generators/templates/controllers/omniauth_callbacks_controller.rb +28 -0
- data/lib/generators/templates/controllers/passwords_controller.rb +32 -0
- data/lib/generators/templates/controllers/registrations_controller.rb +60 -0
- data/lib/generators/templates/controllers/sessions_controller.rb +25 -0
- data/lib/generators/templates/controllers/unlocks_controller.rb +28 -0
- data/lib/generators/templates/devise.rb +80 -43
- data/lib/generators/templates/markerb/confirmation_instructions.markerb +2 -2
- data/lib/generators/templates/markerb/password_change.markerb +3 -0
- data/lib/generators/templates/markerb/reset_password_instructions.markerb +1 -1
- data/lib/generators/templates/markerb/unlock_instructions.markerb +2 -2
- data/lib/generators/templates/simple_form_for/confirmations/new.html.erb +3 -2
- data/lib/generators/templates/simple_form_for/passwords/edit.html.erb +4 -4
- data/lib/generators/templates/simple_form_for/passwords/new.html.erb +2 -2
- data/lib/generators/templates/simple_form_for/registrations/edit.html.erb +11 -6
- data/lib/generators/templates/simple_form_for/registrations/new.html.erb +4 -4
- data/lib/generators/templates/simple_form_for/sessions/new.html.erb +6 -6
- data/lib/generators/templates/simple_form_for/unlocks/new.html.erb +3 -2
- data/script/cached-bundle +49 -0
- data/script/s3-put +71 -0
- data/test/controllers/custom_registrations_controller_test.rb +40 -0
- data/test/controllers/helper_methods_test.rb +21 -0
- data/test/controllers/helpers_test.rb +95 -32
- data/test/controllers/inherited_controller_i18n_messages_test.rb +51 -0
- data/test/controllers/internal_helpers_test.rb +39 -14
- data/test/controllers/load_hooks_controller_test.rb +19 -0
- data/test/controllers/passwords_controller_test.rb +31 -0
- data/test/controllers/sessions_controller_test.rb +66 -6
- data/test/controllers/url_helpers_test.rb +10 -4
- data/test/delegator_test.rb +1 -1
- data/test/devise_test.rb +45 -10
- data/test/failure_app_test.rb +121 -27
- data/test/generators/active_record_generator_test.rb +48 -8
- data/test/generators/controllers_generator_test.rb +48 -0
- data/test/generators/devise_generator_test.rb +2 -2
- data/test/generators/mongoid_generator_test.rb +3 -3
- data/test/generators/views_generator_test.rb +54 -3
- data/test/helpers/devise_helper_test.rb +18 -20
- data/test/integration/authenticatable_test.rb +161 -65
- data/test/integration/confirmable_test.rb +146 -77
- data/test/integration/database_authenticatable_test.rb +43 -30
- data/test/integration/http_authenticatable_test.rb +30 -22
- data/test/integration/lockable_test.rb +64 -49
- data/test/integration/omniauthable_test.rb +17 -15
- data/test/integration/recoverable_test.rb +111 -70
- data/test/integration/registerable_test.rb +114 -79
- data/test/integration/rememberable_test.rb +87 -31
- data/test/integration/timeoutable_test.rb +77 -33
- data/test/integration/trackable_test.rb +5 -5
- data/test/mailers/confirmation_instructions_test.rb +28 -8
- data/test/mailers/reset_password_instructions_test.rb +21 -8
- data/test/mailers/unlock_instructions_test.rb +20 -6
- data/test/mapping_test.rb +12 -5
- data/test/models/authenticatable_test.rb +17 -1
- data/test/models/confirmable_test.rb +216 -62
- data/test/models/database_authenticatable_test.rb +129 -49
- data/test/models/lockable_test.rb +132 -45
- data/test/models/recoverable_test.rb +100 -54
- data/test/models/rememberable_test.rb +89 -94
- data/test/models/serializable_test.rb +12 -11
- data/test/models/timeoutable_test.rb +6 -1
- data/test/models/trackable_test.rb +28 -0
- data/test/models/validatable_test.rb +31 -21
- data/test/models_test.rb +22 -48
- data/test/omniauth/config_test.rb +4 -4
- data/test/omniauth/url_helpers_test.rb +7 -4
- data/test/orm/active_record.rb +1 -0
- data/test/orm/mongoid.rb +2 -3
- data/test/parameter_sanitizer_test.rb +81 -0
- data/test/rails_app/Rakefile +0 -4
- data/test/rails_app/app/active_record/shim.rb +1 -1
- data/test/rails_app/app/active_record/user_on_engine.rb +7 -0
- data/test/rails_app/app/active_record/user_on_main_app.rb +7 -0
- data/test/rails_app/app/active_record/user_without_email.rb +8 -0
- data/test/rails_app/app/controllers/admins/sessions_controller.rb +1 -1
- data/test/rails_app/app/controllers/admins_controller.rb +0 -5
- data/test/rails_app/app/controllers/application_controller.rb +6 -2
- data/test/rails_app/app/controllers/application_with_fake_engine.rb +30 -0
- data/test/rails_app/app/controllers/custom/registrations_controller.rb +31 -0
- data/test/rails_app/app/controllers/home_controller.rb +1 -1
- data/test/rails_app/app/controllers/publisher/registrations_controller.rb +1 -1
- data/test/rails_app/app/controllers/publisher/sessions_controller.rb +1 -1
- data/test/rails_app/app/controllers/users/omniauth_callbacks_controller.rb +4 -4
- data/test/rails_app/app/controllers/users_controller.rb +12 -4
- data/test/rails_app/app/mailers/users/from_proc_mailer.rb +3 -0
- data/test/rails_app/app/mailers/users/mailer.rb +1 -1
- data/test/rails_app/app/mailers/users/reply_to_mailer.rb +4 -0
- data/test/rails_app/app/mongoid/admin.rb +12 -10
- data/test/rails_app/app/mongoid/shim.rb +4 -5
- data/test/rails_app/app/mongoid/user.rb +19 -22
- data/test/rails_app/app/mongoid/user_on_engine.rb +39 -0
- data/test/rails_app/app/mongoid/user_on_main_app.rb +39 -0
- data/test/rails_app/app/mongoid/user_without_email.rb +33 -0
- data/test/rails_app/app/views/admins/sessions/new.html.erb +1 -1
- data/test/rails_app/app/views/home/admin_dashboard.html.erb +1 -1
- data/test/rails_app/app/views/home/index.html.erb +1 -1
- data/test/rails_app/app/views/home/join.html.erb +1 -1
- data/test/rails_app/app/views/home/user_dashboard.html.erb +1 -1
- data/test/rails_app/app/views/layouts/application.html.erb +1 -1
- data/test/rails_app/app/views/users/edit_form.html.erb +1 -0
- data/test/rails_app/bin/bundle +3 -0
- data/test/rails_app/bin/rails +4 -0
- data/test/rails_app/bin/rake +4 -0
- data/test/rails_app/config/application.rb +4 -5
- data/test/rails_app/config/boot.rb +9 -3
- data/test/rails_app/config/environment.rb +2 -2
- data/test/rails_app/config/environments/development.rb +19 -7
- data/test/rails_app/config/environments/production.rb +68 -17
- data/test/rails_app/config/environments/test.rb +24 -16
- data/test/rails_app/config/initializers/devise.rb +22 -20
- data/test/rails_app/config/initializers/secret_token.rb +8 -2
- data/test/rails_app/config/initializers/session_store.rb +1 -0
- data/test/rails_app/config/routes.rb +71 -46
- data/test/rails_app/db/migrate/20100401102949_create_tables.rb +9 -12
- data/test/rails_app/db/schema.rb +21 -18
- data/test/rails_app/lib/shared_admin.rb +7 -4
- data/test/rails_app/lib/shared_user.rb +6 -3
- data/test/rails_app/lib/shared_user_without_email.rb +26 -0
- data/test/rails_app/lib/shared_user_without_omniauth.rb +13 -0
- data/test/rails_test.rb +9 -0
- data/test/routes_test.rb +94 -78
- data/test/support/action_controller/record_identifier.rb +10 -0
- data/test/support/assertions.rb +2 -3
- data/test/support/helpers.rb +18 -32
- data/test/support/integration.rb +17 -16
- data/test/support/locale/en.yml +4 -0
- data/test/support/mongoid.yml +6 -0
- data/test/test_helper.rb +8 -1
- data/test/test_helpers_test.rb +64 -20
- data/test/test_models.rb +33 -0
- data/test/time_helpers.rb +137 -0
- metadata +172 -51
- data/app/views/devise/_links.erb +0 -3
- data/gemfiles/Gemfile.rails-3.1.x +0 -35
- data/gemfiles/Gemfile.rails-3.1.x.lock +0 -167
- data/lib/devise/models/token_authenticatable.rb +0 -77
- data/lib/devise/strategies/token_authenticatable.rb +0 -56
- data/test/indifferent_hash.rb +0 -33
- data/test/integration/token_authenticatable_test.rb +0 -161
- data/test/models/token_authenticatable_test.rb +0 -55
- data/test/rails_app/script/rails +0 -10
@@ -8,14 +8,17 @@ class ViewsGeneratorTest < Rails::Generators::TestCase
|
|
8
8
|
test "Assert all views are properly created with no params" do
|
9
9
|
run_generator
|
10
10
|
assert_files
|
11
|
+
assert_shared_links
|
11
12
|
end
|
12
13
|
|
13
|
-
test "Assert all views are properly created with scope param
|
14
|
+
test "Assert all views are properly created with scope param" do
|
14
15
|
run_generator %w(users)
|
15
16
|
assert_files "users"
|
17
|
+
assert_shared_links "users"
|
16
18
|
|
17
19
|
run_generator %w(admins)
|
18
20
|
assert_files "admins"
|
21
|
+
assert_shared_links "admins"
|
19
22
|
end
|
20
23
|
|
21
24
|
test "Assert views with simple form" do
|
@@ -30,7 +33,43 @@ class ViewsGeneratorTest < Rails::Generators::TestCase
|
|
30
33
|
|
31
34
|
test "Assert views with markerb" do
|
32
35
|
run_generator %w(--markerb)
|
33
|
-
assert_files nil, :
|
36
|
+
assert_files nil, mail_template_engine: "markerb"
|
37
|
+
end
|
38
|
+
|
39
|
+
|
40
|
+
test "Assert only views within specified directories" do
|
41
|
+
run_generator %w(-v sessions registrations)
|
42
|
+
assert_file "app/views/devise/sessions/new.html.erb"
|
43
|
+
assert_file "app/views/devise/registrations/new.html.erb"
|
44
|
+
assert_file "app/views/devise/registrations/edit.html.erb"
|
45
|
+
assert_no_file "app/views/devise/confirmations/new.html.erb"
|
46
|
+
assert_no_file "app/views/devise/mailer/confirmation_instructions.html.erb"
|
47
|
+
end
|
48
|
+
|
49
|
+
test "Assert mailer specific directory with simple form" do
|
50
|
+
run_generator %w(-v mailer -b simple_form_for)
|
51
|
+
assert_file "app/views/devise/mailer/confirmation_instructions.html.erb"
|
52
|
+
assert_file "app/views/devise/mailer/reset_password_instructions.html.erb"
|
53
|
+
assert_file "app/views/devise/mailer/unlock_instructions.html.erb"
|
54
|
+
end
|
55
|
+
|
56
|
+
test "Assert specified directories with scope" do
|
57
|
+
run_generator %w(users -v sessions)
|
58
|
+
assert_file "app/views/users/sessions/new.html.erb"
|
59
|
+
assert_no_file "app/views/users/confirmations/new.html.erb"
|
60
|
+
end
|
61
|
+
|
62
|
+
test "Assert specified directories with simple form" do
|
63
|
+
run_generator %w(-v registrations -b simple_form_for)
|
64
|
+
assert_file "app/views/devise/registrations/new.html.erb", /simple_form_for/
|
65
|
+
assert_no_file "app/views/devise/confirmations/new.html.erb"
|
66
|
+
end
|
67
|
+
|
68
|
+
test "Assert specified directories with markerb" do
|
69
|
+
run_generator %w(--markerb -v passwords mailer)
|
70
|
+
assert_file "app/views/devise/passwords/new.html.erb"
|
71
|
+
assert_no_file "app/views/devise/confirmations/new.html.erb"
|
72
|
+
assert_file "app/views/devise/mailer/reset_password_instructions.markerb"
|
34
73
|
end
|
35
74
|
|
36
75
|
def assert_files(scope = nil, options={})
|
@@ -46,7 +85,19 @@ class ViewsGeneratorTest < Rails::Generators::TestCase
|
|
46
85
|
assert_file "app/views/#{scope}/registrations/new.html.erb"
|
47
86
|
assert_file "app/views/#{scope}/registrations/edit.html.erb"
|
48
87
|
assert_file "app/views/#{scope}/sessions/new.html.erb"
|
49
|
-
assert_file "app/views/#{scope}/shared/_links.erb"
|
88
|
+
assert_file "app/views/#{scope}/shared/_links.html.erb"
|
50
89
|
assert_file "app/views/#{scope}/unlocks/new.html.erb"
|
51
90
|
end
|
91
|
+
|
92
|
+
def assert_shared_links(scope = nil)
|
93
|
+
scope = "devise" if scope.nil?
|
94
|
+
link = /<%= render \"#{scope}\/shared\/links\" %>/
|
95
|
+
|
96
|
+
assert_file "app/views/#{scope}/passwords/edit.html.erb", link
|
97
|
+
assert_file "app/views/#{scope}/passwords/new.html.erb", link
|
98
|
+
assert_file "app/views/#{scope}/confirmations/new.html.erb", link
|
99
|
+
assert_file "app/views/#{scope}/registrations/new.html.erb", link
|
100
|
+
assert_file "app/views/#{scope}/sessions/new.html.erb", link
|
101
|
+
assert_file "app/views/#{scope}/unlocks/new.html.erb", link
|
102
|
+
end
|
52
103
|
end
|
@@ -1,35 +1,34 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
|
-
class DeviseHelperTest <
|
3
|
+
class DeviseHelperTest < ActionDispatch::IntegrationTest
|
4
4
|
setup do
|
5
|
-
model_labels = { :
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
:one => "Erreur lors de l'enregistrement de '%{resource}': 1 erreur.",
|
11
|
-
:other => "Erreur lors de l'enregistrement de '%{resource}': %{count} erreurs."
|
5
|
+
model_labels = { models: { user: "the user" } }
|
6
|
+
translations = {
|
7
|
+
errors: { messages: { not_saved: {
|
8
|
+
one: "Can't save %{resource} because of 1 error",
|
9
|
+
other: "Can't save %{resource} because of %{count} errors",
|
12
10
|
} } },
|
13
|
-
:
|
14
|
-
:
|
11
|
+
activerecord: model_labels,
|
12
|
+
mongoid: model_labels
|
15
13
|
}
|
16
14
|
|
17
|
-
I18n.
|
15
|
+
I18n.available_locales
|
16
|
+
I18n.backend.store_translations(:en, translations)
|
18
17
|
end
|
19
18
|
|
20
19
|
teardown do
|
21
|
-
I18n.
|
20
|
+
I18n.reload!
|
22
21
|
end
|
23
22
|
|
24
23
|
test 'test errors.messages.not_saved with single error from i18n' do
|
25
24
|
get new_user_registration_path
|
26
25
|
|
27
|
-
fill_in 'password', :
|
28
|
-
fill_in 'password confirmation', :
|
26
|
+
fill_in 'password', with: 'new_user123'
|
27
|
+
fill_in 'password confirmation', with: 'new_user123'
|
29
28
|
click_button 'Sign up'
|
30
29
|
|
31
30
|
assert_have_selector '#error_explanation'
|
32
|
-
assert_contain "
|
31
|
+
assert_contain "Can't save the user because of 1 error"
|
33
32
|
end
|
34
33
|
|
35
34
|
test 'test errors.messages.not_saved with multiple errors from i18n' do
|
@@ -39,13 +38,12 @@ class DeviseHelperTest < ActionController::IntegrationTest
|
|
39
38
|
|
40
39
|
get new_user_registration_path
|
41
40
|
|
42
|
-
fill_in 'email', :
|
43
|
-
fill_in 'password', :
|
44
|
-
fill_in 'password confirmation', :
|
41
|
+
fill_in 'email', with: 'invalid_email'
|
42
|
+
fill_in 'password', with: 'new_user123'
|
43
|
+
fill_in 'password confirmation', with: 'new_user321'
|
45
44
|
click_button 'Sign up'
|
46
45
|
|
47
46
|
assert_have_selector '#error_explanation'
|
48
|
-
assert_contain "
|
47
|
+
assert_contain "Can't save the user because of 2 errors"
|
49
48
|
end
|
50
49
|
end
|
51
|
-
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
|
-
class AuthenticationSanityTest <
|
3
|
+
class AuthenticationSanityTest < ActionDispatch::IntegrationTest
|
4
4
|
test 'home should be accessible without sign in' do
|
5
5
|
visit '/'
|
6
6
|
assert_response :success
|
@@ -27,7 +27,7 @@ class AuthenticationSanityTest < ActionController::IntegrationTest
|
|
27
27
|
end
|
28
28
|
|
29
29
|
test 'sign out as user should not touch admin authentication if sign_out_all_scopes is false' do
|
30
|
-
swap Devise, :
|
30
|
+
swap Devise, sign_out_all_scopes: false do
|
31
31
|
sign_in_as_user
|
32
32
|
sign_in_as_admin
|
33
33
|
get destroy_user_session_path
|
@@ -37,7 +37,7 @@ class AuthenticationSanityTest < ActionController::IntegrationTest
|
|
37
37
|
end
|
38
38
|
|
39
39
|
test 'sign out as admin should not touch user authentication if sign_out_all_scopes is false' do
|
40
|
-
swap Devise, :
|
40
|
+
swap Devise, sign_out_all_scopes: false do
|
41
41
|
sign_in_as_user
|
42
42
|
sign_in_as_admin
|
43
43
|
|
@@ -48,7 +48,7 @@ class AuthenticationSanityTest < ActionController::IntegrationTest
|
|
48
48
|
end
|
49
49
|
|
50
50
|
test 'sign out as user should also sign out admin if sign_out_all_scopes is true' do
|
51
|
-
swap Devise, :
|
51
|
+
swap Devise, sign_out_all_scopes: true do
|
52
52
|
sign_in_as_user
|
53
53
|
sign_in_as_admin
|
54
54
|
|
@@ -59,7 +59,7 @@ class AuthenticationSanityTest < ActionController::IntegrationTest
|
|
59
59
|
end
|
60
60
|
|
61
61
|
test 'sign out as admin should also sign out user if sign_out_all_scopes is true' do
|
62
|
-
swap Devise, :
|
62
|
+
swap Devise, sign_out_all_scopes: true do
|
63
63
|
sign_in_as_user
|
64
64
|
sign_in_as_admin
|
65
65
|
|
@@ -118,13 +118,13 @@ class AuthenticationSanityTest < ActionController::IntegrationTest
|
|
118
118
|
assert_not warden.authenticated?(:admin)
|
119
119
|
end
|
120
120
|
|
121
|
-
test 'unauthenticated admin
|
121
|
+
test 'unauthenticated admin set message on sign out' do
|
122
122
|
get destroy_admin_session_path
|
123
123
|
assert_response :redirect
|
124
124
|
assert_redirected_to root_path
|
125
125
|
|
126
126
|
get root_path
|
127
|
-
|
127
|
+
assert_contain 'Signed out successfully'
|
128
128
|
end
|
129
129
|
|
130
130
|
test 'scope uses custom failure app' do
|
@@ -134,7 +134,7 @@ class AuthenticationSanityTest < ActionController::IntegrationTest
|
|
134
134
|
end
|
135
135
|
end
|
136
136
|
|
137
|
-
class AuthenticationRoutesRestrictions <
|
137
|
+
class AuthenticationRoutesRestrictions < ActionDispatch::IntegrationTest
|
138
138
|
test 'not signed in should not be able to access private route (authenticate denied)' do
|
139
139
|
get private_path
|
140
140
|
assert_redirected_to new_admin_session_path
|
@@ -162,7 +162,7 @@ class AuthenticationRoutesRestrictions < ActionController::IntegrationTest
|
|
162
162
|
end
|
163
163
|
|
164
164
|
test 'signed in as inactive admin should not be able to access private/active route restricted to active admins (authenticate denied)' do
|
165
|
-
sign_in_as_admin(:
|
165
|
+
sign_in_as_admin(active: false)
|
166
166
|
assert warden.authenticated?(:admin)
|
167
167
|
assert_not warden.authenticated?(:user)
|
168
168
|
|
@@ -172,7 +172,7 @@ class AuthenticationRoutesRestrictions < ActionController::IntegrationTest
|
|
172
172
|
end
|
173
173
|
|
174
174
|
test 'signed in as active admin should be able to access private/active route restricted to active admins (authenticate accepted)' do
|
175
|
-
sign_in_as_admin(:
|
175
|
+
sign_in_as_admin(active: true)
|
176
176
|
assert warden.authenticated?(:admin)
|
177
177
|
assert_not warden.authenticated?(:user)
|
178
178
|
|
@@ -191,7 +191,7 @@ class AuthenticationRoutesRestrictions < ActionController::IntegrationTest
|
|
191
191
|
get dashboard_path
|
192
192
|
|
193
193
|
assert_response :success
|
194
|
-
assert_template 'home/
|
194
|
+
assert_template 'home/admin_dashboard'
|
195
195
|
assert_contain 'Admin dashboard'
|
196
196
|
end
|
197
197
|
|
@@ -203,7 +203,7 @@ class AuthenticationRoutesRestrictions < ActionController::IntegrationTest
|
|
203
203
|
get dashboard_path
|
204
204
|
|
205
205
|
assert_response :success
|
206
|
-
assert_template 'home/
|
206
|
+
assert_template 'home/user_dashboard'
|
207
207
|
assert_contain 'User dashboard'
|
208
208
|
end
|
209
209
|
|
@@ -214,7 +214,7 @@ class AuthenticationRoutesRestrictions < ActionController::IntegrationTest
|
|
214
214
|
end
|
215
215
|
|
216
216
|
test 'signed in as inactive admin should not be able to access dashboard/active route restricted to active admins (authenticated denied)' do
|
217
|
-
sign_in_as_admin(:
|
217
|
+
sign_in_as_admin(active: false)
|
218
218
|
assert warden.authenticated?(:admin)
|
219
219
|
assert_not warden.authenticated?(:user)
|
220
220
|
|
@@ -224,7 +224,7 @@ class AuthenticationRoutesRestrictions < ActionController::IntegrationTest
|
|
224
224
|
end
|
225
225
|
|
226
226
|
test 'signed in as active admin should be able to access dashboard/active route restricted to active admins (authenticated accepted)' do
|
227
|
-
sign_in_as_admin(:
|
227
|
+
sign_in_as_admin(active: true)
|
228
228
|
assert warden.authenticated?(:admin)
|
229
229
|
assert_not warden.authenticated?(:user)
|
230
230
|
|
@@ -254,7 +254,7 @@ class AuthenticationRoutesRestrictions < ActionController::IntegrationTest
|
|
254
254
|
end
|
255
255
|
end
|
256
256
|
|
257
|
-
class AuthenticationRedirectTest <
|
257
|
+
class AuthenticationRedirectTest < ActionDispatch::IntegrationTest
|
258
258
|
test 'redirect from warden shows sign in or sign up message' do
|
259
259
|
get admins_path
|
260
260
|
|
@@ -277,7 +277,7 @@ class AuthenticationRedirectTest < ActionController::IntegrationTest
|
|
277
277
|
assert_equal users_path, session[:"user_return_to"]
|
278
278
|
|
279
279
|
follow_redirect!
|
280
|
-
sign_in_as_user :
|
280
|
+
sign_in_as_user visit: false
|
281
281
|
|
282
282
|
assert_current_url '/users'
|
283
283
|
assert_nil session[:"user_return_to"]
|
@@ -293,7 +293,7 @@ class AuthenticationRedirectTest < ActionController::IntegrationTest
|
|
293
293
|
assert_equal users_path, session[:"user_return_to"]
|
294
294
|
|
295
295
|
follow_redirect!
|
296
|
-
sign_in_as_user :
|
296
|
+
sign_in_as_user visit: false
|
297
297
|
|
298
298
|
assert_current_url '/users'
|
299
299
|
assert_nil session[:"user_return_to"]
|
@@ -317,7 +317,7 @@ class AuthenticationRedirectTest < ActionController::IntegrationTest
|
|
317
317
|
end
|
318
318
|
end
|
319
319
|
|
320
|
-
class AuthenticationSessionTest <
|
320
|
+
class AuthenticationSessionTest < ActionDispatch::IntegrationTest
|
321
321
|
test 'destroyed account is signed out' do
|
322
322
|
sign_in_as_user
|
323
323
|
get '/users'
|
@@ -327,28 +327,54 @@ class AuthenticationSessionTest < ActionController::IntegrationTest
|
|
327
327
|
assert_redirected_to new_user_session_path
|
328
328
|
end
|
329
329
|
|
330
|
+
test 'refreshes _csrf_token' do
|
331
|
+
ApplicationController.allow_forgery_protection = true
|
332
|
+
|
333
|
+
begin
|
334
|
+
get new_user_session_path
|
335
|
+
token = request.session[:_csrf_token]
|
336
|
+
|
337
|
+
sign_in_as_user
|
338
|
+
assert_not_equal request.session[:_csrf_token], token
|
339
|
+
ensure
|
340
|
+
ApplicationController.allow_forgery_protection = false
|
341
|
+
end
|
342
|
+
end
|
343
|
+
|
330
344
|
test 'allows session to be set for a given scope' do
|
331
345
|
sign_in_as_user
|
332
346
|
get '/users'
|
333
347
|
assert_equal "Cart", @controller.user_session[:cart]
|
334
348
|
end
|
335
349
|
|
336
|
-
test 'does not explode when
|
337
|
-
|
338
|
-
|
339
|
-
|
350
|
+
test 'does not explode when class name is still stored in session' do
|
351
|
+
# In order to test that old sessions do not break with the new scoped
|
352
|
+
# deserialization, we need to serialize the session the old way. This is
|
353
|
+
# done by removing the newly used scoped serialization method
|
354
|
+
# (#user_serialize) and bringing back the old uncsoped #serialize method
|
355
|
+
# that includes the record's class name in the serialization.
|
340
356
|
begin
|
357
|
+
Warden::SessionSerializer.class_eval do
|
358
|
+
alias_method :original_serialize, :serialize
|
359
|
+
alias_method :original_user_serialize, :user_serialize
|
360
|
+
remove_method :user_serialize
|
361
|
+
|
362
|
+
def serialize(record)
|
363
|
+
klass = record.class
|
364
|
+
array = klass.serialize_into_session(record)
|
365
|
+
array.unshift(klass.name)
|
366
|
+
end
|
367
|
+
end
|
368
|
+
|
341
369
|
sign_in_as_user
|
342
370
|
assert warden.authenticated?(:user)
|
343
|
-
|
344
|
-
Object.send :remove_const, :User
|
345
|
-
ActiveSupport::Dependencies.autoload_paths.clear
|
346
|
-
|
347
|
-
visit "/users"
|
348
|
-
assert_not warden.authenticated?(:user)
|
349
371
|
ensure
|
350
|
-
|
351
|
-
|
372
|
+
Warden::SessionSerializer.class_eval do
|
373
|
+
alias_method :serialize, :original_serialize
|
374
|
+
remove_method :original_serialize
|
375
|
+
alias_method :user_serialize, :original_user_serialize
|
376
|
+
remove_method :original_user_serialize
|
377
|
+
end
|
352
378
|
end
|
353
379
|
end
|
354
380
|
|
@@ -364,9 +390,9 @@ class AuthenticationSessionTest < ActionController::IntegrationTest
|
|
364
390
|
end
|
365
391
|
end
|
366
392
|
|
367
|
-
class AuthenticationWithScopedViewsTest <
|
393
|
+
class AuthenticationWithScopedViewsTest < ActionDispatch::IntegrationTest
|
368
394
|
test 'renders the scoped view if turned on and view is available' do
|
369
|
-
swap Devise, :
|
395
|
+
swap Devise, scoped_views: true do
|
370
396
|
assert_raise Webrat::NotFoundError do
|
371
397
|
sign_in_as_user
|
372
398
|
end
|
@@ -389,7 +415,7 @@ class AuthenticationWithScopedViewsTest < ActionController::IntegrationTest
|
|
389
415
|
end
|
390
416
|
|
391
417
|
test 'does not render the scoped view if turned off' do
|
392
|
-
swap Devise, :
|
418
|
+
swap Devise, scoped_views: false do
|
393
419
|
assert_nothing_raised do
|
394
420
|
sign_in_as_user
|
395
421
|
end
|
@@ -397,7 +423,7 @@ class AuthenticationWithScopedViewsTest < ActionController::IntegrationTest
|
|
397
423
|
end
|
398
424
|
|
399
425
|
test 'does not render the scoped view if not available' do
|
400
|
-
swap Devise, :
|
426
|
+
swap Devise, scoped_views: true do
|
401
427
|
assert_nothing_raised do
|
402
428
|
sign_in_as_admin
|
403
429
|
end
|
@@ -405,9 +431,9 @@ class AuthenticationWithScopedViewsTest < ActionController::IntegrationTest
|
|
405
431
|
end
|
406
432
|
end
|
407
433
|
|
408
|
-
class AuthenticationOthersTest <
|
434
|
+
class AuthenticationOthersTest < ActionDispatch::IntegrationTest
|
409
435
|
test 'handles unverified requests gets rid of caches' do
|
410
|
-
swap
|
436
|
+
swap ApplicationController, allow_forgery_protection: true do
|
411
437
|
post exhibit_user_url(1)
|
412
438
|
assert_not warden.authenticated?(:user)
|
413
439
|
|
@@ -422,7 +448,7 @@ class AuthenticationOthersTest < ActionController::IntegrationTest
|
|
422
448
|
|
423
449
|
test 'uses the custom controller with the custom controller view' do
|
424
450
|
get '/admin_area/sign_in'
|
425
|
-
assert_contain '
|
451
|
+
assert_contain 'Log in'
|
426
452
|
assert_contain 'Welcome to "admins/sessions" controller!'
|
427
453
|
assert_contain 'Welcome to "sessions/new" view!'
|
428
454
|
end
|
@@ -447,28 +473,28 @@ class AuthenticationOthersTest < ActionController::IntegrationTest
|
|
447
473
|
test 'sign in with script name' do
|
448
474
|
assert_nothing_raised do
|
449
475
|
get new_user_session_path, {}, "SCRIPT_NAME" => "/omg"
|
450
|
-
fill_in "email", :
|
476
|
+
fill_in "email", with: "user@test.com"
|
451
477
|
end
|
452
478
|
end
|
453
479
|
|
454
480
|
test 'sign in stub in xml format' do
|
455
|
-
get new_user_session_path(:
|
481
|
+
get new_user_session_path(format: 'xml')
|
456
482
|
assert_match '<?xml version="1.0" encoding="UTF-8"?>', response.body
|
457
483
|
assert_match /<user>.*<\/user>/m, response.body
|
458
484
|
assert_match '<email></email>', response.body
|
459
|
-
assert_match '<password nil="true"
|
485
|
+
assert_match '<password nil="true"', response.body
|
460
486
|
end
|
461
487
|
|
462
488
|
test 'sign in stub in json format' do
|
463
|
-
get new_user_session_path(:
|
489
|
+
get new_user_session_path(format: 'json')
|
464
490
|
assert_match '{"user":{', response.body
|
465
491
|
assert_match '"email":""', response.body
|
466
492
|
assert_match '"password":null', response.body
|
467
493
|
end
|
468
494
|
|
469
495
|
test 'sign in stub in json with non attribute key' do
|
470
|
-
swap Devise, :
|
471
|
-
get new_user_session_path(:
|
496
|
+
swap Devise, authentication_keys: [:other_key] do
|
497
|
+
get new_user_session_path(format: 'json')
|
472
498
|
assert_match '{"user":{', response.body
|
473
499
|
assert_match '"other_key":null', response.body
|
474
500
|
assert_match '"password":null', response.body
|
@@ -476,79 +502,110 @@ class AuthenticationOthersTest < ActionController::IntegrationTest
|
|
476
502
|
end
|
477
503
|
|
478
504
|
test 'uses the mapping from router' do
|
479
|
-
sign_in_as_user :
|
505
|
+
sign_in_as_user visit: "/as/sign_in"
|
480
506
|
assert warden.authenticated?(:user)
|
481
507
|
assert_not warden.authenticated?(:admin)
|
482
508
|
end
|
483
509
|
|
484
510
|
test 'sign in with xml format returns xml response' do
|
485
511
|
create_user
|
486
|
-
post user_session_path(:
|
512
|
+
post user_session_path(format: 'xml'), user: {email: "user@test.com", password: '12345678'}
|
487
513
|
assert_response :success
|
488
514
|
assert response.body.include? %(<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<user>)
|
489
515
|
end
|
490
516
|
|
491
517
|
test 'sign in with xml format is idempotent' do
|
492
|
-
get new_user_session_path(:
|
518
|
+
get new_user_session_path(format: 'xml')
|
493
519
|
assert_response :success
|
494
520
|
|
495
521
|
create_user
|
496
|
-
post user_session_path(:
|
522
|
+
post user_session_path(format: 'xml'), user: {email: "user@test.com", password: '12345678'}
|
497
523
|
assert_response :success
|
498
524
|
|
499
|
-
get new_user_session_path(:
|
525
|
+
get new_user_session_path(format: 'xml')
|
500
526
|
assert_response :success
|
501
527
|
|
502
|
-
post user_session_path(:
|
528
|
+
post user_session_path(format: 'xml'), user: {email: "user@test.com", password: '12345678'}
|
503
529
|
assert_response :success
|
504
530
|
assert response.body.include? %(<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<user>)
|
505
531
|
end
|
506
532
|
|
507
|
-
test 'sign out with
|
533
|
+
test 'sign out with html redirects' do
|
534
|
+
sign_in_as_user
|
535
|
+
get destroy_user_session_path
|
536
|
+
assert_response :redirect
|
537
|
+
assert_current_url '/'
|
538
|
+
|
539
|
+
sign_in_as_user
|
540
|
+
get destroy_user_session_path(format: 'html')
|
541
|
+
assert_response :redirect
|
542
|
+
assert_current_url '/'
|
543
|
+
end
|
544
|
+
|
545
|
+
test 'sign out with xml format returns no content' do
|
508
546
|
sign_in_as_user
|
509
|
-
get destroy_user_session_path(:
|
547
|
+
get destroy_user_session_path(format: 'xml')
|
510
548
|
assert_response :no_content
|
511
549
|
assert_not warden.authenticated?(:user)
|
512
550
|
end
|
513
551
|
|
514
|
-
test 'sign out with json format returns
|
552
|
+
test 'sign out with json format returns no content' do
|
515
553
|
sign_in_as_user
|
516
|
-
get destroy_user_session_path(:
|
554
|
+
get destroy_user_session_path(format: 'json')
|
517
555
|
assert_response :no_content
|
518
556
|
assert_not warden.authenticated?(:user)
|
519
557
|
end
|
558
|
+
|
559
|
+
test 'sign out with non-navigational format via XHR does not redirect' do
|
560
|
+
swap Devise, navigational_formats: ['*/*', :html] do
|
561
|
+
sign_in_as_user
|
562
|
+
xml_http_request :get, destroy_user_session_path, {}, { "HTTP_ACCEPT" => "application/json,text/javascript,*/*" } # NOTE: Bug is triggered by combination of XHR and */*.
|
563
|
+
assert_response :no_content
|
564
|
+
assert_not warden.authenticated?(:user)
|
565
|
+
end
|
566
|
+
end
|
567
|
+
|
568
|
+
# Belt and braces ... Perhaps this test is not necessary?
|
569
|
+
test 'sign out with navigational format via XHR does redirect' do
|
570
|
+
swap Devise, navigational_formats: ['*/*', :html] do
|
571
|
+
sign_in_as_user
|
572
|
+
xml_http_request :get, destroy_user_session_path, {}, { "HTTP_ACCEPT" => "text/html,*/*" }
|
573
|
+
assert_response :redirect
|
574
|
+
assert_not warden.authenticated?(:user)
|
575
|
+
end
|
576
|
+
end
|
520
577
|
end
|
521
578
|
|
522
|
-
class AuthenticationKeysTest <
|
579
|
+
class AuthenticationKeysTest < ActionDispatch::IntegrationTest
|
523
580
|
test 'missing authentication keys cause authentication to abort' do
|
524
|
-
swap Devise, :
|
581
|
+
swap Devise, authentication_keys: [:subdomain] do
|
525
582
|
sign_in_as_user
|
526
|
-
assert_contain "Invalid
|
583
|
+
assert_contain "Invalid subdomain or password."
|
527
584
|
assert_not warden.authenticated?(:user)
|
528
585
|
end
|
529
586
|
end
|
530
587
|
|
531
588
|
test 'missing authentication keys cause authentication to abort unless marked as not required' do
|
532
|
-
swap Devise, :
|
589
|
+
swap Devise, authentication_keys: { email: true, subdomain: false } do
|
533
590
|
sign_in_as_user
|
534
591
|
assert warden.authenticated?(:user)
|
535
592
|
end
|
536
593
|
end
|
537
594
|
end
|
538
595
|
|
539
|
-
class AuthenticationRequestKeysTest <
|
596
|
+
class AuthenticationRequestKeysTest < ActionDispatch::IntegrationTest
|
540
597
|
test 'request keys are used on authentication' do
|
541
598
|
host! 'foo.bar.baz'
|
542
599
|
|
543
|
-
swap Devise, :
|
544
|
-
User.expects(:find_for_authentication).with(:
|
600
|
+
swap Devise, request_keys: [:subdomain] do
|
601
|
+
User.expects(:find_for_authentication).with(subdomain: 'foo', email: 'user@test.com').returns(create_user)
|
545
602
|
sign_in_as_user
|
546
603
|
assert warden.authenticated?(:user)
|
547
604
|
end
|
548
605
|
end
|
549
606
|
|
550
607
|
test 'invalid request keys raises NoMethodError' do
|
551
|
-
swap Devise, :
|
608
|
+
swap Devise, request_keys: [:unknown_method] do
|
552
609
|
assert_raise NoMethodError do
|
553
610
|
sign_in_as_user
|
554
611
|
end
|
@@ -560,7 +617,7 @@ class AuthenticationRequestKeysTest < ActionController::IntegrationTest
|
|
560
617
|
test 'blank request keys cause authentication to abort' do
|
561
618
|
host! 'test.com'
|
562
619
|
|
563
|
-
swap Devise, :
|
620
|
+
swap Devise, request_keys: [:subdomain] do
|
564
621
|
sign_in_as_user
|
565
622
|
assert_contain "Invalid email or password."
|
566
623
|
assert_not warden.authenticated?(:user)
|
@@ -570,16 +627,16 @@ class AuthenticationRequestKeysTest < ActionController::IntegrationTest
|
|
570
627
|
test 'blank request keys cause authentication to abort unless if marked as not required' do
|
571
628
|
host! 'test.com'
|
572
629
|
|
573
|
-
swap Devise, :
|
630
|
+
swap Devise, request_keys: { subdomain: false } do
|
574
631
|
sign_in_as_user
|
575
632
|
assert warden.authenticated?(:user)
|
576
633
|
end
|
577
634
|
end
|
578
635
|
end
|
579
636
|
|
580
|
-
class AuthenticationSignOutViaTest <
|
637
|
+
class AuthenticationSignOutViaTest < ActionDispatch::IntegrationTest
|
581
638
|
def sign_in!(scope)
|
582
|
-
sign_in_as_admin(:
|
639
|
+
sign_in_as_admin(visit: send("new_#{scope}_session_path"))
|
583
640
|
assert warden.authenticated?(scope)
|
584
641
|
end
|
585
642
|
|
@@ -631,3 +688,42 @@ class AuthenticationSignOutViaTest < ActionController::IntegrationTest
|
|
631
688
|
assert warden.authenticated?(:sign_out_via_delete_or_post)
|
632
689
|
end
|
633
690
|
end
|
691
|
+
|
692
|
+
class DoubleAuthenticationRedirectTest < ActionDispatch::IntegrationTest
|
693
|
+
test 'signed in as user redirects when visiting user sign in page' do
|
694
|
+
sign_in_as_user
|
695
|
+
get new_user_session_path(format: :html)
|
696
|
+
assert_redirected_to '/'
|
697
|
+
end
|
698
|
+
|
699
|
+
test 'signed in as admin redirects when visiting admin sign in page' do
|
700
|
+
sign_in_as_admin
|
701
|
+
get new_admin_session_path(format: :html)
|
702
|
+
assert_redirected_to '/admin_area/home'
|
703
|
+
end
|
704
|
+
|
705
|
+
test 'signed in as both user and admin redirects when visiting admin sign in page' do
|
706
|
+
sign_in_as_user
|
707
|
+
sign_in_as_admin
|
708
|
+
get new_user_session_path(format: :html)
|
709
|
+
assert_redirected_to '/'
|
710
|
+
get new_admin_session_path(format: :html)
|
711
|
+
assert_redirected_to '/admin_area/home'
|
712
|
+
end
|
713
|
+
end
|
714
|
+
|
715
|
+
class DoubleSignOutRedirectTest < ActionDispatch::IntegrationTest
|
716
|
+
test 'sign out after already having signed out redirects to sign in' do
|
717
|
+
sign_in_as_user
|
718
|
+
|
719
|
+
post destroy_sign_out_via_delete_or_post_session_path
|
720
|
+
|
721
|
+
get root_path
|
722
|
+
assert_contain 'Signed out successfully.'
|
723
|
+
|
724
|
+
post destroy_sign_out_via_delete_or_post_session_path
|
725
|
+
|
726
|
+
get root_path
|
727
|
+
assert_contain 'Signed out successfully.'
|
728
|
+
end
|
729
|
+
end
|