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