devise 2.1.2 → 3.5.10
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of devise might be problematic. Click here for more details.
- checksums.yaml +7 -0
- data/.travis.yml +39 -10
- data/.yardopts +9 -0
- data/{CHANGELOG.rdoc → CHANGELOG.md} +445 -112
- data/CODE_OF_CONDUCT.md +22 -0
- data/CONTRIBUTING.md +16 -0
- data/Gemfile +10 -15
- data/Gemfile.lock +151 -129
- data/MIT-LICENSE +1 -1
- data/README.md +256 -96
- data/Rakefile +4 -2
- data/app/controllers/devise/confirmations_controller.rb +15 -7
- data/app/controllers/devise/omniauth_callbacks_controller.rb +6 -2
- data/app/controllers/devise/passwords_controller.rb +33 -9
- data/app/controllers/devise/registrations_controller.rb +66 -26
- data/app/controllers/devise/sessions_controller.rb +52 -21
- data/app/controllers/devise/unlocks_controller.rb +11 -6
- data/app/controllers/devise_controller.rb +65 -58
- data/app/helpers/devise_helper.rb +2 -2
- data/app/mailers/devise/mailer.rb +19 -10
- data/app/views/devise/confirmations/new.html.erb +8 -4
- data/app/views/devise/mailer/confirmation_instructions.html.erb +2 -2
- data/app/views/devise/mailer/password_change.html.erb +3 -0
- data/app/views/devise/mailer/reset_password_instructions.html.erb +2 -2
- data/app/views/devise/mailer/unlock_instructions.html.erb +2 -2
- data/app/views/devise/passwords/edit.html.erb +15 -6
- data/app/views/devise/passwords/new.html.erb +8 -4
- data/app/views/devise/registrations/edit.html.erb +29 -15
- data/app/views/devise/registrations/new.html.erb +19 -8
- data/app/views/devise/sessions/new.html.erb +17 -8
- data/app/views/devise/shared/{_links.erb → _links.html.erb} +4 -4
- data/app/views/devise/unlocks/new.html.erb +8 -4
- data/config/locales/en.yml +51 -47
- data/devise.gemspec +8 -6
- data/devise.png +0 -0
- data/gemfiles/Gemfile.rails-3.2-stable +29 -0
- data/gemfiles/Gemfile.rails-3.2-stable.lock +172 -0
- data/gemfiles/Gemfile.rails-4.0-stable +30 -0
- data/gemfiles/Gemfile.rails-4.0-stable.lock +166 -0
- data/gemfiles/Gemfile.rails-4.1-stable +30 -0
- data/gemfiles/Gemfile.rails-4.1-stable.lock +171 -0
- data/gemfiles/Gemfile.rails-4.2-stable +30 -0
- data/gemfiles/Gemfile.rails-4.2-stable.lock +193 -0
- data/lib/devise/controllers/helpers.rb +126 -108
- data/lib/devise/controllers/rememberable.rb +19 -17
- data/lib/devise/controllers/scoped_views.rb +1 -1
- data/lib/devise/controllers/sign_in_out.rb +96 -0
- data/lib/devise/controllers/store_location.rb +58 -0
- data/lib/devise/controllers/url_helpers.rb +7 -7
- data/lib/devise/encryptor.rb +22 -0
- data/lib/devise/failure_app.rb +85 -25
- data/lib/devise/hooks/activatable.rb +5 -6
- data/lib/devise/hooks/csrf_cleaner.rb +7 -0
- data/lib/devise/hooks/forgetable.rb +1 -1
- data/lib/devise/hooks/lockable.rb +2 -2
- data/lib/devise/hooks/proxy.rb +21 -0
- data/lib/devise/hooks/rememberable.rb +5 -4
- data/lib/devise/hooks/timeoutable.rb +16 -8
- data/lib/devise/hooks/trackable.rb +1 -1
- data/lib/devise/mailers/helpers.rb +27 -23
- data/lib/devise/mapping.rb +11 -7
- data/lib/devise/models/authenticatable.rb +82 -66
- data/lib/devise/models/confirmable.rb +142 -55
- data/lib/devise/models/database_authenticatable.rb +59 -15
- data/lib/devise/models/lockable.rb +41 -30
- data/lib/devise/models/omniauthable.rb +3 -3
- data/lib/devise/models/recoverable.rb +56 -41
- data/lib/devise/models/rememberable.rb +65 -27
- data/lib/devise/models/timeoutable.rb +2 -8
- data/lib/devise/models/trackable.rb +6 -4
- data/lib/devise/models/validatable.rb +9 -9
- data/lib/devise/models.rb +4 -13
- data/lib/devise/modules.rb +10 -11
- data/lib/devise/omniauth/url_helpers.rb +2 -2
- data/lib/devise/orm/active_record.rb +1 -1
- data/lib/devise/orm/mongoid.rb +1 -1
- data/lib/devise/{param_filter.rb → parameter_filter.rb} +10 -11
- data/lib/devise/parameter_sanitizer.rb +99 -0
- data/lib/devise/rails/routes.rb +173 -115
- data/lib/devise/rails/warden_compat.rb +10 -31
- data/lib/devise/rails.rb +14 -12
- data/lib/devise/strategies/authenticatable.rb +26 -26
- data/lib/devise/strategies/base.rb +1 -1
- data/lib/devise/strategies/database_authenticatable.rb +8 -4
- data/lib/devise/strategies/rememberable.rb +15 -5
- data/lib/devise/test_helpers.rb +7 -5
- data/lib/devise/time_inflector.rb +14 -0
- data/lib/devise/token_generator.rb +70 -0
- data/lib/devise/version.rb +1 -1
- data/lib/devise.rb +110 -52
- data/lib/generators/active_record/devise_generator.rb +34 -18
- data/lib/generators/active_record/templates/migration.rb +5 -6
- data/lib/generators/active_record/templates/migration_existing.rb +5 -6
- data/lib/generators/devise/controllers_generator.rb +44 -0
- data/lib/generators/devise/devise_generator.rb +5 -3
- data/lib/generators/devise/install_generator.rb +5 -0
- data/lib/generators/devise/orm_helpers.rb +25 -6
- data/lib/generators/devise/views_generator.rb +52 -22
- data/lib/generators/mongoid/devise_generator.rb +21 -26
- data/lib/generators/templates/README +9 -5
- data/lib/generators/templates/controllers/README +14 -0
- data/lib/generators/templates/controllers/confirmations_controller.rb +28 -0
- data/lib/generators/templates/controllers/omniauth_callbacks_controller.rb +28 -0
- data/lib/generators/templates/controllers/passwords_controller.rb +32 -0
- data/lib/generators/templates/controllers/registrations_controller.rb +60 -0
- data/lib/generators/templates/controllers/sessions_controller.rb +25 -0
- data/lib/generators/templates/controllers/unlocks_controller.rb +28 -0
- data/lib/generators/templates/devise.rb +80 -43
- data/lib/generators/templates/markerb/confirmation_instructions.markerb +2 -2
- data/lib/generators/templates/markerb/password_change.markerb +3 -0
- data/lib/generators/templates/markerb/reset_password_instructions.markerb +1 -1
- data/lib/generators/templates/markerb/unlock_instructions.markerb +2 -2
- data/lib/generators/templates/simple_form_for/confirmations/new.html.erb +3 -2
- data/lib/generators/templates/simple_form_for/passwords/edit.html.erb +4 -4
- data/lib/generators/templates/simple_form_for/passwords/new.html.erb +2 -2
- data/lib/generators/templates/simple_form_for/registrations/edit.html.erb +11 -6
- data/lib/generators/templates/simple_form_for/registrations/new.html.erb +4 -4
- data/lib/generators/templates/simple_form_for/sessions/new.html.erb +6 -6
- data/lib/generators/templates/simple_form_for/unlocks/new.html.erb +3 -2
- data/script/cached-bundle +49 -0
- data/script/s3-put +71 -0
- data/test/controllers/custom_registrations_controller_test.rb +40 -0
- data/test/controllers/helper_methods_test.rb +21 -0
- data/test/controllers/helpers_test.rb +95 -32
- data/test/controllers/inherited_controller_i18n_messages_test.rb +51 -0
- data/test/controllers/internal_helpers_test.rb +39 -14
- data/test/controllers/load_hooks_controller_test.rb +19 -0
- data/test/controllers/passwords_controller_test.rb +31 -0
- data/test/controllers/sessions_controller_test.rb +66 -6
- data/test/controllers/url_helpers_test.rb +10 -4
- data/test/delegator_test.rb +1 -1
- data/test/devise_test.rb +45 -10
- data/test/failure_app_test.rb +121 -27
- data/test/generators/active_record_generator_test.rb +48 -8
- data/test/generators/controllers_generator_test.rb +48 -0
- data/test/generators/devise_generator_test.rb +2 -2
- data/test/generators/mongoid_generator_test.rb +3 -3
- data/test/generators/views_generator_test.rb +54 -3
- data/test/helpers/devise_helper_test.rb +18 -20
- data/test/integration/authenticatable_test.rb +161 -65
- data/test/integration/confirmable_test.rb +146 -77
- data/test/integration/database_authenticatable_test.rb +43 -30
- data/test/integration/http_authenticatable_test.rb +30 -22
- data/test/integration/lockable_test.rb +64 -49
- data/test/integration/omniauthable_test.rb +17 -15
- data/test/integration/recoverable_test.rb +111 -70
- data/test/integration/registerable_test.rb +114 -79
- data/test/integration/rememberable_test.rb +87 -31
- data/test/integration/timeoutable_test.rb +77 -33
- data/test/integration/trackable_test.rb +5 -5
- data/test/mailers/confirmation_instructions_test.rb +28 -8
- data/test/mailers/reset_password_instructions_test.rb +21 -8
- data/test/mailers/unlock_instructions_test.rb +20 -6
- data/test/mapping_test.rb +12 -5
- data/test/models/authenticatable_test.rb +17 -1
- data/test/models/confirmable_test.rb +216 -62
- data/test/models/database_authenticatable_test.rb +129 -49
- data/test/models/lockable_test.rb +132 -45
- data/test/models/recoverable_test.rb +100 -54
- data/test/models/rememberable_test.rb +89 -94
- data/test/models/serializable_test.rb +12 -11
- data/test/models/timeoutable_test.rb +6 -1
- data/test/models/trackable_test.rb +28 -0
- data/test/models/validatable_test.rb +31 -21
- data/test/models_test.rb +22 -48
- data/test/omniauth/config_test.rb +4 -4
- data/test/omniauth/url_helpers_test.rb +7 -4
- data/test/orm/active_record.rb +1 -0
- data/test/orm/mongoid.rb +2 -3
- data/test/parameter_sanitizer_test.rb +81 -0
- data/test/rails_app/Rakefile +0 -4
- data/test/rails_app/app/active_record/shim.rb +1 -1
- data/test/rails_app/app/active_record/user_on_engine.rb +7 -0
- data/test/rails_app/app/active_record/user_on_main_app.rb +7 -0
- data/test/rails_app/app/active_record/user_without_email.rb +8 -0
- data/test/rails_app/app/controllers/admins/sessions_controller.rb +1 -1
- data/test/rails_app/app/controllers/admins_controller.rb +0 -5
- data/test/rails_app/app/controllers/application_controller.rb +6 -2
- data/test/rails_app/app/controllers/application_with_fake_engine.rb +30 -0
- data/test/rails_app/app/controllers/custom/registrations_controller.rb +31 -0
- data/test/rails_app/app/controllers/home_controller.rb +1 -1
- data/test/rails_app/app/controllers/publisher/registrations_controller.rb +1 -1
- data/test/rails_app/app/controllers/publisher/sessions_controller.rb +1 -1
- data/test/rails_app/app/controllers/users/omniauth_callbacks_controller.rb +4 -4
- data/test/rails_app/app/controllers/users_controller.rb +12 -4
- data/test/rails_app/app/mailers/users/from_proc_mailer.rb +3 -0
- data/test/rails_app/app/mailers/users/mailer.rb +1 -1
- data/test/rails_app/app/mailers/users/reply_to_mailer.rb +4 -0
- data/test/rails_app/app/mongoid/admin.rb +12 -10
- data/test/rails_app/app/mongoid/shim.rb +4 -5
- data/test/rails_app/app/mongoid/user.rb +19 -22
- data/test/rails_app/app/mongoid/user_on_engine.rb +39 -0
- data/test/rails_app/app/mongoid/user_on_main_app.rb +39 -0
- data/test/rails_app/app/mongoid/user_without_email.rb +33 -0
- data/test/rails_app/app/views/admins/sessions/new.html.erb +1 -1
- data/test/rails_app/app/views/home/admin_dashboard.html.erb +1 -1
- data/test/rails_app/app/views/home/index.html.erb +1 -1
- data/test/rails_app/app/views/home/join.html.erb +1 -1
- data/test/rails_app/app/views/home/user_dashboard.html.erb +1 -1
- data/test/rails_app/app/views/layouts/application.html.erb +1 -1
- data/test/rails_app/app/views/users/edit_form.html.erb +1 -0
- data/test/rails_app/bin/bundle +3 -0
- data/test/rails_app/bin/rails +4 -0
- data/test/rails_app/bin/rake +4 -0
- data/test/rails_app/config/application.rb +4 -5
- data/test/rails_app/config/boot.rb +9 -3
- data/test/rails_app/config/environment.rb +2 -2
- data/test/rails_app/config/environments/development.rb +19 -7
- data/test/rails_app/config/environments/production.rb +68 -17
- data/test/rails_app/config/environments/test.rb +24 -16
- data/test/rails_app/config/initializers/devise.rb +22 -20
- data/test/rails_app/config/initializers/secret_token.rb +8 -2
- data/test/rails_app/config/initializers/session_store.rb +1 -0
- data/test/rails_app/config/routes.rb +71 -46
- data/test/rails_app/db/migrate/20100401102949_create_tables.rb +9 -12
- data/test/rails_app/db/schema.rb +21 -18
- data/test/rails_app/lib/shared_admin.rb +7 -4
- data/test/rails_app/lib/shared_user.rb +6 -3
- data/test/rails_app/lib/shared_user_without_email.rb +26 -0
- data/test/rails_app/lib/shared_user_without_omniauth.rb +13 -0
- data/test/rails_test.rb +9 -0
- data/test/routes_test.rb +94 -78
- data/test/support/action_controller/record_identifier.rb +10 -0
- data/test/support/assertions.rb +2 -3
- data/test/support/helpers.rb +18 -32
- data/test/support/integration.rb +17 -16
- data/test/support/locale/en.yml +4 -0
- data/test/support/mongoid.yml +6 -0
- data/test/test_helper.rb +8 -1
- data/test/test_helpers_test.rb +64 -20
- data/test/test_models.rb +33 -0
- data/test/time_helpers.rb +137 -0
- metadata +172 -51
- data/app/views/devise/_links.erb +0 -3
- data/gemfiles/Gemfile.rails-3.1.x +0 -35
- data/gemfiles/Gemfile.rails-3.1.x.lock +0 -167
- data/lib/devise/models/token_authenticatable.rb +0 -77
- data/lib/devise/strategies/token_authenticatable.rb +0 -56
- data/test/indifferent_hash.rb +0 -33
- data/test/integration/token_authenticatable_test.rb +0 -161
- data/test/models/token_authenticatable_test.rb +0 -55
- data/test/rails_app/script/rails +0 -10
@@ -1,19 +1,19 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
|
-
class ConfirmationTest <
|
3
|
+
class ConfirmationTest < ActionDispatch::IntegrationTest
|
4
4
|
|
5
5
|
def visit_user_confirmation_with_token(confirmation_token)
|
6
|
-
visit user_confirmation_path(:
|
6
|
+
visit user_confirmation_path(confirmation_token: confirmation_token)
|
7
7
|
end
|
8
8
|
|
9
9
|
def resend_confirmation
|
10
|
-
user = create_user(:
|
10
|
+
user = create_user(confirm: false)
|
11
11
|
ActionMailer::Base.deliveries.clear
|
12
12
|
|
13
13
|
visit new_user_session_path
|
14
14
|
click_link "Didn't receive confirmation instructions?"
|
15
15
|
|
16
|
-
fill_in 'email', :
|
16
|
+
fill_in 'email', with: user.email
|
17
17
|
click_button 'Resend confirmation instructions'
|
18
18
|
end
|
19
19
|
|
@@ -21,16 +21,14 @@ class ConfirmationTest < ActionController::IntegrationTest
|
|
21
21
|
resend_confirmation
|
22
22
|
|
23
23
|
assert_current_url '/users/sign_in'
|
24
|
-
assert_contain 'You will receive an email with instructions
|
24
|
+
assert_contain 'You will receive an email with instructions for how to confirm your email address in a few minutes'
|
25
25
|
assert_equal 1, ActionMailer::Base.deliveries.size
|
26
26
|
assert_equal ['please-change-me@config-initializers-devise.com'], ActionMailer::Base.deliveries.first.from
|
27
27
|
end
|
28
28
|
|
29
29
|
test 'user should receive a confirmation from a custom mailer' do
|
30
30
|
User.any_instance.stubs(:devise_mailer).returns(Users::Mailer)
|
31
|
-
|
32
31
|
resend_confirmation
|
33
|
-
|
34
32
|
assert_equal ['custom@example.com'], ActionMailer::Base.deliveries.first.from
|
35
33
|
end
|
36
34
|
|
@@ -40,76 +38,106 @@ class ConfirmationTest < ActionController::IntegrationTest
|
|
40
38
|
assert_contain /Confirmation token(.*)invalid/
|
41
39
|
end
|
42
40
|
|
43
|
-
test 'user with valid confirmation token should be able to confirm an account' do
|
44
|
-
|
45
|
-
|
46
|
-
|
41
|
+
test 'user with valid confirmation token should not be able to confirm an account after the token has expired' do
|
42
|
+
swap Devise, confirm_within: 3.days do
|
43
|
+
user = create_user(confirm: false, confirmation_sent_at: 4.days.ago)
|
44
|
+
assert_not user.confirmed?
|
45
|
+
visit_user_confirmation_with_token(user.raw_confirmation_token)
|
47
46
|
|
48
|
-
|
49
|
-
|
50
|
-
|
47
|
+
assert_have_selector '#error_explanation'
|
48
|
+
assert_contain /needs to be confirmed within 3 days/
|
49
|
+
assert_not user.reload.confirmed?
|
50
|
+
assert_current_url "/users/confirmation?confirmation_token=#{user.raw_confirmation_token}"
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
test 'user with valid confirmation token where the token has expired and with application router_name set to a different engine it should raise an error' do
|
55
|
+
user = create_user(confirm: false, confirmation_sent_at: 4.days.ago)
|
56
|
+
|
57
|
+
swap Devise, confirm_within: 3.days, router_name: :fake_engine do
|
58
|
+
assert_raise ActionView::Template::Error do
|
59
|
+
visit_user_confirmation_with_token(user.raw_confirmation_token)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
test 'user with valid confirmation token where the token has expired and with application router_name set to a different engine and route overrides back to main it shows the path' do
|
65
|
+
user = create_user(confirm: false, confirmation_sent_at: 4.days.ago)
|
66
|
+
|
67
|
+
swap Devise, confirm_within: 3.days, router_name: :fake_engine do
|
68
|
+
visit user_on_main_app_confirmation_path(confirmation_token: user.raw_confirmation_token)
|
69
|
+
|
70
|
+
assert_current_url "/user_on_main_apps/confirmation?confirmation_token=#{user.raw_confirmation_token}"
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
test 'user with valid confirmation token where the token has expired with router overrides different engine it shows the path' do
|
75
|
+
user = create_user(confirm: false, confirmation_sent_at: 4.days.ago)
|
76
|
+
|
77
|
+
swap Devise, confirm_within: 3.days do
|
78
|
+
visit user_on_engine_confirmation_path(confirmation_token: user.raw_confirmation_token)
|
79
|
+
|
80
|
+
assert_current_url "/user_on_engines/confirmation?confirmation_token=#{user.raw_confirmation_token}"
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
test 'user with valid confirmation token should be able to confirm an account before the token has expired' do
|
85
|
+
swap Devise, confirm_within: 3.days do
|
86
|
+
user = create_user(confirm: false, confirmation_sent_at: 2.days.ago)
|
87
|
+
assert_not user.confirmed?
|
88
|
+
visit_user_confirmation_with_token(user.raw_confirmation_token)
|
89
|
+
|
90
|
+
assert_contain 'Your email address has been successfully confirmed.'
|
91
|
+
assert_current_url '/users/sign_in'
|
92
|
+
assert user.reload.confirmed?
|
93
|
+
end
|
51
94
|
end
|
52
95
|
|
53
96
|
test 'user should be redirected to a custom path after confirmation' do
|
54
97
|
Devise::ConfirmationsController.any_instance.stubs(:after_confirmation_path_for).returns("/?custom=1")
|
55
98
|
|
56
|
-
user = create_user(:
|
57
|
-
visit_user_confirmation_with_token(user.
|
99
|
+
user = create_user(confirm: false)
|
100
|
+
visit_user_confirmation_with_token(user.raw_confirmation_token)
|
58
101
|
|
59
102
|
assert_current_url "/?custom=1"
|
60
103
|
end
|
61
104
|
|
62
105
|
test 'already confirmed user should not be able to confirm the account again' do
|
63
|
-
user = create_user(:
|
106
|
+
user = create_user(confirm: false)
|
64
107
|
user.confirmed_at = Time.now
|
65
108
|
user.save
|
66
|
-
visit_user_confirmation_with_token(user.
|
109
|
+
visit_user_confirmation_with_token(user.raw_confirmation_token)
|
67
110
|
|
68
111
|
assert_have_selector '#error_explanation'
|
69
112
|
assert_contain 'already confirmed'
|
70
113
|
end
|
71
114
|
|
72
115
|
test 'already confirmed user should not be able to confirm the account again neither request confirmation' do
|
73
|
-
user = create_user(:
|
116
|
+
user = create_user(confirm: false)
|
74
117
|
user.confirmed_at = Time.now
|
75
118
|
user.save
|
76
119
|
|
77
|
-
visit_user_confirmation_with_token(user.
|
120
|
+
visit_user_confirmation_with_token(user.raw_confirmation_token)
|
78
121
|
assert_contain 'already confirmed'
|
79
122
|
|
80
|
-
fill_in 'email', :
|
123
|
+
fill_in 'email', with: user.email
|
81
124
|
click_button 'Resend confirmation instructions'
|
82
125
|
assert_contain 'already confirmed'
|
83
126
|
end
|
84
127
|
|
85
|
-
test 'sign in user automatically after confirming its email' do
|
86
|
-
user = create_user(:confirm => false)
|
87
|
-
visit_user_confirmation_with_token(user.confirmation_token)
|
88
|
-
|
89
|
-
assert warden.authenticated?(:user)
|
90
|
-
end
|
91
|
-
|
92
|
-
test 'increases sign count when signed in through confirmation' do
|
93
|
-
user = create_user(:confirm => false)
|
94
|
-
visit_user_confirmation_with_token(user.confirmation_token)
|
95
|
-
|
96
|
-
user.reload
|
97
|
-
assert_equal 1, user.sign_in_count
|
98
|
-
end
|
99
|
-
|
100
128
|
test 'not confirmed user with setup to block without confirmation should not be able to sign in' do
|
101
|
-
swap Devise, :
|
102
|
-
sign_in_as_user(:
|
129
|
+
swap Devise, allow_unconfirmed_access_for: 0.days do
|
130
|
+
sign_in_as_user(confirm: false)
|
103
131
|
|
104
|
-
assert_contain 'You have to confirm your
|
132
|
+
assert_contain 'You have to confirm your email address before continuing'
|
105
133
|
assert_not warden.authenticated?(:user)
|
106
134
|
end
|
107
135
|
end
|
108
136
|
|
109
137
|
test 'not confirmed user should not see confirmation message if invalid credentials are given' do
|
110
|
-
swap Devise, :
|
111
|
-
sign_in_as_user(:
|
112
|
-
fill_in 'password', :
|
138
|
+
swap Devise, allow_unconfirmed_access_for: 0.days do
|
139
|
+
sign_in_as_user(confirm: false) do
|
140
|
+
fill_in 'password', with: 'invalid'
|
113
141
|
end
|
114
142
|
|
115
143
|
assert_contain 'Invalid email or password'
|
@@ -118,138 +146,179 @@ class ConfirmationTest < ActionController::IntegrationTest
|
|
118
146
|
end
|
119
147
|
|
120
148
|
test 'not confirmed user but configured with some days to confirm should be able to sign in' do
|
121
|
-
swap Devise, :
|
122
|
-
sign_in_as_user(:
|
149
|
+
swap Devise, allow_unconfirmed_access_for: 1.day do
|
150
|
+
sign_in_as_user(confirm: false)
|
123
151
|
|
124
152
|
assert_response :success
|
125
153
|
assert warden.authenticated?(:user)
|
126
154
|
end
|
127
155
|
end
|
128
156
|
|
157
|
+
test 'unconfirmed but signed in user should be redirected to their root path' do
|
158
|
+
swap Devise, allow_unconfirmed_access_for: 1.day do
|
159
|
+
user = sign_in_as_user(confirm: false)
|
160
|
+
|
161
|
+
visit_user_confirmation_with_token(user.raw_confirmation_token)
|
162
|
+
assert_contain 'Your email address has been successfully confirmed.'
|
163
|
+
assert_current_url '/'
|
164
|
+
end
|
165
|
+
end
|
166
|
+
|
167
|
+
test 'user should be redirected to sign in page whenever signed in as another resource at same session already' do
|
168
|
+
sign_in_as_admin
|
169
|
+
|
170
|
+
user = create_user(confirm: false)
|
171
|
+
visit_user_confirmation_with_token(user.raw_confirmation_token)
|
172
|
+
|
173
|
+
assert_current_url '/users/sign_in'
|
174
|
+
end
|
175
|
+
|
129
176
|
test 'error message is configurable by resource name' do
|
130
|
-
store_translations :en, :
|
131
|
-
:
|
177
|
+
store_translations :en, devise: {
|
178
|
+
failure: { user: { unconfirmed: "Not confirmed user" } }
|
132
179
|
} do
|
133
|
-
sign_in_as_user(:
|
180
|
+
sign_in_as_user(confirm: false)
|
134
181
|
assert_contain 'Not confirmed user'
|
135
182
|
end
|
136
183
|
end
|
137
184
|
|
138
185
|
test 'resent confirmation token with valid E-Mail in XML format should return valid response' do
|
139
|
-
user = create_user(:
|
140
|
-
post user_confirmation_path(:
|
186
|
+
user = create_user(confirm: false)
|
187
|
+
post user_confirmation_path(format: 'xml'), user: { email: user.email }
|
141
188
|
assert_response :success
|
142
189
|
assert_equal response.body, {}.to_xml
|
143
190
|
end
|
144
191
|
|
145
192
|
test 'resent confirmation token with invalid E-Mail in XML format should return invalid response' do
|
146
|
-
|
147
|
-
post user_confirmation_path(:
|
193
|
+
create_user(confirm: false)
|
194
|
+
post user_confirmation_path(format: 'xml'), user: { email: 'invalid.test@test.com' }
|
148
195
|
assert_response :unprocessable_entity
|
149
196
|
assert response.body.include? %(<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<errors>)
|
150
197
|
end
|
151
198
|
|
152
199
|
test 'confirm account with valid confirmation token in XML format should return valid response' do
|
153
|
-
user = create_user(:
|
154
|
-
get user_confirmation_path(:
|
200
|
+
user = create_user(confirm: false)
|
201
|
+
get user_confirmation_path(confirmation_token: user.raw_confirmation_token, format: 'xml')
|
155
202
|
assert_response :success
|
156
203
|
assert response.body.include? %(<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<user>)
|
157
204
|
end
|
158
205
|
|
159
206
|
test 'confirm account with invalid confirmation token in XML format should return invalid response' do
|
160
|
-
|
161
|
-
get user_confirmation_path(:
|
207
|
+
create_user(confirm: false)
|
208
|
+
get user_confirmation_path(confirmation_token: 'invalid_confirmation', format: 'xml')
|
162
209
|
assert_response :unprocessable_entity
|
163
210
|
assert response.body.include? %(<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<errors>)
|
164
211
|
end
|
165
212
|
|
166
213
|
test 'request an account confirmation account with JSON, should return an empty JSON' do
|
167
|
-
user = create_user(:
|
214
|
+
user = create_user(confirm: false)
|
168
215
|
|
169
|
-
post user_confirmation_path, :
|
216
|
+
post user_confirmation_path, user: { email: user.email }, format: :json
|
170
217
|
assert_response :success
|
171
218
|
assert_equal response.body, {}.to_json
|
172
219
|
end
|
173
220
|
|
174
221
|
test "when in paranoid mode and with a valid e-mail, should not say that the e-mail is valid" do
|
175
|
-
swap Devise, :
|
176
|
-
user = create_user(:
|
222
|
+
swap Devise, paranoid: true do
|
223
|
+
user = create_user(confirm: false)
|
177
224
|
visit new_user_session_path
|
178
225
|
|
179
226
|
click_link "Didn't receive confirmation instructions?"
|
180
|
-
fill_in 'email', :
|
227
|
+
fill_in 'email', with: user.email
|
181
228
|
click_button 'Resend confirmation instructions'
|
182
229
|
|
183
|
-
assert_contain "If your email address exists in our database, you will receive an email with instructions
|
230
|
+
assert_contain "If your email address exists in our database, you will receive an email with instructions for how to confirm your email address in a few minutes."
|
184
231
|
assert_current_url "/users/sign_in"
|
185
232
|
end
|
186
233
|
end
|
187
234
|
|
188
235
|
test "when in paranoid mode and with a invalid e-mail, should not say that the e-mail is invalid" do
|
189
|
-
swap Devise, :
|
236
|
+
swap Devise, paranoid: true do
|
190
237
|
visit new_user_session_path
|
191
238
|
|
192
239
|
click_link "Didn't receive confirmation instructions?"
|
193
|
-
fill_in 'email', :
|
240
|
+
fill_in 'email', with: "idonthavethisemail@gmail.com"
|
194
241
|
click_button 'Resend confirmation instructions'
|
195
242
|
|
196
243
|
assert_not_contain "1 error prohibited this user from being saved:"
|
197
244
|
assert_not_contain "Email not found"
|
198
245
|
|
199
|
-
assert_contain "If your email address exists in our database, you will receive an email with instructions
|
246
|
+
assert_contain "If your email address exists in our database, you will receive an email with instructions for how to confirm your email address in a few minutes."
|
200
247
|
assert_current_url "/users/sign_in"
|
201
248
|
end
|
202
249
|
end
|
203
250
|
end
|
204
251
|
|
205
|
-
class ConfirmationOnChangeTest <
|
252
|
+
class ConfirmationOnChangeTest < ActionDispatch::IntegrationTest
|
206
253
|
def create_second_admin(options={})
|
207
254
|
@admin = nil
|
208
255
|
create_admin(options)
|
209
256
|
end
|
210
257
|
|
211
258
|
def visit_admin_confirmation_with_token(confirmation_token)
|
212
|
-
visit admin_confirmation_path(:
|
259
|
+
visit admin_confirmation_path(confirmation_token: confirmation_token)
|
213
260
|
end
|
214
261
|
|
215
262
|
test 'admin should be able to request a new confirmation after email changed' do
|
216
263
|
admin = create_admin
|
217
|
-
admin.update_attributes(:
|
264
|
+
admin.update_attributes(email: 'new_test@example.com')
|
218
265
|
|
219
266
|
visit new_admin_session_path
|
220
267
|
click_link "Didn't receive confirmation instructions?"
|
221
268
|
|
222
|
-
fill_in 'email', :
|
269
|
+
fill_in 'email', with: admin.unconfirmed_email
|
223
270
|
assert_difference "ActionMailer::Base.deliveries.size" do
|
224
271
|
click_button 'Resend confirmation instructions'
|
225
272
|
end
|
226
273
|
|
227
274
|
assert_current_url '/admin_area/sign_in'
|
228
|
-
assert_contain 'You will receive an email with instructions
|
275
|
+
assert_contain 'You will receive an email with instructions for how to confirm your email address in a few minutes'
|
229
276
|
end
|
230
277
|
|
231
278
|
test 'admin with valid confirmation token should be able to confirm email after email changed' do
|
232
279
|
admin = create_admin
|
233
|
-
admin.update_attributes(:
|
280
|
+
admin.update_attributes(email: 'new_test@example.com')
|
234
281
|
assert_equal 'new_test@example.com', admin.unconfirmed_email
|
235
|
-
visit_admin_confirmation_with_token(admin.
|
282
|
+
visit_admin_confirmation_with_token(admin.raw_confirmation_token)
|
236
283
|
|
237
|
-
assert_contain 'Your
|
238
|
-
assert_current_url '/admin_area/
|
284
|
+
assert_contain 'Your email address has been successfully confirmed.'
|
285
|
+
assert_current_url '/admin_area/sign_in'
|
286
|
+
assert admin.reload.confirmed?
|
287
|
+
assert_not admin.reload.pending_reconfirmation?
|
288
|
+
end
|
289
|
+
|
290
|
+
test 'admin with previously valid confirmation token should not be able to confirm email after email changed again' do
|
291
|
+
admin = create_admin
|
292
|
+
admin.update_attributes(email: 'first_test@example.com')
|
293
|
+
assert_equal 'first_test@example.com', admin.unconfirmed_email
|
294
|
+
|
295
|
+
raw_confirmation_token = admin.raw_confirmation_token
|
296
|
+
admin = Admin.find(admin.id)
|
297
|
+
|
298
|
+
admin.update_attributes(email: 'second_test@example.com')
|
299
|
+
assert_equal 'second_test@example.com', admin.unconfirmed_email
|
300
|
+
|
301
|
+
visit_admin_confirmation_with_token(raw_confirmation_token)
|
302
|
+
assert_have_selector '#error_explanation'
|
303
|
+
assert_contain(/Confirmation token(.*)invalid/)
|
304
|
+
|
305
|
+
visit_admin_confirmation_with_token(admin.raw_confirmation_token)
|
306
|
+
assert_contain 'Your email address has been successfully confirmed.'
|
307
|
+
assert_current_url '/admin_area/sign_in'
|
239
308
|
assert admin.reload.confirmed?
|
240
309
|
assert_not admin.reload.pending_reconfirmation?
|
241
310
|
end
|
242
311
|
|
243
312
|
test 'admin email should be unique also within unconfirmed_email' do
|
244
313
|
admin = create_admin
|
245
|
-
admin.update_attributes(:
|
314
|
+
admin.update_attributes(email: 'new_admin_test@example.com')
|
246
315
|
assert_equal 'new_admin_test@example.com', admin.unconfirmed_email
|
247
316
|
|
248
|
-
create_second_admin(:
|
317
|
+
create_second_admin(email: "new_admin_test@example.com")
|
249
318
|
|
250
|
-
visit_admin_confirmation_with_token(admin.
|
319
|
+
visit_admin_confirmation_with_token(admin.raw_confirmation_token)
|
251
320
|
assert_have_selector '#error_explanation'
|
252
|
-
assert_contain
|
321
|
+
assert_contain(/Email.*already.*taken/)
|
253
322
|
assert admin.reload.pending_reconfirmation?
|
254
323
|
end
|
255
324
|
end
|
@@ -1,69 +1,71 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
|
-
class DatabaseAuthenticationTest <
|
3
|
+
class DatabaseAuthenticationTest < ActionDispatch::IntegrationTest
|
4
4
|
test 'sign in with email of different case should succeed when email is in the list of case insensitive keys' do
|
5
|
-
create_user(:
|
6
|
-
|
5
|
+
create_user(email: 'Foo@Bar.com')
|
6
|
+
|
7
7
|
sign_in_as_user do
|
8
|
-
fill_in 'email', :
|
8
|
+
fill_in 'email', with: 'foo@bar.com'
|
9
9
|
end
|
10
|
-
|
10
|
+
|
11
11
|
assert warden.authenticated?(:user)
|
12
12
|
end
|
13
13
|
|
14
14
|
test 'sign in with email of different case should fail when email is NOT the list of case insensitive keys' do
|
15
|
-
swap Devise, :
|
16
|
-
create_user(:
|
17
|
-
|
15
|
+
swap Devise, case_insensitive_keys: [] do
|
16
|
+
create_user(email: 'Foo@Bar.com')
|
17
|
+
|
18
18
|
sign_in_as_user do
|
19
|
-
fill_in 'email', :
|
19
|
+
fill_in 'email', with: 'foo@bar.com'
|
20
20
|
end
|
21
|
-
|
21
|
+
|
22
22
|
assert_not warden.authenticated?(:user)
|
23
23
|
end
|
24
24
|
end
|
25
|
-
|
25
|
+
|
26
26
|
test 'sign in with email including extra spaces should succeed when email is in the list of strip whitespace keys' do
|
27
|
-
create_user(:
|
28
|
-
|
27
|
+
create_user(email: ' foo@bar.com ')
|
28
|
+
|
29
29
|
sign_in_as_user do
|
30
|
-
fill_in 'email', :
|
30
|
+
fill_in 'email', with: 'foo@bar.com'
|
31
31
|
end
|
32
|
-
|
32
|
+
|
33
33
|
assert warden.authenticated?(:user)
|
34
34
|
end
|
35
35
|
|
36
36
|
test 'sign in with email including extra spaces should fail when email is NOT the list of strip whitespace keys' do
|
37
|
-
swap Devise, :
|
38
|
-
create_user(:
|
39
|
-
|
37
|
+
swap Devise, strip_whitespace_keys: [] do
|
38
|
+
create_user(email: 'foo@bar.com')
|
39
|
+
|
40
40
|
sign_in_as_user do
|
41
|
-
fill_in 'email', :
|
41
|
+
fill_in 'email', with: ' foo@bar.com '
|
42
42
|
end
|
43
|
-
|
43
|
+
|
44
44
|
assert_not warden.authenticated?(:user)
|
45
45
|
end
|
46
46
|
end
|
47
47
|
|
48
48
|
test 'sign in should not authenticate if not using proper authentication keys' do
|
49
|
-
swap Devise, :
|
49
|
+
swap Devise, authentication_keys: [:username] do
|
50
50
|
sign_in_as_user
|
51
51
|
assert_not warden.authenticated?(:user)
|
52
52
|
end
|
53
53
|
end
|
54
54
|
|
55
55
|
test 'sign in with invalid email should return to sign in form with error message' do
|
56
|
-
|
57
|
-
|
58
|
-
|
56
|
+
store_translations :en, devise: { failure: { admin: { not_found_in_database: 'Invalid email address' } } } do
|
57
|
+
sign_in_as_admin do
|
58
|
+
fill_in 'email', with: 'wrongemail@test.com'
|
59
|
+
end
|
59
60
|
|
60
|
-
|
61
|
-
|
61
|
+
assert_contain 'Invalid email address'
|
62
|
+
assert_not warden.authenticated?(:admin)
|
63
|
+
end
|
62
64
|
end
|
63
65
|
|
64
66
|
test 'sign in with invalid pasword should return to sign in form with error message' do
|
65
67
|
sign_in_as_admin do
|
66
|
-
fill_in 'password', :
|
68
|
+
fill_in 'password', with: 'abcdef'
|
67
69
|
end
|
68
70
|
|
69
71
|
assert_contain 'Invalid email or password'
|
@@ -71,12 +73,23 @@ class DatabaseAuthenticationTest < ActionController::IntegrationTest
|
|
71
73
|
end
|
72
74
|
|
73
75
|
test 'error message is configurable by resource name' do
|
74
|
-
store_translations :en, :
|
76
|
+
store_translations :en, devise: { failure: { admin: { invalid: "Invalid credentials" } } } do
|
75
77
|
sign_in_as_admin do
|
76
|
-
fill_in 'password', :
|
78
|
+
fill_in 'password', with: 'abcdef'
|
77
79
|
end
|
78
80
|
|
79
81
|
assert_contain 'Invalid credentials'
|
80
82
|
end
|
81
83
|
end
|
82
|
-
|
84
|
+
|
85
|
+
test 'valid sign in calls after_database_authentication callback' do
|
86
|
+
user = create_user(email: ' foo@bar.com ')
|
87
|
+
|
88
|
+
User.expects(:find_for_database_authentication).returns user
|
89
|
+
user.expects :after_database_authentication
|
90
|
+
|
91
|
+
sign_in_as_user do
|
92
|
+
fill_in 'email', with: 'foo@bar.com'
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|