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.
Files changed (145) hide show
  1. data/README.md +16 -46
  2. data/app/controllers/devise/passwords_controller.rb +1 -1
  3. data/app/controllers/devise/registrations_controller.rb +1 -1
  4. data/lib/devise/controllers/helpers.rb +3 -6
  5. data/lib/devise/failure_app.rb +1 -8
  6. data/lib/devise/hooks/lockable.rb +1 -1
  7. data/lib/devise/mapping.rb +6 -6
  8. data/lib/devise/models/authenticatable.rb +4 -4
  9. data/lib/devise/models/confirmable.rb +4 -12
  10. data/lib/devise/models/database_authenticatable.rb +1 -1
  11. data/lib/devise/models/lockable.rb +1 -1
  12. data/lib/devise/models/recoverable.rb +2 -7
  13. data/lib/devise/models/rememberable.rb +1 -1
  14. data/lib/devise/{parameter_filter.rb → param_filter.rb} +1 -1
  15. data/lib/devise/parameter_sanitizer.rb +3 -3
  16. data/lib/devise/version.rb +1 -1
  17. data/lib/devise.rb +1 -1
  18. data/lib/generators/templates/README +1 -1
  19. data/lib/loyal_devise.rb +1 -0
  20. metadata +65 -301
  21. data/.gitignore +0 -12
  22. data/.travis.yml +0 -20
  23. data/.yardopts +0 -9
  24. data/CHANGELOG.rdoc +0 -936
  25. data/CONTRIBUTING.md +0 -14
  26. data/Gemfile +0 -31
  27. data/Gemfile.lock +0 -160
  28. data/devise.gemspec +0 -26
  29. data/devise.png +0 -0
  30. data/gemfiles/Gemfile.rails-3.2.x +0 -31
  31. data/gemfiles/Gemfile.rails-3.2.x.lock +0 -156
  32. data/loyal_devise.gemspec +0 -29
  33. data/test/controllers/custom_strategy_test.rb +0 -62
  34. data/test/controllers/helpers_test.rb +0 -253
  35. data/test/controllers/internal_helpers_test.rb +0 -120
  36. data/test/controllers/passwords_controller_test.rb +0 -32
  37. data/test/controllers/sessions_controller_test.rb +0 -85
  38. data/test/controllers/url_helpers_test.rb +0 -59
  39. data/test/delegator_test.rb +0 -19
  40. data/test/devise_test.rb +0 -83
  41. data/test/failure_app_test.rb +0 -221
  42. data/test/generators/active_record_generator_test.rb +0 -73
  43. data/test/generators/devise_generator_test.rb +0 -39
  44. data/test/generators/install_generator_test.rb +0 -13
  45. data/test/generators/mongoid_generator_test.rb +0 -23
  46. data/test/generators/views_generator_test.rb +0 -67
  47. data/test/helpers/devise_helper_test.rb +0 -51
  48. data/test/integration/authenticatable_test.rb +0 -699
  49. data/test/integration/confirmable_test.rb +0 -299
  50. data/test/integration/database_authenticatable_test.rb +0 -84
  51. data/test/integration/http_authenticatable_test.rb +0 -115
  52. data/test/integration/lockable_test.rb +0 -242
  53. data/test/integration/omniauthable_test.rb +0 -133
  54. data/test/integration/recoverable_test.rb +0 -335
  55. data/test/integration/registerable_test.rb +0 -349
  56. data/test/integration/rememberable_test.rb +0 -165
  57. data/test/integration/timeoutable_test.rb +0 -150
  58. data/test/integration/token_authenticatable_test.rb +0 -205
  59. data/test/integration/trackable_test.rb +0 -92
  60. data/test/mailers/confirmation_instructions_test.rb +0 -111
  61. data/test/mailers/reset_password_instructions_test.rb +0 -92
  62. data/test/mailers/unlock_instructions_test.rb +0 -87
  63. data/test/mapping_test.rb +0 -127
  64. data/test/models/authenticatable_test.rb +0 -13
  65. data/test/models/confirmable_test.rb +0 -443
  66. data/test/models/database_authenticatable_test.rb +0 -226
  67. data/test/models/lockable_test.rb +0 -273
  68. data/test/models/omniauthable_test.rb +0 -7
  69. data/test/models/recoverable_test.rb +0 -222
  70. data/test/models/registerable_test.rb +0 -7
  71. data/test/models/rememberable_test.rb +0 -175
  72. data/test/models/serializable_test.rb +0 -49
  73. data/test/models/timeoutable_test.rb +0 -46
  74. data/test/models/token_authenticatable_test.rb +0 -55
  75. data/test/models/trackable_test.rb +0 -13
  76. data/test/models/validatable_test.rb +0 -127
  77. data/test/models_test.rb +0 -163
  78. data/test/omniauth/config_test.rb +0 -57
  79. data/test/omniauth/url_helpers_test.rb +0 -54
  80. data/test/orm/active_record.rb +0 -10
  81. data/test/orm/mongoid.rb +0 -13
  82. data/test/parameter_sanitizer_test.rb +0 -51
  83. data/test/rails_app/Rakefile +0 -6
  84. data/test/rails_app/app/active_record/admin.rb +0 -6
  85. data/test/rails_app/app/active_record/shim.rb +0 -2
  86. data/test/rails_app/app/active_record/user.rb +0 -6
  87. data/test/rails_app/app/controllers/admins/sessions_controller.rb +0 -6
  88. data/test/rails_app/app/controllers/admins_controller.rb +0 -11
  89. data/test/rails_app/app/controllers/application_controller.rb +0 -9
  90. data/test/rails_app/app/controllers/home_controller.rb +0 -25
  91. data/test/rails_app/app/controllers/publisher/registrations_controller.rb +0 -2
  92. data/test/rails_app/app/controllers/publisher/sessions_controller.rb +0 -2
  93. data/test/rails_app/app/controllers/users/omniauth_callbacks_controller.rb +0 -14
  94. data/test/rails_app/app/controllers/users_controller.rb +0 -31
  95. data/test/rails_app/app/helpers/application_helper.rb +0 -3
  96. data/test/rails_app/app/mailers/users/mailer.rb +0 -12
  97. data/test/rails_app/app/mongoid/admin.rb +0 -29
  98. data/test/rails_app/app/mongoid/shim.rb +0 -23
  99. data/test/rails_app/app/mongoid/user.rb +0 -42
  100. data/test/rails_app/app/views/admins/index.html.erb +0 -1
  101. data/test/rails_app/app/views/admins/sessions/new.html.erb +0 -2
  102. data/test/rails_app/app/views/home/admin_dashboard.html.erb +0 -1
  103. data/test/rails_app/app/views/home/index.html.erb +0 -1
  104. data/test/rails_app/app/views/home/join.html.erb +0 -1
  105. data/test/rails_app/app/views/home/private.html.erb +0 -1
  106. data/test/rails_app/app/views/home/user_dashboard.html.erb +0 -1
  107. data/test/rails_app/app/views/layouts/application.html.erb +0 -24
  108. data/test/rails_app/app/views/users/edit_form.html.erb +0 -1
  109. data/test/rails_app/app/views/users/index.html.erb +0 -1
  110. data/test/rails_app/app/views/users/mailer/confirmation_instructions.erb +0 -1
  111. data/test/rails_app/app/views/users/sessions/new.html.erb +0 -1
  112. data/test/rails_app/bin/bundle +0 -3
  113. data/test/rails_app/bin/rails +0 -4
  114. data/test/rails_app/bin/rake +0 -4
  115. data/test/rails_app/config/application.rb +0 -40
  116. data/test/rails_app/config/boot.rb +0 -8
  117. data/test/rails_app/config/database.yml +0 -18
  118. data/test/rails_app/config/environment.rb +0 -5
  119. data/test/rails_app/config/environments/development.rb +0 -34
  120. data/test/rails_app/config/environments/production.rb +0 -84
  121. data/test/rails_app/config/environments/test.rb +0 -36
  122. data/test/rails_app/config/initializers/backtrace_silencers.rb +0 -7
  123. data/test/rails_app/config/initializers/devise.rb +0 -178
  124. data/test/rails_app/config/initializers/inflections.rb +0 -2
  125. data/test/rails_app/config/initializers/secret_token.rb +0 -8
  126. data/test/rails_app/config/initializers/session_store.rb +0 -1
  127. data/test/rails_app/config/routes.rb +0 -104
  128. data/test/rails_app/config.ru +0 -4
  129. data/test/rails_app/db/migrate/20100401102949_create_tables.rb +0 -74
  130. data/test/rails_app/db/schema.rb +0 -52
  131. data/test/rails_app/lib/shared_admin.rb +0 -14
  132. data/test/rails_app/lib/shared_user.rb +0 -25
  133. data/test/rails_app/public/404.html +0 -26
  134. data/test/rails_app/public/422.html +0 -26
  135. data/test/rails_app/public/500.html +0 -26
  136. data/test/rails_app/public/favicon.ico +0 -0
  137. data/test/routes_test.rb +0 -250
  138. data/test/support/assertions.rb +0 -40
  139. data/test/support/helpers.rb +0 -91
  140. data/test/support/integration.rb +0 -92
  141. data/test/support/locale/en.yml +0 -4
  142. data/test/support/webrat/integrations/rails.rb +0 -24
  143. data/test/test_helper.rb +0 -34
  144. data/test/test_helpers_test.rb +0 -151
  145. 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