devise 4.4.3 → 4.7.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (210) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +81 -2
  3. data/MIT-LICENSE +1 -1
  4. data/README.md +50 -21
  5. data/app/controllers/devise/passwords_controller.rb +1 -0
  6. data/app/controllers/devise/registrations_controller.rb +26 -8
  7. data/app/controllers/devise_controller.rb +1 -1
  8. data/app/helpers/devise_helper.rb +10 -19
  9. data/app/views/devise/confirmations/new.html.erb +1 -1
  10. data/app/views/devise/passwords/edit.html.erb +3 -3
  11. data/app/views/devise/passwords/new.html.erb +1 -1
  12. data/app/views/devise/registrations/edit.html.erb +4 -4
  13. data/app/views/devise/registrations/new.html.erb +3 -3
  14. data/app/views/devise/sessions/new.html.erb +3 -3
  15. data/app/views/devise/shared/_error_messages.html.erb +15 -0
  16. data/app/views/devise/shared/_links.html.erb +7 -7
  17. data/app/views/devise/unlocks/new.html.erb +1 -1
  18. data/config/locales/en.yml +2 -1
  19. data/lib/devise/controllers/helpers.rb +1 -1
  20. data/lib/devise/controllers/sign_in_out.rb +3 -0
  21. data/lib/devise/failure_app.rb +24 -3
  22. data/lib/devise/models/authenticatable.rb +38 -40
  23. data/lib/devise/models/confirmable.rb +16 -1
  24. data/lib/devise/models/database_authenticatable.rb +45 -11
  25. data/lib/devise/models/lockable.rb +2 -2
  26. data/lib/devise/models/registerable.rb +2 -0
  27. data/lib/devise/models/trackable.rb +8 -1
  28. data/lib/devise/models/validatable.rb +1 -1
  29. data/lib/devise/parameter_filter.rb +2 -0
  30. data/lib/devise/parameter_sanitizer.rb +13 -1
  31. data/lib/devise/rails/routes.rb +2 -2
  32. data/lib/devise/secret_key_finder.rb +2 -0
  33. data/lib/devise/strategies/authenticatable.rb +1 -1
  34. data/lib/devise/strategies/database_authenticatable.rb +6 -1
  35. data/lib/devise/test/controller_helpers.rb +1 -1
  36. data/lib/devise/version.rb +1 -1
  37. data/lib/devise.rb +4 -0
  38. data/lib/generators/active_record/devise_generator.rb +9 -9
  39. data/lib/generators/devise/controllers_generator.rb +1 -1
  40. data/lib/generators/devise/orm_helpers.rb +2 -2
  41. data/lib/generators/mongoid/devise_generator.rb +5 -5
  42. data/lib/generators/templates/devise.rb +19 -3
  43. data/lib/generators/templates/simple_form_for/confirmations/new.html.erb +5 -1
  44. data/lib/generators/templates/simple_form_for/passwords/edit.html.erb +10 -2
  45. data/lib/generators/templates/simple_form_for/passwords/new.html.erb +4 -1
  46. data/lib/generators/templates/simple_form_for/registrations/edit.html.erb +11 -3
  47. data/lib/generators/templates/simple_form_for/registrations/new.html.erb +11 -3
  48. data/lib/generators/templates/simple_form_for/sessions/new.html.erb +7 -2
  49. data/lib/generators/templates/simple_form_for/unlocks/new.html.erb +4 -1
  50. metadata +5 -310
  51. data/.gitignore +0 -10
  52. data/.travis.yml +0 -68
  53. data/.yardopts +0 -9
  54. data/CODE_OF_CONDUCT.md +0 -22
  55. data/CONTRIBUTING.md +0 -79
  56. data/Gemfile +0 -39
  57. data/Gemfile.lock +0 -193
  58. data/ISSUE_TEMPLATE.md +0 -19
  59. data/Rakefile +0 -37
  60. data/bin/test +0 -13
  61. data/devise.gemspec +0 -28
  62. data/devise.png +0 -0
  63. data/gemfiles/Gemfile.rails-4.1-stable +0 -32
  64. data/gemfiles/Gemfile.rails-4.1-stable.lock +0 -171
  65. data/gemfiles/Gemfile.rails-4.2-stable +0 -32
  66. data/gemfiles/Gemfile.rails-4.2-stable.lock +0 -192
  67. data/gemfiles/Gemfile.rails-5.0-stable +0 -33
  68. data/gemfiles/Gemfile.rails-5.0-stable.lock +0 -192
  69. data/gemfiles/Gemfile.rails-5.2-rc1 +0 -26
  70. data/gemfiles/Gemfile.rails-5.2-rc1.lock +0 -201
  71. data/guides/bug_report_templates/integration_test.rb +0 -106
  72. data/test/controllers/custom_registrations_controller_test.rb +0 -42
  73. data/test/controllers/custom_strategy_test.rb +0 -66
  74. data/test/controllers/helper_methods_test.rb +0 -24
  75. data/test/controllers/helpers_test.rb +0 -318
  76. data/test/controllers/inherited_controller_i18n_messages_test.rb +0 -53
  77. data/test/controllers/internal_helpers_test.rb +0 -129
  78. data/test/controllers/load_hooks_controller_test.rb +0 -21
  79. data/test/controllers/passwords_controller_test.rb +0 -34
  80. data/test/controllers/sessions_controller_test.rb +0 -108
  81. data/test/controllers/url_helpers_test.rb +0 -67
  82. data/test/delegator_test.rb +0 -21
  83. data/test/devise_test.rb +0 -109
  84. data/test/failure_app_test.rb +0 -340
  85. data/test/generators/active_record_generator_test.rb +0 -130
  86. data/test/generators/controllers_generator_test.rb +0 -50
  87. data/test/generators/devise_generator_test.rb +0 -41
  88. data/test/generators/install_generator_test.rb +0 -26
  89. data/test/generators/mongoid_generator_test.rb +0 -25
  90. data/test/generators/views_generator_test.rb +0 -105
  91. data/test/helpers/devise_helper_test.rb +0 -51
  92. data/test/integration/authenticatable_test.rb +0 -706
  93. data/test/integration/confirmable_test.rb +0 -326
  94. data/test/integration/database_authenticatable_test.rb +0 -97
  95. data/test/integration/http_authenticatable_test.rb +0 -114
  96. data/test/integration/lockable_test.rb +0 -242
  97. data/test/integration/mounted_engine_test.rb +0 -38
  98. data/test/integration/omniauthable_test.rb +0 -148
  99. data/test/integration/recoverable_test.rb +0 -349
  100. data/test/integration/registerable_test.rb +0 -365
  101. data/test/integration/rememberable_test.rb +0 -219
  102. data/test/integration/timeoutable_test.rb +0 -186
  103. data/test/integration/trackable_test.rb +0 -99
  104. data/test/mailers/confirmation_instructions_test.rb +0 -117
  105. data/test/mailers/email_changed_test.rb +0 -132
  106. data/test/mailers/mailer_test.rb +0 -20
  107. data/test/mailers/reset_password_instructions_test.rb +0 -98
  108. data/test/mailers/unlock_instructions_test.rb +0 -93
  109. data/test/mapping_test.rb +0 -136
  110. data/test/models/authenticatable_test.rb +0 -25
  111. data/test/models/confirmable_test.rb +0 -549
  112. data/test/models/database_authenticatable_test.rb +0 -283
  113. data/test/models/lockable_test.rb +0 -352
  114. data/test/models/omniauthable_test.rb +0 -9
  115. data/test/models/recoverable_test.rb +0 -263
  116. data/test/models/registerable_test.rb +0 -9
  117. data/test/models/rememberable_test.rb +0 -184
  118. data/test/models/serializable_test.rb +0 -60
  119. data/test/models/timeoutable_test.rb +0 -53
  120. data/test/models/trackable_test.rb +0 -62
  121. data/test/models/validatable_test.rb +0 -121
  122. data/test/models_test.rb +0 -155
  123. data/test/omniauth/config_test.rb +0 -61
  124. data/test/omniauth/url_helpers_test.rb +0 -53
  125. data/test/orm/active_record.rb +0 -24
  126. data/test/orm/mongoid.rb +0 -15
  127. data/test/parameter_sanitizer_test.rb +0 -77
  128. data/test/rails_app/Rakefile +0 -6
  129. data/test/rails_app/app/active_record/admin.rb +0 -8
  130. data/test/rails_app/app/active_record/shim.rb +0 -4
  131. data/test/rails_app/app/active_record/user.rb +0 -20
  132. data/test/rails_app/app/active_record/user_on_engine.rb +0 -9
  133. data/test/rails_app/app/active_record/user_on_main_app.rb +0 -9
  134. data/test/rails_app/app/active_record/user_with_validations.rb +0 -12
  135. data/test/rails_app/app/active_record/user_without_email.rb +0 -10
  136. data/test/rails_app/app/controllers/admins/sessions_controller.rb +0 -8
  137. data/test/rails_app/app/controllers/admins_controller.rb +0 -8
  138. data/test/rails_app/app/controllers/application_controller.rb +0 -13
  139. data/test/rails_app/app/controllers/application_with_fake_engine.rb +0 -32
  140. data/test/rails_app/app/controllers/custom/registrations_controller.rb +0 -33
  141. data/test/rails_app/app/controllers/home_controller.rb +0 -31
  142. data/test/rails_app/app/controllers/publisher/registrations_controller.rb +0 -4
  143. data/test/rails_app/app/controllers/publisher/sessions_controller.rb +0 -4
  144. data/test/rails_app/app/controllers/users/omniauth_callbacks_controller.rb +0 -16
  145. data/test/rails_app/app/controllers/users_controller.rb +0 -33
  146. data/test/rails_app/app/helpers/application_helper.rb +0 -5
  147. data/test/rails_app/app/mailers/users/from_proc_mailer.rb +0 -5
  148. data/test/rails_app/app/mailers/users/mailer.rb +0 -5
  149. data/test/rails_app/app/mailers/users/reply_to_mailer.rb +0 -6
  150. data/test/rails_app/app/mongoid/admin.rb +0 -31
  151. data/test/rails_app/app/mongoid/shim.rb +0 -25
  152. data/test/rails_app/app/mongoid/user.rb +0 -50
  153. data/test/rails_app/app/mongoid/user_on_engine.rb +0 -41
  154. data/test/rails_app/app/mongoid/user_on_main_app.rb +0 -41
  155. data/test/rails_app/app/mongoid/user_with_validations.rb +0 -37
  156. data/test/rails_app/app/mongoid/user_without_email.rb +0 -35
  157. data/test/rails_app/app/views/admins/index.html.erb +0 -1
  158. data/test/rails_app/app/views/admins/sessions/new.html.erb +0 -2
  159. data/test/rails_app/app/views/home/admin_dashboard.html.erb +0 -1
  160. data/test/rails_app/app/views/home/index.html.erb +0 -1
  161. data/test/rails_app/app/views/home/join.html.erb +0 -1
  162. data/test/rails_app/app/views/home/private.html.erb +0 -1
  163. data/test/rails_app/app/views/home/user_dashboard.html.erb +0 -1
  164. data/test/rails_app/app/views/layouts/application.html.erb +0 -24
  165. data/test/rails_app/app/views/users/edit_form.html.erb +0 -1
  166. data/test/rails_app/app/views/users/index.html.erb +0 -1
  167. data/test/rails_app/app/views/users/mailer/confirmation_instructions.erb +0 -1
  168. data/test/rails_app/app/views/users/sessions/new.html.erb +0 -1
  169. data/test/rails_app/bin/bundle +0 -3
  170. data/test/rails_app/bin/rails +0 -4
  171. data/test/rails_app/bin/rake +0 -4
  172. data/test/rails_app/config/application.rb +0 -48
  173. data/test/rails_app/config/boot.rb +0 -27
  174. data/test/rails_app/config/database.yml +0 -18
  175. data/test/rails_app/config/environment.rb +0 -7
  176. data/test/rails_app/config/environments/development.rb +0 -32
  177. data/test/rails_app/config/environments/production.rb +0 -88
  178. data/test/rails_app/config/environments/test.rb +0 -47
  179. data/test/rails_app/config/initializers/backtrace_silencers.rb +0 -9
  180. data/test/rails_app/config/initializers/devise.rb +0 -182
  181. data/test/rails_app/config/initializers/inflections.rb +0 -4
  182. data/test/rails_app/config/initializers/secret_token.rb +0 -5
  183. data/test/rails_app/config/initializers/session_store.rb +0 -3
  184. data/test/rails_app/config/routes.rb +0 -128
  185. data/test/rails_app/config.ru +0 -4
  186. data/test/rails_app/db/migrate/20100401102949_create_tables.rb +0 -77
  187. data/test/rails_app/db/schema.rb +0 -57
  188. data/test/rails_app/lib/shared_admin.rb +0 -23
  189. data/test/rails_app/lib/shared_user.rb +0 -32
  190. data/test/rails_app/lib/shared_user_without_email.rb +0 -28
  191. data/test/rails_app/lib/shared_user_without_omniauth.rb +0 -15
  192. data/test/rails_app/public/404.html +0 -26
  193. data/test/rails_app/public/422.html +0 -26
  194. data/test/rails_app/public/500.html +0 -26
  195. data/test/rails_app/public/favicon.ico +0 -0
  196. data/test/rails_test.rb +0 -11
  197. data/test/routes_test.rb +0 -281
  198. data/test/secret_key_finder_test.rb +0 -97
  199. data/test/support/action_controller/record_identifier.rb +0 -12
  200. data/test/support/assertions.rb +0 -30
  201. data/test/support/helpers.rb +0 -83
  202. data/test/support/http_method_compatibility.rb +0 -53
  203. data/test/support/integration.rb +0 -95
  204. data/test/support/locale/en.yml +0 -8
  205. data/test/support/mongoid.yml +0 -6
  206. data/test/support/webrat/integrations/rails.rb +0 -35
  207. data/test/test/controller_helpers_test.rb +0 -193
  208. data/test/test/integration_helpers_test.rb +0 -34
  209. data/test/test_helper.rb +0 -36
  210. data/test/test_models.rb +0 -35
@@ -1,242 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'test_helper'
4
-
5
- class LockTest < Devise::IntegrationTest
6
-
7
- def visit_user_unlock_with_token(unlock_token)
8
- visit user_unlock_path(unlock_token: unlock_token)
9
- end
10
-
11
- def send_unlock_request
12
- user = create_user(locked: true)
13
- ActionMailer::Base.deliveries.clear
14
-
15
- visit new_user_session_path
16
- click_link "Didn't receive unlock instructions?"
17
-
18
- Devise.stubs(:friendly_token).returns("abcdef")
19
- fill_in 'email', with: user.email
20
- click_button 'Resend unlock instructions'
21
- end
22
-
23
- test 'user should be able to request a new unlock token' do
24
- send_unlock_request
25
-
26
- assert_template 'sessions/new'
27
- assert_contain 'You will receive an email with instructions for how to unlock your account in a few minutes'
28
-
29
- mail = ActionMailer::Base.deliveries.last
30
- assert_equal 1, ActionMailer::Base.deliveries.size
31
- assert_equal ['please-change-me@config-initializers-devise.com'], mail.from
32
- assert_match user_unlock_path(unlock_token: 'abcdef'), mail.body.encoded
33
- end
34
-
35
- test 'user should receive the instructions from a custom mailer' do
36
- User.any_instance.stubs(:devise_mailer).returns(Users::Mailer)
37
-
38
- send_unlock_request
39
-
40
- assert_equal ['custom@example.com'], ActionMailer::Base.deliveries.first.from
41
- end
42
-
43
- test 'unlocked user should not be able to request a unlock token' do
44
- user = create_user(locked: false)
45
- ActionMailer::Base.deliveries.clear
46
-
47
- visit new_user_session_path
48
- click_link "Didn't receive unlock instructions?"
49
-
50
- fill_in 'email', with: user.email
51
- click_button 'Resend unlock instructions'
52
-
53
- assert_template 'unlocks/new'
54
- assert_contain 'not locked'
55
- assert_equal 0, ActionMailer::Base.deliveries.size
56
- end
57
-
58
- test 'unlocked pages should not be available if email strategy is disabled' do
59
- visit "/admin_area/sign_in"
60
-
61
- assert_raise Webrat::NotFoundError do
62
- click_link "Didn't receive unlock instructions?"
63
- end
64
-
65
- assert_raise NameError do
66
- visit new_admin_unlock_path
67
- end
68
-
69
- assert_raise ActionController::RoutingError do
70
- visit "/admin_area/unlock/new"
71
- end
72
- end
73
-
74
- test 'user with invalid unlock token should not be able to unlock an account' do
75
- visit_user_unlock_with_token('invalid_token')
76
-
77
- assert_response :success
78
- assert_current_url '/users/unlock?unlock_token=invalid_token'
79
- assert_have_selector '#error_explanation'
80
- assert_contain %r{Unlock token(.*)invalid}
81
- end
82
-
83
- test "locked user should be able to unlock account" do
84
- user = create_user
85
- raw = user.lock_access!
86
- visit_user_unlock_with_token(raw)
87
-
88
- assert_current_url "/users/sign_in"
89
- assert_contain 'Your account has been unlocked successfully. Please sign in to continue.'
90
- refute user.reload.access_locked?
91
- end
92
-
93
- test "user should not send a new e-mail if already locked" do
94
- user = create_user(locked: true)
95
- user.failed_attempts = User.maximum_attempts + 1
96
- user.save!
97
-
98
- ActionMailer::Base.deliveries.clear
99
-
100
- sign_in_as_user(password: "invalid")
101
- assert_contain 'Your account is locked.'
102
- assert ActionMailer::Base.deliveries.empty?
103
- end
104
-
105
- test 'error message is configurable by resource name' do
106
- store_translations :en, devise: {
107
- failure: {user: {locked: "You are locked!"}}
108
- } do
109
-
110
- user = create_user(locked: true)
111
- user.failed_attempts = User.maximum_attempts + 1
112
- user.save!
113
-
114
- sign_in_as_user(password: "invalid")
115
- assert_contain "You are locked!"
116
- end
117
- end
118
-
119
- test "user should not be able to sign in when locked" do
120
- store_translations :en, devise: {
121
- failure: {user: {locked: "You are locked!"}}
122
- } do
123
-
124
- user = create_user(locked: true)
125
- user.failed_attempts = User.maximum_attempts + 1
126
- user.save!
127
-
128
- sign_in_as_user(password: "123456")
129
- assert_contain "You are locked!"
130
- end
131
- end
132
-
133
- test 'user should be able to request a new unlock token via XML request' do
134
- user = create_user(locked: true)
135
- ActionMailer::Base.deliveries.clear
136
-
137
- post user_unlock_path(format: 'xml'), params: { user: {email: user.email} }
138
- assert_response :success
139
- assert_equal response.body, {}.to_xml
140
-
141
- assert_equal 1, ActionMailer::Base.deliveries.size
142
- end
143
-
144
- test 'unlocked user should not be able to request a unlock token via XML request' do
145
- user = create_user(locked: false)
146
- ActionMailer::Base.deliveries.clear
147
-
148
- post user_unlock_path(format: 'xml'), params: { user: {email: user.email} }
149
- assert_response :unprocessable_entity
150
- assert response.body.include? %(<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<errors>)
151
- assert_equal 0, ActionMailer::Base.deliveries.size
152
- end
153
-
154
- test 'user with valid unlock token should be able to unlock account via XML request' do
155
- user = create_user()
156
- raw = user.lock_access!
157
- assert user.access_locked?
158
- get user_unlock_path(format: 'xml', unlock_token: raw)
159
- assert_response :success
160
- assert response.body.include? %(<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<user>)
161
- end
162
-
163
-
164
- test 'user with invalid unlock token should not be able to unlock the account via XML request' do
165
- get user_unlock_path(format: 'xml', unlock_token: 'invalid_token')
166
- assert_response :unprocessable_entity
167
- assert response.body.include? %(<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<errors>)
168
- end
169
-
170
- test "when using json to ask a unlock request, should not return the user" do
171
- user = create_user(locked: true)
172
- post user_unlock_path(format: "json", user: {email: user.email})
173
- assert_response :success
174
- assert_equal response.body, {}.to_json
175
- end
176
-
177
- test "in paranoid mode, when trying to unlock a user that exists it should not say that it exists if it is locked" do
178
- swap Devise, paranoid: true do
179
- user = create_user(locked: true)
180
-
181
- visit new_user_session_path
182
- click_link "Didn't receive unlock instructions?"
183
-
184
- fill_in 'email', with: user.email
185
- click_button 'Resend unlock instructions'
186
-
187
- assert_current_url "/users/sign_in"
188
- assert_contain "If your account exists, you will receive an email with instructions for how to unlock it in a few minutes."
189
- end
190
- end
191
-
192
- test "in paranoid mode, when trying to unlock a user that exists it should not say that it exists if it is not locked" do
193
- swap Devise, paranoid: true do
194
- user = create_user(locked: false)
195
-
196
- visit new_user_session_path
197
- click_link "Didn't receive unlock instructions?"
198
-
199
- fill_in 'email', with: user.email
200
- click_button 'Resend unlock instructions'
201
-
202
- assert_current_url "/users/sign_in"
203
- assert_contain "If your account exists, you will receive an email with instructions for how to unlock it in a few minutes."
204
- end
205
- end
206
-
207
- test "in paranoid mode, when trying to unlock a user that does not exists it should not say that it does not exists" do
208
- swap Devise, paranoid: true do
209
- visit new_user_session_path
210
- click_link "Didn't receive unlock instructions?"
211
-
212
- fill_in 'email', with: "arandomemail@hotmail.com"
213
- click_button 'Resend unlock instructions'
214
-
215
- assert_not_contain "1 error prohibited this user from being saved:"
216
- assert_not_contain "Email not found"
217
- assert_current_url "/users/sign_in"
218
-
219
- assert_contain "If your account exists, you will receive an email with instructions for how to unlock it in a few minutes."
220
-
221
- end
222
- end
223
-
224
- test "in paranoid mode, when locking a user that exists it should not say that the user was locked" do
225
- swap Devise, paranoid: true, maximum_attempts: 1 do
226
- user = create_user(locked: false)
227
-
228
- visit new_user_session_path
229
- fill_in 'email', with: user.email
230
- fill_in 'password', with: "abadpassword"
231
- click_button 'Log in'
232
-
233
- fill_in 'email', with: user.email
234
- fill_in 'password', with: "abadpassword"
235
- click_button 'Log in'
236
-
237
- assert_current_url "/users/sign_in"
238
- assert_not_contain "locked"
239
- end
240
- end
241
-
242
- end
@@ -1,38 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'test_helper'
4
-
5
- class MyMountableEngine
6
- def self.call(env)
7
- ['200', { 'Content-Type' => 'text/html' }, ['Rendered content of MyMountableEngine']]
8
- end
9
- end
10
-
11
- # If disable_clear_and_finalize is set to true, Rails will not clear other routes when calling
12
- # again the draw method. Look at the source code at:
13
- # http://www.rubydoc.info/docs/rails/ActionDispatch/Routing/RouteSet:draw
14
- Rails.application.routes.disable_clear_and_finalize = true
15
-
16
- Rails.application.routes.draw do
17
- authenticate(:user) do
18
- mount MyMountableEngine, at: '/mountable_engine'
19
- end
20
- end
21
-
22
- class AuthenticatedMountedEngineTest < Devise::IntegrationTest
23
- test 'redirects to the sign in page when not authenticated' do
24
- get '/mountable_engine'
25
- follow_redirect!
26
-
27
- assert_response :ok
28
- assert_contain 'You need to sign in or sign up before continuing.'
29
- end
30
-
31
- test 'renders the mounted engine when authenticated' do
32
- sign_in_as_user
33
- get '/mountable_engine'
34
-
35
- assert_response :success
36
- assert_contain 'Rendered content of MyMountableEngine'
37
- end
38
- end
@@ -1,148 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'test_helper'
4
-
5
-
6
- class OmniauthableIntegrationTest < Devise::IntegrationTest
7
- FACEBOOK_INFO = {
8
- "id" => '12345',
9
- "link" => 'http://facebook.com/josevalim',
10
- "email" => 'user@example.com',
11
- "first_name" => 'Jose',
12
- "last_name" => 'Valim',
13
- "website" => 'http://blog.plataformatec.com.br'
14
- }
15
-
16
- setup do
17
- OmniAuth.config.test_mode = true
18
- OmniAuth.config.mock_auth[:facebook] = {
19
- "uid" => '12345',
20
- "provider" => 'facebook',
21
- "user_info" => {"nickname" => 'josevalim'},
22
- "credentials" => {"token" => 'plataformatec'},
23
- "extra" => {"user_hash" => FACEBOOK_INFO}
24
- }
25
- OmniAuth.config.add_camelization 'facebook', 'FaceBook'
26
- end
27
-
28
- teardown do
29
- OmniAuth.config.camelizations.delete('facebook')
30
- OmniAuth.config.test_mode = false
31
- end
32
-
33
- def stub_action!(name)
34
- Users::OmniauthCallbacksController.class_eval do
35
- alias_method :__old_facebook, :facebook
36
- alias_method :facebook, name
37
- end
38
- yield
39
- ensure
40
- Users::OmniauthCallbacksController.class_eval do
41
- alias_method :facebook, :__old_facebook
42
- end
43
- end
44
-
45
- test "omniauth sign in should not run model validations" do
46
- stub_action!(:sign_in_facebook) do
47
- create_user
48
- visit "/users/sign_in"
49
- click_link "Sign in with FaceBook"
50
- assert warden.authenticated?(:user)
51
-
52
- refute User.validations_performed
53
- end
54
- end
55
-
56
- test "can access omniauth.auth in the env hash" do
57
- visit "/users/sign_in"
58
- click_link "Sign in with FaceBook"
59
-
60
- json = ActiveSupport::JSON.decode(response.body)
61
-
62
- assert_equal "12345", json["uid"]
63
- assert_equal "facebook", json["provider"]
64
- assert_equal "josevalim", json["user_info"]["nickname"]
65
- assert_equal FACEBOOK_INFO, json["extra"]["user_hash"]
66
- assert_equal "plataformatec", json["credentials"]["token"]
67
- end
68
-
69
- test "cleans up session on sign up" do
70
- assert_no_difference "User.count" do
71
- visit "/users/sign_in"
72
- click_link "Sign in with FaceBook"
73
- end
74
-
75
- assert session["devise.facebook_data"]
76
-
77
- assert_difference "User.count" do
78
- visit "/users/sign_up"
79
- fill_in "Password", with: "12345678"
80
- fill_in "Password confirmation", with: "12345678"
81
- click_button "Sign up"
82
- end
83
-
84
- assert_current_url "/"
85
- assert_contain "You have signed up successfully."
86
- assert_contain "Hello User user@example.com"
87
- refute session["devise.facebook_data"]
88
- end
89
-
90
- test "cleans up session on cancel" do
91
- assert_no_difference "User.count" do
92
- visit "/users/sign_in"
93
- click_link "Sign in with FaceBook"
94
- end
95
-
96
- assert session["devise.facebook_data"]
97
- visit "/users/cancel"
98
- assert !session["devise.facebook_data"]
99
- end
100
-
101
- test "cleans up session on sign in" do
102
- assert_no_difference "User.count" do
103
- visit "/users/sign_in"
104
- click_link "Sign in with FaceBook"
105
- end
106
-
107
- assert session["devise.facebook_data"]
108
- sign_in_as_user
109
- assert !session["devise.facebook_data"]
110
- end
111
-
112
- test "sign in and send remember token if configured" do
113
- visit "/users/sign_in"
114
- click_link "Sign in with FaceBook"
115
- assert_nil warden.cookies["remember_user_token"]
116
-
117
- stub_action!(:sign_in_facebook) do
118
- create_user
119
- visit "/users/sign_in"
120
- click_link "Sign in with FaceBook"
121
- assert warden.authenticated?(:user)
122
- assert warden.cookies["remember_user_token"]
123
- end
124
- end
125
-
126
- test "generates a proper link when SCRIPT_NAME is set" do
127
- header 'SCRIPT_NAME', '/q'
128
- visit "/users/sign_in"
129
- assert_select "a", href: "/q/users/auth/facebook"
130
- end
131
-
132
- test "handles callback error parameter according to the specification" do
133
- OmniAuth.config.mock_auth[:facebook] = :access_denied
134
- visit "/users/auth/facebook/callback?error=access_denied"
135
- assert_current_url "/users/sign_in"
136
- assert_contain 'Could not authenticate you from FaceBook because "Access denied".'
137
- end
138
-
139
- test "handles other exceptions from OmniAuth" do
140
- OmniAuth.config.mock_auth[:facebook] = :invalid_credentials
141
-
142
- visit "/users/sign_in"
143
- click_link "Sign in with FaceBook"
144
-
145
- assert_current_url "/users/sign_in"
146
- assert_contain 'Could not authenticate you from FaceBook because "Invalid credentials".'
147
- end
148
- end