loyal_devise 2.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +10 -0
- data/.travis.yml +15 -0
- data/CHANGELOG.rdoc +881 -0
- data/CONTRIBUTING.md +12 -0
- data/Gemfile +31 -0
- data/Gemfile.lock +154 -0
- data/MIT-LICENSE +20 -0
- data/README.md +388 -0
- data/Rakefile +34 -0
- data/app/controllers/devise/confirmations_controller.rb +44 -0
- data/app/controllers/devise/omniauth_callbacks_controller.rb +31 -0
- data/app/controllers/devise/passwords_controller.rb +57 -0
- data/app/controllers/devise/registrations_controller.rb +120 -0
- data/app/controllers/devise/sessions_controller.rb +51 -0
- data/app/controllers/devise/unlocks_controller.rb +45 -0
- data/app/controllers/devise_controller.rb +193 -0
- data/app/helpers/devise_helper.rb +26 -0
- data/app/mailers/devise/mailer.rb +16 -0
- data/app/views/devise/_links.erb +3 -0
- data/app/views/devise/confirmations/new.html.erb +12 -0
- data/app/views/devise/mailer/confirmation_instructions.html.erb +5 -0
- data/app/views/devise/mailer/reset_password_instructions.html.erb +8 -0
- data/app/views/devise/mailer/unlock_instructions.html.erb +7 -0
- data/app/views/devise/passwords/edit.html.erb +16 -0
- data/app/views/devise/passwords/new.html.erb +12 -0
- data/app/views/devise/registrations/edit.html.erb +25 -0
- data/app/views/devise/registrations/new.html.erb +18 -0
- data/app/views/devise/sessions/new.html.erb +17 -0
- data/app/views/devise/shared/_links.erb +25 -0
- data/app/views/devise/unlocks/new.html.erb +12 -0
- data/config/locales/en.yml +59 -0
- data/devise.gemspec +26 -0
- data/gemfiles/Gemfile.rails-3.1.x +35 -0
- data/gemfiles/Gemfile.rails-3.1.x.lock +167 -0
- data/lib/devise/controllers/helpers.rb +273 -0
- data/lib/devise/controllers/rememberable.rb +53 -0
- data/lib/devise/controllers/scoped_views.rb +18 -0
- data/lib/devise/controllers/url_helpers.rb +68 -0
- data/lib/devise/delegator.rb +17 -0
- data/lib/devise/failure_app.rb +188 -0
- data/lib/devise/hooks/activatable.rb +12 -0
- data/lib/devise/hooks/forgetable.rb +10 -0
- data/lib/devise/hooks/lockable.rb +8 -0
- data/lib/devise/hooks/rememberable.rb +7 -0
- data/lib/devise/hooks/timeoutable.rb +26 -0
- data/lib/devise/hooks/trackable.rb +10 -0
- data/lib/devise/mailers/helpers.rb +92 -0
- data/lib/devise/mapping.rb +173 -0
- data/lib/devise/models/authenticatable.rb +269 -0
- data/lib/devise/models/confirmable.rb +271 -0
- data/lib/devise/models/database_authenticatable.rb +127 -0
- data/lib/devise/models/lockable.rb +194 -0
- data/lib/devise/models/omniauthable.rb +28 -0
- data/lib/devise/models/recoverable.rb +141 -0
- data/lib/devise/models/registerable.rb +26 -0
- data/lib/devise/models/rememberable.rb +126 -0
- data/lib/devise/models/timeoutable.rb +50 -0
- data/lib/devise/models/token_authenticatable.rb +90 -0
- data/lib/devise/models/trackable.rb +36 -0
- data/lib/devise/models/validatable.rb +67 -0
- data/lib/devise/models.rb +129 -0
- data/lib/devise/modules.rb +30 -0
- data/lib/devise/omniauth/config.rb +46 -0
- data/lib/devise/omniauth/url_helpers.rb +19 -0
- data/lib/devise/omniauth.rb +29 -0
- data/lib/devise/orm/active_record.rb +4 -0
- data/lib/devise/orm/mongoid.rb +4 -0
- data/lib/devise/param_filter.rb +42 -0
- data/lib/devise/rails/routes.rb +447 -0
- data/lib/devise/rails/warden_compat.rb +44 -0
- data/lib/devise/rails.rb +55 -0
- data/lib/devise/strategies/authenticatable.rb +177 -0
- data/lib/devise/strategies/base.rb +21 -0
- data/lib/devise/strategies/database_authenticatable.rb +21 -0
- data/lib/devise/strategies/rememberable.rb +56 -0
- data/lib/devise/strategies/token_authenticatable.rb +57 -0
- data/lib/devise/test_helpers.rb +132 -0
- data/lib/devise/time_inflector.rb +15 -0
- data/lib/devise/version.rb +4 -0
- data/lib/devise.rb +445 -0
- data/lib/generators/active_record/devise_generator.rb +80 -0
- data/lib/generators/active_record/templates/migration.rb +20 -0
- data/lib/generators/active_record/templates/migration_existing.rb +27 -0
- data/lib/generators/devise/devise_generator.rb +25 -0
- data/lib/generators/devise/install_generator.rb +25 -0
- data/lib/generators/devise/orm_helpers.rb +33 -0
- data/lib/generators/devise/views_generator.rb +117 -0
- data/lib/generators/mongoid/devise_generator.rb +58 -0
- data/lib/generators/templates/README +35 -0
- data/lib/generators/templates/devise.rb +241 -0
- data/lib/generators/templates/markerb/confirmation_instructions.markerb +5 -0
- data/lib/generators/templates/markerb/reset_password_instructions.markerb +8 -0
- data/lib/generators/templates/markerb/unlock_instructions.markerb +7 -0
- data/lib/generators/templates/simple_form_for/confirmations/new.html.erb +15 -0
- data/lib/generators/templates/simple_form_for/passwords/edit.html.erb +19 -0
- data/lib/generators/templates/simple_form_for/passwords/new.html.erb +15 -0
- data/lib/generators/templates/simple_form_for/registrations/edit.html.erb +22 -0
- data/lib/generators/templates/simple_form_for/registrations/new.html.erb +17 -0
- data/lib/generators/templates/simple_form_for/sessions/new.html.erb +15 -0
- data/lib/generators/templates/simple_form_for/unlocks/new.html.erb +15 -0
- data/test/controllers/custom_strategy_test.rb +63 -0
- data/test/controllers/helpers_test.rb +254 -0
- data/test/controllers/internal_helpers_test.rb +111 -0
- data/test/controllers/sessions_controller_test.rb +58 -0
- data/test/controllers/url_helpers_test.rb +60 -0
- data/test/delegator_test.rb +20 -0
- data/test/devise_test.rb +73 -0
- data/test/failure_app_test.rb +222 -0
- data/test/generators/active_record_generator_test.rb +76 -0
- data/test/generators/devise_generator_test.rb +40 -0
- data/test/generators/install_generator_test.rb +14 -0
- data/test/generators/mongoid_generator_test.rb +24 -0
- data/test/generators/views_generator_test.rb +53 -0
- data/test/helpers/devise_helper_test.rb +52 -0
- data/test/indifferent_hash.rb +34 -0
- data/test/integration/authenticatable_test.rb +634 -0
- data/test/integration/confirmable_test.rb +299 -0
- data/test/integration/database_authenticatable_test.rb +83 -0
- data/test/integration/http_authenticatable_test.rb +98 -0
- data/test/integration/lockable_test.rb +243 -0
- data/test/integration/omniauthable_test.rb +134 -0
- data/test/integration/recoverable_test.rb +307 -0
- data/test/integration/registerable_test.rb +346 -0
- data/test/integration/rememberable_test.rb +159 -0
- data/test/integration/timeoutable_test.rb +141 -0
- data/test/integration/token_authenticatable_test.rb +162 -0
- data/test/integration/trackable_test.rb +93 -0
- data/test/mailers/confirmation_instructions_test.rb +103 -0
- data/test/mailers/reset_password_instructions_test.rb +84 -0
- data/test/mailers/unlock_instructions_test.rb +78 -0
- data/test/mapping_test.rb +128 -0
- data/test/models/authenticatable_test.rb +8 -0
- data/test/models/confirmable_test.rb +392 -0
- data/test/models/database_authenticatable_test.rb +190 -0
- data/test/models/lockable_test.rb +274 -0
- data/test/models/omniauthable_test.rb +8 -0
- data/test/models/recoverable_test.rb +206 -0
- data/test/models/registerable_test.rb +8 -0
- data/test/models/rememberable_test.rb +175 -0
- data/test/models/serializable_test.rb +49 -0
- data/test/models/timeoutable_test.rb +47 -0
- data/test/models/token_authenticatable_test.rb +56 -0
- data/test/models/trackable_test.rb +14 -0
- data/test/models/validatable_test.rb +117 -0
- data/test/models_test.rb +180 -0
- data/test/omniauth/config_test.rb +58 -0
- data/test/omniauth/url_helpers_test.rb +52 -0
- data/test/orm/active_record.rb +10 -0
- data/test/orm/mongoid.rb +15 -0
- data/test/rails_app/Rakefile +10 -0
- data/test/rails_app/app/active_record/admin.rb +7 -0
- data/test/rails_app/app/active_record/shim.rb +3 -0
- data/test/rails_app/app/active_record/user.rb +7 -0
- data/test/rails_app/app/controllers/admins/sessions_controller.rb +7 -0
- data/test/rails_app/app/controllers/admins_controller.rb +12 -0
- data/test/rails_app/app/controllers/application_controller.rb +9 -0
- data/test/rails_app/app/controllers/home_controller.rb +26 -0
- data/test/rails_app/app/controllers/publisher/registrations_controller.rb +3 -0
- data/test/rails_app/app/controllers/publisher/sessions_controller.rb +3 -0
- data/test/rails_app/app/controllers/users/omniauth_callbacks_controller.rb +15 -0
- data/test/rails_app/app/controllers/users_controller.rb +24 -0
- data/test/rails_app/app/helpers/application_helper.rb +4 -0
- data/test/rails_app/app/mailers/users/mailer.rb +9 -0
- data/test/rails_app/app/mongoid/admin.rb +28 -0
- data/test/rails_app/app/mongoid/shim.rb +25 -0
- data/test/rails_app/app/mongoid/user.rb +43 -0
- data/test/rails_app/app/views/admins/index.html.erb +1 -0
- data/test/rails_app/app/views/admins/sessions/new.html.erb +2 -0
- data/test/rails_app/app/views/home/admin_dashboard.html.erb +1 -0
- data/test/rails_app/app/views/home/index.html.erb +1 -0
- data/test/rails_app/app/views/home/join.html.erb +1 -0
- data/test/rails_app/app/views/home/private.html.erb +1 -0
- data/test/rails_app/app/views/home/user_dashboard.html.erb +1 -0
- data/test/rails_app/app/views/layouts/application.html.erb +24 -0
- data/test/rails_app/app/views/users/index.html.erb +1 -0
- data/test/rails_app/app/views/users/mailer/confirmation_instructions.erb +1 -0
- data/test/rails_app/app/views/users/sessions/new.html.erb +1 -0
- data/test/rails_app/config/application.rb +42 -0
- data/test/rails_app/config/boot.rb +9 -0
- data/test/rails_app/config/database.yml +18 -0
- data/test/rails_app/config/environment.rb +6 -0
- data/test/rails_app/config/environments/development.rb +19 -0
- data/test/rails_app/config/environments/production.rb +34 -0
- data/test/rails_app/config/environments/test.rb +34 -0
- data/test/rails_app/config/initializers/backtrace_silencers.rb +8 -0
- data/test/rails_app/config/initializers/devise.rb +179 -0
- data/test/rails_app/config/initializers/inflections.rb +3 -0
- data/test/rails_app/config/initializers/secret_token.rb +3 -0
- data/test/rails_app/config/routes.rb +101 -0
- data/test/rails_app/config.ru +4 -0
- data/test/rails_app/db/migrate/20100401102949_create_tables.rb +75 -0
- data/test/rails_app/db/schema.rb +53 -0
- data/test/rails_app/lib/shared_admin.rb +15 -0
- data/test/rails_app/lib/shared_user.rb +27 -0
- data/test/rails_app/public/404.html +26 -0
- data/test/rails_app/public/422.html +26 -0
- data/test/rails_app/public/500.html +26 -0
- data/test/rails_app/public/favicon.ico +0 -0
- data/test/rails_app/script/rails +10 -0
- data/test/routes_test.rb +249 -0
- data/test/support/assertions.rb +41 -0
- data/test/support/helpers.rb +92 -0
- data/test/support/integration.rb +93 -0
- data/test/support/locale/en.yml +4 -0
- data/test/support/webrat/integrations/rails.rb +25 -0
- data/test/test_helper.rb +28 -0
- data/test/test_helpers_test.rb +152 -0
- metadata +407 -0
@@ -0,0 +1,299 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
require 'test_helper'
|
3
|
+
|
4
|
+
class ConfirmationTest < ActionController::IntegrationTest
|
5
|
+
|
6
|
+
def visit_user_confirmation_with_token(confirmation_token)
|
7
|
+
visit user_confirmation_path(:confirmation_token => confirmation_token)
|
8
|
+
end
|
9
|
+
|
10
|
+
def resend_confirmation
|
11
|
+
user = create_user(:confirm => false)
|
12
|
+
ActionMailer::Base.deliveries.clear
|
13
|
+
|
14
|
+
visit new_user_session_path
|
15
|
+
click_link "Didn't receive confirmation instructions?"
|
16
|
+
|
17
|
+
fill_in 'email', :with => user.email
|
18
|
+
click_button 'Resend confirmation instructions'
|
19
|
+
end
|
20
|
+
|
21
|
+
test 'user should be able to request a new confirmation' do
|
22
|
+
resend_confirmation
|
23
|
+
|
24
|
+
assert_current_url '/users/sign_in'
|
25
|
+
assert_contain 'You will receive an email with instructions about how to confirm your account in a few minutes'
|
26
|
+
assert_equal 1, ActionMailer::Base.deliveries.size
|
27
|
+
assert_equal ['please-change-me@config-initializers-devise.com'], ActionMailer::Base.deliveries.first.from
|
28
|
+
end
|
29
|
+
|
30
|
+
test 'user should receive a confirmation from a custom mailer' do
|
31
|
+
User.any_instance.stubs(:devise_mailer).returns(Users::Mailer)
|
32
|
+
|
33
|
+
resend_confirmation
|
34
|
+
|
35
|
+
assert_equal ['custom@example.com'], ActionMailer::Base.deliveries.first.from
|
36
|
+
end
|
37
|
+
|
38
|
+
test 'user with invalid confirmation token should not be able to confirm an account' do
|
39
|
+
visit_user_confirmation_with_token('invalid_confirmation')
|
40
|
+
assert_have_selector '#error_explanation'
|
41
|
+
assert_contain /Confirmation token(.*)invalid/
|
42
|
+
end
|
43
|
+
|
44
|
+
test 'user with valid confirmation token should be able to confirm an account' do
|
45
|
+
user = create_user(:confirm => false)
|
46
|
+
assert_not user.confirmed?
|
47
|
+
visit_user_confirmation_with_token(user.confirmation_token)
|
48
|
+
|
49
|
+
assert_contain 'Your account was successfully confirmed.'
|
50
|
+
assert_current_url '/'
|
51
|
+
assert user.reload.confirmed?
|
52
|
+
end
|
53
|
+
|
54
|
+
test 'user with valid confirmation token should not be able to confirm an account after the token has expired' do
|
55
|
+
swap Devise, :confirm_within => 3.days do
|
56
|
+
user = create_user(:confirm => false, :confirmation_sent_at => 4.days.ago)
|
57
|
+
assert_not user.confirmed?
|
58
|
+
visit_user_confirmation_with_token(user.confirmation_token)
|
59
|
+
|
60
|
+
assert_have_selector '#error_explanation'
|
61
|
+
assert_contain /needs to be confirmed within 3 days/
|
62
|
+
assert_not user.reload.confirmed?
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
test 'user with valid confirmation token should be able to confirm an account before the token has expired' do
|
67
|
+
swap Devise, :confirm_within => 3.days do
|
68
|
+
user = create_user(:confirm => false, :confirmation_sent_at => 2.days.ago)
|
69
|
+
assert_not user.confirmed?
|
70
|
+
visit_user_confirmation_with_token(user.confirmation_token)
|
71
|
+
|
72
|
+
assert_contain 'Your account was successfully confirmed.'
|
73
|
+
assert_current_url '/'
|
74
|
+
assert user.reload.confirmed?
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
test 'user should be redirected to a custom path after confirmation' do
|
79
|
+
Devise::ConfirmationsController.any_instance.stubs(:after_confirmation_path_for).returns("/?custom=1")
|
80
|
+
|
81
|
+
user = create_user(:confirm => false)
|
82
|
+
visit_user_confirmation_with_token(user.confirmation_token)
|
83
|
+
|
84
|
+
assert_current_url "/?custom=1"
|
85
|
+
end
|
86
|
+
|
87
|
+
test 'already confirmed user should not be able to confirm the account again' do
|
88
|
+
user = create_user(:confirm => false)
|
89
|
+
user.confirmed_at = Time.now
|
90
|
+
user.save
|
91
|
+
visit_user_confirmation_with_token(user.confirmation_token)
|
92
|
+
|
93
|
+
assert_have_selector '#error_explanation'
|
94
|
+
assert_contain 'already confirmed'
|
95
|
+
end
|
96
|
+
|
97
|
+
test 'already confirmed user should not be able to confirm the account again neither request confirmation' do
|
98
|
+
user = create_user(:confirm => false)
|
99
|
+
user.confirmed_at = Time.now
|
100
|
+
user.save
|
101
|
+
|
102
|
+
visit_user_confirmation_with_token(user.confirmation_token)
|
103
|
+
assert_contain 'already confirmed'
|
104
|
+
|
105
|
+
fill_in 'email', :with => user.email
|
106
|
+
click_button 'Resend confirmation instructions'
|
107
|
+
assert_contain 'already confirmed'
|
108
|
+
end
|
109
|
+
|
110
|
+
test 'sign in user automatically after confirming its email' do
|
111
|
+
user = create_user(:confirm => false)
|
112
|
+
visit_user_confirmation_with_token(user.confirmation_token)
|
113
|
+
|
114
|
+
assert warden.authenticated?(:user)
|
115
|
+
end
|
116
|
+
|
117
|
+
test 'increases sign count when signed in through confirmation' do
|
118
|
+
user = create_user(:confirm => false)
|
119
|
+
visit_user_confirmation_with_token(user.confirmation_token)
|
120
|
+
|
121
|
+
user.reload
|
122
|
+
assert_equal 1, user.sign_in_count
|
123
|
+
end
|
124
|
+
|
125
|
+
test 'not confirmed user with setup to block without confirmation should not be able to sign in' do
|
126
|
+
swap Devise, :allow_unconfirmed_access_for => 0.days do
|
127
|
+
sign_in_as_user(:confirm => false)
|
128
|
+
|
129
|
+
assert_contain 'You have to confirm your account before continuing'
|
130
|
+
assert_not warden.authenticated?(:user)
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
test 'not confirmed user should not see confirmation message if invalid credentials are given' do
|
135
|
+
swap Devise, :allow_unconfirmed_access_for => 0.days do
|
136
|
+
sign_in_as_user(:confirm => false) do
|
137
|
+
fill_in 'password', :with => 'invalid'
|
138
|
+
end
|
139
|
+
|
140
|
+
assert_contain 'Invalid email or password'
|
141
|
+
assert_not warden.authenticated?(:user)
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
test 'not confirmed user but configured with some days to confirm should be able to sign in' do
|
146
|
+
swap Devise, :allow_unconfirmed_access_for => 1.day do
|
147
|
+
sign_in_as_user(:confirm => false)
|
148
|
+
|
149
|
+
assert_response :success
|
150
|
+
assert warden.authenticated?(:user)
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
test 'error message is configurable by resource name' do
|
155
|
+
store_translations :en, :devise => {
|
156
|
+
:failure => { :user => { :unconfirmed => "Not confirmed user" } }
|
157
|
+
} do
|
158
|
+
sign_in_as_user(:confirm => false)
|
159
|
+
assert_contain 'Not confirmed user'
|
160
|
+
end
|
161
|
+
end
|
162
|
+
|
163
|
+
test 'resent confirmation token with valid E-Mail in XML format should return valid response' do
|
164
|
+
user = create_user(:confirm => false)
|
165
|
+
post user_confirmation_path(:format => 'xml'), :user => { :email => user.email }
|
166
|
+
assert_response :success
|
167
|
+
assert_equal response.body, {}.to_xml
|
168
|
+
end
|
169
|
+
|
170
|
+
test 'resent confirmation token with invalid E-Mail in XML format should return invalid response' do
|
171
|
+
user = create_user(:confirm => false)
|
172
|
+
post user_confirmation_path(:format => 'xml'), :user => { :email => 'invalid.test@test.com' }
|
173
|
+
assert_response :unprocessable_entity
|
174
|
+
assert response.body.include? %(<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<errors>)
|
175
|
+
end
|
176
|
+
|
177
|
+
test 'confirm account with valid confirmation token in XML format should return valid response' do
|
178
|
+
user = create_user(:confirm => false)
|
179
|
+
get user_confirmation_path(:confirmation_token => user.confirmation_token, :format => 'xml')
|
180
|
+
assert_response :success
|
181
|
+
assert response.body.include? %(<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<user>)
|
182
|
+
end
|
183
|
+
|
184
|
+
test 'confirm account with invalid confirmation token in XML format should return invalid response' do
|
185
|
+
user = create_user(:confirm => false)
|
186
|
+
get user_confirmation_path(:confirmation_token => 'invalid_confirmation', :format => 'xml')
|
187
|
+
assert_response :unprocessable_entity
|
188
|
+
assert response.body.include? %(<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<errors>)
|
189
|
+
end
|
190
|
+
|
191
|
+
test 'request an account confirmation account with JSON, should return an empty JSON' do
|
192
|
+
user = create_user(:confirm => false)
|
193
|
+
|
194
|
+
post user_confirmation_path, :user => { :email => user.email }, :format => :json
|
195
|
+
assert_response :success
|
196
|
+
assert_equal response.body, {}.to_json
|
197
|
+
end
|
198
|
+
|
199
|
+
test "when in paranoid mode and with a valid e-mail, should not say that the e-mail is valid" do
|
200
|
+
swap Devise, :paranoid => true do
|
201
|
+
user = create_user(:confirm => false)
|
202
|
+
visit new_user_session_path
|
203
|
+
|
204
|
+
click_link "Didn't receive confirmation instructions?"
|
205
|
+
fill_in 'email', :with => user.email
|
206
|
+
click_button 'Resend confirmation instructions'
|
207
|
+
|
208
|
+
assert_contain "If your email address exists in our database, you will receive an email with instructions about how to confirm your account in a few minutes."
|
209
|
+
assert_current_url "/users/sign_in"
|
210
|
+
end
|
211
|
+
end
|
212
|
+
|
213
|
+
test "when in paranoid mode and with a invalid e-mail, should not say that the e-mail is invalid" do
|
214
|
+
swap Devise, :paranoid => true do
|
215
|
+
visit new_user_session_path
|
216
|
+
|
217
|
+
click_link "Didn't receive confirmation instructions?"
|
218
|
+
fill_in 'email', :with => "idonthavethisemail@gmail.com"
|
219
|
+
click_button 'Resend confirmation instructions'
|
220
|
+
|
221
|
+
assert_not_contain "1 error prohibited this user from being saved:"
|
222
|
+
assert_not_contain "Email not found"
|
223
|
+
|
224
|
+
assert_contain "If your email address exists in our database, you will receive an email with instructions about how to confirm your account in a few minutes."
|
225
|
+
assert_current_url "/users/sign_in"
|
226
|
+
end
|
227
|
+
end
|
228
|
+
end
|
229
|
+
|
230
|
+
class ConfirmationOnChangeTest < ActionController::IntegrationTest
|
231
|
+
def create_second_admin(options={})
|
232
|
+
@admin = nil
|
233
|
+
create_admin(options)
|
234
|
+
end
|
235
|
+
|
236
|
+
def visit_admin_confirmation_with_token(confirmation_token)
|
237
|
+
visit admin_confirmation_path(:confirmation_token => confirmation_token)
|
238
|
+
end
|
239
|
+
|
240
|
+
test 'admin should be able to request a new confirmation after email changed' do
|
241
|
+
admin = create_admin
|
242
|
+
admin.update_attributes(:email => 'new_test@example.com')
|
243
|
+
|
244
|
+
visit new_admin_session_path
|
245
|
+
click_link "Didn't receive confirmation instructions?"
|
246
|
+
|
247
|
+
fill_in 'email', :with => admin.unconfirmed_email
|
248
|
+
assert_difference "ActionMailer::Base.deliveries.size" do
|
249
|
+
click_button 'Resend confirmation instructions'
|
250
|
+
end
|
251
|
+
|
252
|
+
assert_current_url '/admin_area/sign_in'
|
253
|
+
assert_contain 'You will receive an email with instructions about how to confirm your account in a few minutes'
|
254
|
+
end
|
255
|
+
|
256
|
+
test 'admin with valid confirmation token should be able to confirm email after email changed' do
|
257
|
+
admin = create_admin
|
258
|
+
admin.update_attributes(:email => 'new_test@example.com')
|
259
|
+
assert_equal 'new_test@example.com', admin.unconfirmed_email
|
260
|
+
visit_admin_confirmation_with_token(admin.confirmation_token)
|
261
|
+
|
262
|
+
assert_contain 'Your account was successfully confirmed.'
|
263
|
+
assert_current_url '/admin_area/home'
|
264
|
+
assert admin.reload.confirmed?
|
265
|
+
assert_not admin.reload.pending_reconfirmation?
|
266
|
+
end
|
267
|
+
|
268
|
+
test 'admin with previously valid confirmation token should not be able to confirm email after email changed again' do
|
269
|
+
admin = create_admin
|
270
|
+
admin.update_attributes(:email => 'first_test@example.com')
|
271
|
+
assert_equal 'first_test@example.com', admin.unconfirmed_email
|
272
|
+
confirmation_token = admin.confirmation_token
|
273
|
+
admin.update_attributes(:email => 'second_test@example.com')
|
274
|
+
assert_equal 'second_test@example.com', admin.unconfirmed_email
|
275
|
+
|
276
|
+
visit_admin_confirmation_with_token(confirmation_token)
|
277
|
+
assert_have_selector '#error_explanation'
|
278
|
+
assert_contain /Confirmation token(.*)invalid/
|
279
|
+
|
280
|
+
visit_admin_confirmation_with_token(admin.confirmation_token)
|
281
|
+
assert_contain 'Your account was successfully confirmed.'
|
282
|
+
assert_current_url '/admin_area/home'
|
283
|
+
assert admin.reload.confirmed?
|
284
|
+
assert_not admin.reload.pending_reconfirmation?
|
285
|
+
end
|
286
|
+
|
287
|
+
test 'admin email should be unique also within unconfirmed_email' do
|
288
|
+
admin = create_admin
|
289
|
+
admin.update_attributes(:email => 'new_admin_test@example.com')
|
290
|
+
assert_equal 'new_admin_test@example.com', admin.unconfirmed_email
|
291
|
+
|
292
|
+
create_second_admin(:email => "new_admin_test@example.com")
|
293
|
+
|
294
|
+
visit_admin_confirmation_with_token(admin.confirmation_token)
|
295
|
+
assert_have_selector '#error_explanation'
|
296
|
+
assert_contain /Email.*already.*taken/
|
297
|
+
assert admin.reload.pending_reconfirmation?
|
298
|
+
end
|
299
|
+
end
|
@@ -0,0 +1,83 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
require 'test_helper'
|
3
|
+
|
4
|
+
class DatabaseAuthenticationTest < ActionController::IntegrationTest
|
5
|
+
test 'sign in with email of different case should succeed when email is in the list of case insensitive keys' do
|
6
|
+
create_user(:email => 'Foo@Bar.com')
|
7
|
+
|
8
|
+
sign_in_as_user do
|
9
|
+
fill_in 'email', :with => 'foo@bar.com'
|
10
|
+
end
|
11
|
+
|
12
|
+
assert warden.authenticated?(:user)
|
13
|
+
end
|
14
|
+
|
15
|
+
test 'sign in with email of different case should fail when email is NOT the list of case insensitive keys' do
|
16
|
+
swap Devise, :case_insensitive_keys => [] do
|
17
|
+
create_user(:email => 'Foo@Bar.com')
|
18
|
+
|
19
|
+
sign_in_as_user do
|
20
|
+
fill_in 'email', :with => 'foo@bar.com'
|
21
|
+
end
|
22
|
+
|
23
|
+
assert_not warden.authenticated?(:user)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
test 'sign in with email including extra spaces should succeed when email is in the list of strip whitespace keys' do
|
28
|
+
create_user(:email => ' foo@bar.com ')
|
29
|
+
|
30
|
+
sign_in_as_user do
|
31
|
+
fill_in 'email', :with => 'foo@bar.com'
|
32
|
+
end
|
33
|
+
|
34
|
+
assert warden.authenticated?(:user)
|
35
|
+
end
|
36
|
+
|
37
|
+
test 'sign in with email including extra spaces should fail when email is NOT the list of strip whitespace keys' do
|
38
|
+
swap Devise, :strip_whitespace_keys => [] do
|
39
|
+
create_user(:email => 'foo@bar.com')
|
40
|
+
|
41
|
+
sign_in_as_user do
|
42
|
+
fill_in 'email', :with => ' foo@bar.com '
|
43
|
+
end
|
44
|
+
|
45
|
+
assert_not warden.authenticated?(:user)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
test 'sign in should not authenticate if not using proper authentication keys' do
|
50
|
+
swap Devise, :authentication_keys => [:username] do
|
51
|
+
sign_in_as_user
|
52
|
+
assert_not warden.authenticated?(:user)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
test 'sign in with invalid email should return to sign in form with error message' do
|
57
|
+
sign_in_as_admin do
|
58
|
+
fill_in 'email', :with => 'wrongemail@test.com'
|
59
|
+
end
|
60
|
+
|
61
|
+
assert_contain 'Invalid email or password'
|
62
|
+
assert_not warden.authenticated?(:admin)
|
63
|
+
end
|
64
|
+
|
65
|
+
test 'sign in with invalid pasword should return to sign in form with error message' do
|
66
|
+
sign_in_as_admin do
|
67
|
+
fill_in 'password', :with => 'abcdef'
|
68
|
+
end
|
69
|
+
|
70
|
+
assert_contain 'Invalid email or password'
|
71
|
+
assert_not warden.authenticated?(:admin)
|
72
|
+
end
|
73
|
+
|
74
|
+
test 'error message is configurable by resource name' do
|
75
|
+
store_translations :en, :devise => { :failure => { :admin => { :invalid => "Invalid credentials" } } } do
|
76
|
+
sign_in_as_admin do
|
77
|
+
fill_in 'password', :with => 'abcdef'
|
78
|
+
end
|
79
|
+
|
80
|
+
assert_contain 'Invalid credentials'
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
@@ -0,0 +1,98 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
require 'test_helper'
|
3
|
+
|
4
|
+
class HttpAuthenticationTest < ActionController::IntegrationTest
|
5
|
+
test 'handles unverified requests gets rid of caches but continues signed in' do
|
6
|
+
swap UsersController, :allow_forgery_protection => true do
|
7
|
+
create_user
|
8
|
+
post exhibit_user_url(1), {}, "HTTP_AUTHORIZATION" => "Basic #{Base64.encode64("user@test.com:12345678")}"
|
9
|
+
assert warden.authenticated?(:user)
|
10
|
+
assert_equal "User is authenticated", response.body
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
test 'sign in should authenticate with http' do
|
15
|
+
sign_in_as_new_user_with_http
|
16
|
+
assert_response 200
|
17
|
+
assert_match '<email>user@test.com</email>', response.body
|
18
|
+
assert warden.authenticated?(:user)
|
19
|
+
|
20
|
+
get users_path(:format => :xml)
|
21
|
+
assert_response 200
|
22
|
+
end
|
23
|
+
|
24
|
+
test 'sign in should authenticate with http but not emit a cookie if skipping session storage' do
|
25
|
+
swap Devise, :skip_session_storage => [:http_auth] do
|
26
|
+
sign_in_as_new_user_with_http
|
27
|
+
assert_response 200
|
28
|
+
assert_match '<email>user@test.com</email>', response.body
|
29
|
+
assert warden.authenticated?(:user)
|
30
|
+
|
31
|
+
get users_path(:format => :xml)
|
32
|
+
assert_response 401
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
test 'returns a custom response with www-authenticate header on failures' do
|
37
|
+
sign_in_as_new_user_with_http("unknown")
|
38
|
+
assert_equal 401, status
|
39
|
+
assert_equal 'Basic realm="Application"', headers["WWW-Authenticate"]
|
40
|
+
end
|
41
|
+
|
42
|
+
test 'uses the request format as response content type' do
|
43
|
+
sign_in_as_new_user_with_http("unknown")
|
44
|
+
assert_equal 401, status
|
45
|
+
assert_equal "application/xml; charset=utf-8", headers["Content-Type"]
|
46
|
+
assert_match "<error>Invalid email or password.</error>", response.body
|
47
|
+
end
|
48
|
+
|
49
|
+
test 'returns a custom response with www-authenticate and chosen realm' do
|
50
|
+
swap Devise, :http_authentication_realm => "MyApp" do
|
51
|
+
sign_in_as_new_user_with_http("unknown")
|
52
|
+
assert_equal 401, status
|
53
|
+
assert_equal 'Basic realm="MyApp"', headers["WWW-Authenticate"]
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
test 'sign in should authenticate with http even with specific authentication keys' do
|
58
|
+
swap Devise, :authentication_keys => [:username] do
|
59
|
+
sign_in_as_new_user_with_http("usertest")
|
60
|
+
assert_response :success
|
61
|
+
assert_match '<email>user@test.com</email>', response.body
|
62
|
+
assert warden.authenticated?(:user)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
test 'test request with oauth2 header doesnt get mistaken for basic authentication' do
|
67
|
+
swap Devise, :http_authenticatable => true do
|
68
|
+
add_oauth2_header
|
69
|
+
assert_equal 401, status
|
70
|
+
assert_equal 'Basic realm="Application"', headers["WWW-Authenticate"]
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
test 'sign in should authenticate with really long token' do
|
75
|
+
token = "token_containing_so_many_characters_that_the_base64_encoding_will_wrap"
|
76
|
+
user = create_user
|
77
|
+
user.update_attribute :authentication_token, token
|
78
|
+
get users_path(:format => :xml), {}, "HTTP_AUTHORIZATION" => "Basic #{Base64.encode64("#{token}:x")}"
|
79
|
+
assert_response :success
|
80
|
+
assert_match "<email>user@test.com</email>", response.body
|
81
|
+
assert warden.authenticated?(:user)
|
82
|
+
end
|
83
|
+
|
84
|
+
private
|
85
|
+
|
86
|
+
def sign_in_as_new_user_with_http(username="user@test.com", password="12345678")
|
87
|
+
user = create_user
|
88
|
+
get users_path(:format => :xml), {}, "HTTP_AUTHORIZATION" => "Basic #{Base64.encode64("#{username}:#{password}")}"
|
89
|
+
user
|
90
|
+
end
|
91
|
+
|
92
|
+
# Sign in with oauth2 token. This is just to test that it isn't misinterpreted as basic authentication
|
93
|
+
def add_oauth2_header
|
94
|
+
user = create_user
|
95
|
+
get users_path(:format => :xml), {}, "HTTP_AUTHORIZATION" => "OAuth #{Base64.encode64("#{user.email}:12345678")}"
|
96
|
+
end
|
97
|
+
|
98
|
+
end
|